tor-browser

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

browser_996635_remove_non_widgets.js (2025B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // NB: This is testing what happens if something that /isn't/ a customizable
      7 // widget gets used in CustomizableUI APIs. Don't use this as an example of
      8 // what should happen in a "normal" case or how you should use the API.
      9 function test() {
     10  // First create a button that isn't customizable, and add it in the nav-bar,
     11  // but not in the customizable part of it (the customization target) but
     12  // next to the main (hamburger) menu button.
     13  const buttonID = "Test-non-widget-non-removable-button";
     14  let btn = document.createXULElement("toolbarbutton");
     15  btn.id = buttonID;
     16  btn.label = "Hi";
     17  btn.setAttribute("style", "width: 20px; height: 20px; background-color: red");
     18  document.getElementById("nav-bar").appendChild(btn);
     19  registerCleanupFunction(function () {
     20    btn.remove();
     21  });
     22 
     23  // Now try to add this non-customizable button to the tabstrip. This will
     24  // update the internal bookkeeping (ie placements) information, but shouldn't
     25  // move the node.
     26  CustomizableUI.addWidgetToArea(buttonID, CustomizableUI.AREA_TABSTRIP);
     27  let placement = CustomizableUI.getPlacementOfWidget(buttonID);
     28  // Check our bookkeeping
     29  ok(placement, "Button should be placed");
     30  is(
     31    placement && placement.area,
     32    CustomizableUI.AREA_TABSTRIP,
     33    "Should be placed on tabstrip."
     34  );
     35  // Check we didn't move the node.
     36  is(
     37    btn.parentNode && btn.parentNode.id,
     38    "nav-bar",
     39    "Actual button should still be on navbar."
     40  );
     41 
     42  // Now remove the node again. This should remove the bookkeeping, but again
     43  // not affect the actual node.
     44  CustomizableUI.removeWidgetFromArea(buttonID);
     45  placement = CustomizableUI.getPlacementOfWidget(buttonID);
     46  // Check our bookkeeping:
     47  ok(!placement, "Button should no longer have a placement.");
     48  // Check our node.
     49  is(
     50    btn.parentNode && btn.parentNode.id,
     51    "nav-bar",
     52    "Actual button should still be on navbar."
     53  );
     54 }