Commit 0cbea1f0 authored by Eriko Kurimoto's avatar Eriko Kurimoto Committed by Commit Bot

SharedWorker: Add meta.url WPT for SharedWorker with type 'module'

This CL adds a web platform test for checking the behavior of
|import.meta.url| in SharedWorker when the script type is set to module.

Bug: 824646
Change-Id: Ifaa34e238fe0a432137c5e8213e81610249b7e79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2014355
Commit-Queue: Eriko Kurimoto <elkurin@google.com>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734387}
parent ba0f172b
...@@ -19,7 +19,7 @@ promise_test(() => { ...@@ -19,7 +19,7 @@ promise_test(() => {
}, 'Test import.meta.url on the top-level module script.'); }, 'Test import.meta.url on the top-level module script.');
promise_test(() => { promise_test(() => {
const script_url = 'import-meta-url-worker.js'; const script_url = 'import-meta-url-export.js';
const worker = new Worker('resources/dynamic-import-given-url-worker.js', const worker = new Worker('resources/dynamic-import-given-url-worker.js',
{ type: 'module' }); { type: 'module' });
worker.postMessage('./' + script_url); worker.postMessage('./' + script_url);
...@@ -35,7 +35,7 @@ promise_test(() => { ...@@ -35,7 +35,7 @@ promise_test(() => {
}, 'Test import.meta.url on the imported module script.'); }, 'Test import.meta.url on the imported module script.');
promise_test(() => { promise_test(() => {
const script_url = 'import-meta-url-worker.js'; const script_url = 'import-meta-url-export.js';
const worker = new Worker('resources/dynamic-import-given-url-worker.js', const worker = new Worker('resources/dynamic-import-given-url-worker.js',
{ type: 'module' }); { type: 'module' });
worker.postMessage('./' + script_url); worker.postMessage('./' + script_url);
......
// This worker dynamically imports the script URL sent by postMessage(), and // This worker dynamically imports the script URL sent by postMessage(), and
// sends back an error name if the dynamic import fails. // sends back an error name if the dynamic import fails.
self.addEventListener('message', msg_event => { if ('DedicatedWorkerGlobalScope' in self &&
import(msg_event.data).catch(e => postMessage(e.name)); self instanceof DedicatedWorkerGlobalScope) {
}); self.onmessage = msg_event => {
import(msg_event.data)
.then(module => postMessage(module.meta_url))
.catch(e => postMessage(e.name));
};
} else if (
'SharedWorkerGlobalScope' in self &&
self instanceof SharedWorkerGlobalScope) {
self.onconnect = connect_event => {
const port = connect_event.ports[0];
port.onmessage = msg_event => {
import(msg_event.data)
.then(module => port.postMessage(module.meta_url))
.catch(e => port.postMessage(e.name));
};
};
}
postMessage(import.meta.url); if ('DedicatedWorkerGlobalScope' in self &&
self instanceof DedicatedWorkerGlobalScope) {
postMessage(import.meta.url);
} else if (
'SharedWorkerGlobalScope' in self &&
self instanceof SharedWorkerGlobalScope) {
self.onconnect = e => {
e.ports[0].postMessage(import.meta.url);
};
}
This is a testharness.js-based test.
PASS Test import.meta.url on the top-level module script.
PASS Test import.meta.url on the imported module script.
FAIL Test import.meta.url on the imported module script with a fragment. assert_true: expected true got false
Harness: the test ran to completion.
<!DOCTYPE html>
<title>SharedWorker: import.meta</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(() => {
const script_url = 'resources/import-meta-url-worker.js';
const worker = new SharedWorker(script_url, { type: 'module' });
return new Promise((resolve, reject) => {
worker.port.onmessage = resolve;
worker.onerror = (error) => reject(error && error.message);
})
.then(msg_event => assert_true(msg_event.data.endsWith(script_url)));
}, 'Test import.meta.url on the top-level module script.');
promise_test(() => {
const script_url = 'import-meta-url-export.js';
const worker = new SharedWorker(
'resources/dynamic-import-given-url-worker.js',
{ type: 'module' });
worker.port.postMessage('./' + script_url);
return new Promise((resolve, reject) => {
worker.port.onmessage = resolve;
worker.onerror = (error) => reject(error && error.message);
})
.then(msg_event => assert_true(msg_event.data.endsWith(script_url)));
}, 'Test import.meta.url on the imported module script.');
promise_test(() => {
const script_url = 'import-meta-url-export.js';
const worker = new SharedWorker(
'resources/dynamic-import-given-url-worker.js',
{ type: 'module' });
worker.port.postMessage('./' + script_url);
return new Promise((resolve, reject) => {
worker.port.onmessage = resolve;
worker.onerror = (error) => reject(error && error.message);
})
.then(msg_event => assert_true(msg_event.data.endsWith(script_url)))
.then(() => {
worker.port.postMessage('./' + script_url + '#1');
return new Promise(resolve => worker.port.onmessage = resolve);
})
.then(msg_event => assert_true(msg_event.data.endsWith(script_url)));
}, 'Test import.meta.url on the imported module script with a fragment.');
</script>
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