Bug 1553769 - Add a test for switching a tab via window.focus() on a related tab. r=dao
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 24 May 2019 14:11:36 +0000
changeset 475376 a398387437aee799483ac38ed2e7eb72312841f7
parent 475375 e2be65d281b2c1a05129fbd84e3f40e965ad58cb
child 475377 b0a0359fdadb1c7dcd39656c449f3a072f49d66d
push id36060
push usercbrindusan@mozilla.com
push dateFri, 24 May 2019 21:47:21 +0000
treeherdermozilla-central@ac95bdf3c0b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1553769
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1553769 - Add a test for switching a tab via window.focus() on a related tab. r=dao Differential Revision: https://phabricator.services.mozilla.com/D32396
browser/base/content/test/tabs/browser.ini
browser/base/content/test/tabs/browser_tabswitch_window_focus.js
browser/base/content/test/tabs/open_window_in_new_tab.html
--- a/browser/base/content/test/tabs/browser.ini
+++ b/browser/base/content/test/tabs/browser.ini
@@ -81,8 +81,10 @@ skip-if = (debug && os == 'mac') || (deb
 skip-if = !e10s # Tab spinner is e10s only.
 [browser_tabSuccessors.js]
 [browser_tabSwitchPrintPreview.js]
 skip-if = os == 'mac'
 [browser_tabswitch_updatecommands.js]
 [browser_viewsource_of_data_URI_in_file_process.js]
 [browser_visibleTabs_bookmarkAllTabs.js]
 [browser_visibleTabs_contextMenu.js]
+[browser_tabswitch_window_focus.js]
+support-files = open_window_in_new_tab.html
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_tabswitch_window_focus.js
@@ -0,0 +1,35 @@
+"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 + "?opened", true);
+  info("Opening second tab using a click");
+  await ContentTask.spawn(firstTab.linkedBrowser, "", async function() {
+    content.document.querySelector("#open").click();
+  });
+
+  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 ContentTask.spawn(firstTab.linkedBrowser, "", async function() {
+      content.document.querySelector("#focus").click();
+    });
+  });
+
+  is(gBrowser.selectedTab, secondTab, "Should've switched tabs");
+
+  BrowserTestUtils.removeTab(firstTab);
+  BrowserTestUtils.removeTab(secondTab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/open_window_in_new_tab.html
@@ -0,0 +1,8 @@
+<!doctype html>
+<script>
+function openWindow() {
+  window.childWindow = window.open(location.href + "?opened", "", "");
+}
+</script>
+<button id="open" onclick="openWindow()">Open window</button>
+<button id="focus" onclick="window.childWindow.focus()">Focus window</button>