tor-browser

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

browser_unified_extensions_reset.js (2813B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests that if Unified Extensions UI is enabled that resetting the toolbars
      8 * puts all browser action buttons into the AREA_ADDONS area.
      9 */
     10 add_task(async function test_reset_with_unified_extensions_ui() {
     11  const kWebExtensionWidgetIDs = [
     12    "ext0-browser-action",
     13    "ext1-browser-action",
     14    "ext2-browser-action",
     15    "ext3-browser-action",
     16    "ext4-browser-action",
     17    "ext5-browser-action",
     18    "ext6-browser-action",
     19    "ext7-browser-action",
     20    "ext8-browser-action",
     21    "ext9-browser-action",
     22    "ext10-browser-action",
     23  ];
     24 
     25  for (let widgetID of kWebExtensionWidgetIDs) {
     26    CustomizableUI.createWidget({
     27      id: widgetID,
     28      label: "Test extension widget",
     29      defaultArea: CustomizableUI.AREA_NAVBAR,
     30      webExtension: true,
     31    });
     32  }
     33 
     34  // Now let's put these browser actions in a bunch of different places.
     35  // Regardless of where they go, we're going to expect them in AREA_ADDONS
     36  // after we reset.
     37  CustomizableUI.addWidgetToArea(
     38    kWebExtensionWidgetIDs[0],
     39    CustomizableUI.AREA_TABSTRIP
     40  );
     41  CustomizableUI.addWidgetToArea(
     42    kWebExtensionWidgetIDs[1],
     43    CustomizableUI.AREA_TABSTRIP
     44  );
     45 
     46  // macOS doesn't have AREA_MENUBAR registered, so we'll leave these widgets
     47  // behind in the AREA_NAVBAR there, and put them into the menubar on the
     48  // other platforms.
     49  if (AppConstants.platform != "macosx") {
     50    CustomizableUI.addWidgetToArea(
     51      kWebExtensionWidgetIDs[2],
     52      CustomizableUI.AREA_MENUBAR
     53    );
     54    CustomizableUI.addWidgetToArea(
     55      kWebExtensionWidgetIDs[3],
     56      CustomizableUI.AREA_MENUBAR
     57    );
     58  }
     59 
     60  CustomizableUI.addWidgetToArea(
     61    kWebExtensionWidgetIDs[4],
     62    CustomizableUI.AREA_BOOKMARKS
     63  );
     64  CustomizableUI.addWidgetToArea(
     65    kWebExtensionWidgetIDs[5],
     66    CustomizableUI.AREA_BOOKMARKS
     67  );
     68  CustomizableUI.addWidgetToArea(
     69    kWebExtensionWidgetIDs[6],
     70    CustomizableUI.AREA_ADDONS
     71  );
     72  CustomizableUI.addWidgetToArea(
     73    kWebExtensionWidgetIDs[7],
     74    CustomizableUI.AREA_ADDONS
     75  );
     76 
     77  CustomizableUI.reset();
     78 
     79  // Let's force the Unified Extensions panel to register itself now if it
     80  // wasn't already done. Using the getter should be sufficient.
     81  Assert.ok(gUnifiedExtensions.panel, "Should have found the panel.");
     82 
     83  for (let widgetID of kWebExtensionWidgetIDs) {
     84    let { area } = CustomizableUI.getPlacementOfWidget(widgetID);
     85    Assert.equal(area, CustomizableUI.AREA_ADDONS);
     86    // Let's double-check that they're actually in there in the DOM too.
     87    let widget = CustomizableUI.getWidget(widgetID).forWindow(window);
     88    Assert.equal(widget.node.parentElement.id, CustomizableUI.AREA_ADDONS);
     89    CustomizableUI.destroyWidget(widgetID);
     90  }
     91 });