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 the POST requests display the correct information in the UI. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(POST_DATA_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: let { document, L10N, 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: waitForNetworkEvents(aMonitor, 0, 2).then(() => { michael@0: verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0), michael@0: "POST", SIMPLE_SJS + "?foo=bar&baz=42&type=urlencoded", { michael@0: status: 200, michael@0: statusText: "Och Aye", michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), michael@0: time: true michael@0: }); michael@0: verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1), michael@0: "POST", SIMPLE_SJS + "?foo=bar&baz=42&type=multipart", { michael@0: status: 200, michael@0: statusText: "Och Aye", michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), michael@0: time: true michael@0: }); 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: let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED; michael@0: waitFor(aMonitor.panelWin, TAB_UPDATED).then(() => michael@0: testParamsTab("urlencoded") michael@0: ).then(() => { michael@0: RequestsMenu.selectedIndex = 1; michael@0: return waitFor(aMonitor.panelWin, TAB_UPDATED); michael@0: }).then(() => testParamsTab("multipart")) michael@0: .then(() => teardown(aMonitor)) michael@0: .then(finish); michael@0: michael@0: function testParamsTab(aType) { 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(tab.getAttribute("selected"), "true", michael@0: "The params tab in the network details pane should be selected."); michael@0: michael@0: function checkVisibility(aBox) { michael@0: is(tabpanel.querySelector("#request-params-box") michael@0: .hasAttribute("hidden"), !aBox.contains("params"), michael@0: "The request params box doesn't have the indended visibility."); michael@0: is(tabpanel.querySelector("#request-post-data-textarea-box") michael@0: .hasAttribute("hidden"), !aBox.contains("textarea"), michael@0: "The request post data textarea box doesn't have the indended visibility."); michael@0: } michael@0: michael@0: is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, michael@0: "There should be 2 param scopes 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 queryScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; michael@0: let postScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; michael@0: michael@0: is(queryScope.querySelector(".name").getAttribute("value"), michael@0: L10N.getStr("paramsQueryString"), michael@0: "The query scope doesn't have the correct title."); michael@0: michael@0: is(postScope.querySelector(".name").getAttribute("value"), michael@0: L10N.getStr(aType == "urlencoded" ? "paramsFormData" : "paramsPostPayload"), michael@0: "The post scope doesn't have the correct title."); michael@0: michael@0: is(queryScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), michael@0: "foo", "The first query param name was incorrect."); michael@0: is(queryScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), michael@0: "\"bar\"", "The first query param value was incorrect."); michael@0: is(queryScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"), michael@0: "baz", "The second query param name was incorrect."); michael@0: is(queryScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"), michael@0: "\"42\"", "The second query param value was incorrect."); michael@0: is(queryScope.querySelectorAll(".variables-view-variable .name")[2].getAttribute("value"), michael@0: "type", "The third query param name was incorrect."); michael@0: is(queryScope.querySelectorAll(".variables-view-variable .value")[2].getAttribute("value"), michael@0: "\"" + aType + "\"", "The third query param value was incorrect."); michael@0: michael@0: if (aType == "urlencoded") { michael@0: checkVisibility("params"); michael@0: michael@0: is(tabpanel.querySelectorAll(".variables-view-variable").length, 5, michael@0: "There should be 5 param values displayed in this tabpanel."); michael@0: is(queryScope.querySelectorAll(".variables-view-variable").length, 3, michael@0: "There should be 3 param values displayed in the query scope."); michael@0: is(postScope.querySelectorAll(".variables-view-variable").length, 2, michael@0: "There should be 2 param values displayed in the post scope."); michael@0: michael@0: is(postScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), michael@0: "foo", "The first post param name was incorrect."); michael@0: is(postScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), michael@0: "\"bar\"", "The first post param value was incorrect."); michael@0: is(postScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"), michael@0: "baz", "The second post param name was incorrect."); michael@0: is(postScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"), michael@0: "\"123\"", "The second post param value was incorrect."); michael@0: michael@0: return promise.resolve(); michael@0: } michael@0: else { michael@0: checkVisibility("params textarea"); michael@0: michael@0: is(tabpanel.querySelectorAll(".variables-view-variable").length, 3, michael@0: "There should be 3 param values displayed in this tabpanel."); michael@0: is(queryScope.querySelectorAll(".variables-view-variable").length, 3, michael@0: "There should be 3 param values displayed in the query scope."); michael@0: is(postScope.querySelectorAll(".variables-view-variable").length, 0, michael@0: "There should be 0 param values displayed in the post scope."); michael@0: michael@0: return NetMonitorView.editor("#request-post-data-textarea").then((aEditor) => { michael@0: ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"text\""), michael@0: "The text shown in the source editor is incorrect (1.1)."); michael@0: ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"email\""), michael@0: "The text shown in the source editor is incorrect (2.1)."); michael@0: ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"range\""), michael@0: "The text shown in the source editor is incorrect (3.1)."); michael@0: ok(aEditor.getText().contains("Content-Disposition: form-data; name=\"Custom field\""), michael@0: "The text shown in the source editor is incorrect (4.1)."); michael@0: ok(aEditor.getText().contains("Some text..."), michael@0: "The text shown in the source editor is incorrect (2.2)."); michael@0: ok(aEditor.getText().contains("42"), michael@0: "The text shown in the source editor is incorrect (3.2)."); michael@0: ok(aEditor.getText().contains("Extra data"), michael@0: "The text shown in the source editor is incorrect (4.2)."); michael@0: is(aEditor.getMode(), Editor.modes.text, michael@0: "The mode active in the source editor is incorrect."); michael@0: }); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: aDebuggee.performRequests(); michael@0: }); michael@0: }