blob: b2e0ae229119c3200f1666a2f92ab4e065f60843 [file] [log] [blame]
ktyliufdab33b2017-01-24 20:55:221<!DOCTYPE html>
2<body>
3<script src="../resources/testharness.js"></script>
4<script src="../resources/testharnessreport.js"></script>
5<script>
6test(function() {
7 for (var i = 0.0; i <= 1.0; i += 0.01) {
8 var rgba = 'rgba(0, 0, 0, ' + parseFloat(i.toFixed(2)) + ')';
9 document.body.style.color = rgba;
10 assert_equals(document.body.style.color, rgba);
11 assert_equals(getComputedStyle(document.body).color, rgba);
12 }
13}, 'Alpha values should parse and serialize to the same value to 2 decimal places');
14
15test(function() {
16 var testCases = [
17 ['rgba(0, 0, 0, 0.501)', 'rgba(0, 0, 0, 0.5)'],
18 ['rgba(0, 0, 0, 0.011)', 'rgba(0, 0, 0, 0.01)'],
19 ['rgba(0, 0, 0, 0.0041)', 'rgba(0, 0, 0, 0.004)'],
20 ['rgba(0, 0, 0, 0.01601)', 'rgba(0, 0, 0, 0.016)']
21 ];
22 for (var i = 0; i < testCases.length; ++i) {
23 var rgba = testCases[i][0];
24 var expected = testCases[i][1];
25 document.body.style.color = rgba;
26 assert_equals(document.body.style.color, expected);
27 assert_equals(getComputedStyle(document.body).color, expected);
28 }
29}, 'Alpha values with three or more decimals should parse and serialize to ' +
30 '1, 2, or 3 decimal places according to w3c spec');
31</script>
32