Bug 1924993 - [devtools] Debugger tests wait before typing in conditional panel r...
[gecko.git] / devtools / client / netmonitor / test / browser_net_block-extensions.js
blob067f18d3c6c9861be55b9abb6023734d8575a259
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 /**
7 * Test the requests that are blocked by extenstions show correctly.
8 */
9 add_task(async function () {
10 const extensionName = "Test Blocker";
11 info(`Start loading the ${extensionName} extension...`);
12 const extension = ExtensionTestUtils.loadExtension({
13 manifest: {
14 name: extensionName,
15 permissions: ["*://example.com/", "webRequest", "webRequestBlocking"],
17 useAddonManager: "temporary",
18 background() {
19 // eslint-disable-next-line no-undef
20 browser.webRequest.onBeforeRequest.addListener(
21 () => {
22 return {
23 cancel: true,
27 urls: [
28 "https://example.com/browser/devtools/client/netmonitor/test/request_0",
31 ["blocking"]
33 // eslint-disable-next-line no-undef
34 browser.test.sendMessage("ready");
36 });
38 await extension.startup();
39 await extension.awaitMessage("ready");
41 const { tab, monitor } = await initNetMonitor(HTTPS_SINGLE_GET_URL, {
42 requestCount: 2,
43 });
45 const { document } = monitor.panelWin;
47 info("Starting test... ");
49 const waitForNetworkEventsToComplete = waitForNetworkEvents(monitor, 2);
50 const waitForRequestsToRender = waitForDOM(
51 document,
52 ".requests-list-row-group"
54 const waitForReload = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
56 await reloadBrowser();
58 await Promise.all([
59 waitForNetworkEventsToComplete,
60 waitForRequestsToRender,
61 waitForReload,
62 ]);
64 // Find the request list item that matches the blocked url
65 const request = document.querySelector(
66 "td.requests-list-url[title*=request_0]"
67 ).parentNode;
69 info("Assert the blocked request");
70 ok(
71 !!request.querySelector(".requests-list-status .status-code-blocked-icon"),
72 "The request blocked status icon is visible"
75 is(
76 request.querySelector(".requests-list-status .requests-list-status-code")
77 .title,
78 "Blocked",
79 "The request status title is 'Blocked'"
82 is(
83 request.querySelector(".requests-list-type").innerText,
84 "",
85 "The request shows no type"
88 is(
89 request.querySelector(".requests-list-transferred").innerText,
90 `Blocked By ${extensionName}`,
91 "The request shows the blocking extension name"
94 is(
95 request.querySelector(".requests-list-size").innerText,
96 "",
97 "The request shows no size"
100 await teardown(monitor);
101 info(`Unloading the ${extensionName} extension`);
102 await extension.unload();