mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 12:50:09 +00:00
Bug 1425975 P17 Make web extension tests wait for service worker to activate to avoid races. r=kmag
This commit is contained in:
parent
7f0e026bcb
commit
61a07a8b0a
@ -56,3 +56,18 @@ function waitForLoad(win) {
|
||||
});
|
||||
}
|
||||
|
||||
/* exported waitForState */
|
||||
|
||||
function waitForState(sw, state) {
|
||||
return new Promise(resolve => {
|
||||
if (sw.state === state) {
|
||||
return resolve();
|
||||
}
|
||||
sw.addEventListener("statechange", function onStateChange() {
|
||||
if (sw.state === state) {
|
||||
sw.removeEventListener("statechange", onStateChange);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ add_task(async function test_webRequest_serviceworker_events() {
|
||||
|
||||
await extension.startup();
|
||||
let registration = await navigator.serviceWorker.register("webrequest_worker.js", {scope: "."});
|
||||
await waitForState(registration.installing, "activated");
|
||||
await extension.awaitMessage("done");
|
||||
await registration.unregister();
|
||||
await extension.unload();
|
||||
|
@ -90,11 +90,13 @@ add_task(async function test_webRequest_filter_window() {
|
||||
|
||||
// We should not get background events.
|
||||
let registration = await navigator.serviceWorker.register("webrequest_worker.js?test0", {scope: "."});
|
||||
await waitForState(registration.installing, "activated");
|
||||
|
||||
// We should get events for the reload.
|
||||
testWindow.location = "file_image_bad.png";
|
||||
await extension.awaitMessage("done");
|
||||
|
||||
testWindow.location = "about:blank";
|
||||
await registration.unregister();
|
||||
await extension.unload();
|
||||
});
|
||||
@ -138,11 +140,13 @@ add_task(async function test_webRequest_filter_tab() {
|
||||
|
||||
// We should not get background events.
|
||||
let registration = await navigator.serviceWorker.register("webrequest_worker.js?test1", {scope: "."});
|
||||
await waitForState(registration.installing, "activated");
|
||||
|
||||
// We should get events for the reload.
|
||||
testWindow.location = img;
|
||||
await extension.awaitMessage("done");
|
||||
|
||||
testWindow.location = "about:blank";
|
||||
await registration.unregister();
|
||||
await extension.unload();
|
||||
});
|
||||
@ -186,7 +190,9 @@ add_task(async function test_webRequest_filter_background() {
|
||||
|
||||
// We should get events for the background page.
|
||||
let registration = await navigator.serviceWorker.register(SimpleTest.getTestFileURL("webrequest_worker.js?test2"), {scope: "."});
|
||||
await waitForState(registration.installing, "activated");
|
||||
await extension.awaitMessage("done");
|
||||
testWindow.location = "about:blank";
|
||||
await registration.unregister();
|
||||
|
||||
await extension.unload();
|
||||
|
Loading…
x
Reference in New Issue
Block a user