michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if JSONP responses are handled correctly. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(JSONP_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: let { document, L10N, NetMonitorView } = aMonitor.panelWin; michael@0: let { RequestsMenu, NetworkDetails } = NetMonitorView; michael@0: michael@0: RequestsMenu.lazyUpdate = false; michael@0: NetworkDetails._json.lazyEmpty = false; michael@0: michael@0: waitForNetworkEvents(aMonitor, 2).then(() => { michael@0: verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), michael@0: "GET", CONTENT_TYPE_SJS + "?fmt=jsonp&jsonp=$_0123Fun", { michael@0: status: 200, michael@0: statusText: "OK", michael@0: type: "json", michael@0: fullMimeType: "text/json; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04), michael@0: time: true michael@0: }); michael@0: verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1), michael@0: "GET", CONTENT_TYPE_SJS + "?fmt=jsonp2&jsonp=$_4567Sad", { michael@0: status: 200, michael@0: statusText: "OK", michael@0: type: "json", michael@0: fullMimeType: "text/json; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.05), michael@0: time: true michael@0: }); michael@0: michael@0: Task.spawn(function*() { michael@0: let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED; michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: document.getElementById("details-pane-toggle")); michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: document.querySelectorAll("#details-pane tab")[3]); michael@0: michael@0: yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED); michael@0: testResponseTab("$_0123Fun", "\"Hello JSONP!\""); michael@0: michael@0: RequestsMenu.selectedIndex = 1; michael@0: michael@0: yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED); michael@0: testResponseTab("$_4567Sad", "\"Hello weird JSONP!\""); michael@0: michael@0: yield teardown(aMonitor); michael@0: finish(); michael@0: }); michael@0: michael@0: function testResponseTab(aFunction, aGreeting) { michael@0: let tab = document.querySelectorAll("#details-pane tab")[3]; michael@0: let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; michael@0: michael@0: is(tab.getAttribute("selected"), "true", michael@0: "The response tab in the network details pane should be selected."); michael@0: michael@0: is(tabpanel.querySelector("#response-content-info-header") michael@0: .hasAttribute("hidden"), true, michael@0: "The response info header doesn't have the intended visibility."); michael@0: is(tabpanel.querySelector("#response-content-json-box") michael@0: .hasAttribute("hidden"), false, michael@0: "The response content json box doesn't have the intended visibility."); michael@0: is(tabpanel.querySelector("#response-content-textarea-box") michael@0: .hasAttribute("hidden"), true, michael@0: "The response content textarea box doesn't have the intended visibility."); michael@0: is(tabpanel.querySelector("#response-content-image-box") michael@0: .hasAttribute("hidden"), true, michael@0: "The response content image box doesn't have the intended visibility."); michael@0: michael@0: is(tabpanel.querySelectorAll(".variables-view-scope").length, 1, michael@0: "There should be 1 json scope displayed in this tabpanel."); michael@0: is(tabpanel.querySelectorAll(".variables-view-property").length, 2, michael@0: "There should be 2 json properties displayed in this tabpanel."); michael@0: is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, michael@0: "The empty notice should not be displayed in this tabpanel."); michael@0: michael@0: let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; michael@0: michael@0: is(jsonScope.querySelector(".name").getAttribute("value"), michael@0: L10N.getFormatStr("jsonpScopeName", aFunction), michael@0: "The json scope doesn't have the correct title."); michael@0: michael@0: is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"), michael@0: "greeting", "The first json property name was incorrect."); michael@0: is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"), michael@0: aGreeting, "The first json property value was incorrect."); michael@0: michael@0: is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"), michael@0: "__proto__", "The second json property name was incorrect."); michael@0: is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"), michael@0: "Object", "The second json property value was incorrect."); michael@0: } michael@0: }); michael@0: michael@0: aDebuggee.performRequests(); michael@0: }); michael@0: }