зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1553110 - Part 3: add test for Start worker button r=Ola
Differential Revision: https://phabricator.services.mozilla.com/D33929 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
48588a63c9
Коммит
3e3b9a6493
|
@ -212,7 +212,7 @@ class Worker extends Component {
|
|||
dd({},
|
||||
Localized(
|
||||
{ id: "serviceworker-worker-status-" + status },
|
||||
span({}),
|
||||
span({ className: "js-worker-status" }),
|
||||
),
|
||||
!this.isRunning() ? this.renderStartLink() : null,
|
||||
)
|
||||
|
|
|
@ -25,3 +25,4 @@ support-files =
|
|||
[browser_application_panel_list-unicode.js]
|
||||
[browser_application_panel_open-links.js]
|
||||
skip-if = true # Bug 1467256
|
||||
[browser_application_panel_start-service-worker.js]
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const TAB_URL = URL_ROOT + "service-workers/simple.html";
|
||||
|
||||
/**
|
||||
* Tests that the Start button works for service workers who can be debugged
|
||||
*/
|
||||
add_task(async function() {
|
||||
await enableApplicationPanel(); // this also enables SW debugging
|
||||
|
||||
// Setting a low idle_timeout and idle_extended_timeout will allow the service worker
|
||||
// to reach the STOPPED state quickly, which will allow us to test the start button.
|
||||
// The default value is 30000 milliseconds.
|
||||
info("Set a low service worker idle timeout");
|
||||
await pushPref("dom.serviceWorkers.idle_timeout", 1000);
|
||||
await pushPref("dom.serviceWorkers.idle_extended_timeout", 1000);
|
||||
|
||||
const { panel, tab, target } = await openNewTabAndApplicationPanel(TAB_URL);
|
||||
const doc = panel.panelWin.document;
|
||||
|
||||
await waitForWorkerRegistration(tab);
|
||||
|
||||
info("Wait until the service worker appears in the application panel");
|
||||
await waitUntil(() => getWorkerContainers(doc).length === 1);
|
||||
|
||||
info("Wait until the start link is displayed and enabled");
|
||||
const container = getWorkerContainers(doc)[0];
|
||||
await waitUntil(() =>
|
||||
container.querySelector(".js-start-link:not(.disabled-link)"));
|
||||
info("Click the link and wait for the worker to start");
|
||||
const link = container.querySelector(".js-start-link");
|
||||
link.click();
|
||||
await waitUntil(() =>
|
||||
container.querySelector(".js-worker-status").textContent === "Running"
|
||||
);
|
||||
ok(true, "Worker status is 'Running'");
|
||||
|
||||
await unregisterAllWorkers(target.client);
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests that Start button is disabled for service workers, when they cannot be debugged
|
||||
*/
|
||||
add_task(async function() {
|
||||
await enableApplicationPanel();
|
||||
|
||||
// disable sw debugging by increasing the # of processes and thus multi-e10s kicking in
|
||||
info("Disable service worker debugging");
|
||||
await pushPref("dom.ipc.processCount", 8);
|
||||
|
||||
const { panel, tab, target } = await openNewTabAndApplicationPanel(TAB_URL);
|
||||
const doc = panel.panelWin.document;
|
||||
await waitForWorkerRegistration(tab);
|
||||
|
||||
info("Wait until the service worker appears in the application panel");
|
||||
await waitUntil(() => getWorkerContainers(doc).length === 1);
|
||||
|
||||
info("Wait until the start link is displayed");
|
||||
const container = getWorkerContainers(doc)[0];
|
||||
await waitUntil(() => container.querySelector(".js-start-link"));
|
||||
ok(container.querySelector(".js-start-link.disabled-link"),
|
||||
"Start link is disabled");
|
||||
|
||||
await unregisterAllWorkers(target.client);
|
||||
});
|
|
@ -69,3 +69,11 @@ async function unregisterAllWorkers(client) {
|
|||
await worker.registrationFront.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
async function waitForWorkerRegistration(swTab) {
|
||||
info("Wait until the registration appears on the window");
|
||||
const swBrowser = swTab.linkedBrowser;
|
||||
await asyncWaitUntil(async () => ContentTask.spawn(swBrowser, {}, function() {
|
||||
return content.wrappedJSObject.getRegistration();
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -9,7 +9,24 @@
|
|||
<body>
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
window.sw = navigator.serviceWorker.register("empty-sw.js");
|
||||
|
||||
let registration;
|
||||
|
||||
const registerServiceWorker = async function() {
|
||||
try {
|
||||
registration = await navigator.serviceWorker.register("empty-sw.js");
|
||||
dump("Empty service worker registered\n");
|
||||
} catch (e) {
|
||||
dump("Empty service worker not registered: " + e + "\n");
|
||||
}
|
||||
};
|
||||
|
||||
// Helper called from head.js to unregister the service worker.
|
||||
window.getRegistration = function() {
|
||||
return registration;
|
||||
};
|
||||
// Register the service worker.
|
||||
registerServiceWorker();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Загрузка…
Ссылка в новой задаче