summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/test_bug232227.html
blob: 97f31dd25141af093b9be8b5aad561fa8c1d9108 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=232227
-->
<head>
  <title>Test for Bug 232227</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=232227">Mozilla Bug 232227</a>
<script>

/** Test for Bug 232227 **/

function runTest(testCanvasColors) {
  var colorNames = [
    [ "ActiveBorder", 0xB4, 0xB4, 0xB4 ],
    [ "ActiveCaption", 0x99, 0xB4, 0xD1 ],
    [ "AppWorkspace", 0xAB, 0xAB, 0xAB ],
    [ "Background", 0x00, 0x00, 0x00 ],
    [ "ButtonFace", 0xe9, 0xe9, 0xed],
    [ "ButtonHighlight", 0xFF, 0xFF, 0xFF ],
    [ "ButtonShadow", 0xA0, 0xA0, 0xA0 ],
    [ "ButtonText", 0x00, 0x00, 0x00 ],
    [ "CaptionText", 0x00, 0x00, 0x00 ],
    [ "GrayText", 0x6D, 0x6D, 0x6D ],
    [ "Highlight", 0x33, 0x99, 0xFF ],
    [ "HighlightText", 0xFF, 0xFF, 0xFF ],
    [ "InactiveBorder", 0xF4, 0xF7, 0xFC ],
    [ "InactiveCaption", 0xBF, 0xCD, 0xDB ],
    [ "InactiveCaptionText", 0x43, 0x4E, 0x54 ],
    [ "InfoBackground", 0xFF, 0xFF, 0xE1 ],
    [ "InfoText", 0x00, 0x00, 0x00 ],
    [ "Menu", 0xF0, 0xF0, 0xF0 ],
    [ "MenuText", 0x00, 0x00, 0x00 ],
    [ "Scrollbar", 0xC8, 0xC8, 0xC8 ],
    [ "ThreeDDarkShadow", 0x69, 0x69, 0x69 ],
    [ "ThreeDFace", 0xF0, 0xF0, 0xF0 ],
    [ "ThreeDHighlight", 0xFF, 0xFF, 0xFF ],
    [ "ThreeDLightShadow", 0xE3, 0xE3, 0xE3 ],
    [ "ThreeDShadow", 0xA0, 0xA0, 0xA0 ],
    [ "Window", 0xFF, 0xFF, 0xFF ],
    [ "WindowFrame", 0x64, 0x64, 0x64 ],
    [ "WindowText", 0x00, 0x00, 0x00 ],
    [ "-moz-ButtonDefault", 0x69, 0x69, 0x69 ],
    [ "-moz-ButtonHoverFace", 0xd0, 0xd0, 0xd7 ],
    [ "-moz-ButtonHoverText", 0x00, 0x00, 0x00 ],
    [ "-moz-CellHighlight", 0xF0, 0xF0, 0xF0 ],
    [ "-moz-CellHighlightText", 0x00, 0x00, 0x00 ],
    [ "-moz-Combobox", 0xe9, 0xe9, 0xed],
    [ "-moz-ComboboxText", 0x00, 0x00, 0x00 ],
    [ "-moz-Dialog", 0xF0, 0xF0, 0xF0 ],
    [ "-moz-DialogText", 0x00, 0x00, 0x00 ],
    [ "-moz-DragTargetZone", 0xFF, 0xFF, 0xFF ],
    [ "-moz-EvenTreeRow", 0xFF, 0xFF, 0xFF ],
    [ "-moz-Field", 0xFF, 0xFF, 0xFF ],
    [ "-moz-FieldText", 0x00, 0x00, 0x00 ],
    [ "-moz-MenuHover", 0x33, 0x99, 0xFF ],
    [ "-moz-MenuHoverText", 0x00, 0x00, 0x00 ],
    [ "-moz-MenubarText", 0x00, 0x00, 0x00 ],
    [ "-moz-MenubarHoverText", 0x00, 0x00, 0x00 ],
    [ "-moz-NativeHyperlinkText", 0x00, 0x66, 0xCC ],
    [ "-moz-OddTreeRow", 0xFF, 0xFF, 0xFF ],
    [ "-moz-mac-chrome-active", 0xB2, 0xB2, 0xB2 ],
    [ "-moz-mac-chrome-inactive", 0xE1, 0xE1, 0xE1 ],
    [ "-moz-mac-focusring", 0x60, 0x9D, 0xD7 ],
    [ "-moz-mac-menuselect", 0x38, 0x75, 0xD7 ],
    [ "-moz-mac-menushadow", 0xA3, 0xA3, 0xA3 ],
    [ "-moz-mac-menutextdisable", 0x88, 0x88, 0x88 ],
    [ "-moz-mac-menutextselect", 0xFF, 0xFF, 0xFF ],
    [ "-moz-mac-DisabledToolbarText", 0x3F, 0x3F, 0x3F ],
    [ "-moz-mac-SecondaryHighlight", 0xD4, 0xD4, 0xD4 ],
    [ "-moz-win-MediaText", 0xFF, 0xFF, 0xFF ],
    [ "-moz-win-CommunicationsText", 0xFF, 0xFF, 0xFF ],
    [ "SelectedItem", 0x33, 0x99, 0xFF ],
    [ "SelectedItemText", 0xFF, 0xFF, 0xFF ],

    // These five are configured via Tools -> Options -> Content -> Colors.
    //"-moz-ActiveHyperlinkText",
    //"-moz-HyperLinkText",
    //"-moz-VisitedHyperlinkText",
    //"-moz-default-background-color",
    //"-moz-default-color",
  ];

  var colorTestCanvas = document.createElement("canvas");
  colorTestCanvas.width = colorTestCanvas.height = 1;
  colorTestCanvas = colorTestCanvas.getContext("2d");

  var colorTestDiv = document.createElement("div");
  document.body.appendChild(colorTestDiv);

  for (let [colorName, r, g, b] of colorNames) {
    // test value
    var ctest = "rgb(" + r + ", " + g + ", " + b + ")";

    // computed value
    colorTestDiv.style.backgroundColor = "";
    colorTestDiv.style.backgroundColor = colorName;
    var c1 = getComputedStyle(colorTestDiv).backgroundColor;
    is(c1, ctest, "Stand-in computed color: " + colorName + " is correct.");

    // canvas
    if (testCanvasColors && colorTestCanvas) {
      colorTestCanvas.fillStyle = colorName;
      colorTestCanvas.fillRect(0, 0, 1, 1);
      var c2 = colorTestCanvas.getImageData(0, 0, 1, 1).data;
      c2 = "rgb(" + c2[0] + ", " + c2[1] + ", " + c2[2] + ")";
      is(c2, ctest, "Stand-in canvas color: " + colorName + " is correct.");
    }
  }
}

(async function() {
  SimpleTest.waitForExplicitFinish();
  await SpecialPowers.pushPrefEnv({ "set" : [
    [ "ui.use_standins_for_native_colors", true ],
  ]});
  runTest(/* testCanvasColors = */ true);
  await SpecialPowers.pushPrefEnv({ "set" : [
    [ "privacy.resistFingerprinting", true ],
    [ "ui.use_standins_for_native_colors", false ],
  ]});
  // With privacy.resistFingerprinting canvas data doesn't reflect the actual
  // canvas, apparently.
  runTest(/* testCanvasColors = */ false);
  SimpleTest.finish();
}());
</script>
</body>
</html>