browser_browser_toolbox_netmonitor.js (5437B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* global gToolbox */ 7 8 add_task(async function () { 9 // Disable several prefs to avoid network requests. 10 await pushPref("browser.safebrowsing.blockedURIs.enabled", false); 11 await pushPref("browser.safebrowsing.downloads.enabled", false); 12 await pushPref("browser.safebrowsing.malware.enabled", false); 13 await pushPref("browser.safebrowsing.phishing.enabled", false); 14 await pushPref("privacy.query_stripping.enabled", false); 15 await pushPref("extensions.systemAddon.update.enabled", false); 16 17 await pushPref("services.settings.server", "invalid://err"); 18 19 // Define a set list of visible columns 20 await pushPref( 21 "devtools.netmonitor.visibleColumns", 22 JSON.stringify(["file", "url", "status"]) 23 ); 24 25 // Force observice all processes to see the content process requests 26 await pushPref("devtools.browsertoolbox.scope", "everything"); 27 28 const ToolboxTask = await initBrowserToolboxTask(); 29 30 await ToolboxTask.importFunctions({ 31 waitUntil, 32 waitForDOM, 33 }); 34 35 await ToolboxTask.spawn(null, async () => { 36 const { resourceCommand } = gToolbox.commands; 37 38 // Assert that the toolbox is not listening to network events 39 // before the netmonitor panel is opened. 40 is( 41 resourceCommand.isResourceWatched(resourceCommand.TYPES.NETWORK_EVENT), 42 false, 43 "The toolox is not watching for network event resources" 44 ); 45 46 await gToolbox.selectTool("netmonitor"); 47 const monitor = gToolbox.getCurrentPanel(); 48 const { document, store, windowRequire } = monitor.panelWin; 49 50 const Actions = windowRequire( 51 "devtools/client/netmonitor/src/actions/index" 52 ); 53 54 store.dispatch(Actions.batchEnable(false)); 55 56 await waitUntil( 57 () => !!document.querySelector(".request-list-empty-notice") 58 ); 59 60 is( 61 resourceCommand.isResourceWatched(resourceCommand.TYPES.NETWORK_EVENT), 62 true, 63 "The network panel is now watching for network event resources" 64 ); 65 66 const emptyListNotice = document.querySelector( 67 ".request-list-empty-notice" 68 ); 69 70 ok( 71 !!emptyListNotice, 72 "An empty notice should be displayed when the frontend is opened." 73 ); 74 75 is( 76 emptyListNotice.innerText, 77 "Perform a request to see detailed information about network activity.", 78 "The reload and perfomance analysis details should not be visible in the browser toolbox" 79 ); 80 81 is( 82 store.getState().requests.requests.length, 83 0, 84 "The requests should be empty when the frontend is opened." 85 ); 86 87 ok( 88 !document.querySelector(".requests-list-network-summary-button"), 89 "The perfomance analysis button should not be visible in the browser toolbox" 90 ); 91 }); 92 93 info("Trigger request in parent process and check that it shows up"); 94 await fetch("https://example.org/document-builder.sjs?html=fromParent"); 95 96 await ToolboxTask.spawn(null, async () => { 97 const monitor = gToolbox.getCurrentPanel(); 98 const { document, store, windowRequire } = monitor.panelWin; 99 const Actions = windowRequire( 100 "devtools/client/netmonitor/src/actions/index" 101 ); 102 103 await waitUntil( 104 () => !document.querySelector(".request-list-empty-notice") 105 ); 106 ok(true, "The empty notice is no longer displayed"); 107 is( 108 store.getState().requests.requests.length, 109 1, 110 "There's 1 request in the store" 111 ); 112 113 const requests = Array.from( 114 document.querySelectorAll("tbody .requests-list-column.requests-list-url") 115 ); 116 is(requests.length, 1, "One request displayed"); 117 const requestUrl = 118 "https://example.org/document-builder.sjs?html=fromParent"; 119 is(requests[0].textContent, requestUrl, "Expected request is displayed"); 120 121 const waitForHeaders = waitForDOM(document, ".headers-overview"); 122 store.dispatch(Actions.toggleNetworkDetails()); 123 await waitForHeaders; 124 125 const tabpanel = document.querySelector("#headers-panel"); 126 is( 127 tabpanel.querySelector(".url-preview .url").innerText, 128 requestUrl, 129 "The url summary value is incorrect." 130 ); 131 }); 132 133 info("Trigger content process requests"); 134 const urlImg = `${URL_ROOT_SSL}test-image.png?fromContent&${Date.now()}-${Math.random()}`; 135 await addTab( 136 `https://example.com/document-builder.sjs?html=${encodeURIComponent( 137 `<img src='${urlImg}'>` 138 )}` 139 ); 140 141 await ToolboxTask.spawn(urlImg, async innerUrlImg => { 142 const monitor = gToolbox.getCurrentPanel(); 143 const { document, store } = monitor.panelWin; 144 145 // Note that we may have lots of other requests relates to browser activity, 146 // like file:// requests for many internal UI ressources. 147 await waitUntil(() => store.getState().requests.requests.length >= 3); 148 ok(true, "Expected content requests are displayed"); 149 150 async function waitForRequest(url, requestName) { 151 info(`Wait for ${requestName} request`); 152 await waitUntil(() => { 153 const requests = Array.from( 154 document.querySelectorAll( 155 "tbody .requests-list-column.requests-list-url" 156 ) 157 ); 158 return requests.some(r => r.textContent.includes(url)); 159 }); 160 info(`Got ${requestName} request`); 161 } 162 await waitForRequest("https://example.com/document-builder.sjs", "tab"); 163 await waitForRequest(innerUrlImg, "image in tab"); 164 }); 165 });