tor-browser

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

browser_toolbar_collapsed_states.js (3574B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Checks that CustomizableUI reports the expected collapsed toolbar IDs.
      8 *
      9 * Note: on macOS, expectations for CustomizableUI.AREA_MENUBAR are
     10 * automatically skipped since that area isn't available on that platform.
     11 *
     12 * @param {string[]} The IDs of the expected collapsed toolbars.
     13 */
     14 function assertCollapsedToolbarIds(expected) {
     15  if (AppConstants.platform == "macosx") {
     16    let menubarIndex = expected.indexOf(CustomizableUI.AREA_MENUBAR);
     17    if (menubarIndex != -1) {
     18      expected.splice(menubarIndex, 1);
     19    }
     20  }
     21 
     22  let collapsedIds = CustomizableUI.getCollapsedToolbarIds(window);
     23  Assert.equal(collapsedIds.size, expected.length);
     24  for (let expectedId of expected) {
     25    Assert.ok(
     26      collapsedIds.has(expectedId),
     27      `${expectedId} should be collapsed`
     28    );
     29  }
     30 }
     31 
     32 registerCleanupFunction(async () => {
     33  await CustomizableUI.reset();
     34 });
     35 
     36 /**
     37 * Tests that CustomizableUI.getCollapsedToolbarIds will return the IDs of
     38 * toolbars that are collapsed, or menubars that are autohidden.
     39 */
     40 add_task(async function test_toolbar_collapsed_states() {
     41  // By default, we expect the menubar and the bookmarks toolbar to be
     42  // collapsed.
     43  assertCollapsedToolbarIds([
     44    CustomizableUI.AREA_BOOKMARKS,
     45    CustomizableUI.AREA_MENUBAR,
     46  ]);
     47 
     48  let bookmarksToolbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);
     49  // Make sure we're configured to show the bookmarks toolbar on about:newtab.
     50  setToolbarVisibility(bookmarksToolbar, "newtab");
     51 
     52  let newTab = await BrowserTestUtils.openNewForegroundTab({
     53    gBrowser,
     54    opening: "about:newtab",
     55    waitForLoad: false,
     56  });
     57  // Now that we've opened about:newtab, the bookmarks toolbar should now
     58  // be visible.
     59  assertCollapsedToolbarIds([CustomizableUI.AREA_MENUBAR]);
     60  await BrowserTestUtils.removeTab(newTab);
     61 
     62  // And with about:newtab closed again, the bookmarks toolbar should be
     63  // reported as collapsed.
     64  assertCollapsedToolbarIds([
     65    CustomizableUI.AREA_BOOKMARKS,
     66    CustomizableUI.AREA_MENUBAR,
     67  ]);
     68 
     69  // Make sure we're configured to show the bookmarks toolbar on about:newtab.
     70  setToolbarVisibility(bookmarksToolbar, "always");
     71  assertCollapsedToolbarIds([CustomizableUI.AREA_MENUBAR]);
     72 
     73  setToolbarVisibility(bookmarksToolbar, "never");
     74  assertCollapsedToolbarIds([
     75    CustomizableUI.AREA_BOOKMARKS,
     76    CustomizableUI.AREA_MENUBAR,
     77  ]);
     78 
     79  if (AppConstants.platform != "macosx") {
     80    // We'll still consider the menubar collapsed by default, even if it's being temporarily
     81    // shown via the alt key.
     82    let menubarActive = BrowserTestUtils.waitForEvent(
     83      window,
     84      "DOMMenuBarActive"
     85    );
     86    EventUtils.synthesizeKey("VK_ALT", {});
     87    await menubarActive;
     88    assertCollapsedToolbarIds([
     89      CustomizableUI.AREA_BOOKMARKS,
     90      CustomizableUI.AREA_MENUBAR,
     91    ]);
     92    let menubarInactive = BrowserTestUtils.waitForEvent(
     93      window,
     94      "DOMMenuBarInactive"
     95    );
     96    EventUtils.synthesizeKey("VK_ESCAPE", {});
     97    await menubarInactive;
     98    assertCollapsedToolbarIds([
     99      CustomizableUI.AREA_BOOKMARKS,
    100      CustomizableUI.AREA_MENUBAR,
    101    ]);
    102 
    103    let menubar = document.getElementById(CustomizableUI.AREA_MENUBAR);
    104    setToolbarVisibility(menubar, true);
    105    assertCollapsedToolbarIds([CustomizableUI.AREA_BOOKMARKS]);
    106    setToolbarVisibility(menubar, false);
    107    assertCollapsedToolbarIds([
    108      CustomizableUI.AREA_BOOKMARKS,
    109      CustomizableUI.AREA_MENUBAR,
    110    ]);
    111  }
    112 });