1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 add_task(async function testWorker() {
6 const win1 = createChromeWindow();
8 const worker = new ChromeWorker("resource://test/non_shared_worker_1.js");
9 const { promise, resolve } = Promise.withResolvers();
10 worker.onmessage = event => {
13 worker.postMessage("");
15 const result = await promise;
17 Assert.equal(result.c1, 0);
18 Assert.equal(result.c2, 1);
19 Assert.equal(result.loaded, "2,1");
22 add_task(async function testSyncImportBeforeAsyncImportTopLevelInWorker() {
23 const window = createChromeWindow();
25 let worker = new ChromeWorker("resource://test/sync_and_async_in_worker.js");
26 let { promise, resolve } = Promise.withResolvers();
27 worker.onmessage = event => {
30 worker.postMessage({ order: "sync-before-async", target: "top-level" });
42 Assert.equal(sync_beforeInc, 0);
43 Assert.equal(sync_afterInc, 1);
45 Assert.equal(loaded1, "2,1");
47 Assert.equal(async_beforeInc, 1);
48 Assert.equal(async_afterInc, 2);
49 Assert.equal(sync_afterIncInc, 2);
51 Assert.equal(loaded2, "2,1");
54 add_task(async function testSyncImportBeforeAsyncImportDependencyInWorker() {
55 let worker = new ChromeWorker("resource://test/sync_and_async_in_worker.js");
56 let { promise, resolve } = Promise.withResolvers();
57 worker.onmessage = event => {
60 worker.postMessage({ order: "sync-before-async", target: "dependency" });
72 Assert.equal(sync_beforeInc, 0);
73 Assert.equal(sync_afterInc, 1);
75 Assert.equal(loaded1, "2,1");
77 Assert.equal(async_beforeInc, 1);
78 Assert.equal(async_afterInc, 2);
79 Assert.equal(sync_afterIncInc, 2);
81 Assert.equal(loaded2, "2,1");
84 add_task(async function testSyncImportAfterAsyncImportTopLevelInWorker() {
85 const window = createChromeWindow();
87 let worker = new ChromeWorker("resource://test/sync_and_async_in_worker.js");
88 let { promise, resolve } = Promise.withResolvers();
89 worker.onmessage = event => {
92 worker.postMessage({ order: "sync-after-async", target: "top-level" });
104 Assert.equal(async_beforeInc, 0);
105 Assert.equal(async_afterInc, 1);
107 Assert.equal(loaded1, "2,1");
109 Assert.equal(sync_beforeInc, 1);
110 Assert.equal(sync_afterInc, 2);
111 Assert.equal(async_afterIncInc, 2);
113 Assert.equal(loaded2, "2,1");
116 add_task(async function testSyncImportAfterAsyncImportDependencyInWorker() {
117 const window = createChromeWindow();
119 let worker = new ChromeWorker("resource://test/sync_and_async_in_worker.js");
120 let { promise, resolve } = Promise.withResolvers();
121 worker.onmessage = event => {
124 worker.postMessage({ order: "sync-after-async", target: "dependency" });
136 Assert.equal(async_beforeInc, 0);
137 Assert.equal(async_afterInc, 1);
139 Assert.equal(loaded1, "2,1");
141 Assert.equal(sync_beforeInc, 1);
142 Assert.equal(sync_afterInc, 2);
143 Assert.equal(async_afterIncInc, 2);
145 Assert.equal(loaded2, "2,1");
148 add_task(async function testSyncImportWhileAsyncImportTopLevelInWorker() {
149 const window = createChromeWindow();
151 let worker = new ChromeWorker("resource://test/sync_and_async_in_worker.js");
152 let { promise, resolve } = Promise.withResolvers();
153 worker.onmessage = event => {
156 worker.postMessage({ order: "sync-while-async", target: "top-level" });
165 Assert.stringMatches(sync_error, /ChromeUtils.importESModule cannot be used/);
167 Assert.equal(async_beforeInc, 0);
168 Assert.equal(async_afterInc, 1);
170 Assert.equal(loaded, "2,1");
173 add_task(async function testSyncImportWhileAsyncImportDependencyInWorker() {
174 const window = createChromeWindow();
176 let worker = new ChromeWorker("resource://test/sync_and_async_in_worker.js");
177 let { promise, resolve } = Promise.withResolvers();
178 worker.onmessage = event => {
181 worker.postMessage({ order: "sync-while-async", target: "dependency" });
190 Assert.stringMatches(sync_error, /ChromeUtils.importESModule cannot be used/);
192 Assert.equal(async_beforeInc, 0);
193 Assert.equal(async_afterInc, 1);
195 Assert.equal(loaded, "2,1");