tor-browser

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

browser_968565_insert_before_hidden_items.js (2222B)


      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 const kHidden1Id = "test-hidden-button-1";
      8 const kHidden2Id = "test-hidden-button-2";
      9 
     10 var navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
     11 
     12 // When we drag an item onto a customizable area, and not over a specific target, we
     13 // should assume that we're appending them to the area. If doing so, we should scan
     14 // backwards over any hidden items and insert the item before those hidden items.
     15 add_task(async function () {
     16  ok(CustomizableUI.inDefaultState, "Should be in the default state");
     17 
     18  // Iterate backwards over the items in the nav-bar until we find the first
     19  // one that is not hidden.
     20  let placements = CustomizableUI.getWidgetsInArea(CustomizableUI.AREA_NAVBAR);
     21  let lastVisible = null;
     22  for (let widgetGroup of placements.reverse()) {
     23    let widget = widgetGroup.forWindow(window);
     24    if (widget && widget.node && !widget.node.hidden) {
     25      lastVisible = widget.node;
     26      break;
     27    }
     28  }
     29 
     30  if (!lastVisible) {
     31    ok(false, "Apparently, there are no visible items in the nav-bar.");
     32  }
     33 
     34  info("The last visible item in the nav-bar has ID: " + lastVisible.id);
     35 
     36  let hidden1 = createDummyXULButton(kHidden1Id, "You can't see me");
     37  let hidden2 = createDummyXULButton(kHidden2Id, "You can't see me either.");
     38  hidden1.hidden = hidden2.hidden = true;
     39 
     40  // Make sure we have some hidden items at the end of the nav-bar.
     41  CustomizableUI.addWidgetToArea(kHidden1Id, "nav-bar");
     42  CustomizableUI.addWidgetToArea(kHidden2Id, "nav-bar");
     43 
     44  // Drag an item and drop it onto the nav-bar customization target, but
     45  // not over a particular item.
     46  await startCustomizing();
     47  let homeButton = document.getElementById("home-button");
     48  let navbarTarget = CustomizableUI.getCustomizationTarget(navbar);
     49  simulateItemDrag(homeButton, navbarTarget, "end");
     50 
     51  await endCustomizing();
     52 
     53  is(
     54    homeButton.previousElementSibling.id,
     55    lastVisible.id,
     56    "The downloads button should be placed after the last visible item."
     57  );
     58 
     59  await resetCustomization();
     60 });