browser_sidebar_position_start.js (3205B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const LEFT_POSITION = 0; 7 const CUSTOM_POSITION = 2; 8 9 add_setup(async function () { 10 await SpecialPowers.pushPrefEnv({ 11 set: [ 12 ["sidebar.revamp", true], 13 ["sidebar.position_start", true], 14 ["sidebar.verticalTabs", false], 15 ], 16 }); 17 CustomizableUI.reset(); 18 }); 19 20 registerCleanupFunction(() => { 21 CustomizableUI.reset(); 22 }); 23 24 function assertPositionEnd(message) { 25 const widgets = CustomizableUI.getWidgetIdsInArea(CustomizableUI.AREA_NAVBAR); 26 Assert.equal(widgets.at(-1), "sidebar-button", message); 27 } 28 29 add_task(async function test_moving_sidebar_updates_button_placement() { 30 Assert.equal( 31 CustomizableUI.getPlacementOfWidget("sidebar-button").position, 32 LEFT_POSITION, 33 "By default, the sidebar button is on the left." 34 ); 35 36 info("Move sidebar to the right."); 37 await SpecialPowers.pushPrefEnv({ 38 set: [["sidebar.position_start", false]], 39 }); 40 assertPositionEnd( 41 "When the sidebar moves to the right, the toolbar button moves to the right." 42 ); 43 44 info("Move sidebar back to the left."); 45 await SpecialPowers.popPrefEnv(); 46 Assert.equal( 47 CustomizableUI.getPlacementOfWidget("sidebar-button").position, 48 LEFT_POSITION, 49 "When the sidebar moves back to the left, the toolbar button moves to the left." 50 ); 51 }); 52 53 add_task(async function test_retain_user_customized_button_placement() { 54 info("Move sidebar to the right."); 55 await SpecialPowers.pushPrefEnv({ 56 set: [["sidebar.position_start", false]], 57 }); 58 59 info("Move the sidebar button around."); 60 CustomizableUI.moveWidgetWithinArea("sidebar-button", CUSTOM_POSITION); 61 62 info("Move sidebar back to the left."); 63 await SpecialPowers.popPrefEnv(); 64 Assert.equal( 65 CustomizableUI.getPlacementOfWidget("sidebar-button").position, 66 CUSTOM_POSITION, 67 "If user has customized the button placement, it does not auto-move." 68 ); 69 70 CustomizableUI.reset(); 71 }); 72 73 add_task(async function test_reset_after_moving_sidebar() { 74 info("Move sidebar to the right."); 75 await SpecialPowers.pushPrefEnv({ 76 set: [["sidebar.position_start", false]], 77 }); 78 79 info("Reset CustomizableUI."); 80 CustomizableUI.reset(); 81 Assert.ok( 82 Services.prefs.getBoolPref("sidebar.position_start"), 83 "After reset, the sidebar is on the left." 84 ); 85 Assert.equal( 86 CustomizableUI.getPlacementOfWidget("sidebar-button").position, 87 LEFT_POSITION, 88 "After reset, the sidebar button is on the left." 89 ); 90 91 info("Undo CustomizableUI reset."); 92 CustomizableUI.undoReset(); 93 Assert.equal( 94 Services.prefs.getBoolPref("sidebar.position_start"), 95 false, 96 "After undo reset, the sidebar is on the right." 97 ); 98 assertPositionEnd("After undo reset, the sidebar button is on the right."); 99 }); 100 101 add_task(async function test_update_placement_vertical_tabs() { 102 info("Move sidebar to the right and enable vertical tabs."); 103 await SpecialPowers.pushPrefEnv({ 104 set: [ 105 ["sidebar.position_start", false], 106 ["sidebar.verticalTabs", true], 107 ], 108 }); 109 assertPositionEnd( 110 "Toolbar button is on the right side of the vertical tabs navbar." 111 ); 112 });