OLD | NEW |
1 /** | 1 /** |
2 * @fileoverview A standard set of tests for using a single property in an | 2 * @fileoverview A standard set of tests for using a single property in an |
3 * inline StylePropertyMap | 3 * inline StylePropertyMap |
4 * (https://www.w3.org/TR/css-typed-om-1/#the-stylepropertymap). | 4 * (https://www.w3.org/TR/css-typed-om-1/#the-stylepropertymap). |
5 * | 5 * |
6 * Create a config object containing { | 6 * Create a config object containing { |
7 * validKeywords: array of strings, | 7 * validKeywords: array of strings, |
8 * validObjects: array of CSSStyleValue instances that are valid for the | 8 * validObjects: array of CSSStyleValue instances that are valid for the |
9 * property, | 9 * property, |
10 * validStringMappings: object containing a mapping of string to | 10 * validStringMappings: object containing a mapping of string to |
(...skipping 10 matching lines...) Expand all Loading... |
21 * | 21 * |
22 * Note that CSS-wide keywords, and non-CSSStyleValue invalid types do not need | 22 * Note that CSS-wide keywords, and non-CSSStyleValue invalid types do not need |
23 * to be specified. | 23 * to be specified. |
24 * | 24 * |
25 * If necessary, you can continue to define non-standard tests in your html | 25 * If necessary, you can continue to define non-standard tests in your html |
26 * file as usual. | 26 * file as usual. |
27 */ | 27 */ |
28 | 28 |
29 function runInlineStylePropertyMapTests(config) { | 29 function runInlineStylePropertyMapTests(config) { |
30 let element = document.createElement('div'); | 30 let element = document.createElement('div'); |
| 31 document.documentElement.appendChild(element); |
31 let validKeywords = config.validKeywords.concat([ | 32 let validKeywords = config.validKeywords.concat([ |
32 // CSS-wide keywords | 33 // CSS-wide keywords |
33 'initial', | 34 'initial', |
34 'inherit', | 35 'inherit', |
35 'unset' | 36 'unset' |
36 ]); | 37 ]); |
37 let validObjects = config.validObjects; | 38 let validObjects = config.validObjects; |
38 let validStringMappings = config.validStringMappings ? | 39 let validStringMappings = config.validStringMappings ? |
39 config.validStringMappings : {}; | 40 config.validStringMappings : {}; |
40 let invalidObjects = config.invalidObjects.concat([ | 41 let invalidObjects = config.invalidObjects.concat([ |
(...skipping 30 matching lines...) Expand all Loading... |
71 } | 72 } |
72 } | 73 } |
73 | 74 |
74 function runSetterTests( | 75 function runSetterTests( |
75 propertyName, validKeywords, validObjects, invalidObjects, element) { | 76 propertyName, validKeywords, validObjects, invalidObjects, element) { |
76 for (let keyword of validKeywords) { | 77 for (let keyword of validKeywords) { |
77 test(function() { | 78 test(function() { |
78 element.style = ''; | 79 element.style = ''; |
79 element.styleMap.set(propertyName, new CSSKeywordValue(keyword)); | 80 element.styleMap.set(propertyName, new CSSKeywordValue(keyword)); |
80 assert_equals(element.style[propertyName], keyword); | 81 assert_equals(element.style[propertyName], keyword); |
| 82 // Force a style recalc to check for crashes in style recalculation. |
| 83 getComputedStyle(element)[propertyName]; |
| 84 assert_equals(element.style[propertyName], keyword); |
81 }, 'Setting ' + propertyName + ' to ' + keyword); | 85 }, 'Setting ' + propertyName + ' to ' + keyword); |
82 } | 86 } |
83 for (let validObject of validObjects) { | 87 for (let validObject of validObjects) { |
84 test(function() { | 88 test(function() { |
85 element.style = ''; | 89 element.style = ''; |
86 | |
87 element.styleMap.set(propertyName, validObject); | 90 element.styleMap.set(propertyName, validObject); |
88 assert_equals(element.style[propertyName], validObject.cssText); | 91 assert_equals(element.style[propertyName], validObject.cssText); |
| 92 // Force a style recalc to check for crashes in style recalculation. |
| 93 getComputedStyle(element)[propertyName]; |
| 94 assert_equals(element.style[propertyName], validObject.cssText); |
89 }, 'Setting ' + propertyName + ' to ' + validObject.constructor.name + | 95 }, 'Setting ' + propertyName + ' to ' + validObject.constructor.name + |
90 ' with value ' + validObject.cssText); | 96 ' with value ' + validObject.cssText); |
91 } | 97 } |
92 | 98 |
93 // Negative tests | 99 // Negative tests |
94 for (let invalidObject of invalidObjects) { | 100 for (let invalidObject of invalidObjects) { |
95 let name = invalidObject instanceof CSSStyleValue ? | 101 let name = invalidObject instanceof CSSStyleValue ? |
96 invalidObject.constructor.name : invalidObject; | 102 invalidObject.constructor.name : invalidObject; |
97 test(function() { | 103 test(function() { |
98 assert_throws(new TypeError(), function() { | 104 assert_throws(new TypeError(), function() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 assert_equals(result.cssText, validStringMappings[cssText].cssText); | 142 assert_equals(result.cssText, validStringMappings[cssText].cssText); |
137 }, 'Getting ' + propertyName + ' when it is set to "' + | 143 }, 'Getting ' + propertyName + ' when it is set to "' + |
138 cssText + '" via a string'); | 144 cssText + '" via a string'); |
139 } | 145 } |
140 } | 146 } |
141 | 147 |
142 function runSequenceSetterTests( | 148 function runSequenceSetterTests( |
143 propertyName, validObject, invalidObject, element) { | 149 propertyName, validObject, invalidObject, element) { |
144 test(function() { | 150 test(function() { |
145 element.style = ''; | 151 element.style = ''; |
146 | |
147 element.styleMap.set(propertyName, [validObject, validObject]); | 152 element.styleMap.set(propertyName, [validObject, validObject]); |
148 assert_equals( | 153 assert_equals( |
149 element.style[propertyName], validObject.cssText + ', ' + | 154 element.style[propertyName], validObject.cssText + ', ' + |
150 validObject.cssText); | 155 validObject.cssText); |
| 156 // Force a style recalc to check for crashes in style recalculation. |
| 157 getComputedStyle(element)[propertyName]; |
| 158 assert_equals( |
| 159 element.style[propertyName], validObject.cssText + ', ' + |
| 160 validObject.cssText); |
151 }, 'Set ' + propertyName + ' to a sequence'); | 161 }, 'Set ' + propertyName + ' to a sequence'); |
152 | 162 |
153 test(function() { | 163 test(function() { |
154 let sequence = [validObject, invalidObject]; | 164 let sequence = [validObject, invalidObject]; |
155 assert_throws(new TypeError(), function() { | 165 assert_throws(new TypeError(), function() { |
156 element.styleMap.set(propertyName, sequence); | 166 element.styleMap.set(propertyName, sequence); |
157 }); | 167 }); |
158 }, 'Set ' + propertyName + ' to a sequence containing an invalid type'); | 168 }, 'Set ' + propertyName + ' to a sequence containing an invalid type'); |
159 } | 169 } |
160 | 170 |
161 function runAppendTests( | 171 function runAppendTests( |
162 propertyName, validObject, invalidObject, element) { | 172 propertyName, validObject, invalidObject, element) { |
163 test(function() { | 173 test(function() { |
164 element.style = ''; | 174 element.style = ''; |
165 | 175 |
166 element.styleMap.append(propertyName, validObject); | 176 element.styleMap.append(propertyName, validObject); |
167 assert_equals(element.style[propertyName], validObject.cssText); | 177 assert_equals(element.style[propertyName], validObject.cssText); |
168 | 178 |
169 element.styleMap.append(propertyName, validObject); | 179 element.styleMap.append(propertyName, validObject); |
170 assert_equals( | 180 assert_equals( |
171 element.style[propertyName], validObject.cssText + ', ' + | 181 element.style[propertyName], validObject.cssText + ', ' + |
172 validObject.cssText); | 182 validObject.cssText); |
| 183 // Force a style recalc to check for crashes in style recalculation. |
| 184 getComputedStyle(element)[propertyName]; |
| 185 assert_equals( |
| 186 element.style[propertyName], validObject.cssText + ', ' + |
| 187 validObject.cssText); |
173 }, 'Appending a ' + validObject.constructor.name + ' to ' + propertyName); | 188 }, 'Appending a ' + validObject.constructor.name + ' to ' + propertyName); |
174 | 189 |
175 test(function() { | 190 test(function() { |
176 element.style = ''; | 191 element.style = ''; |
177 | 192 |
178 element.styleMap.append(propertyName, [validObject, validObject]); | 193 element.styleMap.append(propertyName, [validObject, validObject]); |
179 assert_equals( | 194 assert_equals( |
180 element.style[propertyName], validObject.cssText + ', ' + | 195 element.style[propertyName], validObject.cssText + ', ' + |
181 validObject.cssText); | 196 validObject.cssText); |
| 197 // Force a style recalc to check for crashes in style recalculation. |
| 198 getComputedStyle(element)[propertyName]; |
| 199 assert_equals( |
| 200 element.style[propertyName], validObject.cssText + ', ' + |
| 201 validObject.cssText); |
182 }, 'Append a sequence to ' + propertyName); | 202 }, 'Append a sequence to ' + propertyName); |
183 | 203 |
184 // Negative tests | 204 // Negative tests |
185 test(function() { | 205 test(function() { |
186 assert_throws(new TypeError(), function() { | 206 assert_throws(new TypeError(), function() { |
187 element.styleMap.append(propertyName, invalidObject); | 207 element.styleMap.append(propertyName, invalidObject); |
188 }); | 208 }); |
189 }, 'Appending an invalid value to ' + propertyName); | 209 }, 'Appending an invalid value to ' + propertyName); |
190 | 210 |
191 test(function() { | 211 test(function() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 250 |
231 function runDeletionTests(propertyName, validObject, element) { | 251 function runDeletionTests(propertyName, validObject, element) { |
232 test(function() { | 252 test(function() { |
233 element.style[propertyName] = validObject.cssText; | 253 element.style[propertyName] = validObject.cssText; |
234 | 254 |
235 assert_not_equals(element.styleMap.get(propertyName), null); | 255 assert_not_equals(element.styleMap.get(propertyName), null); |
236 | 256 |
237 element.styleMap.delete(propertyName); | 257 element.styleMap.delete(propertyName); |
238 assert_equals(element.style[propertyName], ''); | 258 assert_equals(element.style[propertyName], ''); |
239 assert_equals(element.styleMap.get(propertyName), null); | 259 assert_equals(element.styleMap.get(propertyName), null); |
| 260 // Force a style recalc to check for crashes in style recalculation. |
| 261 getComputedStyle(element)[propertyName]; |
| 262 assert_equals(element.style[propertyName], ''); |
| 263 assert_equals(element.styleMap.get(propertyName), null); |
240 }, 'Delete ' + propertyName + ' removes the value from the styleMap'); | 264 }, 'Delete ' + propertyName + ' removes the value from the styleMap'); |
241 } | 265 } |
242 | 266 |
243 function runGetPropertiesTests(propertyName, validObject, element) { | 267 function runGetPropertiesTests(propertyName, validObject, element) { |
244 test(function() { | 268 test(function() { |
245 element.style = ''; | 269 element.style = ''; |
246 assert_array_equals(element.styleMap.getProperties(), []); | 270 assert_array_equals(element.styleMap.getProperties(), []); |
247 | |
248 element.styleMap.set(propertyName, validObject); | 271 element.styleMap.set(propertyName, validObject); |
249 | 272 assert_array_equals(element.styleMap.getProperties(), [propertyName]); |
| 273 // Force a style recalc to check for crashes in style recalculation. |
| 274 getComputedStyle(element)[propertyName]; |
250 assert_array_equals(element.styleMap.getProperties(), [propertyName]); | 275 assert_array_equals(element.styleMap.getProperties(), [propertyName]); |
251 }, propertyName + ' shows up in getProperties'); | 276 }, propertyName + ' shows up in getProperties'); |
252 } | 277 } |
253 | 278 |
254 function runMultipleValuesNotSupportedTests( | 279 function runMultipleValuesNotSupportedTests( |
255 propertyName, validObject, element) { | 280 propertyName, validObject, element) { |
256 test(function() { | 281 test(function() { |
257 element.style = ''; | 282 element.style = ''; |
258 assert_throws(new TypeError(), function() { | 283 assert_throws(new TypeError(), function() { |
259 element.styleMap.set(propertyName, [validObject, validObject]); | 284 element.styleMap.set(propertyName, [validObject, validObject]); |
260 }); | 285 }); |
261 }, 'Setting ' + propertyName + ' to a sequence throws'); | 286 }, 'Setting ' + propertyName + ' to a sequence throws'); |
262 | 287 |
263 test(function() { | 288 test(function() { |
264 element.style = ''; | 289 element.style = ''; |
265 assert_throws(new TypeError(), function() { | 290 assert_throws(new TypeError(), function() { |
266 element.styleMap.append(propertyName, validObject); | 291 element.styleMap.append(propertyName, validObject); |
267 }); | 292 }); |
268 }, 'Appending to ' + propertyName + ' throws'); | 293 }, 'Appending to ' + propertyName + ' throws'); |
269 } | 294 } |
270 | 295 |
OLD | NEW |