Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Tests whether complex request params and payload sent via POST are |
michael@0 | 6 | * displayed correctly. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | function test() { |
michael@0 | 10 | initNetMonitor(PARAMS_URL).then(([aTab, aDebuggee, aMonitor]) => { |
michael@0 | 11 | info("Starting test... "); |
michael@0 | 12 | |
michael@0 | 13 | let { document, L10N, EVENTS, Editor, NetMonitorView } = aMonitor.panelWin; |
michael@0 | 14 | let { RequestsMenu, NetworkDetails } = NetMonitorView; |
michael@0 | 15 | |
michael@0 | 16 | RequestsMenu.lazyUpdate = false; |
michael@0 | 17 | NetworkDetails._params.lazyEmpty = false; |
michael@0 | 18 | |
michael@0 | 19 | Task.spawn(function () { |
michael@0 | 20 | yield waitForNetworkEvents(aMonitor, 0, 6); |
michael@0 | 21 | |
michael@0 | 22 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 23 | document.getElementById("details-pane-toggle")); |
michael@0 | 24 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 25 | document.querySelectorAll("#details-pane tab")[2]); |
michael@0 | 26 | |
michael@0 | 27 | yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
michael@0 | 28 | yield testParamsTab1('a', '""', '{ "foo": "bar" }', '""'); |
michael@0 | 29 | |
michael@0 | 30 | RequestsMenu.selectedIndex = 1; |
michael@0 | 31 | yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
michael@0 | 32 | yield testParamsTab1('a', '"b"', '{ "foo": "bar" }', '""'); |
michael@0 | 33 | |
michael@0 | 34 | RequestsMenu.selectedIndex = 2; |
michael@0 | 35 | yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
michael@0 | 36 | yield testParamsTab1('a', '"b"', 'foo', '"bar"'); |
michael@0 | 37 | |
michael@0 | 38 | RequestsMenu.selectedIndex = 3; |
michael@0 | 39 | yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
michael@0 | 40 | yield testParamsTab2('a', '""', '{ "foo": "bar" }', "js"); |
michael@0 | 41 | |
michael@0 | 42 | RequestsMenu.selectedIndex = 4; |
michael@0 | 43 | yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
michael@0 | 44 | yield testParamsTab2('a', '"b"', '{ "foo": "bar" }', "js"); |
michael@0 | 45 | |
michael@0 | 46 | RequestsMenu.selectedIndex = 5; |
michael@0 | 47 | yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED); |
michael@0 | 48 | yield testParamsTab2('a', '"b"', '?foo=bar', "text"); |
michael@0 | 49 | |
michael@0 | 50 | yield teardown(aMonitor); |
michael@0 | 51 | finish(); |
michael@0 | 52 | }); |
michael@0 | 53 | |
michael@0 | 54 | function testParamsTab1( |
michael@0 | 55 | aQueryStringParamName, aQueryStringParamValue, aFormDataParamName, aFormDataParamValue) |
michael@0 | 56 | { |
michael@0 | 57 | let tab = document.querySelectorAll("#details-pane tab")[2]; |
michael@0 | 58 | let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; |
michael@0 | 59 | |
michael@0 | 60 | is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, |
michael@0 | 61 | "The number of param scopes displayed in this tabpanel is incorrect."); |
michael@0 | 62 | is(tabpanel.querySelectorAll(".variable-or-property").length, 2, |
michael@0 | 63 | "The number of param values displayed in this tabpanel is incorrect."); |
michael@0 | 64 | is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
michael@0 | 65 | "The empty notice should not be displayed in this tabpanel."); |
michael@0 | 66 | |
michael@0 | 67 | is(tabpanel.querySelector("#request-params-box") |
michael@0 | 68 | .hasAttribute("hidden"), false, |
michael@0 | 69 | "The request params box should not be hidden."); |
michael@0 | 70 | is(tabpanel.querySelector("#request-post-data-textarea-box") |
michael@0 | 71 | .hasAttribute("hidden"), true, |
michael@0 | 72 | "The request post data textarea box should be hidden."); |
michael@0 | 73 | |
michael@0 | 74 | let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
michael@0 | 75 | let formDataScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; |
michael@0 | 76 | |
michael@0 | 77 | is(paramsScope.querySelector(".name").getAttribute("value"), |
michael@0 | 78 | L10N.getStr("paramsQueryString"), |
michael@0 | 79 | "The params scope doesn't have the correct title."); |
michael@0 | 80 | is(formDataScope.querySelector(".name").getAttribute("value"), |
michael@0 | 81 | L10N.getStr("paramsFormData"), |
michael@0 | 82 | "The form data scope doesn't have the correct title."); |
michael@0 | 83 | |
michael@0 | 84 | is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
michael@0 | 85 | aQueryStringParamName, |
michael@0 | 86 | "The first query string param name was incorrect."); |
michael@0 | 87 | is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
michael@0 | 88 | aQueryStringParamValue, |
michael@0 | 89 | "The first query string param value was incorrect."); |
michael@0 | 90 | |
michael@0 | 91 | is(formDataScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
michael@0 | 92 | aFormDataParamName, |
michael@0 | 93 | "The first form data param name was incorrect."); |
michael@0 | 94 | is(formDataScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
michael@0 | 95 | aFormDataParamValue, |
michael@0 | 96 | "The first form data param value was incorrect."); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function testParamsTab2( |
michael@0 | 100 | aQueryStringParamName, aQueryStringParamValue, aRequestPayload, aEditorMode) |
michael@0 | 101 | { |
michael@0 | 102 | let tab = document.querySelectorAll("#details-pane tab")[2]; |
michael@0 | 103 | let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; |
michael@0 | 104 | |
michael@0 | 105 | is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, |
michael@0 | 106 | "The number of param scopes displayed in this tabpanel is incorrect."); |
michael@0 | 107 | is(tabpanel.querySelectorAll(".variable-or-property").length, 1, |
michael@0 | 108 | "The number of param values displayed in this tabpanel is incorrect."); |
michael@0 | 109 | is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
michael@0 | 110 | "The empty notice should not be displayed in this tabpanel."); |
michael@0 | 111 | |
michael@0 | 112 | is(tabpanel.querySelector("#request-params-box") |
michael@0 | 113 | .hasAttribute("hidden"), false, |
michael@0 | 114 | "The request params box should not be hidden."); |
michael@0 | 115 | is(tabpanel.querySelector("#request-post-data-textarea-box") |
michael@0 | 116 | .hasAttribute("hidden"), false, |
michael@0 | 117 | "The request post data textarea box should not be hidden."); |
michael@0 | 118 | |
michael@0 | 119 | let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
michael@0 | 120 | let payloadScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; |
michael@0 | 121 | |
michael@0 | 122 | is(paramsScope.querySelector(".name").getAttribute("value"), |
michael@0 | 123 | L10N.getStr("paramsQueryString"), |
michael@0 | 124 | "The params scope doesn't have the correct title."); |
michael@0 | 125 | is(payloadScope.querySelector(".name").getAttribute("value"), |
michael@0 | 126 | L10N.getStr("paramsPostPayload"), |
michael@0 | 127 | "The request payload scope doesn't have the correct title."); |
michael@0 | 128 | |
michael@0 | 129 | is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
michael@0 | 130 | aQueryStringParamName, |
michael@0 | 131 | "The first query string param name was incorrect."); |
michael@0 | 132 | is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
michael@0 | 133 | aQueryStringParamValue, |
michael@0 | 134 | "The first query string param value was incorrect."); |
michael@0 | 135 | |
michael@0 | 136 | return NetMonitorView.editor("#request-post-data-textarea").then((aEditor) => { |
michael@0 | 137 | is(aEditor.getText(), aRequestPayload, |
michael@0 | 138 | "The text shown in the source editor is incorrect."); |
michael@0 | 139 | is(aEditor.getMode(), Editor.modes[aEditorMode], |
michael@0 | 140 | "The mode active in the source editor is incorrect."); |
michael@0 | 141 | }); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | aDebuggee.performRequests(); |
michael@0 | 145 | }); |
michael@0 | 146 | } |