worker-dedicated-importscripts.sub.html (1623B)
1 <!DOCTYPE html> 2 <!-- 3 [%provenance%] 4 --> 5 <html lang="en"> 6 <meta charset="utf-8"> 7 <title>HTTP headers on request for dedicated worker via the "importScripts" API</title> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/fetch/metadata/resources/helper.sub.js"></script> 11 <script type="module"> 12 'use strict'; 13 function induceRequest(url, options) { 14 const src = ` 15 importScripts('${url}'); 16 postMessage('done'); 17 `; 18 const workerUrl = URL.createObjectURL( 19 new Blob([src], { type: 'application/javascript' }) 20 ); 21 return new Promise((resolve, reject) => { 22 const worker = new Worker(workerUrl, options); 23 worker.onmessage = resolve; 24 worker.onerror = reject; 25 }); 26 } 27 28 {%- for subtest in subtests %} 29 30 promise_test(() => { 31 const key = '{{uuid()}}'; 32 const url = makeRequestURL( 33 key, [% subtest.origins %], { mime: 'application/javascript' } 34 ); 35 36 return induceRequest(url 37 {%- if subtest.options -%} 38 , [% subtest.options | tojson %] 39 {%- endif -%} 40 ) 41 .then(() => retrieve(key)) 42 .then((headers) => { 43 {%- if subtest.expected == none %} 44 assert_not_own_property(headers, '[%subtest.headerName%]'); 45 {%- else %} 46 assert_own_property(headers, '[%subtest.headerName%]'); 47 assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']); 48 {%- endif %} 49 }); 50 }, '[%subtest.headerName%][%subtest.description | pad("start", " - ")%]'); 51 52 {%- endfor %} 53 </script> 54 </html>