зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1500395 - Migrate service worker status test to new about:debugging;r=daisuke
Depends on D17630 I am not mentioning the original test in the test file because they are not similar. Original test was not actually testing anything interesting for us. Differential Revision: https://phabricator.services.mozilla.com/D17631 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
292d4c4ddb
Коммит
2630d2487c
|
@ -57,6 +57,7 @@ skip-if = (os == "win" && ccov) # Bug 1521349
|
|||
[browser_aboutdebugging_serviceworker_pushservice_url.js]
|
||||
[browser_aboutdebugging_serviceworker_runtime-page.js]
|
||||
[browser_aboutdebugging_serviceworker_start.js]
|
||||
[browser_aboutdebugging_serviceworker_status.js]
|
||||
[browser_aboutdebugging_serviceworker_timeout.js]
|
||||
[browser_aboutdebugging_sidebar_network_runtimes.js]
|
||||
[browser_aboutdebugging_sidebar_usb_runtime.js]
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* import-globals-from helper-serviceworker.js */
|
||||
Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-serviceworker.js", this);
|
||||
|
||||
const SW_TAB_URL = URL_ROOT + "resources/service-workers/controlled-sw.html";
|
||||
const SW_URL = URL_ROOT + "resources/service-workers/controlled-sw.js";
|
||||
|
||||
/**
|
||||
* Test that the service worker has the status "registering" when the service worker is
|
||||
* not installed yet. Other states (stopped, running) are covered by the existing tests.
|
||||
*/
|
||||
add_task(async function() {
|
||||
await enableServiceWorkerDebugging();
|
||||
|
||||
const { document, tab } = await openAboutDebugging();
|
||||
|
||||
info("Open tab with a service worker that never leaves `registering` status");
|
||||
const swTab = await addTab(SW_TAB_URL);
|
||||
|
||||
// Wait for the registration to make sure service worker has been started, and that we
|
||||
// are not just reading STOPPED as the initial state.
|
||||
await waitForRegistration(swTab);
|
||||
|
||||
info("Wait until the service worker is in registering status");
|
||||
await waitForServiceWorkerRegistering(SW_URL, document);
|
||||
|
||||
// Check that the buttons are displayed as expected.
|
||||
checkButtons({ inspect: true, push: false, start: false }, SW_URL, document);
|
||||
|
||||
info("Install the service worker");
|
||||
ContentTask.spawn(swTab.linkedBrowser, {},
|
||||
() => content.wrappedJSObject.installServiceWorker());
|
||||
|
||||
info("Wait until the service worker is running");
|
||||
await waitForServiceWorkerRunning(SW_URL, document);
|
||||
|
||||
checkButtons({ inspect: true, push: true, start: false }, SW_URL, document);
|
||||
|
||||
info("Unregister service worker");
|
||||
await unregisterServiceWorker(swTab);
|
||||
|
||||
info("Wait until the service worker disappears from about:debugging");
|
||||
await waitUntil(() => !findDebugTargetByText(SW_URL, document));
|
||||
|
||||
info("Remove tabs");
|
||||
await removeTab(swTab);
|
||||
await removeTab(tab);
|
||||
});
|
||||
|
||||
function checkButtons({ inspect, push, start }, workerText, document) {
|
||||
const targetElement = findDebugTargetByText(SW_URL, document);
|
||||
|
||||
const inspectButton = targetElement.querySelector(".js-debug-target-inspect-button");
|
||||
const pushButton = targetElement.querySelector(".js-push-button");
|
||||
const startButton = targetElement.querySelector(".js-start-button");
|
||||
|
||||
is(!!inspectButton, inspect,
|
||||
"Inspect button should be " + (inspect ? "visible" : "hidden"));
|
||||
is(!!pushButton, push,
|
||||
"Push button should be " + (push ? "visible" : "hidden"));
|
||||
is(!!startButton, start,
|
||||
"Start button should be " + (start ? "visible" : "hidden"));
|
||||
}
|
|
@ -61,6 +61,11 @@ async function waitForServiceWorkerRunning(workerText, document) {
|
|||
}
|
||||
/* exported waitForServiceWorkerRunning */
|
||||
|
||||
async function waitForServiceWorkerRegistering(workerText, document) {
|
||||
return _waitForServiceWorkerStatus(workerText, "Registering", document);
|
||||
}
|
||||
/* exported waitForServiceWorkerRegistering */
|
||||
|
||||
async function waitForRegistration(tab) {
|
||||
info("Wait until the registration appears on the window");
|
||||
const swBrowser = tab.linkedBrowser;
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Service worker push test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
|
||||
"use strict";
|
||||
|
||||
let registration;
|
||||
|
||||
const registerServiceWorker = async function() {
|
||||
try {
|
||||
registration = await navigator.serviceWorker.register("controlled-sw.js");
|
||||
dump("Controlled service worker registered\n");
|
||||
} catch (e) {
|
||||
dump("Controlled service worker not registered: " + e + "\n");
|
||||
}
|
||||
};
|
||||
|
||||
// Helper called from helper-serviceworker.js to unregister the service worker.
|
||||
window.getRegistration = function() {
|
||||
return registration;
|
||||
};
|
||||
|
||||
// Called from browser_aboutdebugging_serviceworker_status.js
|
||||
window.installServiceWorker = function() {
|
||||
registration.installing.postMessage("install-service-worker");
|
||||
};
|
||||
|
||||
// Register the service worker.
|
||||
registerServiceWorker();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,31 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/* eslint-env worker */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Copied from shared-head.js
|
||||
function waitUntil(predicate, interval = 10) {
|
||||
if (predicate()) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
setTimeout(function() {
|
||||
waitUntil(predicate, interval).then(() => resolve(true));
|
||||
}, interval);
|
||||
});
|
||||
}
|
||||
|
||||
// This flag will be flipped from controlled-sw.html::installServiceWorker()
|
||||
let canInstall = false;
|
||||
self.addEventListener("message", function(event) {
|
||||
if (event.data === "install-service-worker") {
|
||||
canInstall = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for the canInstall flag to be flipped before completing the install.
|
||||
self.addEventListener("install", function(event) {
|
||||
event.waitUntil(waitUntil(() => canInstall));
|
||||
});
|
Загрузка…
Ссылка в новой задаче