browser_webconsole_network_messages_openinnet.js (3359B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_URI = 7 "data:text/html;charset=utf8,<!DOCTYPE html>Test that 'Open in Network Panel' " + 8 "context menu item opens the selected request in netmonitor panel."; 9 10 const TEST_FILE = "test-network-request.html"; 11 const JSON_TEST_URL = "test-network-request.html"; 12 const TEST_PATH = 13 "https://example.com/browser/devtools/client/webconsole/test/browser/"; 14 15 const NET_PREF = "devtools.webconsole.filter.net"; 16 const XHR_PREF = "devtools.webconsole.filter.netxhr"; 17 18 Services.prefs.setBoolPref(NET_PREF, true); 19 Services.prefs.setBoolPref(XHR_PREF, true); 20 21 registerCleanupFunction(async () => { 22 Services.prefs.clearUserPref(NET_PREF); 23 Services.prefs.clearUserPref(XHR_PREF); 24 25 await new Promise(resolve => { 26 Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () => 27 resolve() 28 ); 29 }); 30 }); 31 32 add_task(async function task() { 33 const hud = await openNewTabAndConsole(TEST_URI); 34 35 const currentTab = gBrowser.selectedTab; 36 const toolbox = gDevTools.getToolboxForTab(currentTab); 37 38 const documentUrl = TEST_PATH + TEST_FILE; 39 await navigateTo(documentUrl); 40 info("Document loaded."); 41 42 await openMessageInNetmonitor(toolbox, hud, documentUrl); 43 44 info( 45 "Wait for the netmonitor headers panel to appear as it spawn RDP requests" 46 ); 47 const netmonitor = toolbox.getCurrentPanel(); 48 await waitUntil(() => 49 netmonitor.panelWin.document.querySelector( 50 "#headers-panel .headers-overview" 51 ) 52 ); 53 54 info( 55 "Wait for the event timings request which do not necessarily update the UI as timings may be undefined for cached requests" 56 ); 57 await waitForRequestData(netmonitor.panelWin.store, ["eventTimings"], 0); 58 59 // Go back to console. 60 await toolbox.selectTool("webconsole"); 61 info("console panel open again."); 62 63 // Fire an XHR request. 64 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 65 // Ensure XHR request is completed 66 await new Promise(resolve => content.wrappedJSObject.testXhrGet(resolve)); 67 }); 68 69 const jsonUrl = TEST_PATH + JSON_TEST_URL; 70 await openMessageInNetmonitor(toolbox, hud, jsonUrl); 71 72 info( 73 "Wait for the netmonitor headers panel to appear as it spawn RDP requests" 74 ); 75 await waitUntil(() => 76 netmonitor.panelWin.document.querySelector( 77 "#headers-panel .headers-overview" 78 ) 79 ); 80 81 info( 82 "Wait for the event timings request which do not necessarily update the UI as timings may be undefined for cached requests" 83 ); 84 85 // Hide the header panel to get the eventTimings 86 const { windowRequire } = netmonitor.panelWin; 87 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 88 info("Closing the header panel"); 89 await netmonitor.panelWin.store.dispatch(Actions.toggleNetworkDetails()); 90 91 await waitForRequestData(netmonitor.panelWin.store, ["eventTimings"], 1); 92 }); 93 94 const { 95 getSortedRequests, 96 } = require("resource://devtools/client/netmonitor/src/selectors/index.js"); 97 98 function waitForRequestData(store, fields, i) { 99 return waitUntil(() => { 100 const item = getSortedRequests(store.getState())[i]; 101 if (!item) { 102 return false; 103 } 104 for (const field of fields) { 105 if (!item[field]) { 106 return false; 107 } 108 } 109 return true; 110 }); 111 }