|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if malformed JSON responses are handled correctly. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(JSON_MALFORMED_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
10 info("Starting test... "); |
|
11 |
|
12 let { document, Editor, 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-malformed", { |
|
20 status: 200, |
|
21 statusText: "OK", |
|
22 type: "json", |
|
23 fullMimeType: "text/json; charset=utf-8" |
|
24 }); |
|
25 |
|
26 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
27 document.getElementById("details-pane-toggle")); |
|
28 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
29 document.querySelectorAll("#details-pane tab")[3]); |
|
30 |
|
31 let tab = document.querySelectorAll("#details-pane tab")[3]; |
|
32 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; |
|
33 |
|
34 let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED; |
|
35 waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED).then(() => { |
|
36 is(tab.getAttribute("selected"), "true", |
|
37 "The response tab in the network details pane should be selected."); |
|
38 |
|
39 is(tabpanel.querySelector("#response-content-info-header") |
|
40 .hasAttribute("hidden"), false, |
|
41 "The response info header doesn't have the intended visibility."); |
|
42 is(tabpanel.querySelector("#response-content-info-header") |
|
43 .getAttribute("value"), |
|
44 "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 40 of the JSON data", |
|
45 "The response info header doesn't have the intended value attribute."); |
|
46 is(tabpanel.querySelector("#response-content-info-header") |
|
47 .getAttribute("tooltiptext"), |
|
48 "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 40 of the JSON data", |
|
49 "The response info header doesn't have the intended tooltiptext attribute."); |
|
50 |
|
51 is(tabpanel.querySelector("#response-content-json-box") |
|
52 .hasAttribute("hidden"), true, |
|
53 "The response content json box doesn't have the intended visibility."); |
|
54 is(tabpanel.querySelector("#response-content-textarea-box") |
|
55 .hasAttribute("hidden"), false, |
|
56 "The response content textarea box doesn't have the intended visibility."); |
|
57 is(tabpanel.querySelector("#response-content-image-box") |
|
58 .hasAttribute("hidden"), true, |
|
59 "The response content image box doesn't have the intended visibility."); |
|
60 |
|
61 NetMonitorView.editor("#response-content-textarea").then((aEditor) => { |
|
62 is(aEditor.getText(), "{ \"greeting\": \"Hello malformed JSON!\" },", |
|
63 "The text shown in the source editor is incorrect."); |
|
64 is(aEditor.getMode(), Editor.modes.js, |
|
65 "The mode active in the source editor is incorrect."); |
|
66 |
|
67 teardown(aMonitor).then(finish); |
|
68 }); |
|
69 }); |
|
70 }); |
|
71 |
|
72 aDebuggee.performRequests(); |
|
73 }); |
|
74 } |