tor-browser

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

browser_bootstrapped_custom_toolbar.js (2490B)


      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 const kTestBarID = "testBar";
     10 const kWidgetID = "characterencoding-button";
     11 
     12 function createTestBar() {
     13  let testBar = document.createXULElement("toolbar");
     14  testBar.id = kTestBarID;
     15  testBar.setAttribute("customizable", "true");
     16  CustomizableUI.registerArea(kTestBarID, {
     17    type: CustomizableUI.TYPE_TOOLBAR,
     18  });
     19  gNavToolbox.appendChild(testBar);
     20  CustomizableUI.registerToolbarNode(testBar);
     21  return testBar;
     22 }
     23 
     24 /**
     25 * Helper function that does the following:
     26 *
     27 * 1) Creates a custom toolbar and registers it
     28 *    with CustomizableUI.
     29 * 2) Adds the widget with ID aWidgetID to that new
     30 *    toolbar.
     31 * 3) Enters customize mode and makes sure that the
     32 *    widget is still in the right toolbar.
     33 * 4) Exits customize mode, then removes and deregisters
     34 *    the custom toolbar.
     35 * 5) Checks that the widget has no placement.
     36 * 6) Re-adds and re-registers a custom toolbar with the same
     37 *    ID and options as the first one.
     38 * 7) Enters customize mode and checks that the widget is
     39 *    properly back in the toolbar.
     40 * 8) Exits customize mode, removes and de-registers the
     41 *    toolbar, and resets the toolbars to default.
     42 */
     43 function checkRestoredPresence(aWidgetID) {
     44  return (async function () {
     45    let testBar = createTestBar();
     46    CustomizableUI.addWidgetToArea(aWidgetID, kTestBarID);
     47    let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
     48    is(
     49      placement.area,
     50      kTestBarID,
     51      "Expected " + aWidgetID + " to be in the test toolbar"
     52    );
     53 
     54    CustomizableUI.unregisterArea(testBar.id);
     55    testBar.remove();
     56 
     57    placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
     58    is(placement, null, "Expected " + aWidgetID + " to be in the palette");
     59 
     60    testBar = createTestBar();
     61 
     62    await startCustomizing();
     63    placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
     64    is(
     65      placement.area,
     66      kTestBarID,
     67      "Expected " + aWidgetID + " to be in the test toolbar"
     68    );
     69    await endCustomizing();
     70 
     71    CustomizableUI.unregisterArea(testBar.id);
     72    testBar.remove();
     73 
     74    await resetCustomization();
     75  })();
     76 }
     77 
     78 add_task(async function () {
     79  await checkRestoredPresence("downloads-button");
     80  await checkRestoredPresence("characterencoding-button");
     81 });