tor-browser

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

browser_938980_navbar_collapsed.js (5817B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 requestLongerTimeout(2);
      8 
      9 var bookmarksToolbar = document.getElementById("PersonalToolbar");
     10 var navbar = document.getElementById("nav-bar");
     11 var tabsToolbar = document.getElementById("TabsToolbar");
     12 
     13 // Customization reset should restore visibility to default-visible toolbars.
     14 add_task(async function () {
     15  is(navbar.collapsed, false, "Test should start with navbar visible");
     16  setToolbarVisibility(navbar, false);
     17  is(navbar.collapsed, true, "navbar should be hidden now");
     18 
     19  await resetCustomization();
     20 
     21  is(
     22    navbar.collapsed,
     23    false,
     24    "Customization reset should restore visibility to the navbar"
     25  );
     26 });
     27 
     28 // Customization reset should restore collapsed-state to default-collapsed toolbars.
     29 add_task(async function () {
     30  ok(
     31    CustomizableUI.inDefaultState,
     32    "Everything should be in its default state"
     33  );
     34 
     35  is(
     36    bookmarksToolbar.collapsed,
     37    true,
     38    "Test should start with bookmarks toolbar collapsed"
     39  );
     40  ok(bookmarksToolbar.collapsed, "bookmarksToolbar should be collapsed");
     41  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
     42  is(navbar.collapsed, false, "The nav-bar should be shown by default");
     43 
     44  setToolbarVisibility(bookmarksToolbar, true);
     45  setToolbarVisibility(navbar, false);
     46  ok(!bookmarksToolbar.collapsed, "bookmarksToolbar should be visible now");
     47  ok(navbar.collapsed, "navbar should be collapsed");
     48  is(
     49    CustomizableUI.inDefaultState,
     50    false,
     51    "Should no longer be in default state"
     52  );
     53 
     54  await startCustomizing();
     55  await gCustomizeMode.reset();
     56  await endCustomizing();
     57 
     58  is(
     59    bookmarksToolbar.collapsed,
     60    true,
     61    "Customization reset should restore collapsed-state to the bookmarks toolbar"
     62  );
     63  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
     64  ok(
     65    bookmarksToolbar.collapsed,
     66    "The bookmarksToolbar should be collapsed after reset"
     67  );
     68  ok(
     69    CustomizableUI.inDefaultState,
     70    "Everything should be back to default state"
     71  );
     72 });
     73 
     74 // Check that the menubar will be collapsed by resetting, if the platform supports it.
     75 add_task(async function () {
     76  let menubar = document.getElementById("toolbar-menubar");
     77  const canMenubarCollapse = CustomizableUI.isToolbarDefaultCollapsed(
     78    menubar.id
     79  );
     80  if (!canMenubarCollapse) {
     81    return;
     82  }
     83  ok(
     84    CustomizableUI.inDefaultState,
     85    "Everything should be in its default state"
     86  );
     87 
     88  is(
     89    menubar.getBoundingClientRect().height,
     90    0,
     91    "menubar should be hidden by default"
     92  );
     93  setToolbarVisibility(menubar, true);
     94  isnot(
     95    menubar.getBoundingClientRect().height,
     96    0,
     97    "menubar should be visible now"
     98  );
     99 
    100  await startCustomizing();
    101  await gCustomizeMode.reset();
    102 
    103  ok(
    104    menubar.hasAttribute("autohide"),
    105    "The menubar should have autohide after reset in customization mode"
    106  );
    107  is(
    108    menubar.getBoundingClientRect().height,
    109    0,
    110    "The menubar should have height=0 after reset in customization mode"
    111  );
    112 
    113  await endCustomizing();
    114 
    115  ok(
    116    menubar.hasAttribute("autohide"),
    117    "The menubar should have autohide after reset"
    118  );
    119  is(
    120    menubar.getBoundingClientRect().height,
    121    0,
    122    "The menubar should have height=0 after reset"
    123  );
    124 });
    125 
    126 // Customization reset should restore collapsed-state to default-collapsed toolbars.
    127 add_task(async function () {
    128  ok(
    129    CustomizableUI.inDefaultState,
    130    "Everything should be in its default state"
    131  );
    132  ok(bookmarksToolbar.collapsed, "bookmarksToolbar should be collapsed");
    133  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
    134 
    135  setToolbarVisibility(bookmarksToolbar, true);
    136  ok(!bookmarksToolbar.collapsed, "bookmarksToolbar should be visible now");
    137  is(
    138    CustomizableUI.inDefaultState,
    139    false,
    140    "Should no longer be in default state"
    141  );
    142 
    143  await startCustomizing();
    144 
    145  ok(
    146    !bookmarksToolbar.collapsed,
    147    "The bookmarksToolbar should be visible before reset"
    148  );
    149  ok(!navbar.collapsed, "The navbar should be visible before reset");
    150  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
    151 
    152  await gCustomizeMode.reset();
    153 
    154  ok(
    155    bookmarksToolbar.collapsed,
    156    "The bookmarksToolbar should be collapsed after reset"
    157  );
    158  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
    159  ok(!navbar.collapsed, "The navbar should still be visible after reset");
    160  ok(
    161    CustomizableUI.inDefaultState,
    162    "Everything should be back to default state"
    163  );
    164  await endCustomizing();
    165 });
    166 
    167 // Check that the menubar will be collapsed by resetting, if the platform supports it.
    168 add_task(async function () {
    169  let menubar = document.getElementById("toolbar-menubar");
    170  const canMenubarCollapse = CustomizableUI.isToolbarDefaultCollapsed(
    171    menubar.id
    172  );
    173  if (!canMenubarCollapse) {
    174    return;
    175  }
    176  ok(
    177    CustomizableUI.inDefaultState,
    178    "Everything should be in its default state"
    179  );
    180  await startCustomizing();
    181  let resetButton = document.getElementById("customization-reset-button");
    182  is(
    183    resetButton.disabled,
    184    true,
    185    "The reset button should be disabled when in default state"
    186  );
    187 
    188  setToolbarVisibility(menubar, true);
    189  is(
    190    resetButton.disabled,
    191    false,
    192    "The reset button should be enabled when not in default state"
    193  );
    194  ok(
    195    !CustomizableUI.inDefaultState,
    196    "No longer in default state when the menubar is shown"
    197  );
    198 
    199  await gCustomizeMode.reset();
    200 
    201  is(
    202    resetButton.disabled,
    203    true,
    204    "The reset button should be disabled when in default state"
    205  );
    206  ok(
    207    CustomizableUI.inDefaultState,
    208    "Everything should be in its default state"
    209  );
    210 
    211  await endCustomizing();
    212 });