summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_icons.js
blob: 2802c6ac339fa37467264293a6041c8c3d4149c9 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"use strict";

// This test checks applied WebExtension themes that attempt to change
// icon color properties

add_task(async function setup_home_button() {
  CustomizableUI.addWidgetToArea("home-button", "nav-bar");
  registerCleanupFunction(() =>
    CustomizableUI.removeWidgetFromArea("home-button")
  );
});

add_task(async function test_icons_properties() {
  const ICONS_COLOR = "#001b47";
  const ICONS_ATTENTION_COLOR = "#44ba77";

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      theme: {
        images: {
          theme_frame: "image1.png",
        },
        colors: {
          frame: ACCENT_COLOR,
          tab_background_text: TEXT_COLOR,
          icons: ICONS_COLOR,
          icons_attention: ICONS_ATTENTION_COLOR,
        },
      },
    },
    files: {
      "image1.png": BACKGROUND,
    },
  });

  await extension.startup();

  let toolbarbutton = document.querySelector("#home-button");
  Assert.equal(
    window.getComputedStyle(toolbarbutton).getPropertyValue("fill"),
    `rgb(${hexToRGB(ICONS_COLOR).join(", ")})`,
    "Buttons fill color set!"
  );

  let starButton = document.querySelector("#star-button");
  starButton.setAttribute("starred", "true");

  let starComputedStyle = window.getComputedStyle(starButton);
  Assert.equal(
    starComputedStyle.getPropertyValue(
      "--lwt-toolbarbutton-icon-fill-attention"
    ),
    `rgb(${hexToRGB(ICONS_ATTENTION_COLOR).join(", ")})`,
    "Variable is properly set"
  );
  Assert.equal(
    starComputedStyle.getPropertyValue("fill"),
    `rgb(${hexToRGB(ICONS_ATTENTION_COLOR).join(", ")})`,
    "Starred icon fill is properly set"
  );

  starButton.removeAttribute("starred");

  await extension.unload();
});

add_task(async function test_no_icons_properties() {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      theme: {
        images: {
          theme_frame: "image1.png",
        },
        colors: {
          frame: ACCENT_COLOR,
          tab_background_text: TEXT_COLOR,
        },
      },
    },
    files: {
      "image1.png": BACKGROUND,
    },
  });

  await extension.startup();

  let toolbarbutton = document.querySelector("#home-button");
  let toolbarbuttonCS = window.getComputedStyle(toolbarbutton);
  let currentColor = toolbarbuttonCS.getPropertyValue("color");
  Assert.equal(
    window.getComputedStyle(toolbarbutton).getPropertyValue("fill"),
    currentColor,
    "Button fill color should be currentColor when no icon color specified."
  );

  let starButton = document.querySelector("#star-button");
  starButton.setAttribute("starred", "true");
  let starComputedStyle = window.getComputedStyle(starButton);
  Assert.equal(
    starComputedStyle.getPropertyValue(
      "--lwt-toolbarbutton-icon-fill-attention"
    ),
    "",
    "Icon attention fill should not be set when the value is not specified in the manifest."
  );
  starButton.removeAttribute("starred");

  await extension.unload();
});