summaryrefslogtreecommitdiffstats
path: root/devtools/shared/commands/resource/tests/browser_resources_watch_unwatch_multiple.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/shared/commands/resource/tests/browser_resources_watch_unwatch_multiple.js')
-rw-r--r--devtools/shared/commands/resource/tests/browser_resources_watch_unwatch_multiple.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/devtools/shared/commands/resource/tests/browser_resources_watch_unwatch_multiple.js b/devtools/shared/commands/resource/tests/browser_resources_watch_unwatch_multiple.js
new file mode 100644
index 0000000000..cc45e7bf7f
--- /dev/null
+++ b/devtools/shared/commands/resource/tests/browser_resources_watch_unwatch_multiple.js
@@ -0,0 +1,88 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Check that watching/unwatching multiple times works as expected
+
+add_task(async function () {
+ const TEST_URL = "data:text/html;charset=utf-8,<!DOCTYPE html>foo";
+ const tab = await addTab(TEST_URL);
+
+ const { client, resourceCommand, targetCommand } = await initResourceCommand(
+ tab
+ );
+
+ let resources = [];
+ const onAvailable = _resources => {
+ resources.push(..._resources);
+ };
+
+ info("Watch for error messages resources");
+ await resourceCommand.watchResources([resourceCommand.TYPES.ERROR_MESSAGE], {
+ onAvailable,
+ });
+
+ ok(
+ resourceCommand.isResourceWatched(resourceCommand.TYPES.ERROR_MESSAGE),
+ "The error message resource is currently been watched."
+ );
+
+ is(
+ resources.length,
+ 0,
+ "no resources were received after the first watchResources call"
+ );
+
+ info("Trigger an error in the page");
+ await ContentTask.spawn(tab.linkedBrowser, [], function frameScript() {
+ const document = content.document;
+ const scriptEl = document.createElement("script");
+ scriptEl.textContent = `document.unknownFunction()`;
+ document.body.appendChild(scriptEl);
+ });
+
+ await waitFor(() => resources.length === 1);
+ const EXPECTED_ERROR_MESSAGE =
+ "TypeError: document.unknownFunction is not a function";
+ is(
+ resources[0].pageError.errorMessage,
+ EXPECTED_ERROR_MESSAGE,
+ "The resource was received"
+ );
+
+ info("Unwatching resources…");
+ resourceCommand.unwatchResources([resourceCommand.TYPES.ERROR_MESSAGE], {
+ onAvailable,
+ });
+
+ ok(
+ !resourceCommand.isResourceWatched(resourceCommand.TYPES.ERROR_MESSAGE),
+ "The error message resource is no longer been watched."
+ );
+ // clearing resources
+ resources = [];
+
+ info("…and watching again");
+ await resourceCommand.watchResources([resourceCommand.TYPES.ERROR_MESSAGE], {
+ onAvailable,
+ });
+
+ ok(
+ resourceCommand.isResourceWatched(resourceCommand.TYPES.ERROR_MESSAGE),
+ "The error message resource is been watched again."
+ );
+ is(
+ resources.length,
+ 1,
+ "we retrieve the expected number of existing resources"
+ );
+ is(
+ resources[0].pageError.errorMessage,
+ EXPECTED_ERROR_MESSAGE,
+ "The resource is the expected one"
+ );
+
+ targetCommand.destroy();
+ await client.close();
+});