summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_url-preview.js
blob: c692f5c02d0c115a1f1fe0371c6589838ad86e29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests the url preview expanded state is persisted across requests selections.
 */

add_task(async function () {
  const { monitor, tab } = await initNetMonitor(PARAMS_URL, {
    requestCount: 1,
  });

  info("Starting test... ");

  const { document, store, windowRequire } = monitor.panelWin;
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");

  store.dispatch(Actions.batchEnable(false));

  // Execute requests.
  await performRequests(monitor, tab, 12);

  let wait = waitForDOM(document, "#headers-panel .url-preview", 1);
  EventUtils.sendMouseEvent(
    { type: "mousedown" },
    document.querySelectorAll(".request-list-item")[0]
  );
  await wait;

  // Expand preview
  await toggleUrlPreview(true, document, monitor);

  // Select the second request
  wait = waitForDOM(document, "#headers-panel .url-preview", 1);
  EventUtils.sendMouseEvent(
    { type: "mousedown" },
    document.querySelectorAll(".request-list-item")[1]
  );
  await wait;

  // Test that the url is still expanded
  const noOfVisibleRowsAfterExpand = document.querySelectorAll(
    "#headers-panel .url-preview tr.treeRow"
  ).length;
  ok(
    noOfVisibleRowsAfterExpand > 1,
    "The url preview should still be expanded."
  );

  // Collapse preview
  await toggleUrlPreview(false, document, monitor);

  // Select the third request
  wait = waitForDOM(document, "#headers-panel .url-preview", 1);
  EventUtils.sendMouseEvent(
    { type: "mousedown" },
    document.querySelectorAll(".request-list-item")[2]
  );
  await wait;

  // Test that the url is still collapsed
  const noOfVisibleRowsAfterCollapse = document.querySelectorAll(
    "#headers-panel .url-preview tr.treeRow"
  ).length;
  ok(
    noOfVisibleRowsAfterCollapse == 1,
    "The url preview should still be collapsed."
  );

  return teardown(monitor);
});

/**
 *  Checks if the query parameter arrays are formatted as we expected.
 */

add_task(async function () {
  const { monitor } = await initNetMonitor(PARAMS_URL, {
    requestCount: 1,
  });

  info("Starting test... ");

  const { document, store, windowRequire } = monitor.panelWin;
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");

  store.dispatch(Actions.batchEnable(false));

  const netWorkEvent = waitForNetworkEvents(monitor, 3);
  await performRequestsInContent([
    // URL with same parameter name with different values
    { url: "sjs_content-type-test-server.sjs?a=3&a=45&a=60" },

    // URL with mix of different parameter names
    { url: "sjs_content-type-test-server.sjs?x=5&a=3&a=4&a=3&b=3" },

    // URL contains a parameter with `query` as the name. This makes sure
    // there is no conflict with the query property on the Url Object in the
    // UrlPreview
    { url: "sjs_content-type-test-server.sjs?x=5&a=3&a=4&a=3&query=3" },

    // URL contains a paramter with `__proto__` as the name. This makes sure
    // there is no conflict with the prototype chain of the JS object.
    { url: "sjs_content-type-test-server.sjs?__proto__=5" },
  ]);
  await netWorkEvent;

  let urlPreview = waitForDOM(document, "#headers-panel .url-preview", 1);
  EventUtils.sendMouseEvent(
    { type: "mousedown" },
    document.querySelectorAll(".request-list-item")[0]
  );
  let urlPreviewValue = (await urlPreview)[0].textContent;

  ok(
    urlPreviewValue.endsWith("?a=3&a=45&a=60"),
    "The parameters in the url preview match."
  );

  urlPreview = waitForDOM(document, "#headers-panel .url-preview", 1);
  EventUtils.sendMouseEvent(
    { type: "mousedown" },
    document.querySelectorAll(".request-list-item")[1]
  );

  urlPreviewValue = (await urlPreview)[0].textContent;
  ok(
    urlPreviewValue.endsWith("?x=5&a=3&a=4&a=3&b=3"),
    "The parameters in the url preview match."
  );

  urlPreview = waitForDOM(document, "#headers-panel .url-preview", 1);
  EventUtils.sendMouseEvent(
    { type: "mousedown" },
    document.querySelectorAll(".request-list-item")[2]
  );

  urlPreviewValue = (await urlPreview)[0].textContent;
  ok(
    urlPreviewValue.endsWith("?x=5&a=3&a=4&a=3&query=3"),
    "The parameters in the url preview match."
  );

  // Expand preview
  await toggleUrlPreview(true, document, monitor);

  // Check if the expanded preview contains the "query" parameter
  is(
    document.querySelector(
      "#headers-panel .url-preview tr#\\/GET\\/query\\/query .treeLabelCell"
    ).textContent,
    "query",
    "Contains the query parameter"
  );

  // Collapse preview
  await toggleUrlPreview(false, document, monitor);

  urlPreview = waitForDOM(document, "#headers-panel .url-preview", 1);
  EventUtils.sendMouseEvent(
    { type: "mousedown" },
    document.querySelectorAll(".request-list-item")[3]
  );

  urlPreviewValue = (await urlPreview)[0].textContent;
  ok(
    urlPreviewValue.endsWith("?__proto__=5"),
    "The parameters in the url preview match."
  );

  // Expand preview
  await toggleUrlPreview(true, document, monitor);

  // Check if the expanded preview contains the "__proto__" parameter
  is(
    document.querySelector(
      "#headers-panel .url-preview tr#\\/GET\\/query\\/__proto__ .treeLabelCell"
    ).textContent,
    "__proto__",
    "Contains the __proto__ parameter"
  );

  return teardown(monitor);
});

async function toggleUrlPreview(shouldExpand, document, monitor) {
  const wait = waitUntil(() => {
    const rowSize = document.querySelectorAll(
      "#headers-panel .url-preview tr.treeRow"
    ).length;
    return shouldExpand ? rowSize > 1 : rowSize == 1;
  });

  clickElement(
    document.querySelector(
      "#headers-panel .url-preview tr:first-child span.treeIcon.theme-twisty"
    ),
    monitor
  );
  return wait;
}