browser/devtools/netmonitor/test/browser_net_jsonp.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 JSONP responses are handled correctly.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 initNetMonitor(JSONP_URL).then(([aTab, aDebuggee, aMonitor]) => {
michael@0 10 info("Starting test... ");
michael@0 11
michael@0 12 let { document, L10N, NetMonitorView } = aMonitor.panelWin;
michael@0 13 let { RequestsMenu, NetworkDetails } = NetMonitorView;
michael@0 14
michael@0 15 RequestsMenu.lazyUpdate = false;
michael@0 16 NetworkDetails._json.lazyEmpty = false;
michael@0 17
michael@0 18 waitForNetworkEvents(aMonitor, 2).then(() => {
michael@0 19 verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
michael@0 20 "GET", CONTENT_TYPE_SJS + "?fmt=jsonp&jsonp=$_0123Fun", {
michael@0 21 status: 200,
michael@0 22 statusText: "OK",
michael@0 23 type: "json",
michael@0 24 fullMimeType: "text/json; charset=utf-8",
michael@0 25 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04),
michael@0 26 time: true
michael@0 27 });
michael@0 28 verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1),
michael@0 29 "GET", CONTENT_TYPE_SJS + "?fmt=jsonp2&jsonp=$_4567Sad", {
michael@0 30 status: 200,
michael@0 31 statusText: "OK",
michael@0 32 type: "json",
michael@0 33 fullMimeType: "text/json; charset=utf-8",
michael@0 34 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.05),
michael@0 35 time: true
michael@0 36 });
michael@0 37
michael@0 38 Task.spawn(function*() {
michael@0 39 let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED;
michael@0 40
michael@0 41 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 42 document.getElementById("details-pane-toggle"));
michael@0 43 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 44 document.querySelectorAll("#details-pane tab")[3]);
michael@0 45
michael@0 46 yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED);
michael@0 47 testResponseTab("$_0123Fun", "\"Hello JSONP!\"");
michael@0 48
michael@0 49 RequestsMenu.selectedIndex = 1;
michael@0 50
michael@0 51 yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED);
michael@0 52 testResponseTab("$_4567Sad", "\"Hello weird JSONP!\"");
michael@0 53
michael@0 54 yield teardown(aMonitor);
michael@0 55 finish();
michael@0 56 });
michael@0 57
michael@0 58 function testResponseTab(aFunction, aGreeting) {
michael@0 59 let tab = document.querySelectorAll("#details-pane tab")[3];
michael@0 60 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
michael@0 61
michael@0 62 is(tab.getAttribute("selected"), "true",
michael@0 63 "The response tab in the network details pane should be selected.");
michael@0 64
michael@0 65 is(tabpanel.querySelector("#response-content-info-header")
michael@0 66 .hasAttribute("hidden"), true,
michael@0 67 "The response info header doesn't have the intended visibility.");
michael@0 68 is(tabpanel.querySelector("#response-content-json-box")
michael@0 69 .hasAttribute("hidden"), false,
michael@0 70 "The response content json box doesn't have the intended visibility.");
michael@0 71 is(tabpanel.querySelector("#response-content-textarea-box")
michael@0 72 .hasAttribute("hidden"), true,
michael@0 73 "The response content textarea box doesn't have the intended visibility.");
michael@0 74 is(tabpanel.querySelector("#response-content-image-box")
michael@0 75 .hasAttribute("hidden"), true,
michael@0 76 "The response content image box doesn't have the intended visibility.");
michael@0 77
michael@0 78 is(tabpanel.querySelectorAll(".variables-view-scope").length, 1,
michael@0 79 "There should be 1 json scope displayed in this tabpanel.");
michael@0 80 is(tabpanel.querySelectorAll(".variables-view-property").length, 2,
michael@0 81 "There should be 2 json properties displayed in this tabpanel.");
michael@0 82 is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
michael@0 83 "The empty notice should not be displayed in this tabpanel.");
michael@0 84
michael@0 85 let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
michael@0 86
michael@0 87 is(jsonScope.querySelector(".name").getAttribute("value"),
michael@0 88 L10N.getFormatStr("jsonpScopeName", aFunction),
michael@0 89 "The json scope doesn't have the correct title.");
michael@0 90
michael@0 91 is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"),
michael@0 92 "greeting", "The first json property name was incorrect.");
michael@0 93 is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"),
michael@0 94 aGreeting, "The first json property value was incorrect.");
michael@0 95
michael@0 96 is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"),
michael@0 97 "__proto__", "The second json property name was incorrect.");
michael@0 98 is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"),
michael@0 99 "Object", "The second json property value was incorrect.");
michael@0 100 }
michael@0 101 });
michael@0 102
michael@0 103 aDebuggee.performRequests();
michael@0 104 });
michael@0 105 }

mercurial