browser_aboutdebugging_serviceworker_unregister.js (1589B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from helper-serviceworker.js */ 7 Services.scriptloader.loadSubScript( 8 CHROME_URL_ROOT + "helper-serviceworker.js", 9 this 10 ); 11 12 const SW_TAB_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.html"; 13 const SW_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.worker.js"; 14 15 /** 16 * Test that service workers can be started using about:debugging. 17 */ 18 add_task(async function () { 19 await enableServiceWorkerDebugging(); 20 21 const { document, tab, window } = await openAboutDebugging({ 22 enableWorkerUpdates: true, 23 }); 24 await selectThisFirefoxPage(document, window.AboutDebugging.store); 25 26 // Open a tab that registers a basic service worker. 27 const swTab = await addTab(SW_TAB_URL); 28 29 info("Wait until the service worker appears and is running"); 30 const targetElement = await waitForServiceWorkerRunning(SW_URL, document); 31 32 // Retrieve the Start button for the worker. 33 const unregisterButton = targetElement.querySelector(".qa-unregister-button"); 34 ok(unregisterButton, "Found its unregister button"); 35 36 info( 37 "Click on the unregister button and wait for the service worker to disappear" 38 ); 39 unregisterButton.click(); 40 await waitUntil(() => !findDebugTargetByText(SW_URL, document)); 41 42 const hasServiceWorkerTarget = !!findDebugTargetByText(SW_URL, document); 43 ok(!hasServiceWorkerTarget, "Service worker was successfully unregistered"); 44 45 info("Remove tabs"); 46 await removeTab(swTab); 47 await removeTab(tab); 48 });