From 23ef4092372acf2751324148c749e1eda5ca07dc Mon Sep 17 00:00:00 2001 From: Catalin Badea Date: Sun, 22 Jan 2017 09:03:00 +0200 Subject: [PATCH] Bug 1328293 - Add test for new entry in about:debugging#workers. r=jdescottes --- .../client/aboutdebugging/test/browser.ini | 3 ++ .../browser_service_workers_fetch_flag.js | 51 +++++++++++++++++++ .../test/service-workers/fetch-sw.html | 22 ++++++++ .../test/service-workers/fetch-sw.js | 6 +++ 4 files changed, 82 insertions(+) create mode 100644 devtools/client/aboutdebugging/test/browser_service_workers_fetch_flag.js create mode 100644 devtools/client/aboutdebugging/test/service-workers/fetch-sw.html create mode 100644 devtools/client/aboutdebugging/test/service-workers/fetch-sw.js diff --git a/devtools/client/aboutdebugging/test/browser.ini b/devtools/client/aboutdebugging/test/browser.ini index 83d4ddff7c96..104686b86f3a 100644 --- a/devtools/client/aboutdebugging/test/browser.ini +++ b/devtools/client/aboutdebugging/test/browser.ini @@ -13,6 +13,8 @@ support-files = service-workers/delay-sw.js service-workers/empty-sw.html service-workers/empty-sw.js + service-workers/fetch-sw.html + service-workers/fetch-sw.js service-workers/push-sw.html service-workers/push-sw.js !/devtools/client/framework/test/shared-head.js @@ -32,6 +34,7 @@ tags = webextensions [browser_addons_toggle_debug.js] [browser_page_not_found.js] [browser_service_workers.js] +[browser_service_workers_fetch_flag.js] [browser_service_workers_not_compatible.js] [browser_service_workers_push.js] [browser_service_workers_push_service.js] diff --git a/devtools/client/aboutdebugging/test/browser_service_workers_fetch_flag.js b/devtools/client/aboutdebugging/test/browser_service_workers_fetch_flag.js new file mode 100644 index 000000000000..77749b873ea0 --- /dev/null +++ b/devtools/client/aboutdebugging/test/browser_service_workers_fetch_flag.js @@ -0,0 +1,51 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Service workers can't be loaded from chrome://, +// but http:// is ok with dom.serviceWorkers.testing.enabled turned on. +const EMPTY_SW_TAB_URL = URL_ROOT + "service-workers/empty-sw.html"; +const FETCH_SW_TAB_URL = URL_ROOT + "service-workers/fetch-sw.html"; + +function* testBody(url, expecting) { + yield new Promise(done => { + let options = {"set": [ + ["dom.serviceWorkers.enabled", true], + ["dom.serviceWorkers.testing.enabled", true], + ]}; + SpecialPowers.pushPrefEnv(options, done); + }); + + let { tab, document } = yield openAboutDebugging("workers"); + + let swTab = yield addTab(url); + + let serviceWorkersElement = getServiceWorkerList(document); + yield waitForMutation(serviceWorkersElement, { childList: true }); + + let fetchFlags = + [...document.querySelectorAll("#service-workers .service-worker-fetch-flag")]; + fetchFlags = fetchFlags.map(element => element.textContent); + ok(fetchFlags.includes(expecting), "Found correct fetch flag."); + + try { + yield unregisterServiceWorker(swTab, serviceWorkersElement); + ok(true, "Service worker registration unregistered"); + } catch (e) { + ok(false, "SW not unregistered; " + e); + } + + // Check that the service worker disappeared from the UI + let names = [...document.querySelectorAll("#service-workers .target-name")]; + names = names.map(element => element.textContent); + ok(names.length == 0, "All service workers were removed from the list."); + + yield removeTab(swTab); + yield closeAboutDebugging(tab); +} + +add_task(function* () { + yield testBody(FETCH_SW_TAB_URL, "Listening for fetch events."); + yield testBody(EMPTY_SW_TAB_URL, "Not listening for fetch events."); +}); diff --git a/devtools/client/aboutdebugging/test/service-workers/fetch-sw.html b/devtools/client/aboutdebugging/test/service-workers/fetch-sw.html new file mode 100644 index 000000000000..9038d4cbb26d --- /dev/null +++ b/devtools/client/aboutdebugging/test/service-workers/fetch-sw.html @@ -0,0 +1,22 @@ + + + + + Service worker test + + + + + diff --git a/devtools/client/aboutdebugging/test/service-workers/fetch-sw.js b/devtools/client/aboutdebugging/test/service-workers/fetch-sw.js new file mode 100644 index 000000000000..de6ee1fb3295 --- /dev/null +++ b/devtools/client/aboutdebugging/test/service-workers/fetch-sw.js @@ -0,0 +1,6 @@ +"use strict"; + +// Bug 1328293 +self.onfetch = function (event) { + // do nothing. +};