summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/browser/browser_ext_themes_chromeparity.js
blob: 086ea396531ccd1216d8b5446b3b8a422c4c2e4b (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
"use strict";

add_task(async function test_support_theme_frame() {
  const FRAME_COLOR = [71, 105, 91];
  const TAB_TEXT_COLOR = [0, 0, 0];
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      theme: {
        images: {
          theme_frame: "face.png",
        },
        colors: {
          frame: FRAME_COLOR,
          tab_background_text: TAB_TEXT_COLOR,
        },
      },
    },
    files: {
      "face.png": imageBufferFromDataURI(ENCODED_IMAGE_DATA),
    },
  });

  await extension.startup();

  let docEl = window.document.documentElement;
  Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");

  Assert.ok(
    docEl.hasAttribute("lwtheme-image"),
    "LWT image attribute should be set"
  );

  Assert.equal(
    docEl.getAttribute("lwtheme-brighttext"),
    null,
    "LWT text color attribute should not be set"
  );

  let toolbox = document.querySelector("#navigator-toolbox");
  let toolboxCS = window.getComputedStyle(toolbox);

  Assert.ok(
    toolboxCS.backgroundImage.includes("face.png"),
    `The backgroundImage should use face.png. Actual value is: ${toolboxCS.backgroundImage}`
  );
  Assert.equal(
    getToolboxBackgroundColor(),
    "rgb(" + FRAME_COLOR.join(", ") + ")",
    "Expected correct background color"
  );
  Assert.equal(
    toolboxCS.color,
    "rgb(" + TAB_TEXT_COLOR.join(", ") + ")",
    "Expected correct text color"
  );

  await extension.unload();

  Assert.ok(!docEl.hasAttribute("lwtheme"), "LWT attribute should not be set");

  Assert.ok(
    !docEl.hasAttribute("lwtheme-image"),
    "LWT image attribute should not be set"
  );

  Assert.ok(
    !docEl.hasAttribute("lwtheme-brighttext"),
    "LWT text color attribute should not be set"
  );
});

add_task(async function test_support_theme_frame_inactive() {
  const FRAME_COLOR = [71, 105, 91];
  const FRAME_COLOR_INACTIVE = [255, 0, 0];
  const TAB_TEXT_COLOR = [207, 221, 192];
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      theme: {
        images: {
          theme_frame: "image1.png",
        },
        colors: {
          frame: FRAME_COLOR,
          frame_inactive: FRAME_COLOR_INACTIVE,
          tab_background_text: TAB_TEXT_COLOR,
        },
      },
    },
    files: {
      "image1.png": BACKGROUND,
    },
  });

  await extension.startup();

  let docEl = window.document.documentElement;

  Assert.equal(
    getToolboxBackgroundColor(),
    "rgb(" + FRAME_COLOR.join(", ") + ")",
    "Window background is set to the colors.frame property"
  );

  // Now we'll open a new window to see if the inactive browser accent color changed
  let window2 = await BrowserTestUtils.openNewBrowserWindow();
  Assert.equal(
    getToolboxBackgroundColor(),
    "rgb(" + FRAME_COLOR_INACTIVE.join(", ") + ")",
    `Inactive window background color should be ${FRAME_COLOR_INACTIVE}`
  );

  await BrowserTestUtils.closeWindow(window2);
  await extension.unload();

  Assert.ok(!docEl.hasAttribute("lwtheme"), "LWT attribute should not be set");
});

add_task(async function test_lack_of_theme_frame_inactive() {
  const FRAME_COLOR = [71, 105, 91];
  const TAB_TEXT_COLOR = [207, 221, 192];
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      theme: {
        images: {
          theme_frame: "image1.png",
        },
        colors: {
          frame: FRAME_COLOR,
          tab_background_text: TAB_TEXT_COLOR,
        },
      },
    },
    files: {
      "image1.png": BACKGROUND,
    },
  });

  await extension.startup();

  let docEl = window.document.documentElement;
  Assert.equal(
    getToolboxBackgroundColor(),
    "rgb(" + FRAME_COLOR.join(", ") + ")",
    "Window background is set to the colors.frame property"
  );

  // Now we'll open a new window to make sure the inactive browser accent color stayed the same
  let window2 = await BrowserTestUtils.openNewBrowserWindow();
  Assert.equal(
    getToolboxBackgroundColor(),
    "rgb(" + FRAME_COLOR.join(", ") + ")",
    "Inactive window background should not change if colors.frame_inactive isn't set"
  );

  await BrowserTestUtils.closeWindow(window2);
  await extension.unload();

  Assert.ok(!docEl.hasAttribute("lwtheme"), "LWT attribute should not be set");
});