|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests whether complex request params and payload sent via POST are |
|
6 * displayed correctly. |
|
7 */ |
|
8 |
|
9 function test() { |
|
10 initNetMonitor(PARAMS_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
11 info("Starting test... "); |
|
12 |
|
13 let { document, L10N, EVENTS, Editor, NetMonitorView } = aMonitor.panelWin; |
|
14 let { RequestsMenu, NetworkDetails } = NetMonitorView; |
|
15 |
|
16 RequestsMenu.lazyUpdate = false; |
|
17 NetworkDetails._params.lazyEmpty = false; |
|
18 |
|
19 Task.spawn(function () { |
|
20 yield waitForNetworkEvents(aMonitor, 0, 6); |
|
21 |
|
22 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
23 document.getElementById("details-pane-toggle")); |
|
24 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
25 document.querySelectorAll("#details-pane tab")[2]); |
|
26 |
|
27 yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
|
28 yield testParamsTab1('a', '""', '{ "foo": "bar" }', '""'); |
|
29 |
|
30 RequestsMenu.selectedIndex = 1; |
|
31 yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
|
32 yield testParamsTab1('a', '"b"', '{ "foo": "bar" }', '""'); |
|
33 |
|
34 RequestsMenu.selectedIndex = 2; |
|
35 yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
|
36 yield testParamsTab1('a', '"b"', 'foo', '"bar"'); |
|
37 |
|
38 RequestsMenu.selectedIndex = 3; |
|
39 yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
|
40 yield testParamsTab2('a', '""', '{ "foo": "bar" }', "js"); |
|
41 |
|
42 RequestsMenu.selectedIndex = 4; |
|
43 yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
|
44 yield testParamsTab2('a', '"b"', '{ "foo": "bar" }', "js"); |
|
45 |
|
46 RequestsMenu.selectedIndex = 5; |
|
47 yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
|
48 yield testParamsTab2('a', '"b"', '?foo=bar', "text"); |
|
49 |
|
50 yield teardown(aMonitor); |
|
51 finish(); |
|
52 }); |
|
53 |
|
54 function testParamsTab1( |
|
55 aQueryStringParamName, aQueryStringParamValue, aFormDataParamName, aFormDataParamValue) |
|
56 { |
|
57 let tab = document.querySelectorAll("#details-pane tab")[2]; |
|
58 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; |
|
59 |
|
60 is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, |
|
61 "The number of param scopes displayed in this tabpanel is incorrect."); |
|
62 is(tabpanel.querySelectorAll(".variable-or-property").length, 2, |
|
63 "The number of param values displayed in this tabpanel is incorrect."); |
|
64 is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
|
65 "The empty notice should not be displayed in this tabpanel."); |
|
66 |
|
67 is(tabpanel.querySelector("#request-params-box") |
|
68 .hasAttribute("hidden"), false, |
|
69 "The request params box should not be hidden."); |
|
70 is(tabpanel.querySelector("#request-post-data-textarea-box") |
|
71 .hasAttribute("hidden"), true, |
|
72 "The request post data textarea box should be hidden."); |
|
73 |
|
74 let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
|
75 let formDataScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; |
|
76 |
|
77 is(paramsScope.querySelector(".name").getAttribute("value"), |
|
78 L10N.getStr("paramsQueryString"), |
|
79 "The params scope doesn't have the correct title."); |
|
80 is(formDataScope.querySelector(".name").getAttribute("value"), |
|
81 L10N.getStr("paramsFormData"), |
|
82 "The form data scope doesn't have the correct title."); |
|
83 |
|
84 is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
|
85 aQueryStringParamName, |
|
86 "The first query string param name was incorrect."); |
|
87 is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
|
88 aQueryStringParamValue, |
|
89 "The first query string param value was incorrect."); |
|
90 |
|
91 is(formDataScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
|
92 aFormDataParamName, |
|
93 "The first form data param name was incorrect."); |
|
94 is(formDataScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
|
95 aFormDataParamValue, |
|
96 "The first form data param value was incorrect."); |
|
97 } |
|
98 |
|
99 function testParamsTab2( |
|
100 aQueryStringParamName, aQueryStringParamValue, aRequestPayload, aEditorMode) |
|
101 { |
|
102 let tab = document.querySelectorAll("#details-pane tab")[2]; |
|
103 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; |
|
104 |
|
105 is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, |
|
106 "The number of param scopes displayed in this tabpanel is incorrect."); |
|
107 is(tabpanel.querySelectorAll(".variable-or-property").length, 1, |
|
108 "The number of param values displayed in this tabpanel is incorrect."); |
|
109 is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
|
110 "The empty notice should not be displayed in this tabpanel."); |
|
111 |
|
112 is(tabpanel.querySelector("#request-params-box") |
|
113 .hasAttribute("hidden"), false, |
|
114 "The request params box should not be hidden."); |
|
115 is(tabpanel.querySelector("#request-post-data-textarea-box") |
|
116 .hasAttribute("hidden"), false, |
|
117 "The request post data textarea box should not be hidden."); |
|
118 |
|
119 let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
|
120 let payloadScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; |
|
121 |
|
122 is(paramsScope.querySelector(".name").getAttribute("value"), |
|
123 L10N.getStr("paramsQueryString"), |
|
124 "The params scope doesn't have the correct title."); |
|
125 is(payloadScope.querySelector(".name").getAttribute("value"), |
|
126 L10N.getStr("paramsPostPayload"), |
|
127 "The request payload scope doesn't have the correct title."); |
|
128 |
|
129 is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
|
130 aQueryStringParamName, |
|
131 "The first query string param name was incorrect."); |
|
132 is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
|
133 aQueryStringParamValue, |
|
134 "The first query string param value was incorrect."); |
|
135 |
|
136 return NetMonitorView.editor("#request-post-data-textarea").then((aEditor) => { |
|
137 is(aEditor.getText(), aRequestPayload, |
|
138 "The text shown in the source editor is incorrect."); |
|
139 is(aEditor.getMode(), Editor.modes[aEditorMode], |
|
140 "The mode active in the source editor is incorrect."); |
|
141 }); |
|
142 } |
|
143 |
|
144 aDebuggee.performRequests(); |
|
145 }); |
|
146 } |