diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js
index 04f771e591d0..d26d02668526 100755
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2239,7 +2239,18 @@ function loadOneOrMoreURIs(aURIString, aTriggeringPrincipal) {
}
}
-function focusAndSelectUrlBar() {
+/**
+ * Focuses the location bar input field and selects its contents.
+ *
+ * @param [optional] userInitiatedFocus
+ * Whether this focus is caused by an user interaction whose intention
+ * was to use the location bar. For example, using a shortcut to go to
+ * the location bar, or a contextual menu to search from it.
+ * The default is false and should be used in all those cases where the
+ * code focuses the location bar but that's not the primary user
+ * intention, like when opening a new tab.
+ */
+function focusAndSelectUrlBar(userInitiatedFocus = false) {
// In customize mode, the url bar is disabled. If a new tab is opened or the
// user switches to a different tab, this function gets called before we've
// finished leaving customize mode, and the url bar will still be disabled.
@@ -2247,7 +2258,7 @@ function focusAndSelectUrlBar() {
// we've finished leaving customize mode.
if (CustomizationHandler.isExitingCustomizeMode) {
gNavToolbox.addEventListener("aftercustomization", function() {
- focusAndSelectUrlBar();
+ focusAndSelectUrlBar(userInitiatedFocus);
}, {once: true});
return true;
@@ -2257,7 +2268,9 @@ function focusAndSelectUrlBar() {
if (window.fullScreen)
FullScreen.showNavToolbox();
+ gURLBar.userInitiatedFocus = userInitiatedFocus;
gURLBar.select();
+ gURLBar.userInitiatedFocus = false;
if (document.activeElement == gURLBar.inputField)
return true;
}
@@ -2265,7 +2278,7 @@ function focusAndSelectUrlBar() {
}
function openLocation() {
- if (focusAndSelectUrlBar())
+ if (focusAndSelectUrlBar(true))
return;
if (window.location.href != getBrowserURL()) {
@@ -3815,7 +3828,7 @@ const BrowserSearch = {
let focusUrlBarIfSearchFieldIsNotActive = function(aSearchBar) {
if (!aSearchBar || document.activeElement != aSearchBar.textbox.inputField) {
- focusAndSelectUrlBar();
+ focusAndSelectUrlBar(true);
}
};
diff --git a/browser/base/content/test/static/browser_all_files_referenced.js b/browser/base/content/test/static/browser_all_files_referenced.js
index 65fd585f6250..206cb17a757b 100644
--- a/browser/base/content/test/static/browser_all_files_referenced.js
+++ b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -133,8 +133,6 @@ var whitelist = [
{file: "chrome://global/content/customizeToolbar.xul"},
// Bug 1343837
{file: "chrome://global/content/findUtils.js"},
- // Bug 1343843
- {file: "chrome://global/content/url-classifier/unittests.xul"},
// Bug 1348362
{file: "chrome://global/skin/icons/warning-64.png", platforms: ["linux", "win"]},
// Bug 1348525
diff --git a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js
index 9fca402f2681..2accabb3833f 100644
--- a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js
+++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js
@@ -1,3 +1,4 @@
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
// The order of the tests here matters!
const SUGGEST_ALL_PREF = "browser.search.suggest.enabled";
@@ -38,7 +39,7 @@ add_task(async function focus() {
setupVisibleHint();
gURLBar.blur();
let popupPromise = promisePopupShown(gURLBar.popup);
- gURLBar.focus();
+ focusAndSelectUrlBar(true);
await popupPromise;
Assert.ok(gURLBar.popup.popupOpen, "popup should be open");
assertVisible(true);
@@ -64,23 +65,40 @@ add_task(async function focus() {
await BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "about:blank");
});
-add_task(async function new_tab() {
- // Opening a new tab when the urlbar is unfocused, should focusing it and thus
- // open the popup in order to show the notification.
+add_task(async function click_on_focused() {
+ // Even if the location bar is already focused, we should still show the popup
+ // and the notification on click.
setupVisibleHint();
gURLBar.blur();
+ // Won't show the hint since it's not user initiated.
+ gURLBar.focus();
+ await new Promise(resolve => setTimeout(resolve, 500));
+ Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed");
+
let popupPromise = promisePopupShown(gURLBar.popup);
- // openNewForegroundTab doesn't focus the urlbar.
- await BrowserTestUtils.synthesizeKey("t", { accelKey: true }, gBrowser.selectedBrowser);
+ EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, { button: 0, type: "mousedown" });
await popupPromise;
+
Assert.ok(gURLBar.popup.popupOpen, "popup should be open");
assertVisible(true);
assertFooterVisible(false);
Assert.equal(gURLBar.popup._matchCount, 0, "popup should have no results");
- await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+ gURLBar.blur();
Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed");
});
+add_task(async function new_tab() {
+ // Opening a new tab when the urlbar is unfocused, should focus it but not
+ // open the popup.
+ setupVisibleHint();
+ gURLBar.blur();
+ // openNewForegroundTab doesn't focus the urlbar.
+ await BrowserTestUtils.synthesizeKey("t", { accelKey: true }, gBrowser.selectedBrowser);
+ await new Promise(resolve => setTimeout(resolve, 500));
+ Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed");
+ await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
add_task(async function privateWindow() {
// Since suggestions are disabled in private windows, the notification should
// not appear even when suggestions are otherwise enabled.
diff --git a/browser/base/content/urlbarBindings.xml b/browser/base/content/urlbarBindings.xml
index cf8fb827ddbc..44aa6b88da79 100644
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -184,6 +184,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.