1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_post-data-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,153 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Tests if the POST requests display the correct information in the UI. 1.9 + */ 1.10 + 1.11 +function test() { 1.12 + initNetMonitor(POST_DATA_URL).then(([aTab, aDebuggee, aMonitor]) => { 1.13 + info("Starting test... "); 1.14 + 1.15 + let { document, L10N, Editor, NetMonitorView } = aMonitor.panelWin; 1.16 + let { RequestsMenu, NetworkDetails } = NetMonitorView; 1.17 + 1.18 + RequestsMenu.lazyUpdate = false; 1.19 + NetworkDetails._params.lazyEmpty = false; 1.20 + 1.21 + waitForNetworkEvents(aMonitor, 0, 2).then(() => { 1.22 + verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), 1.23 + "POST", SIMPLE_SJS + "?foo=bar&baz=42&type=urlencoded", { 1.24 + status: 200, 1.25 + statusText: "Och Aye", 1.26 + type: "plain", 1.27 + fullMimeType: "text/plain; charset=utf-8", 1.28 + size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), 1.29 + time: true 1.30 + }); 1.31 + verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1), 1.32 + "POST", SIMPLE_SJS + "?foo=bar&baz=42&type=multipart", { 1.33 + status: 200, 1.34 + statusText: "Och Aye", 1.35 + type: "plain", 1.36 + fullMimeType: "text/plain; charset=utf-8", 1.37 + size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), 1.38 + time: true 1.39 + }); 1.40 + 1.41 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.42 + document.getElementById("details-pane-toggle")); 1.43 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.44 + document.querySelectorAll("#details-pane tab")[2]); 1.45 + 1.46 + let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED; 1.47 + waitFor(aMonitor.panelWin, TAB_UPDATED).then(() => 1.48 + testParamsTab("urlencoded") 1.49 + ).then(() => { 1.50 + RequestsMenu.selectedIndex = 1; 1.51 + return waitFor(aMonitor.panelWin, TAB_UPDATED); 1.52 + }).then(() => testParamsTab("multipart")) 1.53 + .then(() => teardown(aMonitor)) 1.54 + .then(finish); 1.55 + 1.56 + function testParamsTab(aType) { 1.57 + let tab = document.querySelectorAll("#details-pane tab")[2]; 1.58 + let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; 1.59 + 1.60 + is(tab.getAttribute("selected"), "true", 1.61 + "The params tab in the network details pane should be selected."); 1.62 + 1.63 + function checkVisibility(aBox) { 1.64 + is(tabpanel.querySelector("#request-params-box") 1.65 + .hasAttribute("hidden"), !aBox.contains("params"), 1.66 + "The request params box doesn't have the indended visibility."); 1.67 + is(tabpanel.querySelector("#request-post-data-textarea-box") 1.68 + .hasAttribute("hidden"), !aBox.contains("textarea"), 1.69 + "The request post data textarea box doesn't have the indended visibility."); 1.70 + } 1.71 + 1.72 + is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, 1.73 + "There should be 2 param scopes displayed in this tabpanel."); 1.74 + is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, 1.75 + "The empty notice should not be displayed in this tabpanel."); 1.76 + 1.77 + let queryScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; 1.78 + let postScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; 1.79 + 1.80 + is(queryScope.querySelector(".name").getAttribute("value"), 1.81 + L10N.getStr("paramsQueryString"), 1.82 + "The query scope doesn't have the correct title."); 1.83 + 1.84 + is(postScope.querySelector(".name").getAttribute("value"), 1.85 + L10N.getStr(aType == "urlencoded" ? "paramsFormData" : "paramsPostPayload"), 1.86 + "The post scope doesn't have the correct title."); 1.87 + 1.88 + is(queryScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), 1.89 + "foo", "The first query param name was incorrect."); 1.90 + is(queryScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), 1.91 + "\"bar\"", "The first query param value was incorrect."); 1.92 + is(queryScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"), 1.93 + "baz", "The second query param name was incorrect."); 1.94 + is(queryScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"), 1.95 + "\"42\"", "The second query param value was incorrect."); 1.96 + is(queryScope.querySelectorAll(".variables-view-variable .name")[2].getAttribute("value"), 1.97 + "type", "The third query param name was incorrect."); 1.98 + is(queryScope.querySelectorAll(".variables-view-variable .value")[2].getAttribute("value"), 1.99 + "\"" + aType + "\"", "The third query param value was incorrect."); 1.100 + 1.101 + if (aType == "urlencoded") { 1.102 + checkVisibility("params"); 1.103 + 1.104 + is(tabpanel.querySelectorAll(".variables-view-variable").length, 5, 1.105 + "There should be 5 param values displayed in this tabpanel."); 1.106 + is(queryScope.querySelectorAll(".variables-view-variable").length, 3, 1.107 + "There should be 3 param values displayed in the query scope."); 1.108 + is(postScope.querySelectorAll(".variables-view-variable").length, 2, 1.109 + "There should be 2 param values displayed in the post scope."); 1.110 + 1.111 + is(postScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), 1.112 + "foo", "The first post param name was incorrect."); 1.113 + is(postScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), 1.114 + "\"bar\"", "The first post param value was incorrect."); 1.115 + is(postScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"), 1.116 + "baz", "The second post param name was incorrect."); 1.117 + is(postScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"), 1.118 + "\"123\"", "The second post param value was incorrect."); 1.119 + 1.120 + return promise.resolve(); 1.121 + } 1.122 + else { 1.123 + checkVisibility("params textarea"); 1.124 + 1.125 + is(tabpanel.querySelectorAll(".variables-view-variable").length, 3, 1.126 + "There should be 3 param values displayed in this tabpanel."); 1.127 + is(queryScope.querySelectorAll(".variables-view-variable").length, 3, 1.128 + "There should be 3 param values displayed in the query scope."); 1.129 + is(postScope.querySelectorAll(".variables-view-variable").length, 0, 1.130 + "There should be 0 param values displayed in the post scope."); 1.131 + 1.132 + return NetMonitorView.editor("#request-post-data-textarea").then((aEditor) => { 1.133 + ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"text\""), 1.134 + "The text shown in the source editor is incorrect (1.1)."); 1.135 + ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"email\""), 1.136 + "The text shown in the source editor is incorrect (2.1)."); 1.137 + ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"range\""), 1.138 + "The text shown in the source editor is incorrect (3.1)."); 1.139 + ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"Custom field\""), 1.140 + "The text shown in the source editor is incorrect (4.1)."); 1.141 + ok(aEditor.getText().contains("Some text..."), 1.142 + "The text shown in the source editor is incorrect (2.2)."); 1.143 + ok(aEditor.getText().contains("42"), 1.144 + "The text shown in the source editor is incorrect (3.2)."); 1.145 + ok(aEditor.getText().contains("Extra data"), 1.146 + "The text shown in the source editor is incorrect (4.2)."); 1.147 + is(aEditor.getMode(), Editor.modes.text, 1.148 + "The mode active in the source editor is incorrect."); 1.149 + }); 1.150 + } 1.151 + } 1.152 + }); 1.153 + 1.154 + aDebuggee.performRequests(); 1.155 + }); 1.156 +}