summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_prefers_contrast_color_pairs.html
blob: f4a89458049ecce0d0fa435aa365401978defa27 (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
<!doctype html>
<title>Test for Bug 922669</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script>
  function assertMatches(query) {
    ok(matchMedia(query).matches, `${query} should match`);
  }
  function assertPrefersContrastIs(value) {
    assertMatches(`(prefers-contrast: ${value})`);
  }
  add_task(async function setupPrefs() {
    assertPrefersContrastIs("no-preference");
    await SpecialPowers.pushPrefEnv({
      set: [
        ["browser.display.document_color_use", 2],
        ["browser.display.use_system_colors", false],
      ]
    });
    assertMatches("(prefers-contrast)");
  });
  async function testColors(foreground, background, expected) {
    await SpecialPowers.pushPrefEnv({
      set: [
        ["browser.display.foreground_color", foreground],
        ["browser.display.background_color", background],
      ]
    });

    assertPrefersContrastIs(expected);

    // Test the inversed order too.
    await SpecialPowers.pushPrefEnv({
      set: [
        ["browser.display.foreground_color", background],
        ["browser.display.background_color", foreground],
      ]
    });

    assertPrefersContrastIs(expected);
  }

  add_task(async function test_prefers_contrast_colors() {
    await testColors("black", "black", "less");
    await testColors("black", "white", "more");
    await testColors("red", "black", "custom");
  });
</script>