From 6ea9496773f298a28d51a928c218f6021f0ffa97 Mon Sep 17 00:00:00 2001 From: Ricky Chien Date: Thu, 22 Jun 2017 14:59:51 +0800 Subject: [PATCH] Bug 1374852 - Visiting preferences should always focus on search field r=jaws MozReview-Commit-ID: I7mnm5EkeIg --HG-- extra : rebase_source : 9179cd243e28c70687ef3f1995ca9223add96418 --- .../preferences/in-content-new/findInPage.js | 4 +++ .../browser_search_within_preferences_1.js | 30 +++++++++++++++---- .../browser_search_within_preferences_2.js | 5 +++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/browser/components/preferences/in-content-new/findInPage.js b/browser/components/preferences/in-content-new/findInPage.js index 5a662b91d13b..f58e40f26377 100644 --- a/browser/components/preferences/in-content-new/findInPage.js +++ b/browser/components/preferences/in-content-new/findInPage.js @@ -31,6 +31,10 @@ var gSearchResultsPane = { }); } }); + + window.addEventListener("load", () => { + this.searchInput.focus(); + }); } }, diff --git a/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_1.js b/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_1.js index 17d089106f64..9684844e1bd9 100644 --- a/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_1.js +++ b/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_1.js @@ -45,7 +45,10 @@ add_task(async function() { // Performs search let searchInput = gBrowser.contentDocument.getElementById("searchInput"); - searchInput.focus(); + + is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"), + "Search input should be focused when visiting preferences"); + searchInput.value = "password"; searchInput.doCommand(); @@ -84,7 +87,10 @@ add_task(async function() { // Performs search let searchInput = gBrowser.contentDocument.getElementById("searchInput"); - searchInput.focus(); + + is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"), + "Search input should be focused when visiting preferences"); + searchInput.value = "password"; searchInput.doCommand(); @@ -141,7 +147,10 @@ add_task(async function() { // Performs search let searchInput = gBrowser.contentDocument.getElementById("searchInput"); - searchInput.focus(); + + is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"), + "Search input should be focused when visiting preferences"); + searchInput.value = "coach"; searchInput.doCommand(); @@ -167,7 +176,10 @@ add_task(async function() { // Performs search let searchInput = gBrowser.contentDocument.getElementById("searchInput"); - searchInput.focus(); + + is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"), + "Search input should be focused when visiting preferences"); + searchInput.value = "password"; searchInput.doCommand(); @@ -194,7 +206,10 @@ add_task(async function() { // Performs search let searchInput = gBrowser.contentDocument.getElementById("searchInput"); - searchInput.focus(); + + is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"), + "Search input should be focused when visiting preferences"); + searchInput.value = "site data"; searchInput.doCommand(); @@ -220,7 +235,10 @@ add_task(async function() { await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true}); let searchInput = gBrowser.contentDocument.getElementById("searchInput"); let searchResultsCategory = gBrowser.contentDocument.getElementById("category-search-results"); - searchInput.focus(); + + is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"), + "Search input should be focused when visiting preferences"); + searchInput.value = "password"; searchInput.doCommand(); is(searchResultsCategory.hidden, false, "search results category should be shown"); diff --git a/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js b/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js index 642d16ba9d18..fc7d6119a065 100644 --- a/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js +++ b/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js @@ -27,7 +27,10 @@ add_task(async function() { // Performs search. let searchInput = gBrowser.contentDocument.getElementById("searchInput"); - searchInput.focus(); + + is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"), + "Search input should be focused when visiting preferences"); + searchInput.value = "Create Account"; searchInput.doCommand();