2 postMessage({ type: "check", status: !!a, msg });
5 function is(a, b, msg) {
9 function finish(a, msg) {
10 postMessage({ type: "finish" });
13 async function wait_for_performance_entries() {
14 let promise = new Promise(resolve => {
15 new PerformanceObserver(list => {
16 resolve(list.getEntries());
17 }).observe({ entryTypes: ["resource"] });
19 entries = await promise;
23 async function check(resource, initiatorType, protocol) {
24 let entries = performance.getEntries();
25 if (!entries.length) {
26 entries = await wait_for_performance_entries();
28 ok(entries.length == 1, "We have an entry");
30 ok(entries[0] instanceof PerformanceEntry, "The entry is a PerformanceEntry");
31 ok(entries[0].name.endsWith(resource), "The entry has been found!");
33 is(entries[0].entryType, "resource", "Correct EntryType");
34 ok(entries[0].startTime > 0, "We have a startTime");
35 ok(entries[0].duration > 0, "We have a duration");
38 entries[0] instanceof PerformanceResourceTiming,
39 "The entry is a PerformanceResourceTiming"
42 is(entries[0].initiatorType, initiatorType, "Correct initiatorType");
43 is(entries[0].nextHopProtocol, protocol, "Correct protocol");
45 performance.clearResourceTimings();
48 function simple_checks() {
49 ok("performance" in self, "We have self.performance");
50 performance.clearResourceTimings();
54 function fetch_request() {
55 fetch("test_worker_performance_entries.sjs")
58 check("test_worker_performance_entries.sjs", "fetch", "http/1.1");
63 function xhr_request() {
64 let xhr = new XMLHttpRequest();
65 xhr.open("GET", "test_worker_performance_entries.sjs");
68 check("test_worker_performance_entries.sjs", "xmlhttprequest", "http/1.1");
73 function sync_xhr_request() {
74 let xhr = new XMLHttpRequest();
75 xhr.open("GET", "test_worker_performance_entries.sjs", false);
77 check("test_worker_performance_entries.sjs", "xmlhttprequest", "http/1.1");
81 function import_script() {
82 importScripts(["empty.js"]);
83 check("empty.js", "other", "http/1.1");
88 fetch("test_worker_performance_entries.sjs?redirect")
91 is(text, "Hello world \\o/", "The redirect worked correctly");
93 "test_worker_performance_entries.sjs?redirect",
116 let test = tests.shift();