summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_addons_area.js
blob: 533d48b238ead551d531588f652da239272b83cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Test that widgets provided by extensions can be added to the
 * ADDONS area, but all other widgets cannot.
 */
add_task(async function test_only_extension_widgets_in_addons_area() {
  registerCleanupFunction(async () => {
    await CustomizableUI.reset();
  });

  Assert.ok(
    !CustomizableUI.canWidgetMoveToArea(
      "home-button",
      CustomizableUI.AREA_ADDONS
    ),
    "Cannot move a built-in button to the ADDONS area."
  );

  // Now double-check that we cannot accidentally default a non-extension
  // widget into the ADDONS area.
  const kTestDynamicWidget = "a-test-widget";
  CustomizableUI.createWidget({
    id: kTestDynamicWidget,
    label: "Test widget",
    defaultArea: CustomizableUI.AREA_ADDONS,
  });
  Assert.equal(
    CustomizableUI.getPlacementOfWidget(kTestDynamicWidget),
    null,
    "An attempt to put a non-extension widget into the ADDONS area by default should fail."
  );
  CustomizableUI.destroyWidget(kTestDynamicWidget);

  const kWebExtensionButtonID1 = "a-test-extension-button";

  CustomizableUI.createWidget({
    id: kWebExtensionButtonID1,
    label: "Test extension widget",
    defaultArea: CustomizableUI.AREA_NAVBAR,
    webExtension: true,
  });

  Assert.ok(
    CustomizableUI.canWidgetMoveToArea(
      kWebExtensionButtonID1,
      CustomizableUI.AREA_ADDONS
    ),
    "Can move extension button to the addons area."
  );

  CustomizableUI.destroyWidget(kWebExtensionButtonID1);

  // Now check that extension buttons can default to the ADDONS area, if need
  // be.

  const kWebExtensionButtonID2 = "a-test-extension-button-2";

  CustomizableUI.createWidget({
    id: kWebExtensionButtonID2,
    label: "Test extension widget 2",
    defaultArea: CustomizableUI.AREA_ADDONS,
    webExtension: true,
  });

  Assert.equal(
    CustomizableUI.getPlacementOfWidget(kWebExtensionButtonID2)?.area,
    CustomizableUI.AREA_ADDONS,
    "An attempt to put an extension widget into the ADDONS area by default should work."
  );

  CustomizableUI.destroyWidget(kWebExtensionButtonID2);
});