Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/css/hex-colors.html

Issue 1936913002: [CSS] Accept 8 (#RRGGBBAA) and 4 (#RGBA) value hex colors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add quirks mode fastParseColorInternal() test cases. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <script>
3 if (window.testRunner)
4 testRunner.dumpAsText();
5
6 var TESTS = [
7 ["#000", 0, 0, 0],
8 ["#001", 0, 0, 17],
9 ["#012", 0, 17, 34],
10 ["#123", 17, 34, 51],
11 ["#0001", 0, 0, 0, 17],
12 ["#0012", 0, 0, 17,34],
13 ["#0123", 0, 17, 34, 51],
14 ["#1234", 17, 34, 51, 68],
15 ["#000000", 0, 0, 0],
16 ["#000012", 0, 0, 18],
17 ["#001234", 0, 18, 52],
18 ["#123456", 18, 52, 86],
19 ["#00000000", 0, 0, 0, 0],
20 ["#00000012", 0, 0, 0, 18],
21 ["#00001234", 0, 0, 18, 52],
22 ["#00123456", 0, 18, 52, 86],
23 ["#12345678", 18, 52, 86, 120],
24 // Bad content from here on shows the red failure color.
25 ["#12x3", 255, 0, 0],
26 ["#123x", 255, 0, 0],
27 ["#123x4567", 255, 0, 0],
28 ["#1234567r", 255, 0, 0],
29 ["#123456x6", 255, 0, 0],
30 ];
31
32 function extractComponents(rgbValue) {
33 var re = /rgba?\((\d+),\s(\d+),\s(\d+)(,\s([\d\.]+))?\)/;
34 var match = re.exec(rgbValue);
35 var results = [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])];
36 if (match[5])
37 results.push(Math.round(parseFloat(match[5]) * 255));
38 return results;
39 }
40
41 function componentsMatch(components, expectedR, expectedG, expectedB, expectedA) {
42 if (components[0] == expectedR && components[1] == expectedG && components[2 ] == expectedB) {
43 if (components.length != 4)
44 return true;
45 return components[3] == expectedA;
46 }
47 }
48
49 function componentsAsRGBA(r, g, b, a) {
50 if (a !== undefined)
51 return "red:" + r + " green: " + g + " blue: " + b + " alpha: " + a;
52 return "red:" + r + " green: " + g + " blue: " + b;
53 }
54
55 function runTest() {
56 var element = document.querySelector("p");
57 var results = "";
58
59 for (var test of TESTS) {
60 element.style.color = test[0];
61 var components = extractComponents(window.getComputedStyle(element).colo r);
62 if (componentsMatch(components, test[1], test[2], test[3], test[4]))
63 results += "PASS " + test[0] + " was " + componentsAsRGBA(test[1], t est[2], test[3], test[4]) + "<br>";
64 else
65 results += "FAIL " + test[0] + " should be " + componentsAsRGBA(test [1], test[2], test[3], test[4]) + " but was " + componentsAsRGBA(components[0], components[1], components[2], components[3]) + "<br>";
66
67 // Force a color reset and style recalc.
68 element.style.color = "red";
69 computedStyle = window.getComputedStyle(element).color;
70 }
71
72 document.querySelector("div").innerHTML = results;
73 }
74
75 window.addEventListener("load", runTest, false);
76 </script>
77 <div id="results"></div>
78 <p></p>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698