Bug 1596738 - Don't focus the tab's content area for restores triggered by DocumentChannel process switches, r=dao,nika,mixedpuppy

This causes the browser to steal focus from any element that was focused prior
to the completion of the remoteness flip. This is particularly a problem for
fission because every cross-origin navigation requires a process switch.

This code is still necessary for "normal" session restores (see bug 1410591),
but focus is handled elsewhere for remote navigations.

Differential Revision: https://phabricator.services.mozilla.com/D82783
This commit is contained in:
Kashav Madan 2020-07-15 23:09:09 +00:00
Родитель 115500932d
Коммит 46c04e90f2
4 изменённых файлов: 24 добавлений и 3 удалений

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

@ -20,6 +20,7 @@ async function checkURLBarCaretEvents() {
const kURL = "about:mozilla";
let newWin = await BrowserTestUtils.openNewBrowserWindow();
BrowserTestUtils.loadURI(newWin.gBrowser.selectedBrowser, kURL);
newWin.gBrowser.selectedBrowser.focus();
await waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, event => {
try {

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

@ -401,7 +401,6 @@ tags = fullscreen
[browser_newWindowDrop.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_newwindow_focus.js]
fail-if = fission # URLBar should be focused - [object XULFrameElement] == {} - JS frame :: chrome://mochitests/content/browser/browser/base/content/test/general/browser_newwindow_focus.js :: test_no_steal_focus/< :: line 113
skip-if = os == "linux" && !e10s # Bug 1263254 - Perma fails on Linux without e10s for some reason.
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_bug1299667.js]

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

@ -188,6 +188,15 @@ add_task(async function test_user_defined_commands() {
await BrowserTestUtils.loadURI(win1.gBrowser.selectedBrowser, "about:robots");
await BrowserTestUtils.browserLoaded(win1.gBrowser.selectedBrowser);
// We would have previously focused the window's content area after the
// navigation from about:blank to about:robots, but bug 1596738 changed this
// to prevent the browser element from stealing focus from the urlbar.
//
// Some of these command tests (specifically alt-a on linux) were designed
// based on focus being in the browser content, so we need to manually focus
// the browser here to preserve that assumption.
win1.gBrowser.selectedBrowser.focus();
let commands = {};
let isMac = AppConstants.platform == "macosx";
let totalMacOnlyCommands = 0;
@ -263,6 +272,9 @@ add_task(async function test_user_defined_commands() {
await BrowserTestUtils.loadURI(win2.gBrowser.selectedBrowser, "about:robots");
await BrowserTestUtils.browserLoaded(win2.gBrowser.selectedBrowser);
// See comment above.
win2.gBrowser.selectedBrowser.focus();
let totalTestCommands =
Object.keys(testCommands).length + numberNumericCommands;
let expectedCommandsRegistered = isMac
@ -302,6 +314,10 @@ add_task(async function test_user_defined_commands() {
"about:robots"
);
await BrowserTestUtils.browserLoaded(privateWin.gBrowser.selectedBrowser);
// See comment above.
privateWin.gBrowser.selectedBrowser.focus();
keyset = privateWin.document.getElementById(keysetID);
is(keyset, null, "Expected keyset is not added to private windows");

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

@ -4943,8 +4943,13 @@ var SessionStoreInternal = {
aOptions.restoreContentReason || RESTORE_TAB_CONTENT_REASON.SET_STATE,
});
// Focus the tab's content area.
if (aTab.selected && !window.isBlankPageURL(uri)) {
// Focus the tab's content area, unless the restore is for a new tab URL or
// was triggered by a DocumentChannel process switch.
if (
aTab.selected &&
!window.isBlankPageURL(uri) &&
!aOptions.isRemotenessUpdate
) {
browser.focus();
}
},