Bug 1484213 - Try to make browser_autofocus_background.js more reliable. r=dao

I think the focus shenanigans instead of waiting for tab-switching or what not
may be tripping this tests and causing the background tab to be blurred, but I
didn't spend too much time trying to reproduce the failure.

Differential Revision: https://phabricator.services.mozilla.com/D61096

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2020-02-05 13:14:42 +00:00
Родитель 063b597c47
Коммит 7a8fd6fede
1 изменённых файлов: 38 добавлений и 35 удалений

Просмотреть файл

@ -1,49 +1,52 @@
add_task(async function() { add_task(async function() {
let tabs = [gBrowser.selectedTab, BrowserTestUtils.addTab(gBrowser)]; const URL =
"data:text/html,<!DOCTYPE html><html><body><input autofocus id='target'></body></html>";
const foregroundTab = gBrowser.selectedTab;
const backgroundTab = BrowserTestUtils.addTab(gBrowser);
// The first tab has an autofocused element. // Ensure tab is still in the foreground.
// The second tab is exactly like the first one without the autofocus. is(
let testingList = [ gBrowser.selectedTab,
{ foregroundTab,
uri: "foregroundTab should still be selected"
"data:text/html,<!DOCTYPE html><html><body><input autofocus id='target'></body></html>", );
tagName: "INPUT",
},
];
// Set the focus to the first tab.
tabs[0].linkedBrowser.focus();
// Load the second tab in the background. // Load the second tab in the background.
let loadedPromise = BrowserTestUtils.browserLoaded(tabs[1].linkedBrowser); const loadedPromise = BrowserTestUtils.browserLoaded(
BrowserTestUtils.loadURI(tabs[1].linkedBrowser, testingList[0].uri); backgroundTab.linkedBrowser,
/* includesubframes */ false,
URL
);
BrowserTestUtils.loadURI(backgroundTab.linkedBrowser, URL);
await loadedPromise; await loadedPromise;
for (var i = 0; i < testingList.length; ++i) { // Get active element in the tab.
// Get active element in the tab. let tagName = await SpecialPowers.spawn(
let tagName = await SpecialPowers.spawn( backgroundTab.linkedBrowser,
tabs[i + 1].linkedBrowser, [],
[], async function() {
async function() { return content.document.activeElement.tagName;
return content.document.activeElement.tagName; }
} );
);
is( is(
tagName, tagName,
testingList[i].tagName, "INPUT",
"The background tab's focused element should be " + testingList[i].tagName "The background tab's focused element should be the <input>"
); );
}
is(
gBrowser.selectedTab,
foregroundTab,
"foregroundTab tab should still be selected, shouldn't cause a tab switch"
);
is( is(
document.activeElement, document.activeElement,
tabs[0].linkedBrowser, foregroundTab.linkedBrowser,
"The background tab's focused element should not cause the tab to be focused" "The background tab's focused element should not cause the tab to be selected"
); );
// Cleaning up. // Cleaning up.
for (let i = 1; i < tabs.length; i++) { BrowserTestUtils.removeTab(backgroundTab);
BrowserTestUtils.removeTab(tabs[i]);
}
}); });