Bug 1957630: Restore Unified Search Button availability even after switching tab r=adw
Differential Revision: https://phabricator.services.mozilla.com/D244709
This commit is contained in:
@@ -165,7 +165,7 @@ export class SearchModeSwitcher {
|
||||
|
||||
handleEvent(event) {
|
||||
if (event.type == "focus") {
|
||||
this.#input.toggleAttribute("unifiedsearchbutton-available", true);
|
||||
this.#input.setUnifiedSearchButtonAvailability(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -704,7 +704,7 @@ export class UrlbarController {
|
||||
}
|
||||
|
||||
#focusOnUnifiedSearchButton() {
|
||||
this.input.toggleAttribute("unifiedsearchbutton-available", true);
|
||||
this.input.setUnifiedSearchButtonAvailability(true);
|
||||
|
||||
const switcher = this.input.document.getElementById(
|
||||
"urlbar-searchmode-switcher"
|
||||
|
||||
@@ -594,7 +594,13 @@ export class UrlbarInput {
|
||||
|
||||
// The proxystate must be set before setting search mode below because
|
||||
// search mode depends on it.
|
||||
this.setPageProxyState(valid ? "valid" : "invalid", dueToTabSwitch);
|
||||
this.setPageProxyState(
|
||||
valid ? "valid" : "invalid",
|
||||
dueToTabSwitch,
|
||||
dueToTabSwitch &&
|
||||
this.getBrowserState(this.window.gBrowser.selectedBrowser)
|
||||
.isUnifiedSearchButtonAvailable
|
||||
);
|
||||
|
||||
if (
|
||||
state.persist?.shouldPersist &&
|
||||
@@ -2181,14 +2187,24 @@ export class UrlbarInput {
|
||||
* Indicates whether we should update the PopupNotifications
|
||||
* visibility due to this change, otherwise avoid doing so as it is
|
||||
* being handled somewhere else.
|
||||
* @param {boolean} [forceUnifiedSearchButtonAvailable]
|
||||
* If this parameter is true, force to make Unified Search Button available.
|
||||
* Otherwise, the availability will be depedent on the proxy state.
|
||||
* Default value is false.
|
||||
*/
|
||||
setPageProxyState(state, updatePopupNotifications) {
|
||||
setPageProxyState(
|
||||
state,
|
||||
updatePopupNotifications,
|
||||
forceUnifiedSearchButtonAvailable = false
|
||||
) {
|
||||
let prevState = this.getAttribute("pageproxystate");
|
||||
|
||||
this.setAttribute("pageproxystate", state);
|
||||
this._inputContainer.setAttribute("pageproxystate", state);
|
||||
this._identityBox?.setAttribute("pageproxystate", state);
|
||||
this.toggleAttribute("unifiedsearchbutton-available", state == "invalid");
|
||||
this.setUnifiedSearchButtonAvailability(
|
||||
forceUnifiedSearchButtonAvailable || state == "invalid"
|
||||
);
|
||||
|
||||
if (state == "valid") {
|
||||
this._lastValidURLStr = this.value;
|
||||
@@ -3880,6 +3896,18 @@ export class UrlbarInput {
|
||||
this._addObservers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Unified Search Button availability.
|
||||
*
|
||||
* @param {boolean} available If true Unified Search Button will be available.
|
||||
*/
|
||||
setUnifiedSearchButtonAvailability(available) {
|
||||
this.toggleAttribute("unifiedsearchbutton-available", available);
|
||||
this.getBrowserState(
|
||||
this.window.gBrowser.selectedBrowser
|
||||
).isUnifiedSearchButtonAvailable = available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Promise that resolves with default search engine.
|
||||
*
|
||||
|
||||
@@ -21,40 +21,66 @@ add_task(async function test_button_visibility_by_pageproxystate() {
|
||||
gBrowser,
|
||||
"https://example.com/"
|
||||
);
|
||||
await assertButtonVisibility(false);
|
||||
await assertState(false, "valid");
|
||||
|
||||
info("Click on browser element");
|
||||
await clickOnBrowserElement();
|
||||
await assertButtonVisibility(false);
|
||||
await assertState(false, "valid");
|
||||
|
||||
info("Click on urlbar");
|
||||
EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, {});
|
||||
await assertButtonVisibility(false);
|
||||
await assertState(false, "valid");
|
||||
|
||||
info("Start to edit");
|
||||
EventUtils.synthesizeKey("a");
|
||||
await assertButtonVisibility(true);
|
||||
await assertState(true, "invalid");
|
||||
|
||||
info("Click on browser element");
|
||||
await clickOnBrowserElement();
|
||||
await assertButtonVisibility(true);
|
||||
await assertState(true, "invalid");
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
async function assertButtonVisibility(expected) {
|
||||
add_task(async function test_button_visibility_by_tab_switching() {
|
||||
info("Open pageproxystate valid page");
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
"https://example.com/"
|
||||
);
|
||||
await assertState(false, "valid");
|
||||
|
||||
info("Focus on Unified Search Mode by key");
|
||||
gURLBar.focus();
|
||||
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
|
||||
await assertState(true, "valid");
|
||||
|
||||
info("Open a new tab and select it");
|
||||
let newtab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
"https://example.com/newtab"
|
||||
);
|
||||
await assertState(false, "valid");
|
||||
|
||||
info("Select the previous tab that enables Unified Search Button");
|
||||
gBrowser.selectedTab = tab;
|
||||
await assertState(true, "valid");
|
||||
|
||||
info("Clean up");
|
||||
BrowserTestUtils.removeTab(newtab);
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
async function assertState(expectedVisible, expectedProxyPageState) {
|
||||
let switcher = document.getElementById("urlbar-searchmode-switcher");
|
||||
await BrowserTestUtils.waitForCondition(() => {
|
||||
// If Unified Search Button is displayed as off-screen, the position should
|
||||
// be 'fixed'.
|
||||
let isVisible = window.getComputedStyle(switcher).position != "fixed";
|
||||
return isVisible == expected;
|
||||
}, `Wait until Unified Search Button visibility will be changed to ${expected}`);
|
||||
return isVisible == expectedVisible;
|
||||
}, `Wait until Unified Search Button visibility will be changed to ${expectedVisible}`);
|
||||
Assert.ok(true, "Unified Search Button visibility is correct");
|
||||
Assert.equal(
|
||||
gURLBar.getAttribute("pageproxystate"),
|
||||
expected ? "invalid" : "valid"
|
||||
);
|
||||
Assert.equal(gURLBar.getAttribute("pageproxystate"), expectedProxyPageState);
|
||||
}
|
||||
|
||||
async function clickOnBrowserElement() {
|
||||
|
||||
Reference in New Issue
Block a user