resource_timing.worker.js (1534B)
1 importScripts("/resources/testharness.js"); 2 3 function check(initiatorType, protocol) { 4 let entries = performance.getEntries(); 5 assert_equals(entries.length, 1); 6 7 assert_true(entries[0] instanceof PerformanceEntry); 8 assert_equals(entries[0].entryType, "resource"); 9 assert_true(entries[0].startTime > 0); 10 assert_true(entries[0].duration > 0); 11 12 assert_true(entries[0] instanceof PerformanceResourceTiming); 13 assert_equals(entries[0].initiatorType, initiatorType); 14 assert_equals(entries[0].nextHopProtocol, protocol); 15 } 16 17 async_test(t => { 18 performance.clearResourceTimings(); 19 20 // Fetch 21 fetch("resources/empty.js") 22 .then(r => r.blob()) 23 .then(blob => { 24 check("fetch", "http/1.1"); 25 }) 26 27 // XMLHttpRequest 28 .then(() => { 29 return new Promise(resolve => { 30 performance.clearResourceTimings(); 31 let xhr = new XMLHttpRequest(); 32 xhr.onload = () => { 33 check("xmlhttprequest", "http/1.1"); 34 resolve(); 35 }; 36 xhr.open("GET", "resources/empty.js"); 37 xhr.send(); 38 }); 39 }) 40 41 // Sync XMLHttpREquest 42 .then(() => { 43 performance.clearResourceTimings(); 44 let xhr = new XMLHttpRequest(); 45 xhr.open("GET", "resources/empty.js", false); 46 xhr.send(); 47 48 check("xmlhttprequest", "http/1.1"); 49 }) 50 51 // ImportScripts 52 .then(() => { 53 performance.clearResourceTimings(); 54 importScripts(["resources/empty.js"]); 55 check("other", "http/1.1"); 56 }) 57 58 // All done. 59 .then(() => { 60 t.done(); 61 }); 62 }, "Performance Resource Entries in workers"); 63 64 done();