summaryrefslogtreecommitdiffstats
path: root/remote/cdp/test/browser/target/browser_setDiscoverTargets.js
diff options
context:
space:
mode:
Diffstat (limited to 'remote/cdp/test/browser/target/browser_setDiscoverTargets.js')
-rw-r--r--remote/cdp/test/browser/target/browser_setDiscoverTargets.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/remote/cdp/test/browser/target/browser_setDiscoverTargets.js b/remote/cdp/test/browser/target/browser_setDiscoverTargets.js
new file mode 100644
index 0000000000..81e9990320
--- /dev/null
+++ b/remote/cdp/test/browser/target/browser_setDiscoverTargets.js
@@ -0,0 +1,67 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(
+ async function mainTarget({ client }) {
+ const { Target } = client;
+ const { targetInfo } = await new Promise(resolve => {
+ const unsubscribe = Target.targetCreated(target => {
+ if (target.targetInfo.type == "browser") {
+ unsubscribe();
+ resolve(target);
+ }
+ });
+
+ // Calling `setDiscoverTargets` will dispatch `targetCreated` event for all
+ // already opened tabs and the browser target.
+ Target.setDiscoverTargets({ discover: true });
+ });
+
+ ok(!!targetInfo, "Target info for main target has been found");
+ ok(!!targetInfo.targetId, "Main target has a non-empty target id");
+ is(targetInfo.type, "browser", "Type of target is browser");
+ },
+ { createTab: false }
+);
+
+add_task(async function pageTargets({ client, tab }) {
+ const { Target, target } = client;
+
+ const currentTargetId = target.id;
+ const url = toDataURL("pageTargets");
+ await loadURL(url);
+
+ const targets = await new Promise(resolve => {
+ const targets = [];
+
+ const unsubscribe = Target.targetCreated(target => {
+ if (target.targetInfo.type == "page") {
+ targets.push(target);
+
+ // Return once all page targets have been discovered
+ if (targets.length == gBrowser.tabs.length) {
+ unsubscribe();
+ resolve(targets);
+ }
+ }
+ });
+
+ // Calling `setDiscoverTargets` will dispatch `targetCreated` event for all
+ // already opened tabs and the browser target.
+ Target.setDiscoverTargets({ discover: true });
+ });
+
+ // Get the current target
+ const filtered_targets = targets.filter(target => {
+ return target.targetInfo.targetId == currentTargetId;
+ });
+ is(filtered_targets.length, 1, "The current target has been found");
+ const { targetInfo } = filtered_targets[0];
+
+ ok(!!targetInfo, "Target info for current tab has been found");
+ ok(!!targetInfo.targetId, "Page target has a non-empty target id");
+ is(targetInfo.type, "page", "Type of current target is 'page'");
+ is(targetInfo.url, url, "Page target has a non-empty target id");
+});