Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / client / netmonitor / test / browser_net_json-malformed.js
blob0e29e07e9dd2878b14aa08c8ac36407455224d45
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 /**
7 * Tests if malformed JSON responses are handled correctly.
8 */
10 add_task(async function () {
11 const {
12 L10N,
13 } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
14 const { tab, monitor } = await initNetMonitor(JSON_MALFORMED_URL, {
15 requestCount: 1,
16 });
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));
27 // Execute requests.
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(
37 document,
38 getDisplayedRequests(store.getState()),
39 getSortedRequests(store.getState())[0],
40 "GET",
41 CONTENT_TYPE_SJS + "?fmt=json-malformed",
43 status: 200,
44 statusText: "OK",
45 type: "json",
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");
53 await wait;
55 const tabpanel = document.querySelector("#response-panel");
56 is(
57 tabpanel.querySelector(".response-error-header") === null,
58 false,
59 "The response error header doesn't have the intended visibility."
61 is(
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."
67 is(
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") || {};
74 is(
75 jsonView.textContent === L10N.getStr("jsonScopeName"),
76 false,
77 "The response json view doesn't have the intended visibility."
79 is(
80 tabpanel.querySelector(".CodeMirror-code") === null,
81 false,
82 "The response editor has the intended visibility."
84 is(
85 tabpanel.querySelector(".response-image-box") === null,
86 true,
87 "The response image box doesn't have the intended visibility."
90 is(
91 getCodeMirrorValue(monitor),
92 '{ "greeting": "Hello malformed JSON!" },',
93 "The text shown in the source editor is incorrect."
96 await teardown(monitor);
97 });