browser/devtools/netmonitor/test/browser_net_post-data-03.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:d2185a3f370f
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Tests if the POST requests display the correct information in the UI,
6 * for raw payloads with content-type headers attached to the upload stream.
7 */
8
9 function test() {
10 initNetMonitor(POST_RAW_WITH_HEADERS_URL).then(([aTab, aDebuggee, aMonitor]) => {
11 info("Starting test... ");
12
13 let { document, L10N, NetMonitorView } = aMonitor.panelWin;
14 let { RequestsMenu, NetworkDetails } = NetMonitorView;
15 let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED;
16 RequestsMenu.lazyUpdate = false;
17
18 Task.spawn(function*() {
19 yield waitForNetworkEvents(aMonitor, 0, 1);
20
21 NetMonitorView.toggleDetailsPane({ visible: true });
22 RequestsMenu.selectedIndex = 0;
23
24 yield waitFor(aMonitor.panelWin, TAB_UPDATED);
25
26 let tab = document.querySelectorAll("#details-pane tab")[0];
27 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
28 let requestFromUploadScope = tabpanel.querySelectorAll(".variables-view-scope")[2];
29
30 is(tab.getAttribute("selected"), "true",
31 "The headers tab in the network details pane should be selected.");
32 is(tabpanel.querySelectorAll(".variables-view-scope").length, 3,
33 "There should be 3 header scopes displayed in this tabpanel.");
34
35 is(requestFromUploadScope.querySelector(".name").getAttribute("value"),
36 L10N.getStr("requestHeadersFromUpload") + " (" +
37 L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(74/1024, 3)) + ")",
38 "The request headers from upload scope doesn't have the correct title.");
39
40 is(requestFromUploadScope.querySelectorAll(".variables-view-variable").length, 2,
41 "There should be 2 header values displayed in the request headers from upload scope.");
42
43 is(requestFromUploadScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
44 "content-type", "The first request header name was incorrect.");
45 is(requestFromUploadScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
46 "\"application/x-www-form-urlencoded\"", "The first request header value was incorrect.");
47 is(requestFromUploadScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"),
48 "custom-header", "The second request header name was incorrect.");
49 is(requestFromUploadScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"),
50 "\"hello world!\"", "The second request header value was incorrect.");
51
52 EventUtils.sendMouseEvent({ type: "mousedown" },
53 document.querySelectorAll("#details-pane tab")[2]);
54
55 yield waitFor(aMonitor.panelWin, TAB_UPDATED);
56
57 let tab = document.querySelectorAll("#details-pane tab")[2];
58 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
59 let formDataScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
60
61 is(tab.getAttribute("selected"), "true",
62 "The response tab in the network details pane should be selected.");
63 is(tabpanel.querySelectorAll(".variables-view-scope").length, 1,
64 "There should be 1 header scope displayed in this tabpanel.");
65
66 is(formDataScope.querySelector(".name").getAttribute("value"),
67 L10N.getStr("paramsFormData"),
68 "The form data scope doesn't have the correct title.");
69
70 is(formDataScope.querySelectorAll(".variables-view-variable").length, 2,
71 "There should be 2 payload values displayed in the form data scope.");
72
73 is(formDataScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
74 "foo", "The first payload param name was incorrect.");
75 is(formDataScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
76 "\"bar\"", "The first payload param value was incorrect.");
77 is(formDataScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"),
78 "baz", "The second payload param name was incorrect.");
79 is(formDataScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"),
80 "\"123\"", "The second payload param value was incorrect.");
81
82 teardown(aMonitor).then(finish);
83 });
84
85 aDebuggee.performRequests();
86 });
87 }

mercurial