Bug 1921836 - Consolidate the restoreSidebar implementations, and ensure the sidebar launcher gets un-hidden when a sidebar is shown. r=sidebar-reviewers,sessionstore-reviewers,jsudiaman,sclements
Differential Revision: https://phabricator.services.mozilla.com/D227420
This commit is contained in:
@@ -5646,32 +5646,10 @@ var SessionStoreInternal = {
|
||||
* Object containing command (sidebarcommand/category) and styles
|
||||
*/
|
||||
restoreSidebar(aWindow, aSidebar, isPopup) {
|
||||
if (!aSidebar) {
|
||||
if (!aSidebar || isPopup) {
|
||||
return;
|
||||
}
|
||||
if (!isPopup) {
|
||||
let sidebarBox = aWindow.document.getElementById("sidebar-box");
|
||||
// Always restore sidebar width
|
||||
if (aSidebar.width) {
|
||||
sidebarBox.style.width = aSidebar.width;
|
||||
}
|
||||
if (
|
||||
aSidebar.command &&
|
||||
(sidebarBox.getAttribute("sidebarcommand") != aSidebar.command ||
|
||||
!sidebarBox.getAttribute("checked"))
|
||||
) {
|
||||
aWindow.SidebarController.showInitially(aSidebar.command);
|
||||
}
|
||||
aWindow.SidebarController.uiStateInitialized = true;
|
||||
}
|
||||
if (aWindow.SidebarController.sidebarRevampEnabled) {
|
||||
const { SidebarController } = aWindow;
|
||||
SidebarController.promiseInitialized.then(() => {
|
||||
SidebarController.toggleExpanded(aSidebar.expanded);
|
||||
SidebarController.sidebarContainer.hidden = aSidebar.hidden;
|
||||
SidebarController.updateToolbarButton();
|
||||
});
|
||||
}
|
||||
aWindow.SidebarController.setUIState(aSidebar);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -484,10 +484,18 @@ var SidebarController = {
|
||||
if (!state) {
|
||||
return;
|
||||
}
|
||||
const shouldOpenSidebar =
|
||||
state.command &&
|
||||
this.sidebars.has(state.command) &&
|
||||
this.currentID !== state.command;
|
||||
if (shouldOpenSidebar) {
|
||||
// there's a sidebar to show, so ignore the contradictory hidden property
|
||||
delete state.hidden;
|
||||
}
|
||||
if (state.width) {
|
||||
this._box.style.width = state.width;
|
||||
}
|
||||
if (state.command && this.currentID != state.command && !this.isOpen) {
|
||||
if (shouldOpenSidebar && !this.isOpen) {
|
||||
await this.showInitially(state.command);
|
||||
}
|
||||
if (this.sidebarRevampEnabled) {
|
||||
@@ -1480,6 +1488,7 @@ var SidebarController = {
|
||||
_show(commandID) {
|
||||
return new Promise(resolve => {
|
||||
if (this.sidebarRevampEnabled) {
|
||||
this.sidebarContainer.hidden = false;
|
||||
this._box.dispatchEvent(
|
||||
new CustomEvent("sidebar-show", { detail: { viewId: commandID } })
|
||||
);
|
||||
|
||||
@@ -28,6 +28,8 @@ run-if = ["os == 'mac'"] # Mac only feature
|
||||
|
||||
["browser_sidebar_max_width.js"]
|
||||
|
||||
["browser_sidebar_menubar_item_commands.js"]
|
||||
|
||||
["browser_sidebar_nimbus.js"]
|
||||
|
||||
["browser_sidebar_panel_header.js"]
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
https://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const SIDEBAR_VISIBILITY_PREF = "sidebar.visibility";
|
||||
|
||||
add_setup(async () => {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [[SIDEBAR_VISIBILITY_PREF, "hide-sidebar"]],
|
||||
});
|
||||
// make sure the sidebar is reset after we're done
|
||||
registerCleanupFunction(async () => {
|
||||
await SidebarController.toggleExpanded(false);
|
||||
await SidebarController.sidebarMain.updateComplete;
|
||||
SidebarController.sidebarContainer.hidden = false;
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function test_sidebar_view_commands() {
|
||||
const sidebar = document.querySelector("sidebar-main");
|
||||
const sidebarBox = document.querySelector("#sidebar-box");
|
||||
|
||||
await sidebar.updateComplete;
|
||||
ok(sidebar && BrowserTestUtils.isVisible(sidebar), "Sidebar is shown.");
|
||||
|
||||
// turn off animations for this bit
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["sidebar.animation.enabled", false]],
|
||||
});
|
||||
|
||||
document.getElementById("sidebar-button").doCommand();
|
||||
await sidebar.updateComplete;
|
||||
ok(BrowserTestUtils.isHidden(sidebar), "Sidebar is hidden.");
|
||||
|
||||
const bookmarkMenuItem = document.getElementById("menu_bookmarksSidebar");
|
||||
bookmarkMenuItem.doCommand();
|
||||
await sidebar.updateComplete;
|
||||
|
||||
ok(BrowserTestUtils.isVisible(sidebar), "Sidebar is visible");
|
||||
ok(BrowserTestUtils.isVisible(sidebarBox), "Sidebar box is visible");
|
||||
is(
|
||||
SidebarController.currentID,
|
||||
"viewBookmarksSidebar",
|
||||
"Sidebar controller has the correct currentID"
|
||||
);
|
||||
|
||||
SidebarController.toggle(SidebarController.currentID);
|
||||
await sidebar.updateComplete;
|
||||
ok(BrowserTestUtils.isVisible(sidebar), "Sidebar is visible");
|
||||
ok(sidebar.expanded, "Sidebar is expanded when the view is closed");
|
||||
ok(BrowserTestUtils.isHidden(sidebarBox), "Sidebar box is hidden");
|
||||
|
||||
document.getElementById("sidebar-button").doCommand();
|
||||
await sidebar.updateComplete;
|
||||
ok(BrowserTestUtils.isHidden(sidebar), "Sidebar is hidden.");
|
||||
ok(BrowserTestUtils.isHidden(sidebarBox), "Sidebar box is hidden.");
|
||||
|
||||
// restore the animation pref
|
||||
SpecialPowers.popPrefEnv();
|
||||
});
|
||||
@@ -40,6 +40,15 @@ add_setup(async () => {
|
||||
0,
|
||||
"sidebar-button"
|
||||
);
|
||||
if (window.SidebarController.sidebarMain?.expanded) {
|
||||
info("In setup, the sidebar is currently expanded. Collapsing it");
|
||||
window.SidebarController.toggleExpanded(false);
|
||||
await window.SidebarController.sidebarMain.updateComplete;
|
||||
}
|
||||
ok(
|
||||
BrowserTestUtils.isVisible(window.SidebarController.sidebarMain),
|
||||
"Sidebar launcher is visible at setup"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_toolbar_sidebar_button() {
|
||||
@@ -66,14 +75,19 @@ add_task(async function test_toolbar_sidebar_button() {
|
||||
});
|
||||
|
||||
add_task(async function test_expanded_state_for_always_show() {
|
||||
info(
|
||||
`Current window's sidebarMain.expanded: ${window.SidebarController.sidebarMain?.expanded}`
|
||||
);
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [[SIDEBAR_VISIBILITY_PREF, "always-show"]],
|
||||
});
|
||||
const win = await BrowserTestUtils.openNewBrowserWindow();
|
||||
const {
|
||||
SidebarController: { sidebarMain, toolbarButton },
|
||||
document,
|
||||
} = win;
|
||||
|
||||
const { SidebarController, document } = win;
|
||||
const { sidebarMain, toolbarButton } = SidebarController;
|
||||
|
||||
await SidebarController.promiseInitialized;
|
||||
info(`New window's sidebarMain.expanded: ${sidebarMain?.expanded}`);
|
||||
|
||||
const checkExpandedState = async (
|
||||
expanded,
|
||||
@@ -110,6 +124,10 @@ add_task(async function test_expanded_state_for_always_show() {
|
||||
|
||||
info("Check default expanded state.");
|
||||
await checkExpandedState(false);
|
||||
ok(
|
||||
BrowserTestUtils.isVisible(sidebarMain),
|
||||
"The sidebar launcher is visible"
|
||||
);
|
||||
ok(
|
||||
!toolbarButton.hasAttribute("checked"),
|
||||
"The toolbar button is not checked."
|
||||
@@ -122,7 +140,7 @@ add_task(async function test_expanded_state_for_always_show() {
|
||||
await checkExpandedState(false);
|
||||
|
||||
info("Collapse the sidebar by loading a tool.");
|
||||
sidebarMain.expanded = true;
|
||||
SidebarController.toggleExpanded(true);
|
||||
await sidebarMain.updateComplete;
|
||||
const toolButton = sidebarMain.toolButtons[0];
|
||||
EventUtils.synthesizeMouseAtCenter(toolButton, {}, win);
|
||||
@@ -133,7 +151,7 @@ add_task(async function test_expanded_state_for_always_show() {
|
||||
await checkExpandedState(true);
|
||||
|
||||
info("Load and unload a tool with the sidebar collapsed to begin with.");
|
||||
sidebarMain.expanded = false;
|
||||
SidebarController.toggleExpanded(false);
|
||||
await sidebarMain.updateComplete;
|
||||
EventUtils.synthesizeMouseAtCenter(toolButton, {}, win);
|
||||
await checkExpandedState(false);
|
||||
@@ -141,7 +159,7 @@ add_task(async function test_expanded_state_for_always_show() {
|
||||
await checkExpandedState(false);
|
||||
|
||||
info("Check expanded state on a new window.");
|
||||
sidebarMain.expanded = true;
|
||||
SidebarController.toggleExpanded(true);
|
||||
await sidebarMain.updateComplete;
|
||||
const newWin = await BrowserTestUtils.openNewBrowserWindow();
|
||||
await checkExpandedState(
|
||||
|
||||
Reference in New Issue
Block a user