|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if requests display the correct status code and text in the UI. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(STATUS_CODES_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
10 info("Starting test... "); |
|
11 |
|
12 let { document, L10N, NetMonitorView } = aMonitor.panelWin; |
|
13 let { RequestsMenu, NetworkDetails } = NetMonitorView; |
|
14 |
|
15 RequestsMenu.lazyUpdate = false; |
|
16 NetworkDetails._params.lazyEmpty = false; |
|
17 |
|
18 waitForNetworkEvents(aMonitor, 5).then(() => { |
|
19 let requestItems = []; |
|
20 |
|
21 verifyRequestItemTarget(requestItems[0] = RequestsMenu.getItemAtIndex(0), |
|
22 "GET", STATUS_CODES_SJS + "?sts=100", { |
|
23 status: 101, |
|
24 statusText: "Switching Protocols", |
|
25 type: "plain", |
|
26 fullMimeType: "text/plain; charset=utf-8", |
|
27 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0), |
|
28 time: true |
|
29 }); |
|
30 verifyRequestItemTarget(requestItems[1] = RequestsMenu.getItemAtIndex(1), |
|
31 "GET", STATUS_CODES_SJS + "?sts=200", { |
|
32 status: 202, |
|
33 statusText: "Created", |
|
34 type: "plain", |
|
35 fullMimeType: "text/plain; charset=utf-8", |
|
36 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02), |
|
37 time: true |
|
38 }); |
|
39 verifyRequestItemTarget(requestItems[2] = RequestsMenu.getItemAtIndex(2), |
|
40 "GET", STATUS_CODES_SJS + "?sts=300", { |
|
41 status: 303, |
|
42 statusText: "See Other", |
|
43 type: "plain", |
|
44 fullMimeType: "text/plain; charset=utf-8", |
|
45 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0), |
|
46 time: true |
|
47 }); |
|
48 verifyRequestItemTarget(requestItems[3] = RequestsMenu.getItemAtIndex(3), |
|
49 "GET", STATUS_CODES_SJS + "?sts=400", { |
|
50 status: 404, |
|
51 statusText: "Not Found", |
|
52 type: "plain", |
|
53 fullMimeType: "text/plain; charset=utf-8", |
|
54 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02), |
|
55 time: true |
|
56 }); |
|
57 verifyRequestItemTarget(requestItems[4] = RequestsMenu.getItemAtIndex(4), |
|
58 "GET", STATUS_CODES_SJS + "?sts=500", { |
|
59 status: 501, |
|
60 statusText: "Not Implemented", |
|
61 type: "plain", |
|
62 fullMimeType: "text/plain; charset=utf-8", |
|
63 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02), |
|
64 time: true |
|
65 }); |
|
66 |
|
67 // Test summaries... |
|
68 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
69 document.querySelectorAll("#details-pane tab")[0]); |
|
70 |
|
71 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[0].target); |
|
72 testSummary("GET", STATUS_CODES_SJS + "?sts=100", "101", "Switching Protocols"); |
|
73 |
|
74 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[1].target); |
|
75 testSummary("GET", STATUS_CODES_SJS + "?sts=200", "202", "Created"); |
|
76 |
|
77 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[2].target); |
|
78 testSummary("GET", STATUS_CODES_SJS + "?sts=300", "303", "See Other"); |
|
79 |
|
80 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[3].target); |
|
81 testSummary("GET", STATUS_CODES_SJS + "?sts=400", "404", "Not Found"); |
|
82 |
|
83 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[4].target); |
|
84 testSummary("GET", STATUS_CODES_SJS + "?sts=500", "501", "Not Implemented"); |
|
85 |
|
86 // Test params... |
|
87 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
88 document.querySelectorAll("#details-pane tab")[2]); |
|
89 |
|
90 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[0].target); |
|
91 testParamsTab("\"100\""); |
|
92 |
|
93 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[1].target); |
|
94 testParamsTab("\"200\""); |
|
95 |
|
96 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[2].target); |
|
97 testParamsTab("\"300\""); |
|
98 |
|
99 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[3].target); |
|
100 testParamsTab("\"400\""); |
|
101 |
|
102 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[4].target); |
|
103 testParamsTab("\"500\""); |
|
104 |
|
105 // We're done here. |
|
106 teardown(aMonitor).then(finish); |
|
107 |
|
108 function testSummary(aMethod, aUrl, aStatus, aStatusText) { |
|
109 let tab = document.querySelectorAll("#details-pane tab")[0]; |
|
110 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0]; |
|
111 |
|
112 is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"), |
|
113 aUrl, "The url summary value is incorrect."); |
|
114 is(tabpanel.querySelector("#headers-summary-method-value").getAttribute("value"), |
|
115 aMethod, "The method summary value is incorrect."); |
|
116 is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"), |
|
117 aStatus, "The status summary code is incorrect."); |
|
118 is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"), |
|
119 aStatus + " " + aStatusText, "The status summary value is incorrect."); |
|
120 } |
|
121 |
|
122 function testParamsTab(aStatusParamValue) { |
|
123 let tab = document.querySelectorAll("#details-pane tab")[2]; |
|
124 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; |
|
125 |
|
126 is(tabpanel.querySelectorAll(".variables-view-scope").length, 1, |
|
127 "There should be 1 param scope displayed in this tabpanel."); |
|
128 is(tabpanel.querySelectorAll(".variable-or-property").length, 1, |
|
129 "There should be 1 param value displayed in this tabpanel."); |
|
130 is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
|
131 "The empty notice should not be displayed in this tabpanel."); |
|
132 |
|
133 let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
|
134 |
|
135 is(paramsScope.querySelector(".name").getAttribute("value"), |
|
136 L10N.getStr("paramsQueryString"), |
|
137 "The params scope doesn't have the correct title."); |
|
138 |
|
139 is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
|
140 "sts", "The param name was incorrect."); |
|
141 is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
|
142 aStatusParamValue, "The param value was incorrect."); |
|
143 |
|
144 is(tabpanel.querySelector("#request-params-box") |
|
145 .hasAttribute("hidden"), false, |
|
146 "The request params box should not be hidden."); |
|
147 is(tabpanel.querySelector("#request-post-data-textarea-box") |
|
148 .hasAttribute("hidden"), true, |
|
149 "The request post data textarea box should be hidden."); |
|
150 } |
|
151 }); |
|
152 |
|
153 aDebuggee.performRequests(); |
|
154 }); |
|
155 } |