browser/devtools/netmonitor/test/browser_net_json-malformed.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial