browser_net_fission_switch_target.js (2046B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test switching for the top-level target. 7 8 const EXAMPLE_COM_URL = "https://example.com/document-builder.sjs?html=testcom"; 9 const EXAMPLE_NET_URL = "https://example.net/document-builder.sjs?html=testnet"; 10 const REQUEST_URL = HTTPS_SEARCH_SJS + "?value=test"; 11 const PARENT_PROCESS_URL = "about:blank"; 12 13 add_task(async function () { 14 info("Open a page that runs on the content process and the netmonitor"); 15 const { monitor } = await initNetMonitor(EXAMPLE_COM_URL, { 16 requestCount: 1, 17 }); 18 await assertRequest(monitor, REQUEST_URL); 19 20 info("Navigate to a page that runs in another content process (if fission)"); 21 await waitForUpdatesAndNavigateTo(EXAMPLE_NET_URL); 22 await assertRequest(monitor, REQUEST_URL); 23 24 info("Navigate to a parent process page"); 25 await waitForUpdatesAndNavigateTo(PARENT_PROCESS_URL); 26 await assertRequest(monitor, REQUEST_URL); 27 28 info("Navigate back to the example.com content page"); 29 await waitForUpdatesAndNavigateTo(EXAMPLE_COM_URL); 30 await assertRequest(monitor, REQUEST_URL); 31 32 await teardown(monitor); 33 }); 34 35 async function waitForUpdatesAndNavigateTo(url) { 36 await waitForAllNetworkUpdateEvents(); 37 await navigateTo(url); 38 } 39 40 async function assertRequest(monitor, url) { 41 const waitForRequests = waitForNetworkEvents(monitor, 1); 42 info("Create a request in the target page for the URL: " + url); 43 await SpecialPowers.spawn(gBrowser.selectedBrowser, [url], async _url => { 44 // Note: we are not reusing performRequests available in some netmonitor 45 // test pages because we also need to run this helper against an about: 46 // page, which won't have the helper defined. 47 // Therefore, we use a simplified performRequest implementation here. 48 const xhr = new content.wrappedJSObject.XMLHttpRequest(); 49 xhr.open("GET", _url, true); 50 xhr.send(null); 51 }); 52 info("Wait for the request to be received by the netmonitor UI"); 53 return waitForRequests; 54 }