Bug 1308931 - Make accel+k focus the urlbar if search bar is not present. r=Dao

This commit is contained in:
Kaffeekaethe 2016-11-02 15:44:11 +01:00
Родитель b0e2113477
Коммит 0a6fe253c6
7 изменённых файлов: 23 добавлений и 134 удалений

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

@ -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);
},
/**

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

@ -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");

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

@ -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]

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

@ -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;

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

@ -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]

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

@ -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();
});

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

@ -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")