4 <script src="../js/resources/js-test-pre.js"></script>
9 description("Test case for bug 39168. This tests the CSS color parsing code using <canvas>.");
11 function log(message) {
12 var console = document.getElementById("console");
13 console.appendChild(document.createTextNode(message));
14 console.appendChild(document.createElement("BR"));
17 var canvas = document.getElementById("canvas");
18 var ctx = canvas.getContext("2d");
20 function shouldSuccessfullyParse(color) {
21 ctx.fillStyle = "#f00";
22 ctx.fillStyle = color;
23 // Check that there is no red.
24 if (ctx.fillStyle.match(/^#(?!(FF0000|ff0000|f00)$)/))
25 testPassed("Setting color to " + color + " was successfully set.");
27 testFailed("Setting color to " + color + " was not set but should!");
30 function shouldNotSuccessfullyParse(color) {
31 ctx.fillStyle = "#0f0";
32 ctx.fillStyle = color;
33 // Check that the color is still green.
34 if (ctx.fillStyle.match(/^#(00FF00|00ff00|0f0)$/))
35 testPassed("Setting color to " + color + " was not set (as expected).");
37 testFailed("Setting color to " + color + " was successfully set but should not!");
40 // Taken from CSS 3 color.
41 var deprecatedSystemColors = [
56 "InactiveCaptionText",
72 // Valid values passed in color matching.
73 for (var i = 0; i < deprecatedSystemColors.length; ++i) {
74 shouldSuccessfullyParse(deprecatedSystemColors[i]);
75 shouldSuccessfullyParse(deprecatedSystemColors[i].toLowerCase());
78 // Taken from CSS 3 color.
150 "lightgoldenrodyellow",
199 // We do not test red.
229 // Valid values passed in color matching.
230 for (var i = 0; i < svgColors.length; ++i)
231 shouldSuccessfullyParse(svgColors[i]);
234 shouldSuccessfullyParse("#0f0");
235 shouldSuccessfullyParse("hsl(120, 100%, 50%)"); // Green HSL
238 shouldNotSuccessfullyParse("foobar");
239 shouldNotSuccessfullyParse("counter(foobar)");
240 shouldNotSuccessfullyParse("url(http://127.0.0.1:8080/)");
241 shouldNotSuccessfullyParse("inherited");
242 shouldNotSuccessfullyParse("#100%");
243 shouldNotSuccessfullyParse("#100px");
244 shouldNotSuccessfullyParse('-webkit-var("test")');
246 <script src="../js/resources/js-test-post.js"></script>