summaryrefslogtreecommitdiffstats
path: root/devtools/shared/commands/network/tests/browser_network_command_request_blocking.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/shared/commands/network/tests/browser_network_command_request_blocking.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/commands/network/tests/browser_network_command_request_blocking.js')
-rw-r--r--devtools/shared/commands/network/tests/browser_network_command_request_blocking.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/devtools/shared/commands/network/tests/browser_network_command_request_blocking.js b/devtools/shared/commands/network/tests/browser_network_command_request_blocking.js
new file mode 100644
index 0000000000..dd1167fa9b
--- /dev/null
+++ b/devtools/shared/commands/network/tests/browser_network_command_request_blocking.js
@@ -0,0 +1,61 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test the NetworkCommand API around request blocking
+
+add_task(async function () {
+ info("Test NetworkCommand request blocking");
+ const tab = await addTab("data:text/html,foo");
+ const commands = await CommandsFactory.forTab(tab);
+ const networkCommand = commands.networkCommand;
+ const resourceCommand = commands.resourceCommand;
+
+ // Usage of request blocking APIs requires to listen to NETWORK_EVENT.
+ await resourceCommand.watchResources([resourceCommand.TYPES.NETWORK_EVENT], {
+ onAvailable: () => {},
+ });
+
+ let blockedUrls = await networkCommand.getBlockedUrls();
+ Assert.deepEqual(
+ blockedUrls,
+ [],
+ "The list of blocked URLs is originaly empty"
+ );
+
+ await networkCommand.blockRequestForUrl("https://foo.com");
+ blockedUrls = await networkCommand.getBlockedUrls();
+ Assert.deepEqual(
+ blockedUrls,
+ ["https://foo.com"],
+ "The freshly added blocked URL is reported as blocked"
+ );
+
+ // We pass "url filters" which can be only part of a URL string
+ await networkCommand.blockRequestForUrl("bar");
+ blockedUrls = await networkCommand.getBlockedUrls();
+ Assert.deepEqual(
+ blockedUrls,
+ ["https://foo.com", "bar"],
+ "The second blocked URL is also reported as blocked"
+ );
+
+ await networkCommand.setBlockedUrls(["https://mozilla.org"]);
+ blockedUrls = await networkCommand.getBlockedUrls();
+ Assert.deepEqual(
+ blockedUrls,
+ ["https://mozilla.org"],
+ "setBlockedUrls replace the whole list of blocked URLs"
+ );
+
+ await networkCommand.unblockRequestForUrl("https://mozilla.org");
+ blockedUrls = await networkCommand.getBlockedUrls();
+ Assert.deepEqual(
+ blockedUrls,
+ [],
+ "The unblocked URL disappear from the list of blocked URLs"
+ );
+
+ await commands.destroy();
+});