browser_net_copy_params.js (5169B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Tests whether copying a request item's parameters works. 8 */ 9 10 add_task(async function () { 11 const { tab, monitor } = await initNetMonitor(PARAMS_URL, { 12 requestCount: 1, 13 }); 14 info("Starting test... "); 15 16 const { document, store, windowRequire } = monitor.panelWin; 17 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 18 19 store.dispatch(Actions.batchEnable(false)); 20 21 // Execute requests. 22 await performRequests(monitor, tab, 7); 23 24 await testCopyUrlParamsHidden(0, false); 25 await testCopyUrlParams(0, "a"); 26 await testCopyPostDataHidden(0, false); 27 await testCopyPostData(0, '{ "foo": "bar" }'); 28 29 await testCopyUrlParamsHidden(1, false); 30 await testCopyUrlParams(1, "a=b"); 31 await testCopyPostDataHidden(1, false); 32 await testCopyPostData(1, '{ "foo": "bar" }'); 33 34 await testCopyUrlParamsHidden(2, false); 35 await testCopyUrlParams(2, "a=b"); 36 await testCopyPostDataHidden(2, false); 37 await testCopyPostData(2, "foo=bar=123=xyz"); 38 39 await testCopyUrlParamsHidden(3, false); 40 await testCopyUrlParams(3, "a"); 41 await testCopyPostDataHidden(3, false); 42 await testCopyPostData(3, '{ "foo": "bar" }'); 43 44 await testCopyUrlParamsHidden(4, false); 45 await testCopyUrlParams(4, "a=b"); 46 await testCopyPostDataHidden(4, false); 47 await testCopyPostData(4, '{ "foo": "bar" }'); 48 49 await testCopyUrlParamsHidden(5, false); 50 await testCopyUrlParams(5, "a=b"); 51 await testCopyPostDataHidden(5, false); 52 await testCopyPostData(5, "?foo=bar"); 53 testCopyRequestDataLabel(5, "POST"); 54 55 await testCopyUrlParamsHidden(6, true); 56 await testCopyPostDataHidden(6, true); 57 58 await testCopyPostDataHidden(7, false); 59 testCopyRequestDataLabel(7, "PATCH"); 60 61 await testCopyPostDataHidden(8, false); 62 testCopyRequestDataLabel(8, "PUT"); 63 64 return teardown(monitor); 65 66 async function testCopyUrlParamsHidden(index, hidden) { 67 EventUtils.sendMouseEvent( 68 { type: "mousedown" }, 69 document.querySelectorAll(".request-list-item")[index] 70 ); 71 EventUtils.sendMouseEvent( 72 { type: "contextmenu" }, 73 document.querySelectorAll(".request-list-item")[index] 74 ); 75 76 is( 77 !!getContextMenuItem(monitor, "request-list-context-copy-url-params"), 78 !hidden, 79 'The "Copy URL Parameters" context menu item should' + 80 (hidden ? " " : " not ") + 81 "be hidden." 82 ); 83 } 84 85 async function testCopyUrlParams(index, queryString) { 86 EventUtils.sendMouseEvent( 87 { type: "mousedown" }, 88 document.querySelectorAll(".request-list-item")[index] 89 ); 90 EventUtils.sendMouseEvent( 91 { type: "contextmenu" }, 92 document.querySelectorAll(".request-list-item")[index] 93 ); 94 await waitForClipboardPromise(async function setup() { 95 await selectContextMenuItem( 96 monitor, 97 "request-list-context-copy-url-params" 98 ); 99 }, queryString); 100 ok(true, "The url query string copied from the selected item is correct."); 101 } 102 103 async function testCopyPostDataHidden(index, hidden) { 104 EventUtils.sendMouseEvent( 105 { type: "mousedown" }, 106 document.querySelectorAll(".request-list-item")[index] 107 ); 108 EventUtils.sendMouseEvent( 109 { type: "contextmenu" }, 110 document.querySelectorAll(".request-list-item")[index] 111 ); 112 is( 113 !!getContextMenuItem(monitor, "request-list-context-copy-post-data"), 114 !hidden, 115 'The "Copy POST Data" context menu item should' + 116 (hidden ? " " : " not ") + 117 "be hidden." 118 ); 119 } 120 121 function testCopyRequestDataLabel(index, method) { 122 EventUtils.sendMouseEvent( 123 { type: "mousedown" }, 124 document.querySelectorAll(".request-list-item")[index] 125 ); 126 EventUtils.sendMouseEvent( 127 { type: "contextmenu" }, 128 document.querySelectorAll(".request-list-item")[index] 129 ); 130 const copyPostDataNode = getContextMenuItem( 131 monitor, 132 "request-list-context-copy-post-data" 133 ); 134 is( 135 copyPostDataNode.attributes.label.value, 136 "Copy " + method + " Data", 137 'The "Copy Data" context menu item should have label - Copy ' + 138 method + 139 " Data" 140 ); 141 } 142 143 async function testCopyPostData(index, postData) { 144 // Wait for formDataSections and requestPostData state are ready in redux store 145 // since copyPostData API needs to read these state. 146 await waitUntil(() => { 147 const { requests } = store.getState().requests; 148 const { formDataSections, requestPostData } = requests[index]; 149 return formDataSections && requestPostData; 150 }); 151 EventUtils.sendMouseEvent( 152 { type: "mousedown" }, 153 document.querySelectorAll(".request-list-item")[index] 154 ); 155 EventUtils.sendMouseEvent( 156 { type: "contextmenu" }, 157 document.querySelectorAll(".request-list-item")[index] 158 ); 159 await waitForClipboardPromise(async function setup() { 160 await selectContextMenuItem( 161 monitor, 162 "request-list-context-copy-post-data" 163 ); 164 }, postData); 165 ok(true, "The post data string copied from the selected item is correct."); 166 } 167 });