tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

shared-worker-import-data-url.window.js (1168B)


      1 // META: script=/workers/modules/resources/import-test-cases.js
      2 
      3 // Imports |testCase.scriptURL| on a shared worker loaded from a data URL,
      4 // and waits until the list of imported modules is sent from the worker. Passes
      5 // if the list is equal to |testCase.expectation|.
      6 function import_data_url_test(testCase) {
      7  promise_test(async () => {
      8    // The Access-Control-Allow-Origin header is necessary because a worker
      9    // loaded from a data URL has a null origin and import() on the worker
     10    // without the header is blocked.
     11    const importURL = new URL(testCase.scriptURL, location.href) +
     12        '?pipe=header(Access-Control-Allow-Origin, *)';
     13    const dataURL = `data:text/javascript,import "${importURL}";`;
     14 
     15    const worker = new SharedWorker(dataURL, { type: 'module'});
     16    worker.port.postMessage('Send message for tests from main script.');
     17    const msgEvent = await new Promise((resolve, reject) =>{
     18        worker.port.onmessage = resolve;
     19        worker.onerror = reject;
     20    }).catch(e => assert_true(false));
     21    assert_array_equals(msgEvent.data, testCase.expectation);
     22  }, testCase.description);
     23 }
     24 
     25 testCases.forEach(import_data_url_test);