|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if JSON responses with unusal/custom MIME types are handled correctly. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(JSON_TEXT_MIME_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
10 info("Starting test... "); |
|
11 |
|
12 let { document, L10N, NetMonitorView } = aMonitor.panelWin; |
|
13 let { RequestsMenu } = NetMonitorView; |
|
14 |
|
15 RequestsMenu.lazyUpdate = false; |
|
16 |
|
17 waitForNetworkEvents(aMonitor, 1).then(() => { |
|
18 verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), |
|
19 "GET", CONTENT_TYPE_SJS + "?fmt=json-text-mime", { |
|
20 status: 200, |
|
21 statusText: "OK", |
|
22 type: "plain", |
|
23 fullMimeType: "text/plain; charset=utf-8", |
|
24 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04), |
|
25 time: true |
|
26 }); |
|
27 |
|
28 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
29 document.getElementById("details-pane-toggle")); |
|
30 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
31 document.querySelectorAll("#details-pane tab")[3]); |
|
32 |
|
33 let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED; |
|
34 waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED) |
|
35 .then(testResponseTab) |
|
36 .then(() => teardown(aMonitor)) |
|
37 .then(finish); |
|
38 |
|
39 function testResponseTab() { |
|
40 let tab = document.querySelectorAll("#details-pane tab")[3]; |
|
41 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; |
|
42 |
|
43 is(tab.getAttribute("selected"), "true", |
|
44 "The response tab in the network details pane should be selected."); |
|
45 |
|
46 is(tabpanel.querySelector("#response-content-info-header") |
|
47 .hasAttribute("hidden"), true, |
|
48 "The response info header doesn't have the intended visibility."); |
|
49 is(tabpanel.querySelector("#response-content-json-box") |
|
50 .hasAttribute("hidden"), false, |
|
51 "The response content json box doesn't have the intended visibility."); |
|
52 is(tabpanel.querySelector("#response-content-textarea-box") |
|
53 .hasAttribute("hidden"), true, |
|
54 "The response content textarea box doesn't have the intended visibility."); |
|
55 is(tabpanel.querySelector("#response-content-image-box") |
|
56 .hasAttribute("hidden"), true, |
|
57 "The response content image box doesn't have the intended visibility."); |
|
58 |
|
59 is(tabpanel.querySelectorAll(".variables-view-scope").length, 1, |
|
60 "There should be 1 json scope displayed in this tabpanel."); |
|
61 is(tabpanel.querySelectorAll(".variables-view-property").length, 2, |
|
62 "There should be 2 json properties displayed in this tabpanel."); |
|
63 is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
|
64 "The empty notice should not be displayed in this tabpanel."); |
|
65 |
|
66 let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
|
67 is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"), |
|
68 "greeting", "The first json property name was incorrect."); |
|
69 is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"), |
|
70 "\"Hello third-party JSON!\"", "The first json property value was incorrect."); |
|
71 |
|
72 is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"), |
|
73 "__proto__", "The second json property name was incorrect."); |
|
74 is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"), |
|
75 "Object", "The second json property value was incorrect."); |
|
76 } |
|
77 }); |
|
78 |
|
79 aDebuggee.performRequests(); |
|
80 }); |
|
81 } |