Skip to content

Commit

Permalink
Worker: Add tests for import.meta.url on DedicatedWorker
Browse files Browse the repository at this point in the history
Bug: 680046
Change-Id: Ieb341c5922ad247961ca477893037896dbd88ea6
Reviewed-on: https://chromium-review.googlesource.com/974726
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546254}
  • Loading branch information
nhiroki authored and chromium-wpt-export-bot committed Mar 27, 2018
1 parent 8214a83 commit 8ccaab2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions workers/modules/dedicated-worker-import-meta.html
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<title>DedicatedWorker: 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 Worker(script_url, { type: 'module' });
return new Promise(resolve => worker.onmessage = resolve)
.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-worker.js';
const worker = new Worker('resources/dynamic-import-given-url-worker.js',
{ type: 'module' });
worker.postMessage('./' + script_url);
return new Promise(resolve => worker.onmessage = resolve)
.then(msg_event => assert_true(msg_event.data.endsWith(script_url)));
}, 'Test import.meta.url on the imported module script.');

</script>
4 changes: 4 additions & 0 deletions workers/modules/resources/dynamic-import-given-url-worker.js
@@ -0,0 +1,4 @@
// Dynamically import the script URL sent by postMessage().
self.addEventListener('message', e => {
import(e.data);
});
1 change: 1 addition & 0 deletions workers/modules/resources/import-meta-url-worker.js
@@ -0,0 +1 @@
postMessage(import.meta.url);

0 comments on commit 8ccaab2

Please sign in to comment.