diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /remote/test/browser/target/browser_activateTarget.js | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | remote/test/browser/target/browser_activateTarget.js | 82 |
1 files changed, 82 insertions, 0 deletions
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"); +} |