From 753cf86f059d860d4eb6d0fd9d169ee36c3215b0 Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Mon, 14 Jun 2021 23:38:50 +0000 Subject: [PATCH] Bug 1602396: Set focus to URLBar when an empty tab is moved to new window. r=adw Differential Revision: https://phabricator.services.mozilla.com/D117522 --- browser/base/content/browser.js | 3 ++- .../content/test/general/browser_bug495058.js | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 4fd99348f533..11c4a8d57876 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2151,7 +2151,8 @@ var gBrowserInit = { if ( (isBlankPageURL(uriToLoad) && !aboutWelcomeSkipUrlBarFocus) || - uriToLoad == "about:privatebrowsing" + uriToLoad == "about:privatebrowsing" || + this.getTabToAdopt()?.isEmpty ) { gURLBar.select(); shouldRemoveFocusedAttribute = false; diff --git a/browser/base/content/test/general/browser_bug495058.js b/browser/base/content/test/general/browser_bug495058.js index 34c8c4b80393..6bb1d4a7b2b2 100644 --- a/browser/base/content/test/general/browser_bug495058.js +++ b/browser/base/content/test/general/browser_bug495058.js @@ -3,7 +3,12 @@ * torn out into its own window. */ -const URIS = ["about:blank", "about:sessionrestore", "about:privatebrowsing"]; +const URIS = [ + "about:blank", + "about:home", + "about:sessionrestore", + "about:privatebrowsing", +]; add_task(async function() { for (let uri of URIS) { @@ -35,10 +40,14 @@ add_task(async function() { uri, uri + ": uri loaded in detached tab" ); + + const expectedActiveElement = tab.isEmpty + ? win.gURLBar.inputField + : win.gBrowser.selectedBrowser; Assert.equal( win.document.activeElement, - win.gBrowser.selectedBrowser, - uri + ": browser is focused" + expectedActiveElement, + uri + ": the active element is expected" ); Assert.equal(win.gURLBar.value, "", uri + ": urlbar is empty"); Assert.ok(win.gURLBar.placeholder, uri + ": placeholder text is present");