browser_application_panel_start-service-worker.js (1905B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TAB_URL = URL_ROOT + "resources/service-workers/simple.html"; 7 8 /** 9 * Tests that the Start button works for service workers who can be debugged 10 */ 11 add_task(async function () { 12 await enableApplicationPanel(); // this also enables SW debugging 13 14 // Setting a low idle_timeout and idle_extended_timeout will allow the service worker 15 // to reach the STOPPED state quickly, which will allow us to test the start button. 16 // The default value is 30000 milliseconds. 17 info("Set a low service worker idle timeout"); 18 await pushPref("dom.serviceWorkers.idle_timeout", 1000); 19 await pushPref("dom.serviceWorkers.idle_extended_timeout", 1000); 20 21 const { panel, tab, commands } = await openNewTabAndApplicationPanel(TAB_URL); 22 const doc = panel.panelWin.document; 23 24 selectPage(panel, "service-workers"); 25 26 await waitForWorkerRegistration(tab); 27 28 info("Wait until the service worker appears in the application panel"); 29 await waitUntil(() => getWorkerContainers(doc).length === 1); 30 31 info("Wait until the start button is displayed and enabled"); 32 const container = getWorkerContainers(doc)[0]; 33 await waitUntil(() => { 34 const button = container.querySelector(".js-start-button"); 35 return button && !button.disabled; 36 }); 37 38 info("Click the button and wait for the worker to start"); 39 const button = container.querySelector(".js-start-button"); 40 button.click(); 41 42 info("Wait until status 'Running' is displayed"); 43 await waitUntil(() => { 44 const statusEl = container.querySelector(".js-worker-status"); 45 return statusEl && statusEl.textContent === "Running"; 46 }); 47 ok(true, "Worker status is 'Running'"); 48 49 await unregisterAllWorkers(commands.client, doc); 50 51 // close the tab 52 info("Closing the tab."); 53 await BrowserTestUtils.removeTab(tab); 54 });