Bug 1308931 - Make cmd k focus the urlbar if search bar is not present. r=Dao
☠☠ backed out by 5fb5979e6bfb ☠ ☠
authorKaffeekaethe <katharina.utecht@student.hpi.de>
Sat, 29 Oct 2016 15:19:44 +0200
changeset 320185 992fa87b5fbee066579a359fcecd7d4b0054ff9f
parent 320184 309ecb16acfe18bcf53d42497d0c3a489b43bc9e
child 320186 a3b6b6e39c7965561fc750d022bee96055731226
push id20751
push userphilringnalda@gmail.com
push dateSun, 30 Oct 2016 18:06:35 +0000
treeherderfx-team@e3279760cd97 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDao
bugs1308931
milestone52.0a1
Bug 1308931 - Make cmd k focus the urlbar if search bar is not present. r=Dao
browser/base/content/browser.js
browser/base/content/test/general/browser_aboutHome.js
browser/base/content/test/newtab/browser_newtab_search.js
browser/base/content/test/urlbar/browser.ini
browser/base/content/test/urlbar/browser_urlbarFocusedCmdK.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -3639,36 +3639,28 @@ const BrowserSearch = {
         }
         win = window.openDialog(getBrowserURL(), "_blank",
                                 "chrome,all,dialog=no", "about:blank");
         Services.obs.addObserver(observer, "browser-delayed-startup-finished", false);
       }
       return;
     }
 
-    let openSearchPageIfFieldIsNotActive = function(aSearchBar) {
+    let focusUrlBarIfSearchFieldIsNotActive = function(aSearchBar) {
       if (!aSearchBar || document.activeElement != aSearchBar.textbox.inputField) {
-        let url = gBrowser.currentURI.spec.toLowerCase();
-        let mm = gBrowser.selectedBrowser.messageManager;
-        let newTabRemoted = Services.prefs.getBoolPref("browser.newtabpage.remote");
-        let localNewTabEnabled = url === "about:newtab" && !newTabRemoted && NewTabUtils.allPages.enabled;
-        if (url === "about:home" || localNewTabEnabled) {
-          ContentSearch.focusInput(mm);
-        } else {
-          openUILinkIn("about:home", "current");
-        }
+      	 focusAndSelectUrlBar();
       }
     };
 
     let searchBar = this.searchBar;
     let placement = CustomizableUI.getPlacementOfWidget("search-container");
     let focusSearchBar = () => {
       searchBar = this.searchBar;
       searchBar.select();
-      openSearchPageIfFieldIsNotActive(searchBar);
+      focusUrlBarIfSearchFieldIsNotActive(searchBar);
     };
     if (placement && placement.area == CustomizableUI.AREA_PANEL) {
       // The panel is not constructed until the first time it is shown.
       PanelUI.show().then(focusSearchBar);
       return;
     }
     if (placement && placement.area == CustomizableUI.AREA_NAVBAR && searchBar &&
         searchBar.parentNode.getAttribute("overflowedItem") == "true") {
@@ -3678,17 +3670,17 @@ const BrowserSearch = {
       });
       return;
     }
     if (searchBar) {
       if (window.fullScreen)
         FullScreen.showNavToolbox();
       searchBar.select();
     }
