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.

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

mercurial