1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_json_text_mime.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Tests if JSON responses with unusal/custom MIME types are handled correctly. 1.9 + */ 1.10 + 1.11 +function test() { 1.12 + initNetMonitor(JSON_TEXT_MIME_URL).then(([aTab, aDebuggee, aMonitor]) => { 1.13 + info("Starting test... "); 1.14 + 1.15 + let { document, L10N, NetMonitorView } = aMonitor.panelWin; 1.16 + let { RequestsMenu } = NetMonitorView; 1.17 + 1.18 + RequestsMenu.lazyUpdate = false; 1.19 + 1.20 + waitForNetworkEvents(aMonitor, 1).then(() => { 1.21 + verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), 1.22 + "GET", CONTENT_TYPE_SJS + "?fmt=json-text-mime", { 1.23 + status: 200, 1.24 + statusText: "OK", 1.25 + type: "plain", 1.26 + fullMimeType: "text/plain; charset=utf-8", 1.27 + size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04), 1.28 + time: true 1.29 + }); 1.30 + 1.31 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.32 + document.getElementById("details-pane-toggle")); 1.33 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.34 + document.querySelectorAll("#details-pane tab")[3]); 1.35 + 1.36 + let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED; 1.37 + waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED) 1.38 + .then(testResponseTab) 1.39 + .then(() => teardown(aMonitor)) 1.40 + .then(finish); 1.41 + 1.42 + function testResponseTab() { 1.43 + let tab = document.querySelectorAll("#details-pane tab")[3]; 1.44 + let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; 1.45 + 1.46 + is(tab.getAttribute("selected"), "true", 1.47 + "The response tab in the network details pane should be selected."); 1.48 + 1.49 + is(tabpanel.querySelector("#response-content-info-header") 1.50 + .hasAttribute("hidden"), true, 1.51 + "The response info header doesn't have the intended visibility."); 1.52 + is(tabpanel.querySelector("#response-content-json-box") 1.53 + .hasAttribute("hidden"), false, 1.54 + "The response content json box doesn't have the intended visibility."); 1.55 + is(tabpanel.querySelector("#response-content-textarea-box") 1.56 + .hasAttribute("hidden"), true, 1.57 + "The response content textarea box doesn't have the intended visibility."); 1.58 + is(tabpanel.querySelector("#response-content-image-box") 1.59 + .hasAttribute("hidden"), true, 1.60 + "The response content image box doesn't have the intended visibility."); 1.61 + 1.62 + is(tabpanel.querySelectorAll(".variables-view-scope").length, 1, 1.63 + "There should be 1 json scope displayed in this tabpanel."); 1.64 + is(tabpanel.querySelectorAll(".variables-view-property").length, 2, 1.65 + "There should be 2 json properties displayed in this tabpanel."); 1.66 + is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, 1.67 + "The empty notice should not be displayed in this tabpanel."); 1.68 + 1.69 + let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; 1.70 + is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"), 1.71 + "greeting", "The first json property name was incorrect."); 1.72 + is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"), 1.73 + "\"Hello third-party JSON!\"", "The first json property value was incorrect."); 1.74 + 1.75 + is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"), 1.76 + "__proto__", "The second json property name was incorrect."); 1.77 + is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"), 1.78 + "Object", "The second json property value was incorrect."); 1.79 + } 1.80 + }); 1.81 + 1.82 + aDebuggee.performRequests(); 1.83 + }); 1.84 +}