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