summaryrefslogtreecommitdiffstats
path: root/remote/test/browser/target
diff options
context:
space:
mode:
Diffstat (limited to 'remote/test/browser/target')
-rw-r--r--remote/test/browser/target/browser.ini22
-rw-r--r--remote/test/browser/target/browser_activateTarget.js82
-rw-r--r--remote/test/browser/target/browser_attachToTarget.js45
-rw-r--r--remote/test/browser/target/browser_attachedToTarget.js45
-rw-r--r--remote/test/browser/target/browser_browserContext.js39
-rw-r--r--remote/test/browser/target/browser_closeTarget.js43
-rw-r--r--remote/test/browser/target/browser_getTargets.js43
-rw-r--r--remote/test/browser/target/browser_sendMessageToTarget.js41
-rw-r--r--remote/test/browser/target/browser_setDiscoverTargets.js71
-rw-r--r--remote/test/browser/target/browser_targetCreated.js18
-rw-r--r--remote/test/browser/target/browser_targetDestroyed.js21
-rw-r--r--remote/test/browser/target/doc_test.html8
-rw-r--r--remote/test/browser/target/head.js11
13 files changed, 489 insertions, 0 deletions
diff --git a/remote/test/browser/target/browser.ini b/remote/test/browser/target/browser.ini
new file mode 100644
index 0000000000..d0f854decd
--- /dev/null
+++ b/remote/test/browser/target/browser.ini
@@ -0,0 +1,22 @@
+[DEFAULT]
+tags = remote
+subsuite = remote
+prefs =
+ remote.enabled=true
+support-files =
+ !/remote/test/browser/chrome-remote-interface.js
+ !/remote/test/browser/head.js
+ head.js
+ doc_test.html
+
+[browser_activateTarget.js]
+[browser_attachToTarget.js]
+[browser_attachedToTarget.js]
+[browser_browserContext.js]
+[browser_closeTarget.js]
+[browser_getTargets.js]
+[browser_sendMessageToTarget.js]
+skip-if = true # bug 1598468 - temporarily stop emitting event due to spamming
+[browser_setDiscoverTargets.js]
+[browser_targetCreated.js]
+[browser_targetDestroyed.js]
diff --git a/remote/test/browser/target/browser_activateTarget.js b/remote/test/browser/target/browser_activateTarget.js
new file mode 100644
index 0000000000..481ea2e810
--- /dev/null
+++ b/remote/test/browser/target/browser_activateTarget.js
@@ -0,0 +1,82 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function raisesWithoutArguments({ client, tab }) {
+ const { Target } = client;
+ let errorThrown = false;
+ try {
+ await Target.activateTarget();
+ } catch (e) {
+ errorThrown = true;
+ }
+ ok(errorThrown, "activateTarget raised error without an argument");
+});
+
+add_task(async function raisesWithUnknownTargetId({ client, tab }) {
+ const { Target } = client;
+ let errorThrown = false;
+ try {
+ await Target.activateTarget({ targetId: "-1" });
+ } catch (e) {
+ errorThrown = true;
+ }
+ ok(errorThrown, "activateTarget raised error with unkown target id");
+});
+
+add_task(async function selectTabInOtherWindow({ client, tab }) {
+ const { Target, target } = client;
+ is(
+ target.browsingContextId,
+ tab.linkedBrowser.browsingContext.id,
+ "Current target has expected browsing context id"
+ );
+ const currentTargetId = target.id;
+ const targets = await getDiscoveredTargets(Target);
+ const filtered_targets = targets.filter(target => {
+ return target.targetInfo.targetId == currentTargetId;
+ });
+ is(filtered_targets.length, 1, "The current target has been found");
+ const initialTarget = filtered_targets[0];
+
+ is(tab.ownerGlobal, getFocusedNavigator(), "Initial window is focused");
+
+ // open some more tabs in the initial window
+ await openTab(Target);
+ await openTab(Target);
+ const lastTabFirstWindow = await openTab(Target);
+ is(
+ gBrowser.selectedTab,
+ lastTabFirstWindow.newTab,
+ "Last openend tab in initial window is the selected tab"
+ );
+
+ const { newWindow } = await openWindow(Target);
+
+ const lastTabSecondWindow = await openTab(Target);
+ is(
+ gBrowser.selectedTab,
+ lastTabSecondWindow.newTab,
+ "Last openend tab in new window is the selected tab"
+ );
+
+ try {
+ is(newWindow, getFocusedNavigator(), "The new window is focused");
+ await Target.activateTarget({
+ targetId: initialTarget.targetInfo.targetId,
+ });
+ is(
+ tab.ownerGlobal,
+ getFocusedNavigator(),
+ "Initial window is focused again"
+ );
+ is(gBrowser.selectedTab, tab, "Selected tab is the initial tab again");
+ } finally {
+ await BrowserTestUtils.closeWindow(newWindow);
+ }
+});
+
+function getFocusedNavigator() {
+ return Services.wm.getMostRecentWindow("navigator:browser");
+}
diff --git a/remote/test/browser/target/browser_attachToTarget.js b/remote/test/browser/target/browser_attachToTarget.js
new file mode 100644
index 0000000000..6fa75431d1
--- /dev/null
+++ b/remote/test/browser/target/browser_attachToTarget.js
@@ -0,0 +1,45 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function raisesWithoutArguments({ client, tab }) {
+ const { Target } = client;
+ let errorThrown = false;
+ try {
+ await Target.attachToTarget();
+ } catch (e) {
+ errorThrown = true;
+ }
+ ok(errorThrown, "attachToTarget raised error without an argument");
+});
+
+add_task(async function raisesWithUnknownTargetId({ client, tab }) {
+ const { Target } = client;
+ let errorThrown = false;
+ try {
+ await Target.attachToTarget({ targetId: "-1" });
+ } catch (e) {
+ errorThrown = true;
+ }
+ ok(errorThrown, "attachToTarget raised error with unkown target id");
+});
+
+add_task(
+ async function attachPageTarget({ client }) {
+ const { Target } = client;
+ const { targetInfo } = await openTab(Target);
+
+ info("Attach new target");
+ const { sessionId } = await Target.attachToTarget({
+ targetId: targetInfo.targetId,
+ });
+
+ is(
+ typeof sessionId,
+ "string",
+ "attachToTarget returns the session id as string"
+ );
+ },
+ { createTab: false }
+);
diff --git a/remote/test/browser/target/browser_attachedToTarget.js b/remote/test/browser/target/browser_attachedToTarget.js
new file mode 100644
index 0000000000..27ffba30cf
--- /dev/null
+++ b/remote/test/browser/target/browser_attachedToTarget.js
@@ -0,0 +1,45 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const PAGE_TEST =
+ "http://example.com/browser/remote/test/browser/target/doc_test.html";
+
+add_task(
+ async function attachedPageTarget({ client }) {
+ const { Target } = client;
+ const { targetInfo } = await openTab(Target);
+
+ await loadURL(PAGE_TEST);
+
+ info("Attach new page target");
+ const attachedToTarget = Target.attachedToTarget();
+ const { sessionId } = await Target.attachToTarget({
+ targetId: targetInfo.targetId,
+ });
+ const {
+ targetInfo: eventTargetInfo,
+ sessionId: eventSessionId,
+ waitingForDebugger: eventWaitingForDebugger,
+ } = await attachedToTarget;
+
+ is(eventTargetInfo.targetId, targetInfo.targetId, "Got expected target id");
+ is(eventTargetInfo.type, "page", "Got expected target type");
+ is(eventTargetInfo.title, "Test Page", "Got expected target title");
+ is(eventTargetInfo.url, PAGE_TEST, "Got expected target URL");
+ todo(eventTargetInfo.attached, "Set correct attached status (bug 1680780)");
+
+ is(
+ eventSessionId,
+ sessionId,
+ "attachedToTarget and attachToTarget refer to the same session id"
+ );
+ is(
+ typeof eventWaitingForDebugger,
+ "boolean",
+ "Got expected type for waitingForDebugger"
+ );
+ },
+ { createTab: false }
+);
diff --git a/remote/test/browser/target/browser_browserContext.js b/remote/test/browser/target/browser_browserContext.js
new file mode 100644
index 0000000000..5c2c25d640
--- /dev/null
+++ b/remote/test/browser/target/browser_browserContext.js
@@ -0,0 +1,39 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function({ CDP }) {
+ // Connect to the server
+ const { webSocketDebuggerUrl } = await CDP.Version();
+ const client = await CDP({ target: webSocketDebuggerUrl });
+ info("CDP client has been instantiated");
+
+ const { Target } = client;
+ await getDiscoveredTargets(Target);
+
+ const { browserContextId } = await Target.createBrowserContext();
+
+ const targetCreated = Target.targetCreated();
+ const { targetId } = await Target.createTarget({ browserContextId });
+ ok(!!targetId, "Target.createTarget returns a non-empty target id");
+
+ const { targetInfo } = await targetCreated;
+ is(
+ targetId,
+ targetInfo.targetId,
+ "targetCreated refers to the same target id"
+ );
+ is(
+ browserContextId,
+ targetInfo.browserContextId,
+ "targetCreated refers to the same browser context"
+ );
+ is(targetInfo.type, "page", "The target is a page");
+
+ // Releasing the browser context is going to remove the tab opened when calling createTarget
+ await Target.disposeBrowserContext({ browserContextId });
+
+ await client.close();
+ info("The client is closed");
+});
diff --git a/remote/test/browser/target/browser_closeTarget.js b/remote/test/browser/target/browser_closeTarget.js
new file mode 100644
index 0000000000..34d557c9d8
--- /dev/null
+++ b/remote/test/browser/target/browser_closeTarget.js
@@ -0,0 +1,43 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function raisesWithoutArguments({ client, tab }) {
+ const { Target } = client;
+ let exceptionThrown = false;
+ try {
+ await Target.closeTarget();
+ } catch (e) {
+ exceptionThrown = true;
+ }
+ ok(exceptionThrown, "closeTarget raised error without an argument");
+});
+
+add_task(async function raisesWithUnknownTargetId({ client, tab }) {
+ const { Target } = client;
+ let exceptionThrown = false;
+ try {
+ await Target.closeTarget({ targetId: "-1" });
+ } catch (e) {
+ exceptionThrown = true;
+ }
+ ok(exceptionThrown, "closeTarget raised error with unkown target id");
+});
+
+add_task(async function triggersTargetDestroyed({ client, tab }) {
+ const { Target } = client;
+ const { targetInfo, newTab } = await openTab(Target);
+
+ const tabClosed = BrowserTestUtils.waitForEvent(newTab, "TabClose");
+ const targetDestroyed = Target.targetDestroyed();
+
+ info("Closing the target");
+ Target.closeTarget({ targetId: targetInfo.targetId });
+
+ await tabClosed;
+ info("Tab was closed");
+
+ await targetDestroyed;
+ info("Received the Target.targetDestroyed event");
+});
diff --git a/remote/test/browser/target/browser_getTargets.js b/remote/test/browser/target/browser_getTargets.js
new file mode 100644
index 0000000000..a867a0d18d
--- /dev/null
+++ b/remote/test/browser/target/browser_getTargets.js
@@ -0,0 +1,43 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const PAGE_TEST =
+ "http://example.com/browser/remote/test/browser/target/doc_test.html";
+
+add_task(
+ async function getTargetsDetails({ client }) {
+ const { Target, target } = client;
+
+ await loadURL(PAGE_TEST);
+
+ const { targetInfos } = await Target.getTargets();
+
+ Assert.equal(targetInfos.length, 1, "Got expected amount of targets");
+
+ const targetInfo = targetInfos[0];
+ is(targetInfo.id, target.id, "Got expected target id");
+ is(targetInfo.type, "page", "Got expected target type");
+ is(targetInfo.title, "Test Page", "Got expected target title");
+ is(targetInfo.url, PAGE_TEST, "Got expected target URL");
+ },
+ { createTab: false }
+);
+
+add_task(
+ async function getTargetsCount({ client }) {
+ const { Target, target } = client;
+ const { targetInfo: newTabTargetInfo } = await openTab(Target);
+
+ await loadURL(PAGE_TEST);
+
+ const { targetInfos } = await Target.getTargets();
+
+ Assert.equal(targetInfos.length, 2, "Got expected amount of targets");
+ const targetIds = targetInfos.map(info => info.id);
+ ok(targetIds.includes(target.id), "Got expected original target id");
+ ok(targetIds.includes(newTabTargetInfo.id), "Got expected new target id");
+ },
+ { createTab: false }
+);
diff --git a/remote/test/browser/target/browser_sendMessageToTarget.js b/remote/test/browser/target/browser_sendMessageToTarget.js
new file mode 100644
index 0000000000..b440066178
--- /dev/null
+++ b/remote/test/browser/target/browser_sendMessageToTarget.js
@@ -0,0 +1,41 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function sendToAttachedTarget({ client }) {
+ const { Target } = client;
+ const { targetInfo } = await openTab(Target);
+
+ const attachedToTarget = Target.attachedToTarget();
+ const { sessionId } = await Target.attachToTarget({
+ targetId: targetInfo.targetId,
+ });
+ await attachedToTarget;
+ info("Target attached");
+
+ const id = 1;
+ const message = JSON.stringify({
+ id,
+ method: "Page.navigate",
+ params: {
+ url: toDataURL("new-page"),
+ },
+ });
+
+ info("Calling Target.sendMessageToTarget");
+ const onResponse = Target.receivedMessageFromTarget();
+ await Target.sendMessageToTarget({ sessionId, message });
+ const response = await onResponse;
+ info("Message from target received");
+
+ ok(!!response, "The response is not empty");
+ is(response.sessionId, sessionId, "The response is from the same session");
+
+ const responseMessage = JSON.parse(response.message);
+ is(responseMessage.id, id, "The response is from the same session");
+ ok(
+ !!responseMessage.result.frameId,
+ "received the `frameId` out of `Page.navigate` request"
+ );
+});
diff --git a/remote/test/browser/target/browser_setDiscoverTargets.js b/remote/test/browser/target/browser_setDiscoverTargets.js
new file mode 100644
index 0000000000..9e3107eb8c
--- /dev/null
+++ b/remote/test/browser/target/browser_setDiscoverTargets.js
@@ -0,0 +1,71 @@
+/* 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;
+ is(
+ target.browsingContextId,
+ tab.linkedBrowser.browsingContext.id,
+ "Current target has expected browsing context id"
+ );
+ 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");
+});
diff --git a/remote/test/browser/target/browser_targetCreated.js b/remote/test/browser/target/browser_targetCreated.js
new file mode 100644
index 0000000000..bfb7287f87
--- /dev/null
+++ b/remote/test/browser/target/browser_targetCreated.js
@@ -0,0 +1,18 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function eventFiredWhenTabIsCreated({ client }) {
+ const { Target } = client;
+
+ const targetCreated = Target.targetCreated();
+ await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ const { targetInfo } = await targetCreated;
+
+ is(typeof targetInfo.targetId, "string", "Got expected type for target id");
+ is(targetInfo.type, "page", "Got expected target type");
+ is(targetInfo.title, "", "Got expected target title");
+ is(targetInfo.url, "about:blank", "Got expected target URL");
+ is(targetInfo.attached, false, "Got expected attached status");
+});
diff --git a/remote/test/browser/target/browser_targetDestroyed.js b/remote/test/browser/target/browser_targetDestroyed.js
new file mode 100644
index 0000000000..2ad657b135
--- /dev/null
+++ b/remote/test/browser/target/browser_targetDestroyed.js
@@ -0,0 +1,21 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function eventFiredWhenTabIsClosed({ client, tab }) {
+ const { Target } = client;
+ const { newTab } = await openTab(Target);
+
+ const tabClosed = BrowserTestUtils.waitForEvent(newTab, "TabClose");
+ const targetDestroyed = Target.targetDestroyed();
+
+ info("Closing the tab");
+ BrowserTestUtils.removeTab(newTab);
+
+ await tabClosed;
+ info("Tab was closed");
+
+ await targetDestroyed;
+ info("Received the Target.targetDestroyed event");
+});
diff --git a/remote/test/browser/target/doc_test.html b/remote/test/browser/target/doc_test.html
new file mode 100644
index 0000000000..c779ea0773
--- /dev/null
+++ b/remote/test/browser/target/doc_test.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Test Page</title>
+</head>
+<body>
+</body>
+</html>
diff --git a/remote/test/browser/target/head.js b/remote/test/browser/target/head.js
new file mode 100644
index 0000000000..7131e98b6f
--- /dev/null
+++ b/remote/test/browser/target/head.js
@@ -0,0 +1,11 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from ../head.js */
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/remote/test/browser/head.js",
+ this
+);