Backed out changeset f56181344f2a (bug 1921536) for causing bc failures @ browser_bookmark_context_menu_contents.js & browser_reviewchecker_sidebar.js CLOSED TREE

This commit is contained in:
Sandor Molnar
2025-03-06 06:15:10 +02:00
parent 584caf8dca
commit b51ff49434
11 changed files with 122 additions and 422 deletions

View File

@@ -27,14 +27,7 @@ var showSidebar = async function (win = window) {
var hideSidebar = async function (win = window) { var hideSidebar = async function (win = window) {
let button = win.document.getElementById("sidebar-button"); let button = win.document.getElementById("sidebar-button");
let box = win.document.getElementById("sidebar-box");
EventUtils.synthesizeMouseAtCenter(button, {}, win); EventUtils.synthesizeMouseAtCenter(button, {}, win);
await BrowserTestUtils.waitForMutationCondition(
box,
{ attributes: true, attributeFilter: ["hidden"] },
() => box.hidden
);
ok(!win.SidebarController.isOpen, "Sidebar is closed"); ok(!win.SidebarController.isOpen, "Sidebar is closed");
ok(!button.hasAttribute("checked"), "Toolbar button isn't checked"); ok(!button.hasAttribute("checked"), "Toolbar button isn't checked");
}; };
@@ -81,16 +74,7 @@ add_task(async function () {
} }
} }
let otherWin = await BrowserTestUtils.openNewBrowserWindow(); let otherWin = await BrowserTestUtils.openNewBrowserWindow();
info("Waiting for the sidebar to initialize in the new browser window");
await BrowserTestUtils.waitForCondition(
() => otherWin.SidebarController.uiStateInitialized,
"The uiStateInitialized is true in the new window"
);
if (!sidebarRevampEnabled) { if (!sidebarRevampEnabled) {
ok(
!otherWin.SidebarController.isOpen,
"The sidebar panel isn't open in the new window"
);
await showSidebar(otherWin); await showSidebar(otherWin);
is( is(
otherWin.SidebarController.currentID, otherWin.SidebarController.currentID,

View File

@@ -43,14 +43,12 @@ class TestSessionRestore(SessionStoreTestCase):
1, 1,
msg="Should have 1 window open.", msg="Should have 1 window open.",
) )
self.marionette.execute_async_script( self.marionette.execute_script(
""" """
const resolve = arguments[0];
let window = BrowserWindowTracker.getTopWindow() let window = BrowserWindowTracker.getTopWindow()
window.SidebarController.show("viewHistorySidebar").then(() => { window.SidebarController.show("viewHistorySidebar");
let sidebarBox = window.document.getElementById("sidebar-box") let sidebarBox = window.document.getElementById("sidebar-box")
sidebarBox.style.width = "100px"; sidebarBox.style.width = "100px";
}).then(resolve);
""" """
) )
@@ -112,15 +110,13 @@ class TestSessionRestore(SessionStoreTestCase):
) )
def test_restore_sidebar_closed(self): def test_restore_sidebar_closed(self):
self.marionette.execute_async_script( self.marionette.execute_script(
""" """
const resolve = arguments[0];
let window = BrowserWindowTracker.getTopWindow() let window = BrowserWindowTracker.getTopWindow()
window.SidebarController.show("viewHistorySidebar").then(() => { window.SidebarController.show("viewHistorySidebar");
let sidebarBox = window.document.getElementById("sidebar-box") let sidebarBox = window.document.getElementById("sidebar-box")
sidebarBox.style.width = "100px"; sidebarBox.style.width = "100px";
window.SidebarController.toggle(); window.SidebarController.toggle();
}).then(resolve);
""" """
) )

View File

