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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-05-24 14:11:36 +00:00
parent 25f075630a
commit 5f33ea86d5
3 changed files with 45 additions and 0 deletions

View File

@ -86,3 +86,5 @@ skip-if = os == 'mac'
[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

View File

@ -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);
});

View File

@ -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>