Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Tests if the POST requests display the correct information in the UI. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | initNetMonitor(POST_DATA_URL).then(([aTab, aDebuggee, aMonitor]) => { |
michael@0 | 10 | info("Starting test... "); |
michael@0 | 11 | |
michael@0 | 12 | let { document, L10N, Editor, NetMonitorView } = aMonitor.panelWin; |
michael@0 | 13 | let { RequestsMenu, NetworkDetails } = NetMonitorView; |
michael@0 | 14 | |
michael@0 | 15 | RequestsMenu.lazyUpdate = false; |
michael@0 | 16 | NetworkDetails._params.lazyEmpty = false; |
michael@0 | 17 | |
michael@0 | 18 | waitForNetworkEvents(aMonitor, 0, 2).then(() => { |
michael@0 | 19 | verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), |
michael@0 | 20 | "POST", SIMPLE_SJS + "?foo=bar&baz=42&type=urlencoded", { |
michael@0 | 21 | status: 200, |
michael@0 | 22 | statusText: "Och Aye", |
michael@0 | 23 | type: "plain", |
michael@0 | 24 | fullMimeType: "text/plain; charset=utf-8", |
michael@0 | 25 | size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), |
michael@0 | 26 | time: true |
michael@0 | 27 | }); |
michael@0 | 28 | verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1), |
michael@0 | 29 | "POST", SIMPLE_SJS + "?foo=bar&baz=42&type=multipart", { |
michael@0 | 30 | status: 200, |
michael@0 | 31 | statusText: "Och Aye", |
michael@0 | 32 | type: "plain", |
michael@0 | 33 | fullMimeType: "text/plain; charset=utf-8", |
michael@0 | 34 | size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), |
michael@0 | 35 | time: true |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 39 | document.getElementById("details-pane-toggle")); |
michael@0 | 40 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 41 | document.querySelectorAll("#details-pane tab")[2]); |
michael@0 | 42 | |
michael@0 | 43 | let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED; |
michael@0 | 44 | waitFor(aMonitor.panelWin, TAB_UPDATED).then(() => |
michael@0 | 45 | testParamsTab("urlencoded") |
michael@0 | 46 | ).then(() => { |
michael@0 | 47 | RequestsMenu.selectedIndex = 1; |
michael@0 | 48 | return waitFor(aMonitor.panelWin, TAB_UPDATED); |
michael@0 | 49 | }).then(() => testParamsTab("multipart")) |
michael@0 | 50 | .then(() => teardown(aMonitor)) |
michael@0 | 51 | .then(finish); |
michael@0 | 52 | |
michael@0 | 53 | function testParamsTab(aType) { |
michael@0 | 54 | let tab = document.querySelectorAll("#details-pane tab")[2]; |
michael@0 | 55 | let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; |
michael@0 | 56 | |
michael@0 | 57 | is(tab.getAttribute("selected"), "true", |
michael@0 | 58 | "The params tab in the network details pane should be selected."); |
michael@0 | 59 | |
michael@0 | 60 | function checkVisibility(aBox) { |
michael@0 | 61 | is(tabpanel.querySelector("#request-params-box") |
michael@0 | 62 | .hasAttribute("hidden"), !aBox.contains("params"), |
michael@0 | 63 | "The request params box doesn't have the indended visibility."); |
michael@0 | 64 | is(tabpanel.querySelector("#request-post-data-textarea-box") |
michael@0 | 65 | .hasAttribute("hidden"), !aBox.contains("textarea"), |
michael@0 | 66 | "The request post data textarea box doesn't have the indended visibility."); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, |
michael@0 | 70 | "There should be 2 param scopes displayed in this tabpanel."); |
michael@0 | 71 | is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
michael@0 | 72 | "The empty notice should not be displayed in this tabpanel."); |
michael@0 | 73 | |
michael@0 | 74 | let queryScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
michael@0 | 75 | let postScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; |
michael@0 | 76 | |
michael@0 | 77 | is(queryScope.querySelector(".name").getAttribute("value"), |
michael@0 | 78 | L10N.getStr("paramsQueryString"), |
michael@0 | 79 | "The query scope doesn't have the correct title."); |
michael@0 | 80 | |
michael@0 | 81 | is(postScope.querySelector(".name").getAttribute("value"), |
michael@0 | 82 | L10N.getStr(aType == "urlencoded" ? "paramsFormData" : "paramsPostPayload"), |
michael@0 | 83 | "The post scope doesn't have the correct title."); |
michael@0 | 84 | |
michael@0 | 85 | is(queryScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
michael@0 | 86 | "foo", "The first query param name was incorrect."); |
michael@0 | 87 | is(queryScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
michael@0 | 88 | "\"bar\"", "The first query param value was incorrect."); |
michael@0 | 89 | is(queryScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"), |
michael@0 | 90 | "baz", "The second query param name was incorrect."); |
michael@0 | 91 | is(queryScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"), |
michael@0 | 92 | "\"42\"", "The second query param value was incorrect."); |
michael@0 | 93 | is(queryScope.querySelectorAll(".variables-view-variable .name")[2].getAttribute("value"), |
michael@0 | 94 | "type", "The third query param name was incorrect."); |
michael@0 | 95 | is(queryScope.querySelectorAll(".variables-view-variable .value")[2].getAttribute("value"), |
michael@0 | 96 | "\"" + aType + "\"", "The third query param value was incorrect."); |
michael@0 | 97 | |
michael@0 | 98 | if (aType == "urlencoded") { |
michael@0 | 99 | checkVisibility("params"); |
michael@0 | 100 | |
michael@0 | 101 | is(tabpanel.querySelectorAll(".variables-view-variable").length, 5, |
michael@0 | 102 | "There should be 5 param values displayed in this tabpanel."); |
michael@0 | 103 | is(queryScope.querySelectorAll(".variables-view-variable").length, 3, |
michael@0 | 104 | "There should be 3 param values displayed in the query scope."); |
michael@0 | 105 | is(postScope.querySelectorAll(".variables-view-variable").length, 2, |
michael@0 | 106 | "There should be 2 param values displayed in the post scope."); |
michael@0 | 107 | |
michael@0 | 108 | is(postScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
michael@0 | 109 | "foo", "The first post param name was incorrect."); |
michael@0 | 110 | is(postScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
michael@0 | 111 | "\"bar\"", "The first post param value was incorrect."); |
michael@0 | 112 | is(postScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"), |
michael@0 | 113 | "baz", "The second post param name was incorrect."); |
michael@0 | 114 | is(postScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"), |
michael@0 | 115 | "\"123\"", "The second post param value was incorrect."); |
michael@0 | 116 | |
michael@0 | 117 | return promise.resolve(); |
michael@0 | 118 | } |
michael@0 | 119 | else { |
michael@0 | 120 | checkVisibility("params textarea"); |
michael@0 | 121 | |
michael@0 | 122 | is(tabpanel.querySelectorAll(".variables-view-variable").length, 3, |
michael@0 | 123 | "There should be 3 param values displayed in this tabpanel."); |
michael@0 | 124 | is(queryScope.querySelectorAll(".variables-view-variable").length, 3, |
michael@0 | 125 | "There should be 3 param values displayed in the query scope."); |
michael@0 | 126 | is(postScope.querySelectorAll(".variables-view-variable").length, 0, |
michael@0 | 127 | "There should be 0 param values displayed in the post scope."); |
michael@0 | 128 | |
michael@0 | 129 | return NetMonitorView.editor("#request-post-data-textarea").then((aEditor) => { |
michael@0 | 130 | ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"text\""), |
michael@0 | 131 | "The text shown in the source editor is incorrect (1.1)."); |
michael@0 | 132 | ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"email\""), |
michael@0 | 133 | "The text shown in the source editor is incorrect (2.1)."); |
michael@0 | 134 | ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"range\""), |
michael@0 | 135 | "The text shown in the source editor is incorrect (3.1)."); |
michael@0 | 136 | ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"Custom field\""), |
michael@0 | 137 | "The text shown in the source editor is incorrect (4.1)."); |
michael@0 | 138 | ok(aEditor.getText().contains("Some text..."), |
michael@0 | 139 | "The text shown in the source editor is incorrect (2.2)."); |
michael@0 | 140 | ok(aEditor.getText().contains("42"), |
michael@0 | 141 | "The text shown in the source editor is incorrect (3.2)."); |
michael@0 | 142 | ok(aEditor.getText().contains("Extra data"), |
michael@0 | 143 | "The text shown in the source editor is incorrect (4.2)."); |
michael@0 | 144 | is(aEditor.getMode(), Editor.modes.text, |
michael@0 | 145 | "The mode active in the source editor is incorrect."); |
michael@0 | 146 | }); |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | }); |
michael@0 | 150 | |
michael@0 | 151 | aDebuggee.performRequests(); |
michael@0 | 152 | }); |
michael@0 | 153 | } |