зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1500397 - Add test for service worker unregister in new aboutdebugging;r=daisuke
Depends on D17642 Differential Revision: https://phabricator.services.mozilla.com/D17643 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
0db652598d
Коммит
f115820d7e
|
@ -59,6 +59,7 @@ skip-if = (os == "win" && ccov) # Bug 1521349
|
|||
[browser_aboutdebugging_serviceworker_start.js]
|
||||
[browser_aboutdebugging_serviceworker_status.js]
|
||||
[browser_aboutdebugging_serviceworker_timeout.js]
|
||||
[browser_aboutdebugging_serviceworker_unregister.js]
|
||||
[browser_aboutdebugging_sidebar_network_runtimes.js]
|
||||
[browser_aboutdebugging_sidebar_usb_runtime.js]
|
||||
[browser_aboutdebugging_sidebar_usb_runtime_connect.js]
|
||||
|
|
|
@ -29,7 +29,8 @@ add_task(async function() {
|
|||
await waitForServiceWorkerRegistering(SW_URL, document);
|
||||
|
||||
// Check that the buttons are displayed as expected.
|
||||
checkButtons({ inspect: true, push: false, start: false }, SW_URL, document);
|
||||
checkButtons({ inspect: true, push: false, start: false, unregister: false },
|
||||
SW_URL, document);
|
||||
|
||||
info("Install the service worker");
|
||||
ContentTask.spawn(swTab.linkedBrowser, {},
|
||||
|
@ -38,7 +39,8 @@ add_task(async function() {
|
|||
info("Wait until the service worker is running");
|
||||
await waitForServiceWorkerRunning(SW_URL, document);
|
||||
|
||||
checkButtons({ inspect: true, push: true, start: false }, SW_URL, document);
|
||||
checkButtons({ inspect: true, push: true, start: false, unregister: true },
|
||||
SW_URL, document);
|
||||
|
||||
info("Unregister service worker");
|
||||
await unregisterServiceWorker(swTab);
|
||||
|
@ -51,12 +53,13 @@ add_task(async function() {
|
|||
await removeTab(tab);
|
||||
});
|
||||
|
||||
function checkButtons({ inspect, push, start }, workerText, document) {
|
||||
function checkButtons({ inspect, push, start, unregister }, 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");
|
||||
const unregisterButton = targetElement.querySelector(".js-unregister-button");
|
||||
|
||||
is(!!inspectButton, inspect,
|
||||
"Inspect button should be " + (inspect ? "visible" : "hidden"));
|
||||
|
@ -64,4 +67,6 @@ function checkButtons({ inspect, push, start }, workerText, document) {
|
|||
"Push button should be " + (push ? "visible" : "hidden"));
|
||||
is(!!startButton, start,
|
||||
"Start button should be " + (start ? "visible" : "hidden"));
|
||||
is(!!unregisterButton, unregister,
|
||||
"Unregister button should be " + (unregister ? "visible" : "hidden"));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* 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/empty-sw.html";
|
||||
const SW_URL = URL_ROOT + "resources/service-workers/empty-sw.js";
|
||||
|
||||
// This is a migration from:
|
||||
// https://searchfox.org/mozilla-central/source/devtools/client/aboutdebugging/test/browser_service_workers_unregister.js
|
||||
|
||||
/**
|
||||
* Test that service workers can be started using about:debugging.
|
||||
*/
|
||||
add_task(async function() {
|
||||
await enableServiceWorkerDebugging();
|
||||
|
||||
const { document, tab } = await openAboutDebugging();
|
||||
|
||||
// Open a tab that registers a basic service worker.
|
||||
const swTab = await addTab(SW_TAB_URL);
|
||||
|
||||
info("Wait until the service worker appears and is running");
|
||||
const targetElement = await waitForServiceWorkerRunning(SW_URL, document);
|
||||
|
||||
// Retrieve the Start button for the worker.
|
||||
const unregisterButton = targetElement.querySelector(".js-unregister-button");
|
||||
ok(unregisterButton, "Found its unregister button");
|
||||
|
||||
info("Click on the unregister button and wait for the service worker to disappear");
|
||||
unregisterButton.click();
|
||||
await waitUntil(() => !findDebugTargetByText(SW_URL, document));
|
||||
|
||||
const hasServiceWorkerTarget = !!findDebugTargetByText(SW_URL, document);
|
||||
ok(!hasServiceWorkerTarget, "Service worker was successfully unregistered");
|
||||
|
||||
info("Remove tabs");
|
||||
await removeTab(swTab);
|
||||
await removeTab(tab);
|
||||
});
|
Загрузка…
Ссылка в новой задаче