summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/browser/browser_ext_themes_lwtsupport.js
blob: 4293e5eb199ecbafb0a3a16863b133be4b0d2864 (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
"use strict";

const DEFAULT_THEME_BG_COLOR = "rgb(255, 255, 255)";
const DEFAULT_THEME_TEXT_COLOR = "rgb(0, 0, 0)";

add_task(async function test_deprecated_LWT_properties_ignored() {
  // This test uses deprecated theme properties, so warnings are expected.
  ExtensionTestUtils.failOnSchemaWarnings(false);

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      theme: {
        images: {
          headerURL: "image1.png",
        },
        colors: {
          accentcolor: ACCENT_COLOR,
          textcolor: TEXT_COLOR,
        },
      },
    },
    files: {
      "image1.png": BACKGROUND,
    },
  });

  await extension.startup();

  let docEl = window.document.documentElement;
  let docStyle = window.getComputedStyle(docEl);
  let navigatorStyle = window.getComputedStyle(
    docEl.querySelector("#navigator-toolbox")
  );

  Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
  Assert.ok(
    !docEl.hasAttribute("lwtheme-image"),
    "LWT image attribute should not be set on deprecated headerURL alias"
  );
  Assert.ok(
    !docEl.getAttribute("lwtheme-brighttext"),
    "LWT text color attribute should not be set on deprecated textcolor alias"
  );

  if (backgroundColorSetOnRoot()) {
    let rootCS = window.getComputedStyle(docEl);
    Assert.equal(
      rootCS.backgroundColor,
      DEFAULT_THEME_BG_COLOR,
      "Expected default theme background color"
    );
  } else {
    Assert.equal(
      navigatorStyle.backgroundColor,
      DEFAULT_THEME_BG_COLOR,
      "Expected default theme background color"
    );
  }

  Assert.equal(
    docStyle.color,
    DEFAULT_THEME_TEXT_COLOR,
    "Expected default theme text color"
  );

  await extension.unload();

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