Bug 1943208 - Allow callout primary CTA to flip multiple prefs and open the chatbot panel r=sidebar-reviewers,sclements

Reopen panel if one was open when toggling revamp and still available. This avoids race condition of trying to open chatbot and flip revamp at the same time.

Differential Revision: https://phabricator.services.mozilla.com/D245367
This commit is contained in:
Ed Lee
2025-04-14 14:23:39 +00:00
parent 5acaa33ed6
commit 26865b29fa
2 changed files with 37 additions and 7 deletions

View File

@@ -203,13 +203,15 @@ var SidebarController = {
}
);
this._sidebars.set("viewCustomizeSidebar", {
url: "chrome://browser/content/sidebar/sidebar-customize.html",
revampL10nId: "sidebar-menu-customize-label",
iconUrl: "chrome://global/skin/icons/settings.svg",
gleanEvent: Glean.sidebarCustomize.panelToggle,
visible: false,
});
if (this.sidebarRevampEnabled) {
this._sidebars.set("viewCustomizeSidebar", {
url: "chrome://browser/content/sidebar/sidebar-customize.html",
revampL10nId: "sidebar-menu-customize-label",
iconUrl: "chrome://global/skin/icons/settings.svg",
gleanEvent: Glean.sidebarCustomize.panelToggle,
visible: false,
});
}
return this._sidebars;
},
@@ -801,10 +803,16 @@ var SidebarController = {
}
if (!this._sidebars.get(this.lastOpenedId)) {
this.lastOpenedId = this.DEFAULT_SIDEBAR_ID;
wasOpen = false;
}
this.updateToolbarButton();
this._inited = false;
this.init();
// Reopen the panel in the new or old sidebar now that we've inited
if (wasOpen) {
this.toggle();
}
},
/**

View File

@@ -230,6 +230,28 @@ add_task(async function test_flip_revamp_pref() {
await BrowserTestUtils.closeWindow(win);
});
/**
* Check that panels can stay open when flipping sidebar.revamp
*/
add_task(async function test_flip_revamp_pref_with_panel() {
await toggleSidebarPanel(window, "viewGenaiChatSidebar");
ok(SidebarController.isOpen, "panel open with revamp");
await SpecialPowers.pushPrefEnv({
set: [["sidebar.revamp", false]],
});
ok(SidebarController.isOpen, "panel still open after old");
await SpecialPowers.pushPrefEnv({
set: [["sidebar.revamp", true]],
});
ok(SidebarController.isOpen, "panel still open after new");
await SidebarController.hide();
});
add_task(async function test_opening_panel_flips_has_used_pref() {
Services.prefs.clearUserPref("sidebar.old-sidebar.has-used");
Services.prefs.clearUserPref("sidebar.new-sidebar.has-used");