browser_remove_sidebar_button_and_sidebar.js (3928B)
1 /* Any copyright is dedicated to the Public Domain. 2 * https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 add_setup(async () => { 7 await SpecialPowers.pushPrefEnv({ 8 set: [ 9 ["sidebar.revamp", true], 10 ["sidebar.verticalTabs", true], 11 ], 12 }); 13 }); 14 15 registerCleanupFunction(async () => { 16 await SpecialPowers.popPrefEnv(); 17 gBrowser.removeAllTabsBut(gBrowser.tabs[0]); 18 // Ensure sidebar is hidden after each test: 19 if (!document.getElementById("sidebar-box").hidden) { 20 SidebarController.hide({ dismissPanel: true }); 21 } 22 }); 23 24 add_task(async function test_button_removed() { 25 const { SidebarController } = window; 26 await SidebarController.show("viewBookmarksSidebar"); 27 28 let sidebarButton = await BrowserTestUtils.waitForCondition( 29 () => document.getElementById("sidebar-button"), 30 "Sidebar button is shown." 31 ); 32 ok(sidebarButton, "Sidebar button is shown."); 33 let sidebarMain = document.getElementById("sidebar-main"); 34 ok(sidebarMain, "Sidebar launcher is shown."); 35 let sidebarBox = await BrowserTestUtils.waitForCondition( 36 () => document.getElementById("sidebar-box"), 37 "Sidebar panel is shown." 38 ); 39 ok(sidebarBox, "Sidebar panel is shown."); 40 41 await startCustomizing(); 42 is(gBrowser.tabs.length, 2, "Should have 2 tabs"); 43 let nonCustomizingTab = gBrowser.tabContainer.querySelector( 44 "tab:not([customizemode=true])" 45 ); 46 let finishedCustomizing = BrowserTestUtils.waitForEvent( 47 gNavToolbox, 48 "aftercustomization" 49 ); 50 CustomizableUI.removeWidgetFromArea("sidebar-button"); 51 await BrowserTestUtils.switchTab(gBrowser, nonCustomizingTab); 52 await finishedCustomizing; 53 await BrowserTestUtils.waitForCondition(() => { 54 sidebarButton = document.getElementById("sidebar-button"); 55 return !sidebarButton && sidebarMain.hidden && sidebarBox.hidden; 56 }, "Sidebar button, panel and launcher are not present"); 57 58 ok(!sidebarButton, "Sidebar button has been removed."); 59 ok(sidebarMain.hidden, "Sidebar launcher has been hidden."); 60 ok(sidebarBox.hidden, "Sidebar panel has been hidden."); 61 62 const tabstrip = document.getElementById("tabbrowser-tabs"); 63 info("Tab orientation should change to horizontal."); 64 await BrowserTestUtils.waitForMutationCondition( 65 tabstrip, 66 { attributeFilter: ["orient"] }, 67 () => tabstrip.getAttribute("orient") === "horizontal" 68 ); 69 70 CustomizableUI.reset(); 71 CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar", 0); 72 }); 73 74 add_task(async function test_button_moved() { 75 const { SidebarController } = window; 76 await SidebarController.show("viewBookmarksSidebar"); 77 78 let sidebarButton = document.getElementById("sidebar-button"); 79 let sidebarMain = document.getElementById("sidebar-main"); 80 let sidebarBox = document.getElementById("sidebar-box"); 81 82 await startCustomizing(); 83 is(gBrowser.tabs.length, 2, "Should have 2 tabs"); 84 let nonCustomizingTab = gBrowser.tabContainer.querySelector( 85 "tab:not([customizemode=true])" 86 ); 87 let finishedCustomizing = BrowserTestUtils.waitForEvent( 88 gNavToolbox, 89 "aftercustomization" 90 ); 91 // Add the button to the tabstrip. 92 CustomizableUI.addWidgetToArea("sidebar-button", "TabsToolbar"); 93 // This is a little tricky to test "properly": the button removal 94 // handling code inside sidebar is async, but we are asserting that 95 // it does nothing, so there's nothing to wait for. 96 // In practice, switching tabs and customizing are both sufficiently 97 // slow that the test would fail if the code did decide to hide the 98 // sidebar again. 99 await BrowserTestUtils.switchTab(gBrowser, nonCustomizingTab); 100 await finishedCustomizing; 101 102 ok(sidebarButton, "Sidebar button has not been removed."); 103 ok(!sidebarMain.hidden, "Sidebar launcher has not been hidden."); 104 ok(!sidebarBox.hidden, "Sidebar panel has not been hidden."); 105 106 CustomizableUI.reset(); 107 CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar", 0); 108 });