browser_aboutdebugging_addons_debug_netmonitor.js (4014B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 /* import-globals-from helper-addons.js */ 6 Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this); 7 8 // There are shutdown issues for which multiple rejections are left uncaught. 9 // See bug 1018184 for resolving these issues. 10 const { PromiseTestUtils } = ChromeUtils.importESModule( 11 "resource://testing-common/PromiseTestUtils.sys.mjs" 12 ); 13 PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/); 14 15 const ADDON_ID = "test-devtools-webextension@mozilla.org"; 16 const ADDON_NAME = "test-devtools-webextension"; 17 18 /** 19 * Cover usages of the Network Monitor panel when debugging a Web Extension. 20 */ 21 add_task(async function testWebExtensionsToolboxNetmonitor() { 22 await enableExtensionDebugging(); 23 const { document, tab, window } = await openAboutDebugging(); 24 await selectThisFirefoxPage(document, window.AboutDebugging.store); 25 26 await installTemporaryExtensionFromXPI( 27 { 28 background() { 29 document.body.innerText = "Background Page Body Test Content"; 30 }, 31 id: ADDON_ID, 32 name: ADDON_NAME, 33 }, 34 document 35 ); 36 37 info("Open a toolbox to debug the addon"); 38 const { devtoolsWindow } = await openAboutDevtoolsToolbox( 39 document, 40 tab, 41 window, 42 ADDON_NAME 43 ); 44 const toolbox = getToolbox(devtoolsWindow); 45 46 const monitor = await toolbox.selectTool("netmonitor"); 47 const { document: monitorDocument, store } = monitor.panelWin; 48 49 await waitUntil( 50 () => !!monitorDocument.querySelector(".request-list-empty-notice") 51 ); 52 53 const emptyListNotice = monitorDocument.querySelector( 54 ".request-list-empty-notice" 55 ); 56 57 ok( 58 !!emptyListNotice, 59 "An empty notice should be displayed when the frontend is opened." 60 ); 61 62 is( 63 emptyListNotice.innerText, 64 "Perform a request to see detailed information about network activity.", 65 "The reload and perfomance analysis details should not be visible in the netmonitor" 66 ); 67 68 const expectedURL = "https://example.org/?test_netmonitor=1"; 69 70 await toolbox.commands.scriptCommand.execute(`fetch("${expectedURL}");`); 71 72 // NOTE: we need to filter the requests to the ones that we expect until 73 // the network monitor is not yet filtering out the requests that are not 74 // coming from an extension window or a descendent of an extension window, 75 // in both oop and non-oop extension mode (filed as Bug 1442621). 76 function getExpectedStoreRequests() { 77 return Array.from(store.getState().requests.requests.values()).filter( 78 request => request.url === expectedURL 79 ); 80 } 81 82 let requests; 83 84 await waitFor(() => { 85 requests = getExpectedStoreRequests(); 86 87 return requests.length == 1; 88 }); 89 90 is(requests.length, 1, "Got one request logged"); 91 is(requests[0].method, "GET", "Got a GET request"); 92 is(requests[0].url, expectedURL, "Got the expected request url"); 93 94 info("Resend webextension request"); 95 const firstRequest = 96 monitorDocument.querySelectorAll(".request-list-item")[0]; 97 const waitForHeaders = waitUntil(() => 98 monitorDocument.querySelector(".headers-overview") 99 ); 100 EventUtils.sendMouseEvent({ type: "mousedown" }, firstRequest); 101 await waitForHeaders; 102 EventUtils.sendMouseEvent({ type: "contextmenu" }, firstRequest); 103 await selectNetmonitorContextMenuItem( 104 monitor, 105 "request-list-context-edit-resend" 106 ); 107 108 await waitUntil( 109 () => 110 monitorDocument.querySelector(".http-custom-request-panel") && 111 monitorDocument.querySelector("#http-custom-request-send-button") 112 .disabled === false 113 ); 114 monitorDocument.querySelector("#http-custom-request-send-button").click(); 115 116 await waitFor(() => { 117 requests = getExpectedStoreRequests(); 118 119 return requests.length == 2; 120 }, "Wait for resent request to be received"); 121 122 await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window); 123 await removeTemporaryExtension(ADDON_NAME, document); 124 await removeTab(tab); 125 });