Bug 1459953 - Part 2: Add mochitest r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D64782

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Belén Albeza 2020-03-09 11:50:42 +00:00
Родитель 40432665ef
Коммит cad36d87f0
4 изменённых файлов: 118 добавлений и 0 удалений

Просмотреть файл

@ -12,6 +12,8 @@ support-files =
resources/manifest/load-ok-warnings.html
resources/manifest/load-ok.html
resources/manifest/manifest.json
resources/service-workers/controlled-install-sw.js
resources/service-workers/controlled-install.html
resources/service-workers/debug-sw.js
resources/service-workers/debug.html
resources/service-workers/dynamic-registration.html
@ -44,6 +46,8 @@ skip-if = asan || debug || !serviceworker_e10s # Bug 1559487, 1559591, 1608640
skip-if = debug # Bug 1559591
[browser_application_panel_unregister-worker.js]
skip-if = debug # Bug 1559591
[browser_application_panel_worker-states.js]
skip-if = asan || debug || !serviceworker_e10s # Bug 1559487, 1559591, 1608640
# Manifest-related tests
[browser_application_panel_manifest-display.js]
[browser_application_panel_manifest-load.js]

Просмотреть файл

@ -0,0 +1,58 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TAB_URL = URL_ROOT + "resources/service-workers/controlled-install.html";
add_task(async function() {
await enableApplicationPanel();
const { panel, tab } = await openNewTabAndApplicationPanel(TAB_URL);
const doc = panel.panelWin.document;
selectPage(panel, "service-workers");
info("Check for non-existing service worker");
const isWorkerListEmpty = !!doc.querySelector(".worker-list-empty");
ok(isWorkerListEmpty, "No Service Worker displayed");
info("Register a service worker with a controlled install in the page.");
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
content.wrappedJSObject.registerServiceWorker();
});
info("Wait until the service worker appears in the application panel");
await waitUntil(() => getWorkerContainers(doc).length > 0);
info("Wait until the 'Installing' state is displayed");
await waitUntil(() => {
const containers = getWorkerContainers(doc);
if (containers.length === 0) {
return false;
}
const stateEl = containers[0].querySelector(".js-worker-status");
return stateEl.textContent.toLowerCase() === "installing";
});
info("Allow the service worker to complete installation");
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
content.wrappedJSObject.installServiceWorker();
});
info("Wait until the 'running' state is displayed");
await waitUntil(() => {
const workerContainer = getWorkerContainers(doc)[0];
const stateEl = workerContainer.querySelector(".js-worker-status");
return stateEl.textContent.toLowerCase() === "running";
});
info("Unregister the service worker");
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
const registration = await content.wrappedJSObject.sw;
registration.unregister();
});
info("Wait until the service worker is removed from the application panel");
await waitUntil(() => getWorkerContainers(doc).length === 0);
});

Просмотреть файл

@ -0,0 +1,29 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"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 externally from controlled-install.html
// by sending a message event to the worker
let canInstall = false;
self.addEventListener("message", event => {
if (event.data === "install-service-worker") {
canInstall = true;
}
});
self.addEventListener("install", event => {
event.waitUntil(waitUntil(() => canInstall));
});

Просмотреть файл

@ -0,0 +1,27 @@
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Service worker test</title>
</head>
<body>
<script type="text/javascript">
"use strict";
let registration;
window.registerServiceWorker = async function() {
registration = await navigator.serviceWorker.register(
"controlled-install-sw.js"
);
window.sw = registration;
};
window.installServiceWorker = function() {
registration.installing.postMessage("install-service-worker");
};
</script>
</body>
</html>