summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_tabswitch_window_focus.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /browser/base/content/test/tabs/browser_tabswitch_window_focus.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/tabs/browser_tabswitch_window_focus.js')
-rw-r--r--browser/base/content/test/tabs/browser_tabswitch_window_focus.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/browser/base/content/test/tabs/browser_tabswitch_window_focus.js b/browser/base/content/test/tabs/browser_tabswitch_window_focus.js
new file mode 100644
index 0000000000..a808ab4f09
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_tabswitch_window_focus.js
@@ -0,0 +1,78 @@
+"use strict";
+
+// Allow to open popups without any kind of interaction.
+SpecialPowers.pushPrefEnv({ set: [["dom.disable_window_flip", false]] });
+
+const FILE = getRootDirectory(gTestPath) + "open_window_in_new_tab.html";
+
+add_task(async function () {
+ info("Opening first tab: " + FILE);
+ let firstTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, FILE);
+
+ let promiseTabOpened = BrowserTestUtils.waitForNewTab(
+ gBrowser,
+ FILE + "?open-click",
+ true
+ );
+ info("Opening second tab using a click");
+ await BrowserTestUtils.synthesizeMouseAtCenter(
+ "#open-click",
+ {},
+ firstTab.linkedBrowser
+ );
+
+ info("Waiting for the second tab to be opened");
+ let secondTab = await promiseTabOpened;
+
+ info("Going back to the first tab");
+ await BrowserTestUtils.switchTab(gBrowser, firstTab);
+
+ info("Focusing second tab by clicking on the first tab");
+ await BrowserTestUtils.switchTab(gBrowser, async function () {
+ await SpecialPowers.spawn(firstTab.linkedBrowser, [""], async function () {
+ content.document.querySelector("#focus").click();
+ });
+ });
+
+ is(gBrowser.selectedTab, secondTab, "Should've switched tabs");
+
+ await BrowserTestUtils.removeTab(firstTab);
+ await BrowserTestUtils.removeTab(secondTab);
+});
+
+add_task(async function () {
+ info("Opening first tab: " + FILE);
+ let firstTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, FILE);
+
+ let promiseTabOpened = BrowserTestUtils.waitForNewTab(
+ gBrowser,
+ FILE + "?open-mousedown",
+ true
+ );
+ info("Opening second tab using a click");
+ await BrowserTestUtils.synthesizeMouseAtCenter(
+ "#open-mousedown",
+ { type: "mousedown" },
+ firstTab.linkedBrowser
+ );
+
+ info("Waiting for the second tab to be opened");
+ let secondTab = await promiseTabOpened;
+
+ is(gBrowser.selectedTab, secondTab, "Should've switched tabs");
+
+ info("Ensuring we don't switch back");
+ await new Promise(resolve => {
+ // We need to wait for something _not_ happening, so we need to use an arbitrary setTimeout.
+ //
+ // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
+ setTimeout(function () {
+ is(gBrowser.selectedTab, secondTab, "Should've remained in original tab");
+ resolve();
+ }, 500);
+ });
+
+ info("cleanup");
+ await BrowserTestUtils.removeTab(firstTab);
+ await BrowserTestUtils.removeTab(secondTab);
+});