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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test that the URL Preview can be copied
*/
add_task(async function () {
const { monitor } = await initNetMonitor(SIMPLE_URL, {
requestCount: 1,
});
info("Starting the url preview copy test... ");
const { document, store, windowRequire } = monitor.panelWin;
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
store.dispatch(Actions.batchEnable(false));
const wait = waitForNetworkEvents(monitor, 1);
await reloadBrowser();
await wait;
store.dispatch(Actions.toggleNetworkDetails());
await waitForDOM(document, "#headers-panel .url-preview", 1);
const urlPreview = document.querySelector("#headers-panel .url-preview");
const urlRow = urlPreview.querySelector(".objectRow");
/* Test for copy value on the url */
EventUtils.sendMouseEvent({ type: "contextmenu" }, urlRow);
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
);
}, "http://example.com/browser/devtools/client/netmonitor/test/html_simple-test-page.html");
ok(true, "The copy value action put expected url string into clipboard");
/* Test for copy all */
EventUtils.sendMouseEvent({ type: "contextmenu" }, urlRow);
const expected = JSON.stringify(
{
GET: {
scheme: "http",
host: "example.com",
filename:
"/browser/devtools/client/netmonitor/test/html_simple-test-page.html",
remote: {
Address: "127.0.0.1:8888",
},
},
},
null,
"\t"
);
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(
monitor,
"properties-view-context-menu-copyall"
);
}, expected);
ok(true, "The copy all action put expected json data into clipboard");
await teardown(monitor);
});
/**
* Test that the Headers summary can be copied
*/
add_task(async function () {
const { monitor } = await initNetMonitor(SIMPLE_URL, {
requestCount: 1,
});
info("Starting the headers summary copy test... ");
const { document, store, windowRequire } = monitor.panelWin;
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
store.dispatch(Actions.batchEnable(false));
const wait = waitForNetworkEvents(monitor, 1);
await reloadBrowser();
await wait;
store.dispatch(Actions.toggleNetworkDetails());
await waitForDOM(document, "#headers-panel .summary", 1);
const headersSummary = document.querySelector("#headers-panel .summary");
const httpSummaryValue = headersSummary.querySelectorAll(
".tabpanel-summary-value"
)[1];
/* Test for copy value */
EventUtils.sendMouseEvent({ type: "contextmenu" }, httpSummaryValue);
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(
monitor,
"headers-panel-context-menu-copyvalue"
);
}, "HTTP/1.1");
ok(true, "The copy value action put expected text into clipboard");
/* Test for copy all */
EventUtils.sendMouseEvent({ type: "contextmenu" }, httpSummaryValue);
const expected = JSON.stringify(
{
Status: "200OK",
Version: "HTTP/1.1",
Transferred: "650 B (465 B size)",
"Request Priority": "Highest",
"DNS Resolution": "System",
},
null,
"\t"
);
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(monitor, "headers-panel-context-menu-copyall");
}, expected);
ok(true, "The copy all action put expected json into clipboard");
await teardown(monitor);
});
/**
* Test if response JSON in PropertiesView can be copied
*/
add_task(async function () {
const { tab, monitor } = await initNetMonitor(
JSON_BASIC_URL + "?name=nogrip",
{ requestCount: 1 }
);
info("Starting the json in properties view copy test... ");
const { document, store, windowRequire } = monitor.panelWin;
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
store.dispatch(Actions.batchEnable(false));
await performRequests(monitor, tab, 1);
const onResponsePanelReady = waitForDOM(
document,
"#response-panel .treeTable"
);
store.dispatch(Actions.toggleNetworkDetails());
clickOnSidebarTab(document, "response");
await onResponsePanelReady;
const responsePanel = document.querySelector("#response-panel");
const objectRow = responsePanel.querySelectorAll(".objectRow")[0];
// Open the node to get the string
const waitOpenNode = waitForDOM(document, ".stringRow");
const toggleButton = objectRow.querySelector("td span.treeIcon");
toggleButton.click();
await waitOpenNode;
const stringRow = responsePanel.querySelectorAll(".stringRow")[0];
/* Test for copy value on an object */
EventUtils.sendMouseEvent({ type: "contextmenu" }, objectRow);
const expected = JSON.stringify({ obj: { type: "string" } }, null, "\t");
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
);
}, expected);
ok(true, "The copy value action put expected json into clipboard");
/* Test for copy all */
EventUtils.sendMouseEvent({ type: "contextmenu" }, objectRow);
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(
monitor,
"properties-view-context-menu-copyall"
);
}, expected);
ok(true, "The copy all action put expected json into clipboard");
/* Test for copy value of a single row */
EventUtils.sendMouseEvent({ type: "contextmenu" }, stringRow);
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
);
}, "string");
ok(true, "The copy value action put expected text into clipboard");
await teardown(monitor);
});
/**
* Test if response/request Cookies in PropertiesView can be copied
*/
add_task(async function () {
const { monitor } = await initNetMonitor(SIMPLE_UNSORTED_COOKIES_SJS, {
requestCount: 1,
});
info(
"Starting the request/response cookies in properties view copy test... "
);
const { document, store, windowRequire } = monitor.panelWin;
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
store.dispatch(Actions.batchEnable(false));
let wait = waitForNetworkEvents(monitor, 1);
await reloadBrowser();
await wait;
wait = waitForDOM(document, ".headers-overview");
EventUtils.sendMouseEvent(
{ type: "mousedown" },
document.querySelectorAll(".request-list-item")[0]
);
await wait;
EventUtils.sendMouseEvent(
{ type: "mousedown" },
document.querySelectorAll(".request-list-item")[0]
);
clickOnSidebarTab(document, "cookies");
const cookiesPanel = document.querySelector("#cookies-panel");
const objectRows = cookiesPanel.querySelectorAll(".objectRow");
const stringRows = cookiesPanel.querySelectorAll(".stringRow");
const expectedResponseCookies = [
`{
"__proto__": {
"httpOnly": true,
"value": "2"
}
}`,
`{
"bob": {
"httpOnly": true,
"value": "true"
}
}`,
`{
"foo": {
"httpOnly": true,
"value": "bar"
}
}`,
`{
"tom": {
"httpOnly": true,
"value": "cool"
}
}`,
];
for (let i = 0; i < objectRows.length; i++) {
const cur = objectRows[i];
EventUtils.sendMouseEvent({ type: "contextmenu" }, cur);
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
);
}, expectedResponseCookies[i]);
}
const expectedRequestCookies = ["2", "true", "bar", "cool"];
for (let i = 0; i < expectedRequestCookies.length; i++) {
const cur = stringRows[objectRows.length + i];
EventUtils.sendMouseEvent({ type: "contextmenu" }, cur);
await waitForClipboardPromise(async function setup() {
await selectContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
);
}, expectedRequestCookies[i]);
}
await teardown(monitor);
});
|