tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_vertical_tabs_customize_navbar.js (5717B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const kPrefCustomizationNavBarWhenVerticalTabs =
      7  "browser.uiCustomization.navBarWhenVerticalTabs";
      8 const tabsToolbar = "TabsToolbar";
      9 const navBar = "nav-bar";
     10 
     11 add_setup(async () => {
     12  Services.prefs.setCharPref(kPrefCustomizationNavBarWhenVerticalTabs, "");
     13  await SpecialPowers.pushPrefEnv({
     14    set: [["sidebar.revamp", true]],
     15  });
     16 });
     17 
     18 registerCleanupFunction(async () => {
     19  await SpecialPowers.popPrefEnv();
     20  gBrowser.removeAllTabsBut(gBrowser.tabs[0]);
     21 });
     22 
     23 // When switching to vertical tabs, the nav-bar customizations remain the same
     24 // as when in horizontal tabs mode, with the addition of tab strip widgets
     25 // This test asserts we remember any tab strip widget customizations in the nav-bar
     26 // when switching between vertical and horizontal modes
     27 add_task(async function () {
     28  let defaultHorizontalAllTabsPlacement =
     29    CustomizableUI.getPlacementOfWidget("alltabs-button");
     30  let defaultHorizontalFirefoxViewPlacement =
     31    CustomizableUI.getPlacementOfWidget("firefox-view-button");
     32  is(
     33    defaultHorizontalAllTabsPlacement.area,
     34    tabsToolbar,
     35    `alltabs-button is in the ${tabsToolbar}`
     36  );
     37  is(
     38    defaultHorizontalFirefoxViewPlacement.area,
     39    tabsToolbar,
     40    `firefox-view-button is in the ${tabsToolbar}`
     41  );
     42  info(
     43    `alltabs-button is in its original default position ${defaultHorizontalAllTabsPlacement.position} for horizontal tabs mode`
     44  );
     45  info(
     46    `firefox-view-button is in its original default position ${defaultHorizontalFirefoxViewPlacement.position} for horizontal tabs mode`
     47  );
     48 
     49  await SpecialPowers.pushPrefEnv({
     50    set: [["sidebar.verticalTabs", true]],
     51  });
     52 
     53  await startCustomizing();
     54  is(gBrowser.tabs.length, 2, "Should have 2 tabs");
     55 
     56  let nonCustomizingTab = gBrowser.tabContainer.querySelector(
     57    "tab:not([customizemode=true])"
     58  );
     59  let finishedCustomizing = BrowserTestUtils.waitForEvent(
     60    gNavToolbox,
     61    "aftercustomization"
     62  );
     63 
     64  let defaultVerticalAllTabsPlacement =
     65    CustomizableUI.getPlacementOfWidget("alltabs-button");
     66  let defaultVerticalFirefoxViewPlacement = CustomizableUI.getPlacementOfWidget(
     67    "firefox-view-button"
     68  );
     69  is(
     70    defaultVerticalAllTabsPlacement.area,
     71    navBar,
     72    `alltabs-button is in the ${navBar}`
     73  );
     74  is(
     75    defaultVerticalFirefoxViewPlacement.area,
     76    navBar,
     77    `firefox-view-button is in the ${navBar}`
     78  );
     79  info(
     80    `alltabs-button is in its original default position ${defaultVerticalAllTabsPlacement.position} for vertical tabs mode`
     81  );
     82  info(
     83    `firefox-view-button is in its original default position ${defaultVerticalFirefoxViewPlacement.position} for vertical tabs mode`
     84  );
     85 
     86  let customAllTabsPosition = 1;
     87  let customFirefoxViewPosition = 2;
     88  CustomizableUI.moveWidgetWithinArea("alltabs-button", customAllTabsPosition);
     89  CustomizableUI.moveWidgetWithinArea(
     90    "firefox-view-button",
     91    customFirefoxViewPosition
     92  );
     93 
     94  await BrowserTestUtils.switchTab(gBrowser, nonCustomizingTab);
     95  await finishedCustomizing;
     96 
     97  let alltabsPlacement = CustomizableUI.getPlacementOfWidget("alltabs-button");
     98  let firefoxViewPlacement = CustomizableUI.getPlacementOfWidget(
     99    "firefox-view-button"
    100  );
    101  is(alltabsPlacement.area, navBar, `alltabs-button is in the ${navBar}`);
    102  is(
    103    firefoxViewPlacement.area,
    104    navBar,
    105    `firefox-view-button is in the ${navBar}`
    106  );
    107  isnot(
    108    defaultVerticalAllTabsPlacement.position,
    109    alltabsPlacement.position,
    110    "alltabs-button has been moved from its default position"
    111  );
    112  isnot(
    113    defaultVerticalFirefoxViewPlacement.position,
    114    firefoxViewPlacement.position,
    115    "firefox-view-button has been moved from its default position"
    116  );
    117  is(
    118    alltabsPlacement.position,
    119    customAllTabsPosition,
    120    "alltabs-button is in its new custom position"
    121  );
    122  is(
    123    firefoxViewPlacement.position,
    124    customFirefoxViewPosition,
    125    "firefox-view-button is in its new custom position"
    126  );
    127 
    128  await SpecialPowers.pushPrefEnv({
    129    set: [["sidebar.verticalTabs", false]],
    130  });
    131 
    132  let horizontalAlltabsPlacement =
    133    CustomizableUI.getPlacementOfWidget("alltabs-button");
    134  let horizontalFirefoxViewPlacement = CustomizableUI.getPlacementOfWidget(
    135    "firefox-view-button"
    136  );
    137  is(
    138    horizontalAlltabsPlacement.area,
    139    tabsToolbar,
    140    `alltabs-button is in the ${tabsToolbar}`
    141  );
    142  is(
    143    horizontalFirefoxViewPlacement.area,
    144    tabsToolbar,
    145    `firefox-view-button is in the ${tabsToolbar}`
    146  );
    147  is(
    148    horizontalAlltabsPlacement.position,
    149    defaultHorizontalAllTabsPlacement.position,
    150    "alltabs-button is in its default horizontal mode position"
    151  );
    152  is(
    153    horizontalFirefoxViewPlacement.position,
    154    defaultHorizontalFirefoxViewPlacement.position,
    155    "firefox-view-button is in its default horizontal mode position"
    156  );
    157 
    158  // Switching from vertical to horizontal and back to vertical, the customization should be remembered
    159  await SpecialPowers.pushPrefEnv({
    160    set: [["sidebar.verticalTabs", true]],
    161  });
    162 
    163  let newAlltabsPlacement =
    164    CustomizableUI.getPlacementOfWidget("alltabs-button");
    165  let newFirefoxViewPlacement = CustomizableUI.getPlacementOfWidget(
    166    "firefox-view-button"
    167  );
    168  is(newAlltabsPlacement.area, navBar, `alltabs-button is in the ${navBar}`);
    169  is(
    170    newFirefoxViewPlacement.area,
    171    navBar,
    172    `firefox-view-button is in the ${navBar}`
    173  );
    174  is(
    175    newAlltabsPlacement.position,
    176    customAllTabsPosition,
    177    "alltabs-button is in its new custom position"
    178  );
    179  is(
    180    newFirefoxViewPlacement.position,
    181    customFirefoxViewPosition,
    182    "firefox-view-button is in its new custom position"
    183  );
    184 });