OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // testharness.js and testharnessreport.js need to be included first | 5 // testharness.js and testharnessreport.js need to be included first |
6 | 6 |
7 // Properties should be given in camelCase format | 7 // Properties should be given in camelCase format |
8 | 8 |
9 function convert_to_dashes(property) { | 9 function convert_to_dashes(property) { |
10 return property.replace(/[A-Z]/g, function(letter) { | 10 return property.replace(/[A-Z]/g, function(letter) { |
11 return "-" + letter.toLowerCase(); | 11 return "-" + letter.toLowerCase(); |
12 }); | 12 }); |
13 } | 13 } |
14 | 14 |
15 function assert_valid_value(property, value) { | 15 function assert_valid_value(property, value, serializedValue) { |
| 16 if (arguments.length != 3) |
| 17 serializedValue = value; |
| 18 |
16 test(function(){ | 19 test(function(){ |
17 assert_true(CSS.supports(convert_to_dashes(property), value)); | 20 assert_true(CSS.supports(convert_to_dashes(property), value)); |
18 }, "CSS.supports('" + property + "', '" + value + "') should return true"); | 21 }, "CSS.supports('" + property + "', '" + value + "') should return true"); |
19 | 22 |
20 test(function(){ | 23 test(function(){ |
21 var div = document.createElement('div'); | 24 var div = document.createElement('div'); |
22 div.style[property] = value; | 25 div.style[property] = value; |
23 assert_not_equals(div.style[property], ""); | 26 assert_not_equals(div.style[property], ""); |
24 }, "e.style['" + property + "'] = '" + value + "' should set the value"); | 27 }, "e.style['" + property + "'] = '" + value + "' should set the value"); |
25 | 28 |
26 test(function(){ | 29 test(function(){ |
27 var div = document.createElement('div'); | 30 var div = document.createElement('div'); |
28 div.style[property] = value; | 31 div.style[property] = value; |
29 var readValue = div.style[property]; | 32 var readValue = div.style[property]; |
| 33 assert_equals(readValue, serializedValue); |
30 div.style[property] = readValue; | 34 div.style[property] = readValue; |
31 assert_equals(div.style[property], readValue); | 35 assert_equals(div.style[property], readValue); |
32 }, "Serialization should round-trip after setting e.style['" + property + "'
] = '" + value + "'"); | 36 }, "Serialization should round-trip after setting e.style['" + property + "'
] = '" + value + "'"); |
33 } | 37 } |
34 | 38 |
35 function assert_invalid_value(property, value) { | 39 function assert_invalid_value(property, value) { |
36 test(function(){ | 40 test(function(){ |
37 assert_false(CSS.supports(convert_to_dashes(property), value)); | 41 assert_false(CSS.supports(convert_to_dashes(property), value)); |
38 }, "CSS.supports('" + property + "', '" + value + "') should return false"); | 42 }, "CSS.supports('" + property + "', '" + value + "') should return false"); |
39 | 43 |
40 test(function(){ | 44 test(function(){ |
41 var div = document.createElement('div'); | 45 var div = document.createElement('div'); |
42 div.style[property] = value; | 46 div.style[property] = value; |
43 assert_equals(div.style[property], ""); | 47 assert_equals(div.style[property], ""); |
44 }, "e.style['" + property + "'] = '" + value + "' should not set the value")
; | 48 }, "e.style['" + property + "'] = '" + value + "' should not set the value")
; |
45 } | 49 } |
OLD | NEW |