Bug 1803681 - Show the search term if returning to a tab contains a blank value - r=adw

Differential Revision: https://phabricator.services.mozilla.com/D163730
This commit is contained in:
James Teow
2023-01-03 18:24:36 +00:00
parent 13c0f6ea74
commit 537118e46e
2 changed files with 27 additions and 1 deletions

View File

@@ -337,7 +337,11 @@ export class UrlbarInput {
dueToSessionRestore = false,
dontShowSearchTerms = false
) {
if (!dontShowSearchTerms && this.window.gBrowser.userTypedValue == null) {
if (
!dontShowSearchTerms &&
(this.window.gBrowser.userTypedValue == null ||
this.window.gBrowser.userTypedValue == "")
) {
this.window.gBrowser.selectedBrowser.showingSearchTerms = false;
if (lazy.UrlbarPrefs.isPersistedSearchTermsEnabled()) {
let term = lazy.UrlbarSearchUtils.getSearchTermIfDefaultSerpUri(

View File

@@ -135,3 +135,25 @@ add_task(async function user_overwrites_search_term() {
BrowserTestUtils.removeTab(tab1);
BrowserTestUtils.removeTab(tab2);
});
// If a user clears the URL bar, and goes to a different tab,
// the original tab should show the search term again.
add_task(async function user_overwrites_search_term() {
let { tab: tab1 } = await searchWithTab(SEARCH_STRING);
gURLBar.focus();
gURLBar.select();
EventUtils.sendKey("delete");
Assert.equal(gURLBar.value, "", "Empty string should be in url bar.");
// Open a new tab, switch back to the first and check
// the blank string is replaced with the search string.
let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser);
await BrowserTestUtils.switchTab(gBrowser, tab1);
assertSearchStringIsInUrlbar(SEARCH_STRING);
BrowserTestUtils.removeTab(tab1);
BrowserTestUtils.removeTab(tab2);
});