resource_dedicated_worker.html (2312B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>Resource Timing in dedicated workers</title> 6 <link rel="author" title="Google" href="http://www.google.com/" /> 7 <link rel="help" href="http://www.w3.org/TR/resource-timing/"/> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="resources/webperftestharness.js"></script> 11 <script src="resources/webperftestharnessextension.js"></script> 12 <script src="/common/get-host-info.sub.js"></script> 13 <script> 14 15 const mainDocResource = "/images/red.png?noCacheResourceDedicatedWorker"; 16 // Resources below are requested in the worker thread 17 // "resources/worker_with_images.js". 18 const workerResources = [ 19 "/resource-timing/resources/blue.png", 20 "/resource-timing/resources/resource_timing_test0.png", 21 ]; 22 23 const {promise: mainDocPromise, resolve: resolveMainDoc} = Promise.withResolvers(); 24 const {promise: workerPromise, resolve: resolveWorker} = Promise.withResolvers(); 25 26 // Load main document resource 27 var xhr = new XMLHttpRequest; 28 xhr.open('get', mainDocResource, true); 29 xhr.onload = function() { 30 resolveMainDoc(); 31 } 32 xhr.send(); 33 34 const worker = new Worker("resources/worker_with_images.js"); 35 worker.onmessage = function(event) { 36 resolveWorker(); 37 } 38 39 promise_test(async () => { 40 await Promise.all([ 41 mainDocPromise, 42 workerPromise, 43 ]); 44 45 const context = new PerformanceContext(window.performance); 46 47 // The main doc resource appears in the main document. 48 const mainDocResourceUrl = new URL(mainDocResource, get_host_info().HTTP_ORIGIN).href; 49 const mainDocEntries = context.getEntriesByName(mainDocResourceUrl); 50 assert_greater_than(mainDocEntries.length, 0, "main doc resource appears"); 51 52 // On the other hand, the worker resources don't. 53 for(resource of workerResources) { 54 let workerResourceUrl = new URL(resource, get_host_info().HTTP_ORIGIN).href; 55 let workerEntries = context.getEntriesByName(workerResourceUrl); 56 assert_equals(workerEntries.length, 0, "worker resources don't appear"); 57 } 58 }, "Verify that resources requested by dedicated workers don't appear in the main document"); 59 60 </script> 61 </head> 62 <body> 63 <h1>Description</h1> 64 <p>This test validates that resources requested by dedicated workers don't appear in the main document.</p> 65 </body> 66 </html>