diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /remote/cdp/test/browser/target/browser_activateTarget.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream/115.8.0esr.tar.xz firefox-esr-upstream/115.8.0esr.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/cdp/test/browser/target/browser_activateTarget.js')
-rw-r--r-- | remote/cdp/test/browser/target/browser_activateTarget.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/remote/cdp/test/browser/target/browser_activateTarget.js b/remote/cdp/test/browser/target/browser_activateTarget.js new file mode 100644 index 0000000000..fb1e0700f5 --- /dev/null +++ b/remote/cdp/test/browser/target/browser_activateTarget.js @@ -0,0 +1,78 @@ +/* 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; + + const currentTargetId = target.id; + const targets = await getDiscoveredTargets(Target); + const filtered_targets = targets.filter(target => { + return target.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.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"); +} |