Skip to content

Commit d00ed80

Browse files
Bug 1903496 - [devtools] Add tests for file URL in netmonitor r=devtools-reviewers,bomsy
Depends on D230656 Differential Revision: https://phabricator.services.mozilla.com/D230657
1 parent 89c835a commit d00ed80

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

devtools/client/netmonitor/test/browser.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ support-files = [
2525
"html_fonts-test-page.html",
2626
"html_frame-test-page.html",
2727
"html_frame-subdocument.html",
28+
"html_file_channel.html",
2829
"html_filter-test-page.html",
2930
"html_infinite-get-page.html",
3031
"html_internal-stylesheet.html",
@@ -264,6 +265,8 @@ fail-if = ["a11y_checks"] # Bug 1849028 clicked element may not be focusable and
264265

265266
["browser_net_error-boundary-01.js"]
266267

268+
["browser_net_file_uri.js"]
269+
267270
["browser_net_filter-01.js"]
268271

269272
["browser_net_filter-02.js"]
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
"use strict";
5+
6+
/**
7+
* Tests that file URL requests are properly displayed in the network monitor.
8+
*/
9+
add_task(async function test_file_uris() {
10+
const TEST_URI = Services.io.newFileURI(
11+
new FileUtils.File(getTestFilePath("html_file_channel.html"))
12+
).spec;
13+
14+
const { monitor } = await initNetMonitor(TEST_URI, {
15+
requestCount: 2,
16+
waitForLoad: false,
17+
});
18+
info("Starting test... ");
19+
20+
const { document, store, windowRequire } = monitor.panelWin;
21+
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
22+
23+
store.dispatch(Actions.batchEnable(false));
24+
25+
const wait = waitForNetworkEvents(monitor, 2);
26+
reloadBrowser({ waitForLoad: false });
27+
await wait;
28+
29+
const htmlEntry = document.querySelectorAll(".request-list-item")[0];
30+
ok(
31+
htmlEntry
32+
.querySelector(".requests-list-url")
33+
.innerText.endsWith("file_channel.html"),
34+
"The url for the html request is correct"
35+
);
36+
is(
37+
htmlEntry.querySelector(".requests-list-scheme").innerText,
38+
"file",
39+
"The scheme for the html request is correct"
40+
);
41+
ok(hasValidSize(htmlEntry), "The request shows a valid size");
42+
43+
const imageEntry = document.querySelectorAll(".request-list-item")[1];
44+
ok(
45+
imageEntry
46+
.querySelector(".requests-list-url")
47+
.innerText.endsWith("test-image.png"),
48+
"The url for the image request is correct"
49+
);
50+
is(
51+
imageEntry.querySelector(".requests-list-scheme").innerText,
52+
"file",
53+
"The scheme for the image request is correct"
54+
);
55+
ok(hasValidSize(imageEntry), "The request shows a valid size");
56+
57+
const onResponseContent = monitor.panelWin.api.once(
58+
TEST_EVENTS.RECEIVED_RESPONSE_CONTENT
59+
);
60+
61+
info("Check that a valid image is loaded in the response tab");
62+
const waitDOM = waitForDOM(document, "#response-panel .response-image");
63+
store.dispatch(Actions.selectRequestByIndex(1));
64+
document.querySelector("#response-tab").click();
65+
const [imageNode] = await waitDOM;
66+
await once(imageNode, "load");
67+
await onResponseContent;
68+
69+
info("Verify we only have 2 requests, and the chrome request was not listed");
70+
const sortedRequests = getSortedRequests(store.getState());
71+
is(sortedRequests.length, 2, "Only 2 requests are displayed");
72+
73+
await teardown(monitor);
74+
});
75+
76+
function hasValidSize(request) {
77+
const VALID_SIZE_RE = /^\d+(\.\d+)? \w+/;
78+
return VALID_SIZE_RE.test(
79+
request.querySelector(".requests-list-size").innerText
80+
);
81+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
Test page for file channels.
3+
<img src="test-image.png">
4+
<!-- Load the image a second time via a chrome URL -->
5+
<img src="chrome://mochitests/content/browser/devtools/client/netmonitor/test/test-image.png?fromchrome">
6+
</html>

0 commit comments

Comments
 (0)