1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_json-malformed.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Tests if malformed JSON responses are handled correctly. 1.9 + */ 1.10 + 1.11 +function test() { 1.12 + initNetMonitor(JSON_MALFORMED_URL).then(([aTab, aDebuggee, aMonitor]) => { 1.13 + info("Starting test... "); 1.14 + 1.15 + let { document, Editor, NetMonitorView } = aMonitor.panelWin; 1.16 + let { RequestsMenu } = NetMonitorView; 1.17 + 1.18 + RequestsMenu.lazyUpdate = false; 1.19 + 1.20 + waitForNetworkEvents(aMonitor, 1).then(() => { 1.21 + verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), 1.22 + "GET", CONTENT_TYPE_SJS + "?fmt=json-malformed", { 1.23 + status: 200, 1.24 + statusText: "OK", 1.25 + type: "json", 1.26 + fullMimeType: "text/json; charset=utf-8" 1.27 + }); 1.28 + 1.29 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.30 + document.getElementById("details-pane-toggle")); 1.31 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.32 + document.querySelectorAll("#details-pane tab")[3]); 1.33 + 1.34 + let tab = document.querySelectorAll("#details-pane tab")[3]; 1.35 + let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; 1.36 + 1.37 + let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED; 1.38 + waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED).then(() => { 1.39 + is(tab.getAttribute("selected"), "true", 1.40 + "The response tab in the network details pane should be selected."); 1.41 + 1.42 + is(tabpanel.querySelector("#response-content-info-header") 1.43 + .hasAttribute("hidden"), false, 1.44 + "The response info header doesn't have the intended visibility."); 1.45 + is(tabpanel.querySelector("#response-content-info-header") 1.46 + .getAttribute("value"), 1.47 + "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 40 of the JSON data", 1.48 + "The response info header doesn't have the intended value attribute."); 1.49 + is(tabpanel.querySelector("#response-content-info-header") 1.50 + .getAttribute("tooltiptext"), 1.51 + "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 40 of the JSON data", 1.52 + "The response info header doesn't have the intended tooltiptext attribute."); 1.53 + 1.54 + is(tabpanel.querySelector("#response-content-json-box") 1.55 + .hasAttribute("hidden"), true, 1.56 + "The response content json box doesn't have the intended visibility."); 1.57 + is(tabpanel.querySelector("#response-content-textarea-box") 1.58 + .hasAttribute("hidden"), false, 1.59 + "The response content textarea box doesn't have the intended visibility."); 1.60 + is(tabpanel.querySelector("#response-content-image-box") 1.61 + .hasAttribute("hidden"), true, 1.62 + "The response content image box doesn't have the intended visibility."); 1.63 + 1.64 + NetMonitorView.editor("#response-content-textarea").then((aEditor) => { 1.65 + is(aEditor.getText(), "{ \"greeting\": \"Hello malformed JSON!\" },", 1.66 + "The text shown in the source editor is incorrect."); 1.67 + is(aEditor.getMode(), Editor.modes.js, 1.68 + "The mode active in the source editor is incorrect."); 1.69 + 1.70 + teardown(aMonitor).then(finish); 1.71 + }); 1.72 + }); 1.73 + }); 1.74 + 1.75 + aDebuggee.performRequests(); 1.76 + }); 1.77 +}