diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index a0592f799c7d..dff277da9d13 100755 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -3576,17 +3576,9 @@ const BrowserSearch = { 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(); } }; @@ -3595,7 +3587,7 @@ const BrowserSearch = { 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. @@ -3615,7 +3607,7 @@ const BrowserSearch = { FullScreen.showNavToolbox(); searchBar.select(); } - openSearchPageIfFieldIsNotActive(searchBar); + focusUrlBarIfSearchFieldIsNotActive(searchBar); }, /** diff --git a/browser/base/content/test/general/browser_aboutHome.js b/browser/base/content/test/general/browser_aboutHome.js index 8cadf3dfb9e0..f0e19e852d6c 100644 --- a/browser/base/content/test/general/browser_aboutHome.js +++ b/browser/base/content/test/general/browser_aboutHome.js @@ -475,34 +475,6 @@ add_task(function* () { }); }); -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"); diff --git a/browser/base/content/test/newtab/browser.ini b/browser/base/content/test/newtab/browser.ini index 418c2852b560..21b1c2fb861b 100644 --- a/browser/base/content/test/newtab/browser.ini +++ b/browser/base/content/test/newtab/browser.ini @@ -45,6 +45,7 @@ support-files = ../general/searchSuggestionEngine.xml ../general/searchSuggestionEngine.sjs [browser_newtab_sponsored_icon_click.js] +skip-if = true # Bug 1314619 [browser_newtab_undo.js] [browser_newtab_unpin.js] [browser_newtab_update.js] diff --git a/browser/base/content/test/newtab/browser_newtab_search.js b/browser/base/content/test/newtab/browser_newtab_search.js index 949d2303c649..19ed4ba74ee1 100644 --- a/browser/base/content/test/newtab/browser_newtab_search.js +++ b/browser/base/content/test/newtab/browser_newtab_search.js @@ -178,65 +178,6 @@ add_task(function* () { "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(); - // Remove the search bar from toolbar - CustomizableUI.removeWidgetFromArea("search-container"); - NewTabUtils.allPages.enabled = false; - EventUtils.synthesizeKey("k", { accelKey: true }); - - - let aboutHomeLoaded = new Promise(resolve => { - tab.linkedBrowser.addEventListener("AboutHomeLoadSnippetsCompleted", function loadListener(event) { - tab.linkedBrowser.removeEventListener("AboutHomeLoadSnippetsCompleted", loadListener, true); - resolve(); - }, true, true); - }); - - tab.linkedBrowser.loadURI("about:home"); - yield aboutHomeLoaded; - - yield ContentTask.spawn(gBrowser.selectedBrowser, { }, function* () { - Assert.equal(content.document.documentURI.toLowerCase(), "about:home", - "New tab's uri should be about:home"); - let searchInput = content.document.getElementById("searchText"); - Assert.equal(searchInput, content.document.activeElement, - "Search input must be the selected element"); - }); - - NewTabUtils.allPages.enabled = true; - CustomizableUI.reset(); - yield BrowserTestUtils.removeTab(gBrowser.selectedTab); - // Done. Revert the current engine and remove the new engines. searchEventsPromise = promiseSearchEvents(["CurrentEngine"]); Services.search.currentEngine = oldCurrentEngine; diff --git a/browser/base/content/test/urlbar/browser.ini b/browser/base/content/test/urlbar/browser.ini index cdc43fee8f7c..ca6d70f401a9 100644 --- a/browser/base/content/test/urlbar/browser.ini +++ b/browser/base/content/test/urlbar/browser.ini @@ -55,6 +55,7 @@ support-files = [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] diff --git a/browser/base/content/test/urlbar/browser_urlbarFocusedCmdK.js b/browser/base/content/test/urlbar/browser_urlbarFocusedCmdK.js new file mode 100644 index 000000000000..8c9e2c9f2985 --- /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 + let focusPromise = BrowserTestUtils.waitForEvent(gURLBar, "focus"); + EventUtils.synthesizeKey("k", { accelKey: true }); + yield focusPromise; + Assert.equal(document.activeElement, gURLBar.inputField, "URL Bar should be focused"); + + // Reset changes made to toolbar + CustomizableUI.reset(); +}); + diff --git a/browser/components/customizableui/test/browser_901207_searchbar_in_panel.js b/browser/components/customizableui/test/browser_901207_searchbar_in_panel.js index 2f5ce66b8c8a..3bc449add744 100644 --- a/browser/components/customizableui/test/browser_901207_searchbar_in_panel.js +++ b/browser/components/customizableui/test/browser_901207_searchbar_in_panel.js @@ -4,17 +4,6 @@ "use strict"; -var openUILinkInCalled = false; -var expectOpenUILinkInCall = false; -this.originalOpenUILinkIn = openUILinkIn; -openUILinkIn = (aUrl, aWhichTab) => { - is(aUrl, "about:home", "about:home should be requested to open."); - is(aWhichTab, "current", "Should use the current tab for the search page."); - openUILinkInCalled = true; - if (!expectOpenUILinkInCall) { - ok(false, "OpenUILinkIn was called when it shouldn't have been."); - } -}; logActiveElement(); function* waitForSearchBarFocus() @@ -105,30 +94,6 @@ add_task(function*() { yield waitForSearchBarFocus(); }); -// Ctrl+K should open the search page if the search bar has been customized out. -add_task(function*() { - try { - expectOpenUILinkInCall = true; - CustomizableUI.removeWidgetFromArea("search-container"); - let placement = CustomizableUI.getPlacementOfWidget("search-container"); - is(placement, null, "Search container should be in palette"); - - openUILinkInCalled = false; - - sendWebSearchKeyCommand(); - yield waitForCondition(() => openUILinkInCalled); - ok(openUILinkInCalled, "The search page should have been opened.") - expectOpenUILinkInCall = false; - } catch (e) { - ok(false, e); - } - CustomizableUI.reset(); -}); - -registerCleanupFunction(function() { - openUILinkIn = this.originalOpenUILinkIn; - delete this.originalOpenUILinkIn; -}); function sendWebSearchKeyCommand() { if (Services.appinfo.OS === "Darwin")