|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if JSONP responses are handled correctly. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(JSONP_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._json.lazyEmpty = false; |
|
17 |
|
18 waitForNetworkEvents(aMonitor, 2).then(() => { |
|
19 verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), |
|
20 "GET", CONTENT_TYPE_SJS + "?fmt=jsonp&jsonp=$_0123Fun", { |
|
21 status: 200, |
|
22 statusText: "OK", |
|
23 type: "json", |
|
24 fullMimeType: "text/json; charset=utf-8", |
|
25 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04), |
|
26 time: true |
|
27 }); |
|
28 verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1), |
|
29 "GET", CONTENT_TYPE_SJS + "?fmt=jsonp2&jsonp=$_4567Sad", { |
|
30 status: 200, |
|
31 statusText: "OK", |
|
32 type: "json", |
|
33 fullMimeType: "text/json; charset=utf-8", |
|
34 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.05), |
|
35 time: true |
|
36 }); |
|
37 |
|
38 Task.spawn(function*() { |
|
39 let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED; |
|
40 |
|
41 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
42 document.getElementById("details-pane-toggle")); |
|
43 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
44 document.querySelectorAll("#details-pane tab")[3]); |
|
45 |
|
46 yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED); |
|
47 testResponseTab("$_0123Fun", "\"Hello JSONP!\""); |
|
48 |
|
49 RequestsMenu.selectedIndex = 1; |
|
50 |
|
51 yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED); |
|
52 testResponseTab("$_4567Sad", "\"Hello weird JSONP!\""); |
|
53 |
|
54 yield teardown(aMonitor); |
|
55 finish(); |
|
56 }); |
|
57 |
|
58 function testResponseTab(aFunction, aGreeting) { |
|
59 let tab = document.querySelectorAll("#details-pane tab")[3]; |
|
60 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; |
|
61 |
|
62 is(tab.getAttribute("selected"), "true", |
|
63 "The response tab in the network details pane should be selected."); |
|
64 |
|
65 is(tabpanel.querySelector("#response-content-info-header") |
|
66 .hasAttribute("hidden"), true, |
|
67 "The response info header doesn't have the intended visibility."); |
|
68 is(tabpanel.querySelector("#response-content-json-box") |
|
69 .hasAttribute("hidden"), false, |
|
70 "The response content json box doesn't have the intended visibility."); |
|
71 is(tabpanel.querySelector("#response-content-textarea-box") |
|
72 .hasAttribute("hidden"), true, |
|
73 "The response content textarea box doesn't have the intended visibility."); |
|
74 is(tabpanel.querySelector("#response-content-image-box") |
|
75 .hasAttribute("hidden"), true, |
|
76 "The response content image box doesn't have the intended visibility."); |
|
77 |
|
78 is(tabpanel.querySelectorAll(".variables-view-scope").length, 1, |
|
79 "There should be 1 json scope displayed in this tabpanel."); |
|
80 is(tabpanel.querySelectorAll(".variables-view-property").length, 2, |
|
81 "There should be 2 json properties displayed in this tabpanel."); |
|
82 is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
|
83 "The empty notice should not be displayed in this tabpanel."); |
|
84 |
|
85 let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
|
86 |
|
87 is(jsonScope.querySelector(".name").getAttribute("value"), |
|
88 L10N.getFormatStr("jsonpScopeName", aFunction), |
|
89 "The json scope doesn't have the correct title."); |
|
90 |
|
91 is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"), |
|
92 "greeting", "The first json property name was incorrect."); |
|
93 is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"), |
|
94 aGreeting, "The first json property value was incorrect."); |
|
95 |
|
96 is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"), |
|
97 "__proto__", "The second json property name was incorrect."); |
|
98 is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"), |
|
99 "Object", "The second json property value was incorrect."); |
|
100 } |
|
101 }); |
|
102 |
|
103 aDebuggee.performRequests(); |
|
104 }); |
|
105 } |