Bug 1611348 [wpt PR 21402] - SharedWorker: Add WPT for testing data URL, a=testonly
authorEriko Kurimoto <elkurin@google.com>
Wed, 29 Jan 2020 08:05:14 +0000
changeset 512250 08ef56a69ca13291f8dcea2b461ece89e94f7bb1
parent 512249 a0998c4808fe466cc1f2ddbb40e3989d3b1f570e
child 512251 39eddfba6c78d70c112b76e9c7e04384b60cc811
push id37078
push useropoprus@mozilla.com
push dateSat, 01 Feb 2020 09:28:06 +0000
treeherdermozilla-central@cd7d8aad0306 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1611348, 21402, 824646, 2016784, 735311
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1611348 [wpt PR 21402] - SharedWorker: Add WPT for testing data URL, a=testonly Automatic update from web-platform-tests 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: Hiroki Nakagawa <nhiroki@chromium.org> Cr-Commit-Position: refs/heads/master@{#735311} -- wpt-commits: 92deffa9b4427db8bcc0ebf7f4328d81d2a958e0 wpt-pr: 21402
testing/web-platform/tests/workers/modules/shared-worker-import-data-url.any.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/modules/shared-worker-import-data-url.any.js
@@ -0,0 +1,24 @@
+// 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);