browser_net_new_request_panel.js (3659B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const asyncStorage = require("resource://devtools/shared/async-storage.js"); 7 8 /** 9 * Test if the New Request panel shows up as a expected when opened from the toolbar 10 */ 11 12 add_task(async function () { 13 // Turn on the pref 14 await pushPref("devtools.netmonitor.features.newEditAndResend", true); 15 // Reset the storage for the persisted custom request 16 await asyncStorage.removeItem("devtools.netmonitor.customRequest"); 17 18 const { monitor } = await initNetMonitor(HTTPS_CUSTOM_GET_URL, { 19 requestCount: 1, 20 }); 21 info("Starting test... "); 22 23 const { document, store, windowRequire } = monitor.panelWin; 24 25 // Action should be processed synchronously in tests. 26 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 27 store.dispatch(Actions.batchEnable(false)); 28 29 info("Open the HTTP Custom Panel through the toolbar button"); 30 let HTTPCustomRequestButton = document.querySelector( 31 "#netmonitor-toolbar-container .devtools-http-custom-request-icon" 32 ); 33 ok(HTTPCustomRequestButton, "The Toolbar button should be visible."); 34 is( 35 HTTPCustomRequestButton.getAttribute("aria-pressed"), 36 "false", 37 "The custom request toolbar button should not be pressed" 38 ); 39 40 const waitForPanels = waitForDOM( 41 document, 42 ".monitor-panel .network-action-bar" 43 ); 44 HTTPCustomRequestButton.click(); 45 await waitForPanels; 46 47 is( 48 !!document.querySelector("#network-action-bar-HTTP-custom-request-panel"), 49 true, 50 "The 'New Request' header should be visible when the pref is true." 51 ); 52 is( 53 HTTPCustomRequestButton.getAttribute("aria-pressed"), 54 "true", 55 "The custom request toolbar button should be highlighted" 56 ); 57 is( 58 document 59 .querySelector(".devtools-search-icon") 60 .getAttribute("aria-pressed"), 61 "false", 62 "The search toolbar button should not be highlighted" 63 ); 64 is( 65 document 66 .querySelector(".requests-list-blocking-button") 67 .getAttribute("aria-pressed"), 68 "false", 69 "The block toolbar button should not be highlighted" 70 ); 71 72 info("if the default state is empty"); 73 is( 74 document.querySelector(".http-custom-method-value").value, 75 "GET", 76 "The method input should be 'GET' by default" 77 ); 78 is( 79 document.querySelector(".http-custom-url-value").textContent, 80 "", 81 "The URL input should be empty" 82 ); 83 const urlParametersValue = document.querySelectorAll( 84 "#http-custom-query .tabpanel-summary-container.http-custom-input" 85 ); 86 is(urlParametersValue.length, 0, "The URL Parameters input should be empty"); 87 const headersValue = document.querySelectorAll( 88 "#http-custom-headers .tabpanel-summary-container.http-custom-input" 89 ); 90 is(headersValue.length, 0, "The Headers input should be empty"); 91 is( 92 document.querySelector("#http-custom-postdata-value").textContent, 93 "", 94 "The Post body input should be empty" 95 ); 96 97 // Turn off the pref 98 await pushPref("devtools.netmonitor.features.newEditAndResend", false); 99 info("Close the panel to update the interface after changing the pref"); 100 const closePanel = document.querySelector( 101 ".network-action-bar .tabs-navigation .sidebar-toggle" 102 ); 103 closePanel.click(); 104 105 info("Check if the toolbar button is hidden when the pref is false"); 106 HTTPCustomRequestButton = document.querySelector( 107 "#netmonitor-toolbar-container .devtools-http-custom-request-icon" 108 ); 109 is( 110 !!HTTPCustomRequestButton, 111 false, 112 "The toolbar button should be hidden when the pref is false." 113 ); 114 115 await teardown(monitor); 116 });