@@ -58,9 +58,8 @@ export class SidebarState {
launcherDragActive: false, launcherDragActive: false,
launcherHoverActive: false, launcherHoverActive: false,
collapsedLauncherWidth: undefined, collapsedLauncherWidth: undefined,
command: undefined,
}; };
#previousLauncherExpanded = undefined; #previousLauncherVisible = undefined;
/** /**
* Construct a new SidebarState. * Construct a new SidebarState.
@@ -154,7 +153,7 @@ export class SidebarState {
} }
switch (key) { switch (key) {
case "command": case "command":
this.command = value; this.#controller.showInitially(value);
break; break;
case "panelWidth": case "panelWidth":
this.#panelEl.style.width = `${value}px`; this.#panelEl.style.width = `${value}px`;
@@ -168,33 +167,10 @@ export class SidebarState {
case "hidden": case "hidden":
this.launcherVisible = !value; this.launcherVisible = !value;
break; break;
case "panelOpen":
// we need to know if we have a command value before finalizing panelOpen
break;
default: default:
this[key] = value; this[key] = value;
} }
} }
if (this.revampEnabled) {
if (this.command && !this.launcherVisible) {
// We're restoring a session or state saved with an open sidebar panel when sidebar.revamp was false
props.panelOpen = true;
}
}
if (this.command && !props.hasOwnProperty("panelOpen")) {
// legacy state saved before panelOpen was a thing
props.panelOpen = true;
}
if (!this.command) {
props.panelOpen = false;
}
this.panelOpen = !!props.panelOpen;
if (this.command && this.panelOpen) {
this.launcherVisible = true;
// show() is async, so make sure we return its promise here
return this.#controller.showInitially(this.command);
}
return this.#controller.hide();
} }
/** /**
@@ -216,8 +192,7 @@ export class SidebarState {
*/ */
getProperties() { getProperties() {
return { return {
command: this.command, command: this.#controller.currentID,
panelOpen: this.panelOpen,
panelWidth: this.panelWidth, panelWidth: this.panelWidth,
launcherWidth: convertToInt(this.launcherWidth), launcherWidth: convertToInt(this.launcherWidth),
expandedLauncherWidth: convertToInt(this.expandedLauncherWidth), expandedLauncherWidth: convertToInt(this.expandedLauncherWidth),
@@ -235,24 +210,20 @@ export class SidebarState {
} }
set panelOpen(open) { set panelOpen(open) {
if (this.#props.panelOpen == open) { this.#props.panelOpen = open;
return;
}
this.#props.panelOpen = !!open;
if (open) { if (open) {
// Launcher must be visible to open a panel. // Launcher must be visible to open a panel.
this.#previousLauncherVisible = this.launcherVisible;
this.launcherVisible = true; this.launcherVisible = true;
// We need to know how to revert the launcher when the panel closes
this.#previousLauncherExpanded = this.launcherExpanded;
Services.prefs.setBoolPref( Services.prefs.setBoolPref(
this.revampEnabled ? REVAMP_USED_PREF : LEGACY_USED_PREF, this.revampEnabled ? REVAMP_USED_PREF : LEGACY_USED_PREF,
true true
); );
} else if (this.revampVisibility === "hide-sidebar") { } else if (this.revampVisibility === "hide-sidebar") {
this.launcherExpanded = lazy.verticalTabsEnabled this.launcherExpanded = lazy.verticalTabsEnabled
? this.#previousLauncherExpanded ? this.#previousLauncherVisible
: false; : false;
this.launcherVisible = this.#previousLauncherVisible;
} }
} }
@@ -294,7 +265,7 @@ export class SidebarState {
case "hide-sidebar": case "hide-sidebar":
if (onToolbarButtonRemoval) { if (onToolbarButtonRemoval) {
// If we are hiding the sidebar because we removed the toolbar button, close everything // If we are hiding the sidebar because we removed the toolbar button, close everything
this.#previousLauncherExpanded = false; this.#previousLauncherVisible = false;
this.launcherVisible = false; this.launcherVisible = false;
this.launcherExpanded = false; this.launcherExpanded = false;
@@ -312,7 +283,7 @@ export class SidebarState {
} else { } else {
// Hide the launcher when the pref is set to hide-sidebar // Hide the launcher when the pref is set to hide-sidebar
this.launcherVisible = false; this.launcherVisible = false;
this.#previousLauncherExpanded = false; this.#previousLauncherVisible = false;
return; return;
} }
} }
@@ -321,11 +292,8 @@ export class SidebarState {
case "always-show": case "always-show":
case "expand-on-hover": case "expand-on-hover":
this.launcherVisible = true; this.launcherVisible = true;
if (forceExpandValue !== null) { this.launcherExpanded =
this.launcherExpanded = forceExpandValue; forceExpandValue !== null ? forceExpandValue : !this.launcherExpanded;
} else if (onUserToggle) {
this.launcherExpanded = !this.launcherExpanded;
}
break; break;
} }
} }
@@ -452,24 +420,6 @@ export class SidebarState {
.getElementById("tabbrowser-tabbox") .getElementById("tabbrowser-tabbox")
.toggleAttribute("sidebar-shown", isSidebarShown); .toggleAttribute("sidebar-shown", isSidebarShown);
} }
get command() {
return this.#props.command || "";
}
set command(id) {
if (id && !this.#controller.sidebars.has(id)) {
throw new Error("Setting command to an invalid value");
}
if (id && id !== this.#props.command) {
this.#props.command = id;
// We need the attribute to mirror the command property as its used as a CSS hook
this.#controller._box.setAttribute("sidebarcommand", id);
} else if (!id) {
delete this.#props.command;
this.#controller._box.setAttribute("sidebarcommand", "");
}
}
} }
/** /**

View File

@@ -526,15 +526,7 @@ var SidebarController = {
}, },
getUIState() { getUIState() {
if (this.inPopup) { return this.inPopup ? null : this._state.getProperties();
return null;
}
let snapshot = this._state.getProperties();
// we don't persist the sidebar command when the panel is closed
if (!this._state.panelOpen) {
delete snapshot.command;
}
return snapshot;
}, },
/** /**
@@ -547,23 +539,19 @@ var SidebarController = {
if (!state) { if (!state) {
return; return;
} }
const isValidSidebar = !state.command || this.sidebars.has(state.command);
if (!isValidSidebar) {
state.command = "";
}
const hasOpenPanel = const hasOpenPanel =
state.panelOpen &&
state.command && state.command &&
this.sidebars.has(state.command) && this.sidebars.has(state.command) &&
this.currentID !== state.command; this.currentID !== state.command;
if (hasOpenPanel) { if (hasOpenPanel) {
// There's a panel to show, so ignore the contradictory hidden property. // There's a panel to show, so ignore the contradictory hidden property.
delete state.hidden; delete state.hidden;
} else {
delete state.command;
} }
await this.promiseInitialized; await this.promiseInitialized;
await this.waitUntilStable(); // Finish currently scheduled tasks. await this.waitUntilStable(); // Finish currently scheduled tasks.
await this._state.loadInitialState(state); this._state.loadInitialState(state);
await this.waitUntilStable(); // Finish newly scheduled tasks. await this.waitUntilStable(); // Finish newly scheduled tasks.
this.updateToolbarButton(); this.updateToolbarButton();
this.uiStateInitialized = true; this.uiStateInitialized = true;
@@ -864,12 +852,16 @@ var SidebarController = {
document.getElementById("sidebar-main").hidden = true; document.getElementById("sidebar-main").hidden = true;
return false; return false;
} }
// Adopt the other window's UI state (it too could be a popup)
// We get the properties directly forom the SidebarState instance as in this case // Set sidebar command even if hidden, so that we keep the same sidebar
// we need the command property even if no panel is currently open. // even if it's currently closed.
const sourceState = sourceController.inPopup let commandID = sourceController._box.getAttribute("sidebarcommand");
? null if (commandID) {
: sourceController._state?.getProperties(); this._box.setAttribute("sidebarcommand", commandID);
}
// Adopt the other window's UI state.
const sourceState = sourceController.getUIState();
await this.initializeUIState(sourceState); await this.initializeUIState(sourceState);
return true; return true;
@@ -917,15 +909,17 @@ var SidebarController = {
return; return;
} }
let commandID = this._state.command; let commandID = this._box.getAttribute("sidebarcommand");
if (commandID && this.sidebars.has(commandID)) { if (commandID && this.sidebars.has(commandID)) {
this.showInitially(commandID); this.showInitially(commandID);
} else { } else {
this._box.removeAttribute("checked"); this._box.removeAttribute("checked");
// Update the state, because the element it // Remove the |sidebarcommand| attribute, because the element it
// refers to no longer exists, so we should assume this sidebar // refers to no longer exists, so we should assume this sidebar
// panel has been uninstalled. (249883) // panel has been uninstalled. (249883)
this._state.command = ""; // We use setAttribute rather than removeAttribute so it persists
// correctly.
this._box.setAttribute("sidebarcommand", "");
// On a startup in which the startup cache was invalidated (e.g. app update) // On a startup in which the startup cache was invalidated (e.g. app update)
// extensions will not be started prior to delayedLoad, thus the // extensions will not be started prior to delayedLoad, thus the
// sidebarcommand element will not exist yet. Store the commandID so // sidebarcommand element will not exist yet. Store the commandID so
@@ -976,7 +970,7 @@ var SidebarController = {
* The ID of the current sidebar. * The ID of the current sidebar.
*/ */
get currentID() { get currentID() {
return this.isOpen ? this._state.command : ""; return this.isOpen ? this._box.getAttribute("sidebarcommand") : "";
}, },
/** /**
@@ -1020,7 +1014,7 @@ var SidebarController = {
// have a persisted command either, or the command doesn't exist anymore, then // have a persisted command either, or the command doesn't exist anymore, then
// fallback to a default sidebar. // fallback to a default sidebar.
if (!commandID) { if (!commandID) {
commandID = this._state.command; commandID = this._box.getAttribute("sidebarcommand");
} }
if (!commandID || !this.sidebars.has(commandID)) { if (!commandID || !this.sidebars.has(commandID)) {
if (this.sidebarRevampEnabled && this.sidebars.size) { if (this.sidebarRevampEnabled && this.sidebars.size) {
@@ -1202,9 +1196,6 @@ var SidebarController = {
} }
}, },
/**
* For sidebar.revamp=true only, handle the keyboard or sidebar-button command to toggle the sidebar state
*/
async handleToolbarButtonClick() { async handleToolbarButtonClick() {
let initialExpandedValue = this._state.launcherExpanded; let initialExpandedValue = this._state.launcherExpanded;
if (this.inPopup || this.uninitializing) { if (this.inPopup || this.uninitializing) {
@@ -1213,12 +1204,8 @@ var SidebarController = {
if (this._animationEnabled && !window.gReduceMotion) { if (this._animationEnabled && !window.gReduceMotion) {
this._animateSidebarMain(); this._animateSidebarMain();
} }
const showLauncher = !this._state.launcherVisible;
this._state.updateVisibility(showLauncher, true); this._state.updateVisibility(!this._state.launcherVisible, true);
if (showLauncher && this._state.command) {
this._show(this._state.command);
}
if (this.sidebarRevampVisibility === "expand-on-hover") { if (this.sidebarRevampVisibility === "expand-on-hover") {
this.toggleExpandOnHover(initialExpandedValue); this.toggleExpandOnHover(initialExpandedValue);
} }
@@ -1676,7 +1663,7 @@ var SidebarController = {
this._box.hidden = this._splitter.hidden = false; this._box.hidden = this._splitter.hidden = false;
this._box.setAttribute("checked", "true"); this._box.setAttribute("checked", "true");
this._state.command = commandID; this._box.setAttribute("sidebarcommand", commandID);
let { icon, url, title, sourceL10nEl, contextMenuId } = let { icon, url, title, sourceL10nEl, contextMenuId } =
this.sidebars.get(commandID); this.sidebars.get(commandID);
@@ -1787,17 +1774,6 @@ var SidebarController = {
if (triggerNode) { if (triggerNode) {
updateToggleControlLabel(triggerNode); updateToggleControlLabel(triggerNode);
} }
let showLauncher = false;
if (
this.sidebarRevampEnabled &&
this.sidebarRevampVisibility !== "hide-sidebar"
) {
showLauncher = true;
}
this._state.updateVisibility(
showLauncher,
false // onUserToggle param means "did the user click the sidebar-button", which is false here
);
this.updateToolbarButton(); this.updateToolbarButton();
}, },
@@ -1809,9 +1785,6 @@ var SidebarController = {
*/ */
_recordPanelToggle(commandID, opened) { _recordPanelToggle(commandID, opened) {
const sidebar = this.sidebars.get(commandID); const sidebar = this.sidebars.get(commandID);
if (!sidebar) {
return;
}
const isExtension = sidebar && Object.hasOwn(sidebar, "extensionId"); const isExtension = sidebar && Object.hasOwn(sidebar, "extensionId");
const version = this.sidebarRevampEnabled ? "new" : "old"; const version = this.sidebarRevampEnabled ? "new" : "old";
if (isExtension) { if (isExtension) {
@@ -2125,13 +2098,9 @@ XPCOMUtils.defineLazyPreferenceGetter(
const forceExpand = isVerticalTabs && newValue === "always-show"; const forceExpand = isVerticalTabs && newValue === "always-show";
// horizontal tabs and hide-sidebar = visible initially. // horizontal tabs and hide-sidebar = visible initially.
// vertical tab and hide-sidebar = not visible initially // vertical tab and hide-sidebar = not visible initally.
let showLauncher = true;
if (newValue == "hide-sidebar" && isVerticalTabs) {
showLauncher = false;
}
SidebarController._state.updateVisibility( SidebarController._state.updateVisibility(
showLauncher, (newValue != "hide-sidebar" && isVerticalTabs) || !isVerticalTabs,
false, false,
false, false,
forceExpand forceExpand

View File

@@ -84,7 +84,7 @@ add_task(async function test_keyboard_navigation() {
info("Press Tab key."); info("Press Tab key.");
EventUtils.synthesizeKey("KEY_Tab", {}, win); EventUtils.synthesizeKey("KEY_Tab", {}, win);
ok(isActiveElement(customizeButton), "Customize button is focused."); ok(isActiveElement(customizeButton), "Customize button is focused.");
}).skip(); // Bug 1950504 });
add_task(async function test_menu_items_labeled() { add_task(async function test_menu_items_labeled() {
const { document, SidebarController } = win; const { document, SidebarController } = win;

View File

@@ -8,9 +8,6 @@ requestLongerTimeout(10);
const lazy = {}; const lazy = {};
const TAB_DIRECTION_PREF = "sidebar.verticalTabs"; const TAB_DIRECTION_PREF = "sidebar.verticalTabs";
const initialTabDirection = Services.prefs.getBoolPref(TAB_DIRECTION_PREF)
? "vertical"
: "horizontal";
ChromeUtils.defineESModuleGetters(lazy, { ChromeUtils.defineESModuleGetters(lazy, {
TabsSetupFlowManager: TabsSetupFlowManager:
@@ -19,10 +16,9 @@ ChromeUtils.defineESModuleGetters(lazy, {
}); });
add_setup(async () => { add_setup(async () => {
await SidebarController.promiseInitialized; SidebarController.init();
await SidebarController.sidebarMain?.updateComplete; await TestUtils.waitForTick();
}); });
registerCleanupFunction(() => { registerCleanupFunction(() => {
while (gBrowser.tabs.length > 1) { while (gBrowser.tabs.length > 1) {
BrowserTestUtils.removeTab(gBrowser.tabs[0]); BrowserTestUtils.removeTab(gBrowser.tabs[0]);
@@ -50,33 +46,31 @@ add_task(async function test_sidebar_expand() {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [[TAB_DIRECTION_PREF, true]], set: [[TAB_DIRECTION_PREF, true]],
}); });
await waitForTabstripOrientation("vertical");
// Vertical tabs are expanded by default // Vertical tabs are expanded by default
Assert.ok(SidebarController.sidebarMain.expanded, "Sidebar is expanded."); await TestUtils.waitForCondition(
() => SidebarController.sidebarMain.expanded,
"Sidebar is expanded."
);
info("Collapse the sidebar."); info("Collapse the sidebar.");
EventUtils.synthesizeMouseAtCenter(SidebarController.toolbarButton, {}); EventUtils.synthesizeMouseAtCenter(SidebarController.toolbarButton, {});
await TestUtils.waitForCondition(
await BrowserTestUtils.waitForMutationCondition( () => !SidebarController.sidebarMain.expanded,
SidebarController.sidebarMain, "Sidebar is collapsed."
{ attributes: true, attributeFilter: ["expanded"] },
() => !SidebarController.sidebarMain.expanded
); );
info("Re-expand the sidebar."); info("Re-expand the sidebar.");
EventUtils.synthesizeMouseAtCenter(SidebarController.toolbarButton, {}); EventUtils.synthesizeMouseAtCenter(SidebarController.toolbarButton, {});
await BrowserTestUtils.waitForMutationCondition( await TestUtils.waitForCondition(
SidebarController.sidebarMain, () => SidebarController.sidebarMain.expanded,
{ attributes: true, attributeFilter: ["expanded"] }, "Sidebar is expanded."
() => SidebarController.sidebarMain.expanded
); );
const events = Glean.sidebar.expand.testGetValue(); const events = Glean.sidebar.expand.testGetValue();
Assert.equal(events?.length, 2, "Two events were reported."); Assert.equal(events?.length, 2, "Two events were reported.");
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await waitForTabstripOrientation(initialTabDirection);
}); });
async function testSidebarToggle(commandID, gleanEvent, otherCommandID) { async function testSidebarToggle(commandID, gleanEvent, otherCommandID) {
@@ -106,11 +100,9 @@ async function testSidebarToggle(commandID, gleanEvent, otherCommandID) {
"false", "false",
"Event indicates that the panel was closed." "Event indicates that the panel was closed."
); );
await SidebarController.initializeUIState({ if (otherCommandID) {
panelOpen: false, SidebarController.hide();
command: "", }
launcherVisible: true,
});
} }
add_task(async function test_history_sidebar_toggle() { add_task(async function test_history_sidebar_toggle() {
@@ -174,7 +166,6 @@ async function test_synced_tabs_sidebar_toggle(revampEnabled) {
sandbox.restore(); sandbox.restore();
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await SidebarController.waitUntilStable();
Services.fog.testResetFOG(); Services.fog.testResetFOG();
} }
@@ -244,11 +235,9 @@ add_task(async function test_contextual_manager_toggle() {
["sidebar.revamp", false], ["sidebar.revamp", false],
], ],
}); });
await SidebarController.waitUntilStable();
const gleanEvent = Glean.contextualManager.sidebarToggle; const gleanEvent = Glean.contextualManager.sidebarToggle;
await testSidebarToggle("viewCPMSidebar", gleanEvent); await testSidebarToggle("viewCPMSidebar", gleanEvent);
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await SidebarController.waitUntilStable();
}); });
add_task(async function test_customize_panel_toggle() { add_task(async function test_customize_panel_toggle() {
@@ -261,14 +250,8 @@ add_task(async function test_customize_panel_toggle() {
add_task(async function test_customize_icon_click() { add_task(async function test_customize_icon_click() {
info("Click on the gear icon."); info("Click on the gear icon.");
const { customizeButton } = SidebarController.sidebarMain; const { customizeButton } = SidebarController.sidebarMain;
Assert.ok(
BrowserTestUtils.isVisible(customizeButton),
"The customize button is visible to click on"
);
const sideShown = BrowserTestUtils.waitForEvent(document, "SidebarShown");
EventUtils.synthesizeMouseAtCenter(customizeButton, {}); EventUtils.synthesizeMouseAtCenter(customizeButton, {});
await sideShown;
const events = Glean.sidebarCustomize.iconClick.testGetValue(); const events = Glean.sidebarCustomize.iconClick.testGetValue();
Assert.equal(events?.length, 1, "One event was reported."); Assert.equal(events?.length, 1, "One event was reported.");
@@ -330,8 +313,6 @@ add_task(async function test_customize_chatbot_enabled() {
"viewGenaiChatSidebar", "viewGenaiChatSidebar",
Glean.sidebarCustomize.chatbotEnabled Glean.sidebarCustomize.chatbotEnabled
); );
await SpecialPowers.popPrefEnv();
await SidebarController.waitUntilStable();
}); });
add_task(async function test_customize_synced_tabs_enabled() { add_task(async function test_customize_synced_tabs_enabled() {
@@ -365,8 +346,6 @@ add_task(async function test_customize_review_checker_enabled() {
Glean.sidebarCustomize.shoppingReviewCheckerEnabled, Glean.sidebarCustomize.shoppingReviewCheckerEnabled,
false false
); );
await SpecialPowers.popPrefEnv();
await SidebarController.waitUntilStable();
}); });
add_task(async function test_customize_extensions_clicked() { add_task(async function test_customize_extensions_clicked() {
@@ -442,7 +421,6 @@ add_task(async function test_customize_sidebar_display() {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [[TAB_DIRECTION_PREF, true]], set: [[TAB_DIRECTION_PREF, true]],
}); });
await waitForTabstripOrientation("vertical");
await testCustomizeSetting( await testCustomizeSetting(
"visibilityInput", "visibilityInput",
Glean.sidebarCustomize.sidebarDisplay, Glean.sidebarCustomize.sidebarDisplay,
@@ -450,7 +428,6 @@ add_task(async function test_customize_sidebar_display() {
{ preference: "always" } { preference: "always" }
); );
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await waitForTabstripOrientation(initialTabDirection);
}); });
add_task(async function test_customize_sidebar_position() { add_task(async function test_customize_sidebar_position() {
@@ -489,7 +466,6 @@ add_task(async function test_sidebar_resize() {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [[TAB_DIRECTION_PREF, true]], set: [[TAB_DIRECTION_PREF, true]],
}); });
await waitForTabstripOrientation("vertical");
await SidebarController.show("viewHistorySidebar"); await SidebarController.show("viewHistorySidebar");
const originalWidth = SidebarController._box.style.width; const originalWidth = SidebarController._box.style.width;
SidebarController._box.style.width = "500px"; SidebarController._box.style.width = "500px";
@@ -513,14 +489,12 @@ add_task(async function test_sidebar_resize() {
SidebarController._box.style.width = originalWidth; SidebarController._box.style.width = originalWidth;
SidebarController.hide(); SidebarController.hide();
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await waitForTabstripOrientation(initialTabDirection);
}); });
add_task(async function test_sidebar_display_settings() { add_task(async function test_sidebar_display_settings() {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [[TAB_DIRECTION_PREF, true]], set: [[TAB_DIRECTION_PREF, true]],
}); });
await waitForTabstripOrientation("vertical");
await testCustomizeSetting( await testCustomizeSetting(
"visibilityInput", "visibilityInput",
Glean.sidebar.displaySettings, Glean.sidebar.displaySettings,
@@ -528,7 +502,6 @@ add_task(async function test_sidebar_display_settings() {
"always" "always"
); );
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await waitForTabstripOrientation(initialTabDirection);
}); });
add_task(async function test_sidebar_position_settings() { add_task(async function test_sidebar_position_settings() {
@@ -572,7 +545,6 @@ add_task(async function test_sidebar_position_rtl_ui() {
sandbox.restore(); sandbox.restore();
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await SidebarController.waitUntilStable();
}); });
async function testIconClick(expanded) { async function testIconClick(expanded) {
@@ -583,7 +555,6 @@ async function testIconClick(expanded) {
[TAB_DIRECTION_PREF, true], [TAB_DIRECTION_PREF, true],
], ],
}); });
await waitForTabstripOrientation("vertical");
const { sidebarMain } = SidebarController; const { sidebarMain } = SidebarController;
const gleanEvents = [ const gleanEvents = [
@@ -593,16 +564,7 @@ async function testIconClick(expanded) {
Glean.sidebar.bookmarksIconClick, Glean.sidebar.bookmarksIconClick,
]; ];
for (const [i, button] of Array.from(sidebarMain.toolButtons).entries()) { for (const [i, button] of Array.from(sidebarMain.toolButtons).entries()) {
await SidebarController.initializeUIState({ await SidebarController.initializeUIState({ launcherExpanded: expanded });
launcherExpanded: expanded,
command: "",
});
Assert.equal(
SidebarController.sidebarMain.expanded,
expanded,
`The launcher is ${expanded ? "expanded" : "collapsed"}`
);
Assert.ok(!SidebarController._state.panelOpen, "No panel is open");
info(`Click the icon for: ${button.getAttribute("view")}`); info(`Click the icon for: ${button.getAttribute("view")}`);
EventUtils.synthesizeMouseAtCenter(button, {}); EventUtils.synthesizeMouseAtCenter(button, {});
@@ -619,22 +581,11 @@ async function testIconClick(expanded) {
} }
info("Load an extension."); info("Load an extension.");
// The extensions's sidebar will open when it loads
const extension = ExtensionTestUtils.loadExtension({ ...extData }); const extension = ExtensionTestUtils.loadExtension({ ...extData });
await extension.startup(); await extension.startup();
await extension.awaitMessage("sidebar"); await extension.awaitMessage("sidebar");
await SidebarController.initializeUIState({ await SidebarController.initializeUIState({ launcherExpanded: expanded });
launcherExpanded: expanded,
panelOpen: false,
command: "",
});
Assert.equal(
SidebarController.sidebarMain.expanded,
expanded,
`The launcher is ${expanded ? "expanded" : "collapsed"}`
);
Assert.ok(!SidebarController._state.panelOpen, "No panel is open");
info("Click the icon for the extension."); info("Click the icon for the extension.");
const extensionButton = await TestUtils.waitForCondition( const extensionButton = await TestUtils.waitForCondition(
@@ -656,7 +607,6 @@ async function testIconClick(expanded) {
await extension.unload(); await extension.unload();
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await waitForTabstripOrientation(initialTabDirection);
Services.fog.testResetFOG(); Services.fog.testResetFOG();
} }
@@ -672,17 +622,7 @@ async function testIconClickReviewChecker(expanded) {
const { sidebarMain } = SidebarController; const { sidebarMain } = SidebarController;
await SidebarController.initializeUIState({ await SidebarController.initializeUIState({ launcherExpanded: expanded });
launcherVisible: true,
launcherExpanded: expanded,
command: "",
});
Assert.equal(
SidebarController.sidebarMain.expanded,
expanded,
`The launcher is ${expanded ? "expanded" : "collapsed"}`
);
Assert.ok(!SidebarController._state.panelOpen, "No panel is open");
let reviewCheckerButton = sidebarMain.shadowRoot.querySelector( let reviewCheckerButton = sidebarMain.shadowRoot.querySelector(
"moz-button[view='viewReviewCheckerSidebar']" "moz-button[view='viewReviewCheckerSidebar']"
@@ -698,11 +638,6 @@ async function testIconClickReviewChecker(expanded) {
); );
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await SidebarController.initializeUIState({
launcherExpanded: false,
launcherVisible: true,
command: "",
});
Services.fog.testResetFOG(); Services.fog.testResetFOG();
} }
@@ -715,19 +650,9 @@ add_task(async function test_icon_click_expanded_sidebar() {
}); });
add_task(async function test_review_checker_icon_click_collapsed_sidebar() { add_task(async function test_review_checker_icon_click_collapsed_sidebar() {
await SpecialPowers.pushPrefEnv({
set: [["browser.shopping.experience2023.integratedSidebar", true]],
});
await testIconClickReviewChecker(false); await testIconClickReviewChecker(false);
await SpecialPowers.popPrefEnv();
await SidebarController.waitUntilStable();
}); });
add_task(async function test_review_checker_icon_click_expanded_sidebar() { add_task(async function test_review_checker_icon_click_expanded_sidebar() {
await SpecialPowers.pushPrefEnv({
set: [["browser.shopping.experience2023.integratedSidebar", true]],
});
await testIconClickReviewChecker(true); await testIconClickReviewChecker(true);
await SpecialPowers.popPrefEnv();
await SidebarController.waitUntilStable();
}); });

View File

@@ -10,17 +10,13 @@ add_setup(async () => {
}); });
}); });
const initialTabDirection = Services.prefs.getBoolPref("sidebar.verticalTabs")
? "vertical"
: "horizontal";
add_task(async function test_extension_context_menu() { add_task(async function test_extension_context_menu() {
const win = await BrowserTestUtils.openNewBrowserWindow(); const win = await BrowserTestUtils.openNewBrowserWindow();
await waitForBrowserWindowActive(win); await waitForBrowserWindowActive(win);
const { document } = win; const { document } = win;
const sidebar = document.querySelector("sidebar-main"); const sidebar = document.querySelector("sidebar-main");
await sidebar.updateComplete; await sidebar.updateComplete;
ok(BrowserTestUtils.isVisible(sidebar), "Sidebar is shown."); ok(sidebar, "Sidebar is shown.");
const manageStub = sinon.stub(sidebar, "manageExtension"); const manageStub = sinon.stub(sidebar, "manageExtension");
const reportStub = sinon.stub(sidebar, "reportExtension"); const reportStub = sinon.stub(sidebar, "reportExtension");
@@ -182,20 +178,14 @@ add_task(async function test_extension_context_menu() {
sinon.restore(); sinon.restore();
await extension.unload(); await extension.unload();
ok(
BrowserTestUtils.isHidden(sidebar),
"Unloading the extension causes the sidebar launcher to hide"
);
await BrowserTestUtils.closeWindow(win); await BrowserTestUtils.closeWindow(win);
}); });
add_task(async function test_sidebar_context_menu() { add_task(async function test_sidebar_context_menu() {
const { document, SidebarController } = window; const { document, SidebarController } = window;
const { sidebarMain, sidebarContainer } = SidebarController; const { sidebarMain, sidebarContainer } = SidebarController;
await SidebarController.initializeUIState({ await sidebarMain.updateComplete;
launcherVisible: true, ok(sidebarMain, "Sidebar is shown.");
});
ok(BrowserTestUtils.isVisible(sidebarMain), "Sidebar is shown.");
const contextMenu = document.getElementById("sidebar-context-menu"); const contextMenu = document.getElementById("sidebar-context-menu");
is(contextMenu.state, "closed", "Checking if context menu is closed"); is(contextMenu.state, "closed", "Checking if context menu is closed");
@@ -251,10 +241,9 @@ add_task(async function test_sidebar_context_menu() {
}); });
ok( ok(
Services.prefs.getBoolPref("sidebar.verticalTabs", false), Services.prefs.getBoolPref("sidebar.verticalTabs", false),
"Vertical tabs disabled" "Vertical tabs enabled"
); );
Services.prefs.clearUserPref("sidebar.verticalTabs"); Services.prefs.clearUserPref("sidebar.verticalTabs");
await waitForTabstripOrientation(initialTabDirection);
is(contextMenu.state, "closed", "Context menu closed for vertical tabs"); is(contextMenu.state, "closed", "Context menu closed for vertical tabs");
}); });
@@ -331,5 +320,4 @@ add_task(async function test_toggle_vertical_tabs_from_sidebar_button() {
window.SidebarController.hide(); window.SidebarController.hide();
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await window.SidebarController.waitUntilStable();
}); });

View File

@@ -9,19 +9,10 @@ add_setup(async () => {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [[SIDEBAR_VISIBILITY_PREF, "hide-sidebar"]], set: [[SIDEBAR_VISIBILITY_PREF, "hide-sidebar"]],
}); });
await SidebarController.waitUntilStable();
await SidebarController.initializeUIState({ await SidebarController.initializeUIState({
launcherExpanded: false, launcherExpanded: false,
launcherVisible: false, launcherVisible: false,
}); });
info("Waiting for a mutation condition where sidebarContainer is hidden");
await BrowserTestUtils.waitForMutationCondition(
SidebarController.sidebarContainer,
{ attributes: true, attributeFilter: ["hidden"] },
() => SidebarController.sidebarContainer.hasAttribute("hidden")
);
// make sure the sidebar is reset after we're done // make sure the sidebar is reset after we're done
registerCleanupFunction(async () => { registerCleanupFunction(async () => {
await SidebarController.sidebarMain.updateComplete; await SidebarController.sidebarMain.updateComplete;
@@ -64,16 +55,10 @@ add_task(async function test_sidebar_view_commands() {
ok(!sidebar.expanded, "Sidebar is not expanded when the view is closed"); ok(!sidebar.expanded, "Sidebar is not expanded when the view is closed");
ok(BrowserTestUtils.isHidden(sidebarBox), "Sidebar box is hidden"); ok(BrowserTestUtils.isHidden(sidebarBox), "Sidebar box is hidden");
// Confirm that toggling the sidebar using the toolbarbutton re-opens it with the previous panel
document.getElementById("sidebar-button").doCommand(); document.getElementById("sidebar-button").doCommand();
await sidebar.updateComplete; await sidebar.updateComplete;
ok(BrowserTestUtils.isVisible(sidebar), "Sidebar is visible again."); ok(BrowserTestUtils.isVisible(sidebar), "Sidebar is visible again.");
ok(BrowserTestUtils.isVisible(sidebarBox), "Sidebar panel is visible."); ok(BrowserTestUtils.isHidden(sidebarBox), "Sidebar box is hidden.");
is(
SidebarController.currentID,
"viewBookmarksSidebar",
"Sidebar controller re-opened the previous panel"
);
// restore the animation pref // restore the animation pref
SpecialPowers.popPrefEnv(); SpecialPowers.popPrefEnv();

View File

@@ -94,21 +94,15 @@ add_task(async function test_expanded_state_for_always_show() {
component = sidebarMain, component = sidebarMain,
button = toolbarButton button = toolbarButton
) => { ) => {
info( await TestUtils.waitForCondition(
`Waiting for component to become ${expanded ? "expanded" : "collapsed"}` () => Boolean(component.expanded) == expanded,
expanded ? "Sidebar is expanded." : "Sidebar is collapsed."
); );
await BrowserTestUtils.waitForMutationCondition( await TestUtils.waitForCondition(
component, () => Boolean(button.checked) == expanded,
{ attributes: true, attributeFilter: ["expanded"] }, expanded
() => Boolean(component.expanded) == expanded ? "Toolbar button is highlighted."
); : "Toolbar button is not highlighted."
info(
`Waiting for button to become ${expanded ? "highlighted" : "not highlighted"}`
);
await BrowserTestUtils.waitForMutationCondition(
button,
{ attributes: true, attributeFilter: ["checked"] },
() => Boolean(button.checked) == expanded
); );
Assert.deepEqual( Assert.deepEqual(
document.l10n.getAttributes(button), document.l10n.getAttributes(button),
@@ -123,9 +117,8 @@ add_task(async function test_expanded_state_for_always_show() {
}, },
"Toolbar button has the correct tooltip." "Toolbar button has the correct tooltip."
); );
Assert.equal( await TestUtils.waitForCondition(
button.hasAttribute("expanded"), () => button.hasAttribute("expanded") == expanded,
expanded,
expanded expanded
? "Toolbar button expanded attribute is present." ? "Toolbar button expanded attribute is present."
: "Toolbar button expanded attribute is absent." : "Toolbar button expanded attribute is absent."
@@ -140,50 +133,26 @@ add_task(async function test_expanded_state_for_always_show() {
await checkExpandedState(false); await checkExpandedState(false);
info("Don't collapse the sidebar by loading a tool."); info("Don't collapse the sidebar by loading a tool.");
await SidebarController.initializeUIState({ await SidebarController.initializeUIState({ launcherExpanded: true });
launcherExpanded: true, await SidebarController.waitUntilStable();
command: "",
});
info("Waiting to re-initialize UI state to make the launcher expanded");
await BrowserTestUtils.waitForMutationCondition(
sidebarMain,
{ attributes: true, attributeFilter: ["expanded"] },
() => Boolean(sidebarMain.expanded)
);
const toolButton = sidebarMain.toolButtons[0]; const toolButton = sidebarMain.toolButtons[0];
EventUtils.synthesizeMouseAtCenter(toolButton, {}, window); EventUtils.synthesizeMouseAtCenter(toolButton, {}, window);
await SidebarController.waitUntilStable();
await checkExpandedState(true); await checkExpandedState(true);
SidebarController.hide();
info("Load and unload a tool with the sidebar collapsed to begin with."); info("Load and unload a tool with the sidebar collapsed to begin with.");
await SidebarController.initializeUIState({ await SidebarController.initializeUIState({ launcherExpanded: false });
launcherExpanded: false, await SidebarController.waitUntilStable();
command: "",
});
info("Waiting to re-initialize UI state to make the launcher collapsed");
await BrowserTestUtils.waitForMutationCondition(
sidebarMain,
{ attributes: true, attributeFilter: ["expanded"] },
() => !sidebarMain.expanded
);
EventUtils.synthesizeMouseAtCenter(toolButton, {}, window); EventUtils.synthesizeMouseAtCenter(toolButton, {}, window);
await SidebarController.waitUntilStable();
await checkExpandedState(false); await checkExpandedState(false);
SidebarController.hide();
await SidebarController.initializeUIState({
launcherExpanded: true,
command: "",
});
info("Waiting to re-initialize UI state to make the launcher expanded");
await BrowserTestUtils.waitForMutationCondition(
sidebarMain,
{ attributes: true, attributeFilter: ["expanded"] },
() => Boolean(sidebarMain.expanded)
);
info("Check expanded state on a new window."); info("Check expanded state on a new window.");
await SidebarController.initializeUIState({ launcherExpanded: true });
await SidebarController.waitUntilStable();
const newWin = await BrowserTestUtils.openNewBrowserWindow(); const newWin = await BrowserTestUtils.openNewBrowserWindow();
await waitForTabstripOrientation("vertical", newWin); await waitForTabstripOrientation("vertical", newWin);
await checkExpandedState( await checkExpandedState(
@@ -228,23 +197,17 @@ add_task(async function test_states_for_hide_sidebar() {
component = sidebarMain, component = sidebarMain,
button = toolbarButton button = toolbarButton
) => { ) => {
info(`Waiting for container to become ${hidden ? "hidden" : "not hidden"}`); await TestUtils.waitForCondition(
await BrowserTestUtils.waitForMutationCondition( () => container.hidden == hidden,
container, "Hidden state is correct."
{ attributes: true, attributeFilter: ["hidden"] },
() => Boolean(container.hidden) == hidden
); );
info("Waiting for component to be not expanded"); await TestUtils.waitForCondition(
await BrowserTestUtils.waitForMutationCondition( () => !component.expanded,
component, "Expanded state is correct."
{ attributes: true, attributeFilter: ["expanded"] },
() => !component.expanded
); );
info("Waiting for button to be highlighted"); await TestUtils.waitForCondition(
await BrowserTestUtils.waitForMutationCondition( () => button.checked == !hidden,
button, "Toolbar button state is correct."
{ attributes: true, attributeFilter: ["checked"] },
() => Boolean(button.checked) == !hidden
); );
Assert.deepEqual( Assert.deepEqual(
document.l10n.getAttributes(button), document.l10n.getAttributes(button),
@@ -322,27 +285,17 @@ add_task(async function test_states_for_hide_sidebar_vertical() {
component = sidebarMain, component = sidebarMain,
button = toolbarButton button = toolbarButton
) => { ) => {
info(`Waiting for container to become ${hidden ? "hidden" : "not hidden"}`); await TestUtils.waitForCondition(
await BrowserTestUtils.waitForMutationCondition( () => container.hidden == hidden,
container, "Hidden state is correct."
{ attributes: true, attributeFilter: ["hidden"] },
() => Boolean(container.hidden) == hidden
); );
info( await TestUtils.waitForCondition(
`Waiting for component to be ${expanded ? "expanded" : "not expanded"}` () => component.expanded == expanded,
"Expanded state is correct."
); );
await BrowserTestUtils.waitForMutationCondition( await TestUtils.waitForCondition(
component, () => button.checked == !hidden,
{ attributes: true, attributeFilter: ["expanded"] }, "Toolbar button state is correct."
() => Boolean(component.expanded) == expanded
);
info(
`Waiting for button to be ${hidden ? "not highlighted" : "highlighted"}`
);
await BrowserTestUtils.waitForMutationCondition(
button,
{ attributes: true, attributeFilter: ["checked"] },
() => Boolean(button.checked) == !hidden
); );
Assert.deepEqual( Assert.deepEqual(
document.l10n.getAttributes(button), document.l10n.getAttributes(button),
@@ -377,19 +330,20 @@ add_task(async function test_states_for_hide_sidebar_vertical() {
const toolButton = sidebarMain.toolButtons[0]; const toolButton = sidebarMain.toolButtons[0];
EventUtils.synthesizeMouseAtCenter(toolButton, {}, win); EventUtils.synthesizeMouseAtCenter(toolButton, {}, win);
await TestUtils.waitForCondition(
() => SidebarController.isOpen,
"Panel is open"
);
await checkStates({ hidden: false, expanded: true }); await checkStates({ hidden: false, expanded: true });
ok(SidebarController.isOpen, "Panel is open.");
info("Close a panel using the toolbar button."); info("Close a panel using the toolbar button.");
EventUtils.synthesizeMouseAtCenter(toolbarButton, {}, win); EventUtils.synthesizeMouseAtCenter(toolbarButton, {}, win);
await checkStates({ hidden: true, expanded: false });
ok(!SidebarController.isOpen, "Panel is closed."); ok(!SidebarController.isOpen, "Panel is closed.");
await checkStates({ hidden: true, expanded: true });
EventUtils.synthesizeMouseAtCenter(toolbarButton, {}, win);
await checkStates({ hidden: false, expanded: true });
info("Check states on a new window."); info("Check states on a new window.");
EventUtils.synthesizeMouseAtCenter(toolbarButton, {}, win);
await checkStates({ hidden: false, expanded: true });
const newWin = await BrowserTestUtils.openNewBrowserWindow(); const newWin = await BrowserTestUtils.openNewBrowserWindow();
await checkStates( await checkStates(
{ hidden: false, expanded: true }, { hidden: false, expanded: true },
@@ -443,29 +397,23 @@ add_task(async function test_sidebar_button_runtime_pref_enabled() {
"Sidebar button should not be checked when old sidebar is not showing." "Sidebar button should not be checked when old sidebar is not showing."
); );
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
await SidebarController.waitUntilStable();
// When the button was removed, "hide-sidebar" was set automatically. Revert for the next test.
// Expanded is the default when "hide-sidebar" is set - revert to collapsed for the next test.
await SpecialPowers.pushPrefEnv({
set: [[SIDEBAR_VISIBILITY_PREF, "always-show"]],
});
await SidebarController.initializeUIState({ expanded: false });
}); });
/** /**
* Check that keyboard shortcut toggles sidebar * Check that keyboard shortcut toggles sidebar
*/ */
add_task(async function test_keyboard_shortcut() { add_task(async function test_keyboard_shortcut() {
// When the button was removed, "hide-sidebar" was set automatically. Revert for this test.
// Expanded is the default when "hide-sidebar" is set - revert to collapsed.
await SpecialPowers.pushPrefEnv({
set: [[SIDEBAR_VISIBILITY_PREF, "always-show"]],
});
await SidebarController.initializeUIState({ launcherExpanded: false });
const sidebar = document.querySelector("sidebar-main"); const sidebar = document.querySelector("sidebar-main");
const key = document.getElementById("toggleSidebarKb"); const key = document.getElementById("toggleSidebarKb");
Assert.equal( Assert.ok(!sidebar.expanded, "Sidebar collapsed by default");
Services.prefs.getStringPref("sidebar.visibility"),
"always-show",
"Got expected visibility value"
);
Assert.ok(!sidebar.expanded, "Sidebar initially not expanded");
key.doCommand(); key.doCommand();

View File

@@ -94,18 +94,6 @@ const extData = {
}, },
}; };
// Ensure each test leaves the sidebar in its initial state when it completes
const initialSidebarState = { ...SidebarController.getUIState(), command: "" };
async function resetSidebarToInitialState() {
info(
`Restoring sidebar state from: ${JSON.stringify(SidebarController.getUIState())}, back to: ${JSON.stringify(initialSidebarState)}`
);
await SidebarController.initializeUIState(initialSidebarState);
}
registerCleanupFunction(async () => {
await resetSidebarToInitialState();
});
function waitForBrowserWindowActive(win) { function waitForBrowserWindowActive(win) {
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
return new Promise(resolve => { return new Promise(resolve => {

View File

@@ -24,7 +24,6 @@ const mockGlobal = {
}; };
const mockController = { const mockController = {
_box: mockElement, _box: mockElement,
hide: sinon.stub(),
showInitially: sinon.stub(), showInitially: sinon.stub(),
sidebarContainer: { ownerGlobal: mockGlobal }, sidebarContainer: { ownerGlobal: mockGlobal },
sidebarMain: mockElement, sidebarMain: mockElement,
@@ -53,35 +52,3 @@ add_task(async function test_load_legacy_session_restore_data() {
"Bookmarks panel was shown." "Bookmarks panel was shown."
); );
}); });
add_task(async function test_load_prerevamp_session_restore_data() {
const sidebarState = new SidebarState(mockController);
sidebarState.loadInitialState({
command: "viewBookmarksSidebar",
});
const props = sidebarState.getProperties();
Assert.ok(props.panelOpen, "The panel is marked as open.");
Assert.equal(props.launcherVisible, true, "The launcher is visible.");
Assert.equal(props.command, "viewBookmarksSidebar", "The command matches.");
Assert.ok(
mockController.showInitially.calledWith("viewBookmarksSidebar"),
"Bookmarks panel was shown."
);
});
add_task(async function test_load_hidden_panel_state() {
const sidebarState = new SidebarState(mockController);
sidebarState.loadInitialState({
command: "viewBookmarksSidebar",
panelOpen: false,
launcherVisible: true,
});
const props = sidebarState.getProperties();
Assert.ok(!props.panelOpen, "The panel is marked as closed.");
Assert.equal(props.launcherVisible, true, "The launcher is visible.");
Assert.equal(props.command, "viewBookmarksSidebar", "The command matches.");
});