Bug 1425458 - Resource timing entries Workers - part 7 - mochitests, r=smaug

This commit is contained in:
Andrea Marchesini 2018-01-24 17:17:32 +01:00
Родитель 692e6f7518
Коммит 3df0fd7a06
5 изменённых файлов: 150 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1 @@
/* Nothing here */

Просмотреть файл

@ -6,6 +6,9 @@ support-files =
worker_performance_user_timing.js
worker_performance_observer.js
sharedworker_performance_user_timing.js
test_worker_performance_entries.js
test_worker_performance_entries.sjs
empty.js
[test_performance_observer.html]
[test_performance_user_timing.html]
@ -14,3 +17,4 @@ support-files =
[test_sharedWorker_performance_user_timing.html]
[test_worker_performance_now.html]
[test_timeOrigin.html]
[test_worker_performance_entries.html]

Просмотреть файл

@ -0,0 +1,31 @@
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<!DOCTYPE HTML>
<html>
<head>
<title>PerformanceResouceTiming in workers</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var worker = new Worker('test_worker_performance_entries.js');
worker.onmessage = function(event) {
if (event.data.type == "check") {
ok(event.data.status, event.data.msg);
return;
}
if (event.data.type == "finish") {
SimpleTest.finish();
return;
}
ok(false, "?!?");
}
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,102 @@
function ok(a, msg) {
postMessage({type: "check", status: !!a, msg });
}
function is(a, b, msg) {
ok(a === b, msg);
}
function finish(a, msg) {
postMessage({type: "finish" });
}
function check(resource, initiatorType, protocol) {
let entries = performance.getEntries();
ok(entries.length == 1, "We have an entry");
ok(entries[0] instanceof PerformanceEntry,
"The entry is a PerformanceEntry");
ok(entries[0].name.endsWith(resource), "The entry has been found!");
is(entries[0].entryType, "resource", "Correct EntryType");
ok(entries[0].startTime > 0, "We have a startTime");
ok(entries[0].duration > 0, "We have a duration");
ok(entries[0] instanceof PerformanceResourceTiming,
"The entry is a PerformanceResourceTiming");
is(entries[0].initiatorType, initiatorType, "Correct initiatorType");
is(entries[0].nextHopProtocol, protocol, "Correct protocol");
performance.clearResourceTimings();
}
function simple_checks() {
ok("performance" in self, "We have self.performance");
performance.clearResourceTimings();
next();
}
function fetch_request() {
fetch("test_worker_performance_entries.sjs")
.then(r => r.blob())
.then(blob => {
check("test_worker_performance_entries.sjs", "fetch", "http/1.1");
})
.then(next);
}
function xhr_request() {
let xhr = new XMLHttpRequest();
xhr.open("GET", "test_worker_performance_entries.sjs");
xhr.send();
xhr.onload = () => {
check("test_worker_performance_entries.sjs", "xmlhttprequest", "http/1.1");
next();
}
}
function sync_xhr_request() {
let xhr = new XMLHttpRequest();
xhr.open("GET", "test_worker_performance_entries.sjs", false);
xhr.send();
check("test_worker_performance_entries.sjs", "xmlhttprequest", "http/1.1");
next();
}
function import_script() {
importScripts(["empty.js"]);
check("empty.js", "other", "http/1.1");
next();
}
function redirect() {
fetch("test_worker_performance_entries.sjs?redirect")
.then(r => r.text())
.then(text => {
is(text, "Hello world \\o/", "The redirect worked correctly");
check("test_worker_performance_entries.sjs?redirect", "fetch", "http/1.1");
})
.then(next);
}
let tests = [
simple_checks,
fetch_request,
xhr_request,
sync_xhr_request,
import_script,
redirect,
];
function next() {
if (!tests.length) {
finish();
return;
}
let test = tests.shift();
test();
}
next();

Просмотреть файл

@ -0,0 +1,12 @@
function handleRequest(request, response)
{
response.setHeader("Content-Type", "text/html");
if (request.queryString == "redirect") {
response.setStatusLine(request.httpVersion, 302, "See Other");
response.setHeader("Location", "test_worker_performance_entries.sjs?ok");
} else {
response.setStatusLine(request.httpVersion, 200, "OK");
response.write("Hello world \\o/");
}
}