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 whether complex request params and payload sent via POST are michael@0: * displayed correctly. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(PARAMS_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: let { document, L10N, EVENTS, Editor, 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: Task.spawn(function () { michael@0: yield waitForNetworkEvents(aMonitor, 0, 6); 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")[2]); michael@0: michael@0: yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); michael@0: yield testParamsTab1('a', '""', '{ "foo": "bar" }', '""'); michael@0: michael@0: RequestsMenu.selectedIndex = 1; michael@0: yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); michael@0: yield testParamsTab1('a', '"b"', '{ "foo": "bar" }', '""'); michael@0: michael@0: RequestsMenu.selectedIndex = 2; michael@0: yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); michael@0: yield testParamsTab1('a', '"b"', 'foo', '"bar"'); michael@0: michael@0: RequestsMenu.selectedIndex = 3; michael@0: yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); michael@0: yield testParamsTab2('a', '""', '{ "foo": "bar" }', "js"); michael@0: michael@0: RequestsMenu.selectedIndex = 4; michael@0: yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); michael@0: yield testParamsTab2('a', '"b"', '{ "foo": "bar" }', "js"); michael@0: michael@0: RequestsMenu.selectedIndex = 5; michael@0: yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); michael@0: yield testParamsTab2('a', '"b"', '?foo=bar', "text"); michael@0: michael@0: yield teardown(aMonitor); michael@0: finish(); michael@0: }); michael@0: michael@0: function testParamsTab1( michael@0: aQueryStringParamName, aQueryStringParamValue, aFormDataParamName, aFormDataParamValue) michael@0: { 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, 2, michael@0: "The number of param scopes displayed in this tabpanel is incorrect."); michael@0: is(tabpanel.querySelectorAll(".variable-or-property").length, 2, michael@0: "The number of param values displayed in this tabpanel is incorrect."); 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: 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: let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; michael@0: let formDataScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; 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: is(formDataScope.querySelector(".name").getAttribute("value"), michael@0: L10N.getStr("paramsFormData"), michael@0: "The form data scope doesn't have the correct title."); michael@0: michael@0: is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), michael@0: aQueryStringParamName, michael@0: "The first query string param name was incorrect."); michael@0: is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), michael@0: aQueryStringParamValue, michael@0: "The first query string param value was incorrect."); michael@0: michael@0: is(formDataScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), michael@0: aFormDataParamName, michael@0: "The first form data param name was incorrect."); michael@0: is(formDataScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), michael@0: aFormDataParamValue, michael@0: "The first form data param value was incorrect."); michael@0: } michael@0: michael@0: function testParamsTab2( michael@0: aQueryStringParamName, aQueryStringParamValue, aRequestPayload, aEditorMode) michael@0: { 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, 2, michael@0: "The number of param scopes displayed in this tabpanel is incorrect."); michael@0: is(tabpanel.querySelectorAll(".variable-or-property").length, 1, michael@0: "The number of param values displayed in this tabpanel is incorrect."); 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: 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"), false, michael@0: "The request post data textarea box should not be hidden."); michael@0: michael@0: let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; michael@0: let payloadScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; 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: is(payloadScope.querySelector(".name").getAttribute("value"), michael@0: L10N.getStr("paramsPostPayload"), michael@0: "The request payload scope doesn't have the correct title."); michael@0: michael@0: is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), michael@0: aQueryStringParamName, michael@0: "The first query string param name was incorrect."); michael@0: is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), michael@0: aQueryStringParamValue, michael@0: "The first query string param value was incorrect."); michael@0: michael@0: return NetMonitorView.editor("#request-post-data-textarea").then((aEditor) => { michael@0: is(aEditor.getText(), aRequestPayload, michael@0: "The text shown in the source editor is incorrect."); michael@0: is(aEditor.getMode(), Editor.modes[aEditorMode], michael@0: "The mode active in the source editor is incorrect."); michael@0: }); michael@0: } michael@0: michael@0: aDebuggee.performRequests(); michael@0: }); michael@0: }