Commit 82459860 authored by Eriko Kurimoto's avatar Eriko Kurimoto Committed by Commit Bot

SharedWorker: Add WPT for testing data URL

This CL adds WPT for a worker loaded from a data URL.
This test is basically same to dedicated-worker-import-data-url.any.js

Bug: 824646
Change-Id: I43faf747c9877c431157e2a3b71d3a2bbad05130
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2016784
Commit-Queue: Eriko Kurimoto <elkurin@google.com>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735311}
parent eb9d12ab
// META: global=!worker
// META: script=/workers/modules/resources/import-test-cases.js
// Imports |testCase.scriptURL| on a shared worker loaded from a data 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_data_url_test(testCase) {
promise_test(async () => {
// The Access-Control-Allow-Origin header is necessary because a worker
// loaded from a data URL has a null origin and import() on the worker
// without the header is blocked.
const importURL = new URL(testCase.scriptURL, location.href) +
'?pipe=header(Access-Control-Allow-Origin, *)';
const dataURL = `data:text/javascript,import "${importURL}";`;
const worker = new SharedWorker(dataURL, { type: 'module'});
worker.port.postMessage('Send message for tests from main script.');
const msgEvent =
await new Promise(resolve => worker.port.onmessage = resolve);
assert_array_equals(msgEvent.data, testCase.expectation);
}, testCase.description);
}
testCases.forEach(import_data_url_test);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment