tor-browser

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

browser_addons_area.js (2177B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Test that widgets provided by extensions can be added to the
      8 * ADDONS area, but all other widgets cannot.
      9 */
     10 add_task(async function test_only_extension_widgets_in_addons_area() {
     11  registerCleanupFunction(async () => {
     12    await CustomizableUI.reset();
     13  });
     14 
     15  Assert.ok(
     16    !CustomizableUI.canWidgetMoveToArea(
     17      "home-button",
     18      CustomizableUI.AREA_ADDONS
     19    ),
     20    "Cannot move a built-in button to the ADDONS area."
     21  );
     22 
     23  // Now double-check that we cannot accidentally default a non-extension
     24  // widget into the ADDONS area.
     25  const kTestDynamicWidget = "a-test-widget";
     26  CustomizableUI.createWidget({
     27    id: kTestDynamicWidget,
     28    label: "Test widget",
     29    defaultArea: CustomizableUI.AREA_ADDONS,
     30  });
     31  Assert.equal(
     32    CustomizableUI.getPlacementOfWidget(kTestDynamicWidget),
     33    null,
     34    "An attempt to put a non-extension widget into the ADDONS area by default should fail."
     35  );
     36  CustomizableUI.destroyWidget(kTestDynamicWidget);
     37 
     38  const kWebExtensionButtonID1 = "a-test-extension-button";
     39 
     40  CustomizableUI.createWidget({
     41    id: kWebExtensionButtonID1,
     42    label: "Test extension widget",
     43    defaultArea: CustomizableUI.AREA_NAVBAR,
     44    webExtension: true,
     45  });
     46 
     47  Assert.ok(
     48    CustomizableUI.canWidgetMoveToArea(
     49      kWebExtensionButtonID1,
     50      CustomizableUI.AREA_ADDONS
     51    ),
     52    "Can move extension button to the addons area."
     53  );
     54 
     55  CustomizableUI.destroyWidget(kWebExtensionButtonID1);
     56 
     57  // Now check that extension buttons can default to the ADDONS area, if need
     58  // be.
     59 
     60  const kWebExtensionButtonID2 = "a-test-extension-button-2";
     61 
     62  CustomizableUI.createWidget({
     63    id: kWebExtensionButtonID2,
     64    label: "Test extension widget 2",
     65    defaultArea: CustomizableUI.AREA_ADDONS,
     66    webExtension: true,
     67  });
     68 
     69  Assert.equal(
     70    CustomizableUI.getPlacementOfWidget(kWebExtensionButtonID2)?.area,
     71    CustomizableUI.AREA_ADDONS,
     72    "An attempt to put an extension widget into the ADDONS area by default should work."
     73  );
     74 
     75  CustomizableUI.destroyWidget(kWebExtensionButtonID2);
     76 });