1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Tests if malformed JSON responses are handled correctly.
10 add_task(async
function () {
13 } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
14 const { tab
, monitor
} = await
initNetMonitor(JSON_MALFORMED_URL
, {
17 info("Starting test... ");
19 const { document
, store
, windowRequire
} = monitor
.panelWin
;
20 const Actions
= windowRequire("devtools/client/netmonitor/src/actions/index");
21 const { getDisplayedRequests
, getSortedRequests
} = windowRequire(
22 "devtools/client/netmonitor/src/selectors/index"
25 store
.dispatch(Actions
.batchEnable(false));
28 await
performRequests(monitor
, tab
, 1);
30 const requestItem
= document
.querySelector(".request-list-item");
31 const requestsListStatus
= requestItem
.querySelector(".status-code");
32 EventUtils
.sendMouseEvent({ type
: "mouseover" }, requestsListStatus
);
33 await
waitUntil(() => requestsListStatus
.title
);
34 await
waitForDOMIfNeeded(requestItem
, ".requests-list-timings-total");
36 verifyRequestItemTarget(
38 getDisplayedRequests(store
.getState()),
39 getSortedRequests(store
.getState())[0],
41 CONTENT_TYPE_SJS
+ "?fmt=json-malformed",
46 fullMimeType
: "text/json; charset=utf-8",
50 const wait
= waitForDOM(document
, "#response-panel .CodeMirror-code");
51 store
.dispatch(Actions
.toggleNetworkDetails());
52 clickOnSidebarTab(document
, "response");
55 const tabpanel
= document
.querySelector("#response-panel");
57 tabpanel
.querySelector(".response-error-header") === null,
59 "The response error header doesn't have the intended visibility."
62 tabpanel
.querySelector(".response-error-header").textContent
,
63 "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data" +
64 " at line 1 column 40 of the JSON data",
65 "The response error header doesn't have the intended text content."
68 tabpanel
.querySelector(".response-error-header").getAttribute("title"),
69 "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data" +
70 " at line 1 column 40 of the JSON data",
71 "The response error header doesn't have the intended tooltiptext attribute."
73 const jsonView
= tabpanel
.querySelector(".tree-section .treeLabel") || {};
75 jsonView
.textContent
=== L10N
.getStr("jsonScopeName"),
77 "The response json view doesn't have the intended visibility."
80 tabpanel
.querySelector(".CodeMirror-code") === null,
82 "The response editor has the intended visibility."
85 tabpanel
.querySelector(".response-image-box") === null,
87 "The response image box doesn't have the intended visibility."
91 getCodeMirrorValue(monitor
),
92 '{ "greeting": "Hello malformed JSON!" },',
93 "The text shown in the source editor is incorrect."
96 await
teardown(monitor
);