-    openSearchPageIfFieldIsNotActive(searchBar);
+    focusUrlBarIfSearchFieldIsNotActive(searchBar);
   },
 
   /**
    * Loads a search results page, given a set of search terms. Uses the current
    * engine if the search bar is visible, or the default engine otherwise.
    *
    * @param searchText
    *        The search terms to use for the search.
--- a/browser/base/content/test/general/browser_aboutHome.js
+++ b/browser/base/content/test/general/browser_aboutHome.js
@@ -471,44 +471,16 @@ add_task(function* () {
       yield ContentTaskUtils.waitForCondition(() => doc.activeElement === searchInput,
         "Search input should be the active element.");
       is(searchInput.value, "a", "Search input should be 'a'.");
     });
   });
 });
 
 add_task(function* () {
-  info("Cmd+k should focus the search box in the page when the search box in the toolbar is absent");
-
-  // Remove the search bar from toolbar
-  CustomizableUI.removeWidgetFromArea("search-container");
-
-  yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:home" }, function* (browser) {
-    yield BrowserTestUtils.synthesizeMouseAtCenter("#brandLogo", {}, browser);
-    yield ContentTask.spawn(browser, null, function* () {
-      let doc = content.document;
-      isnot(doc.getElementById("searchText"), doc.activeElement,
-        "Search input should not be the active element.");
-    });
-
-    EventUtils.synthesizeKey("k", { accelKey: true });
-
-    yield ContentTask.spawn(browser, null, function* () {
-      let doc = content.document;
-      let searchInput = doc.getElementById("searchText");
-
-      yield ContentTaskUtils.waitForCondition(() => doc.activeElement === searchInput,
-        "Search input should be the active element.");
-    });
-  });
-
-  CustomizableUI.reset();
-});
-
-add_task(function* () {
   info("Cmd+k should focus the search box in the toolbar when it's present");
 
   yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:home" }, function* (browser) {
     yield BrowserTestUtils.synthesizeMouseAtCenter("#brandLogo", {}, browser);
 
     let doc = window.document;
     let searchInput = doc.getElementById("searchbar").textbox.inputField;
     isnot(searchInput, doc.activeElement, "Search bar should not be the active element.");
--- a/browser/base/content/test/newtab/browser_newtab_search.js
+++ b/browser/base/content/test/newtab/browser_newtab_search.js
@@ -173,39 +173,16 @@ add_task(function* () {
   EventUtils.synthesizeKey("a", { accelKey: true });
   EventUtils.synthesizeKey("VK_DELETE", {});
 
   yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
     Assert.ok(content.document.getElementById("searchSuggestionTable").hidden,
       "Search suggestion table hidden");
   });
 
-  // Remove the search bar from toolbar
-  CustomizableUI.removeWidgetFromArea("search-container");
-  // Focus a different element than the search input from the page.
-  yield BrowserTestUtils.synthesizeMouseAtCenter("#newtab-customize-button", { }, gBrowser.selectedBrowser);
-
-  yield ContentTask.spawn(gBrowser.selectedBrowser, { }, function* () {
-    let input = content.document.getElementById("newtab-search-text");
-    Assert.notEqual(input, content.document.activeElement, "Search input should not be focused");
-  });
-
-  // Test that Ctrl/Cmd + K will focus the input field from the page.
-  let focusPromise = promiseSearchEvents(["FocusInput"]);
-  EventUtils.synthesizeKey("k", { accelKey: true });
-  yield focusPromise;
-
-  yield ContentTask.spawn(gBrowser.selectedBrowser, { }, function* () {
-    let input = content.document.getElementById("newtab-search-text");
-    Assert.equal(input, content.document.activeElement, "Search input should be focused");
-  });
-
-  // Reset changes made to toolbar
-  CustomizableUI.reset();
-
   // Test that Ctrl/Cmd + K will focus the search bar from toolbar.
   EventUtils.synthesizeKey("k", { accelKey: true });
   let searchBar = document.getElementById("searchbar");
   is(searchBar.textbox.inputField, document.activeElement, "Toolbar's search bar should be focused");
 
   // Test that Ctrl/Cmd + K will focus the search bar from a new about:home page if
   // the newtab is disabled from `NewTabUtils.allPages.enabled`.
   let tab = yield* addNewTabPageTab();
--- a/browser/base/content/test/urlbar/browser.ini
+++ b/browser/base/content/test/urlbar/browser.ini
@@ -50,16 +50,17 @@ skip-if = os == 'linux' # Bug 1104755
 subsuite = clipboard
 support-files =
   authenticate.sjs
 [browser_urlbarDecode.js]
 [browser_urlbarDelete.js]
 [browser_urlbarEnter.js]
 [browser_urlbarEnterAfterMouseOver.js]
 skip-if = os == "linux" # Bug 1073339 - Investigate autocomplete test unreliability on Linux/e10s
+[browser_urlbarFocusedCmdK.js]
 [browser_urlbarHashChangeProxyState.js]
 [browser_urlbarKeepStateAcrossTabSwitches.js]
 [browser_urlbarOneOffs.js]
 [browser_urlbarPrivateBrowsingWindowChange.js]
 [browser_urlbarRaceWithTabs.js]
 [browser_urlbarRevert.js]
 [browser_urlbarSearchSingleWordNotification.js]
 [browser_urlbarSearchSuggestions.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/urlbar/browser_urlbarFocusedCmdK.js
@@ -0,0 +1,17 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(function*() {
+
+  // Remove the search bar from toolbar
+  CustomizableUI.removeWidgetFromArea("search-container");
+
+  // Test that Ctrl/Cmd + K will focus the url bar
+  yield EventUtils.synthesizeKey("k", { accelKey: true });
+  yield BrowserTestUtils.waitForEvent(gURLBar, "focus");
+  Assert.equal(document.activeElement, gURLBar.inputField, "URL Bar should be focused");
+
+  // Reset changes made to toolbar
+  CustomizableUI.reset();
+});
+