michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if malformed JSON responses are handled correctly. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(JSON_MALFORMED_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: let { document, Editor, NetMonitorView } = aMonitor.panelWin; michael@0: let { RequestsMenu } = NetMonitorView; michael@0: michael@0: RequestsMenu.lazyUpdate = false; michael@0: michael@0: waitForNetworkEvents(aMonitor, 1).then(() => { michael@0: verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), michael@0: "GET", CONTENT_TYPE_SJS + "?fmt=json-malformed", { michael@0: status: 200, michael@0: statusText: "OK", michael@0: type: "json", michael@0: fullMimeType: "text/json; charset=utf-8" michael@0: }); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: document.getElementById("details-pane-toggle")); michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: document.querySelectorAll("#details-pane tab")[3]); michael@0: michael@0: let tab = document.querySelectorAll("#details-pane tab")[3]; michael@0: let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; michael@0: michael@0: let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED; michael@0: waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED).then(() => { michael@0: is(tab.getAttribute("selected"), "true", michael@0: "The response tab in the network details pane should be selected."); michael@0: michael@0: is(tabpanel.querySelector("#response-content-info-header") michael@0: .hasAttribute("hidden"), false, michael@0: "The response info header doesn't have the intended visibility."); michael@0: is(tabpanel.querySelector("#response-content-info-header") michael@0: .getAttribute("value"), michael@0: "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 40 of the JSON data", michael@0: "The response info header doesn't have the intended value attribute."); michael@0: is(tabpanel.querySelector("#response-content-info-header") michael@0: .getAttribute("tooltiptext"), michael@0: "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 40 of the JSON data", michael@0: "The response info header doesn't have the intended tooltiptext attribute."); michael@0: michael@0: is(tabpanel.querySelector("#response-content-json-box") michael@0: .hasAttribute("hidden"), true, michael@0: "The response content json box doesn't have the intended visibility."); michael@0: is(tabpanel.querySelector("#response-content-textarea-box") michael@0: .hasAttribute("hidden"), false, michael@0: "The response content textarea box doesn't have the intended visibility."); michael@0: is(tabpanel.querySelector("#response-content-image-box") michael@0: .hasAttribute("hidden"), true, michael@0: "The response content image box doesn't have the intended visibility."); michael@0: michael@0: NetMonitorView.editor("#response-content-textarea").then((aEditor) => { michael@0: is(aEditor.getText(), "{ \"greeting\": \"Hello malformed JSON!\" },", michael@0: "The text shown in the source editor is incorrect."); michael@0: is(aEditor.getMode(), Editor.modes.js, michael@0: "The mode active in the source editor is incorrect."); michael@0: michael@0: teardown(aMonitor).then(finish); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: aDebuggee.performRequests(); michael@0: }); michael@0: }