browser_aboutdebugging_serviceworker_runtime-page-origin.js (2336B)
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 /* import-globals-from helper-collapsibilities.js */ 12 Services.scriptloader.loadSubScript( 13 CHROME_URL_ROOT + "helper-collapsibilities.js", 14 this 15 ); 16 17 const SW_TAB_URL = URL_ROOT_SSL + "resources/service-workers/push-sw.html"; 18 const SW_URL = URL_ROOT_SSL + "resources/service-workers/push-sw.worker.js"; 19 20 /** 21 * Test that service workers' origin attributes are displayed in the runtime page. 22 */ 23 add_task(async function () { 24 await SpecialPowers.pushPrefEnv({ 25 set: [["privacy.firstparty.isolate", true]], 26 }); 27 28 prepareCollapsibilitiesTest(); 29 await enableServiceWorkerDebugging(); 30 const { document, tab, window } = await openAboutDebugging({ 31 enableWorkerUpdates: true, 32 }); 33 const store = window.AboutDebugging.store; 34 35 await selectThisFirefoxPage(document, store); 36 37 // open a tab and register service worker 38 info("Register a service worker"); 39 const swTab = await addTab(SW_TAB_URL); 40 41 // check that service worker is rendered 42 info("Wait until the service worker appears and is running"); 43 await waitForServiceWorkerRunning(SW_URL, document); 44 45 let swPane = getDebugTargetPane("Service Workers", document); 46 Assert.strictEqual( 47 swPane.querySelectorAll(".qa-debug-target-item").length, 48 1, 49 "Service worker list has one element" 50 ); 51 const url = new URL(SW_URL); 52 const firstPartyAttribute = url.origin + "^firstPartyDomain=" + url.hostname; 53 ok( 54 swPane 55 .querySelector(".qa-debug-target-item") 56 .textContent.includes(firstPartyAttribute), 57 "Service worker list displays the origin information correctly" 58 ); 59 60 // unregister the service worker 61 info("Unregister service worker"); 62 await unregisterServiceWorker(swTab); 63 // check that service worker is not rendered anymore 64 info("Wait for service worker to disappear"); 65 await waitUntil(() => { 66 swPane = getDebugTargetPane("Service Workers", document); 67 return swPane.querySelectorAll(".qa-debug-target-item").length === 0; 68 }); 69 70 info("Remove tabs"); 71 await removeTab(swTab); 72 await removeTab(tab); 73 await SpecialPowers.popPrefEnv(); 74 });