browser_aboutdebugging_serviceworker_push.js (1955B)
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 SERVICE_WORKER = 13 URL_ROOT_SSL + "resources/service-workers/push-sw.worker.js"; 14 const TAB_URL = URL_ROOT_SSL + "resources/service-workers/push-sw.html"; 15 16 // Test that clicking on the Push button next to a Service Worker works as intended. 17 // It should trigger a "push" notification in the worker. 18 add_task(async function () { 19 await enableServiceWorkerDebugging(); 20 const { document, tab, window } = await openAboutDebugging({ 21 enableWorkerUpdates: true, 22 }); 23 await selectThisFirefoxPage(document, window.AboutDebugging.store); 24 25 // Open a tab that registers a push service worker. 26 const swTab = await addTab(TAB_URL); 27 28 info( 29 "Wait for the service worker to claim the test window before proceeding." 30 ); 31 await SpecialPowers.spawn( 32 swTab.linkedBrowser, 33 [], 34 () => content.wrappedJSObject.onSwClaimed 35 ); 36 37 info("Wait until the service worker appears and is running"); 38 const targetElement = await waitForServiceWorkerRunning( 39 SERVICE_WORKER, 40 document 41 ); 42 43 // Retrieve the Push button for the worker. 44 const pushButton = targetElement.querySelector(".qa-push-button"); 45 ok(pushButton, "Found its push button"); 46 47 info("Click on the Push button and wait for the push notification"); 48 const onPushNotification = onServiceWorkerMessage(swTab, "sw-pushed"); 49 pushButton.click(); 50 await onPushNotification; 51 52 info("Unregister the service worker"); 53 await unregisterServiceWorker(swTab); 54 55 info("Wait until the service worker disappears from about:debugging"); 56 await waitUntil(() => !findDebugTargetByText(SERVICE_WORKER, document)); 57 58 info("Remove the service worker tab"); 59 await removeTab(swTab); 60 61 await removeTab(tab); 62 });