browser/devtools/netmonitor/test/browser_net_json-long.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 very long JSON responses are handled correctly.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 initNetMonitor(JSON_LONG_URL).then(([aTab, aDebuggee, aMonitor]) => {
michael@0 10 info("Starting test... ");
michael@0 11
michael@0 12 // This is receiving over 80 KB of json and will populate over 6000 items
michael@0 13 // in a variables view instance. Debug builds are slow.
michael@0 14 requestLongerTimeout(4);
michael@0 15
michael@0 16 let { document, L10N, NetMonitorView } = aMonitor.panelWin;
michael@0 17 let { RequestsMenu } = NetMonitorView;
michael@0 18
michael@0 19 RequestsMenu.lazyUpdate = false;
michael@0 20
michael@0 21 waitForNetworkEvents(aMonitor, 1).then(() => {
michael@0 22 verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
michael@0 23 "GET", CONTENT_TYPE_SJS + "?fmt=json-long", {
michael@0 24 status: 200,
michael@0 25 statusText: "OK",
michael@0 26 type: "json",
michael@0 27 fullMimeType: "text/json; charset=utf-8",
michael@0 28 size: L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(85975/1024, 2)),
michael@0 29 time: true
michael@0 30 });
michael@0 31
michael@0 32 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED, () => {
michael@0 33 testResponseTab();
michael@0 34 teardown(aMonitor).then(finish);
michael@0 35 });
michael@0 36
michael@0 37 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 38 document.getElementById("details-pane-toggle"));
michael@0 39 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 40 document.querySelectorAll("#details-pane tab")[3]);
michael@0 41
michael@0 42 function testResponseTab() {
michael@0 43 let tab = document.querySelectorAll("#details-pane tab")[3];
michael@0 44 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
michael@0 45
michael@0 46 is(tab.getAttribute("selected"), "true",
michael@0 47 "The response tab in the network details pane should be selected.");
michael@0 48
michael@0 49 is(tabpanel.querySelector("#response-content-info-header")
michael@0 50 .hasAttribute("hidden"), true,
michael@0 51 "The response info header doesn't have the intended visibility.");
michael@0 52 is(tabpanel.querySelector("#response-content-json-box")
michael@0 53 .hasAttribute("hidden"), false,
michael@0 54 "The response content json box doesn't have the intended visibility.");
michael@0 55 is(tabpanel.querySelector("#response-content-textarea-box")
michael@0 56 .hasAttribute("hidden"), true,
michael@0 57 "The response content textarea box doesn't have the intended visibility.");
michael@0 58 is(tabpanel.querySelector("#response-content-image-box")
michael@0 59 .hasAttribute("hidden"), true,
michael@0 60 "The response content image box doesn't have the intended visibility.");
michael@0 61
michael@0 62 is(tabpanel.querySelectorAll(".variables-view-scope").length, 1,
michael@0 63 "There should be 1 json scope displayed in this tabpanel.");
michael@0 64 is(tabpanel.querySelectorAll(".variables-view-property").length, 6143,
michael@0 65 "There should be 6143 json properties displayed in this tabpanel.");
michael@0 66 is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
michael@0 67 "The empty notice should not be displayed in this tabpanel.");
michael@0 68
michael@0 69 let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
michael@0 70 let names = ".variables-view-property > .title > .name";
michael@0 71 let values = ".variables-view-property > .title > .value";
michael@0 72
michael@0 73 is(jsonScope.querySelector(".name").getAttribute("value"),
michael@0 74 L10N.getStr("jsonScopeName"),
michael@0 75 "The json scope doesn't have the correct title.");
michael@0 76
michael@0 77 is(jsonScope.querySelectorAll(names)[0].getAttribute("value"),
michael@0 78 "0", "The first json property name was incorrect.");
michael@0 79 is(jsonScope.querySelectorAll(values)[0].getAttribute("value"),
michael@0 80 "Object", "The first json property value was incorrect.");
michael@0 81
michael@0 82 is(jsonScope.querySelectorAll(names)[1].getAttribute("value"),
michael@0 83 "greeting", "The second json property name was incorrect.");
michael@0 84 is(jsonScope.querySelectorAll(values)[1].getAttribute("value"),
michael@0 85 "\"Hello long string JSON!\"", "The second json property value was incorrect.");
michael@0 86 }
michael@0 87 });
michael@0 88
michael@0 89 aDebuggee.performRequests();
michael@0 90 });
michael@0 91 }

mercurial