summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/modules/shared-worker-import-blob-url.window.js
blob: a79d5725ad879106ec78bd4a66977352db756818 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// META: script=/workers/modules/resources/import-test-cases.js

// Imports |testCase.scriptURL| on a shared worker loaded from a blob URL,
// and waits until the list of imported modules is sent from the worker. Passes
// if the list is equal to |testCase.expectation|.
function import_blob_url_test(testCase) {
  promise_test(async () => {
    const importURL = new URL(testCase.scriptURL, location.href);
    const blob =
        new Blob([`import "${importURL}";`], {type: 'text/javascript'});
    const blobURL = URL.createObjectURL(blob);
    const worker = new SharedWorker(blobURL, {type: 'module'});
    worker.port.postMessage('Send message for tests from main script.');
    const msgEvent = await new Promise((resolve, reject) => {
      worker.port.onmessage = resolve;
      worker.onerror = error => {
        const msg = error instanceof ErrorEvent ? error.message
                                                : 'unknown error';
        reject(msg);
      };
    });
    assert_array_equals(msgEvent.data, testCase.expectation);
  }, testCase.description);
}

testCases.forEach(import_blob_url_test);