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

// This test checks whether applied WebExtension themes that attempt to change
// the color of the font and background in a selection are applied properly.
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
add_setup(async function () {
  await gCUITestUtils.addSearchBar();
  await gFindBarPromise;
  registerCleanupFunction(() => {
    gFindBar.close();
    gCUITestUtils.removeSearchBar();
  });
});

add_task(async function test_support_selection() {
  const HIGHLIGHT_TEXT_COLOR = "#9400FF";
  const HIGHLIGHT_COLOR = "#F89919";
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      theme: {
        colors: {
          toolbar_field_highlight: HIGHLIGHT_COLOR,
          toolbar_field_highlight_text: HIGHLIGHT_TEXT_COLOR,
        },
      },
    },
  });
  await extension.startup();

  let fields = [
    gURLBar.inputField,
    document.querySelector("#searchbar .searchbar-textbox"),
    document.querySelector(".findbar-textbox"),
  ].filter(field => {
    let bounds = field.getBoundingClientRect();
    return bounds.width > 0 && bounds.height > 0;
  });

  Assert.equal(fields.length, 3, "Should be testing three elements");

  info(
    `Checking background colors and colors for ${fields.length} toolbar input fields.`
  );
  for (let field of fields) {
    info(`Testing ${field.id || field.className}`);
    field.focus();
    Assert.equal(
      window.getComputedStyle(field, "::selection").backgroundColor,
      hexToCSS(HIGHLIGHT_COLOR),
      "Input selection background should be set."
    );
    Assert.equal(
      window.getComputedStyle(field, "::selection").color,
      hexToCSS(HIGHLIGHT_TEXT_COLOR),
      "Input selection color should be set."
    );
  }

  await extension.unload();
});