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 requests display the correct status code and text in the UI. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(STATUS_CODES_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._params.lazyEmpty = false; michael@0: michael@0: waitForNetworkEvents(aMonitor, 5).then(() => { michael@0: let requestItems = []; michael@0: michael@0: verifyRequestItemTarget(requestItems[0] = RequestsMenu.getItemAtIndex(0), michael@0: "GET", STATUS_CODES_SJS + "?sts=100", { michael@0: status: 101, michael@0: statusText: "Switching Protocols", michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0), michael@0: time: true michael@0: }); michael@0: verifyRequestItemTarget(requestItems[1] = RequestsMenu.getItemAtIndex(1), michael@0: "GET", STATUS_CODES_SJS + "?sts=200", { michael@0: status: 202, michael@0: statusText: "Created", michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02), michael@0: time: true michael@0: }); michael@0: verifyRequestItemTarget(requestItems[2] = RequestsMenu.getItemAtIndex(2), michael@0: "GET", STATUS_CODES_SJS + "?sts=300", { michael@0: status: 303, michael@0: statusText: "See Other", michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0), michael@0: time: true michael@0: }); michael@0: verifyRequestItemTarget(requestItems[3] = RequestsMenu.getItemAtIndex(3), michael@0: "GET", STATUS_CODES_SJS + "?sts=400", { michael@0: status: 404, michael@0: statusText: "Not Found", michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02), michael@0: time: true michael@0: }); michael@0: verifyRequestItemTarget(requestItems[4] = RequestsMenu.getItemAtIndex(4), michael@0: "GET", STATUS_CODES_SJS + "?sts=500", { michael@0: status: 501, michael@0: statusText: "Not Implemented", michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02), michael@0: time: true michael@0: }); michael@0: michael@0: // Test summaries... michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: document.querySelectorAll("#details-pane tab")[0]); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[0].target); michael@0: testSummary("GET", STATUS_CODES_SJS + "?sts=100", "101", "Switching Protocols"); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[1].target); michael@0: testSummary("GET", STATUS_CODES_SJS + "?sts=200", "202", "Created"); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[2].target); michael@0: testSummary("GET", STATUS_CODES_SJS + "?sts=300", "303", "See Other"); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[3].target); michael@0: testSummary("GET", STATUS_CODES_SJS + "?sts=400", "404", "Not Found"); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[4].target); michael@0: testSummary("GET", STATUS_CODES_SJS + "?sts=500", "501", "Not Implemented"); michael@0: michael@0: // Test params... michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: document.querySelectorAll("#details-pane tab")[2]); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[0].target); michael@0: testParamsTab("\"100\""); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[1].target); michael@0: testParamsTab("\"200\""); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[2].target); michael@0: testParamsTab("\"300\""); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[3].target); michael@0: testParamsTab("\"400\""); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[4].target); michael@0: testParamsTab("\"500\""); michael@0: michael@0: // We're done here. michael@0: teardown(aMonitor).then(finish); michael@0: michael@0: function testSummary(aMethod, aUrl, aStatus, aStatusText) { michael@0: let tab = document.querySelectorAll("#details-pane tab")[0]; michael@0: let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0]; michael@0: michael@0: is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"), michael@0: aUrl, "The url summary value is incorrect."); michael@0: is(tabpanel.querySelector("#headers-summary-method-value").getAttribute("value"), michael@0: aMethod, "The method summary value is incorrect."); michael@0: is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"), michael@0: aStatus, "The status summary code is incorrect."); michael@0: is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"), michael@0: aStatus + " " + aStatusText, "The status summary value is incorrect."); michael@0: } michael@0: michael@0: function testParamsTab(aStatusParamValue) { michael@0: let tab = document.querySelectorAll("#details-pane tab")[2]; michael@0: let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; michael@0: michael@0: is(tabpanel.querySelectorAll(".variables-view-scope").length, 1, michael@0: "There should be 1 param scope displayed in this tabpanel."); michael@0: is(tabpanel.querySelectorAll(".variable-or-property").length, 1, michael@0: "There should be 1 param value 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 paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; michael@0: michael@0: is(paramsScope.querySelector(".name").getAttribute("value"), michael@0: L10N.getStr("paramsQueryString"), michael@0: "The params scope doesn't have the correct title."); michael@0: michael@0: is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), michael@0: "sts", "The param name was incorrect."); michael@0: is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), michael@0: aStatusParamValue, "The param value was incorrect."); michael@0: michael@0: is(tabpanel.querySelector("#request-params-box") michael@0: .hasAttribute("hidden"), false, michael@0: "The request params box should not be hidden."); michael@0: is(tabpanel.querySelector("#request-post-data-textarea-box") michael@0: .hasAttribute("hidden"), true, michael@0: "The request post data textarea box should be hidden."); michael@0: } michael@0: }); michael@0: michael@0: aDebuggee.performRequests(); michael@0: }); michael@0: }