OLD | NEW |
1 | 1 |
2 let testNumber = 1; | 2 let testNumber = 1; |
3 | 3 |
4 function testNodeConnector(testFunction, name) { | 4 function testNodeConnector(testFunction, name) { |
5 let container = document.createElement('div'); | 5 let container = document.createElement('div'); |
6 container.appendChild(document.createElement('div')); | 6 container.appendChild(document.createElement('div')); |
7 document.body.appendChild(container); | 7 document.body.appendChild(container); |
8 | 8 |
9 test(function () { | 9 test(function () { |
10 var element = define_new_custom_element(); | 10 var element = define_new_custom_element(); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 253 |
254 test(function () { | 254 test(function () { |
255 var element = define_new_custom_element([]); | 255 var element = define_new_custom_element([]); |
256 var instance = document.createElement(element.name); | 256 var instance = document.createElement(element.name); |
257 instance.setAttribute('data-lang', 'ja'); | 257 instance.setAttribute('data-lang', 'ja'); |
258 assert_array_equals(element.takeLog().types(), ['constructed']); | 258 assert_array_equals(element.takeLog().types(), ['constructed']); |
259 testFunction(instance, 'data-lang'); | 259 testFunction(instance, 'data-lang'); |
260 assert_array_equals(element.takeLog().types(), []); | 260 assert_array_equals(element.takeLog().types(), []); |
261 }, name + ' must not enqueue an attributeChanged reaction when removing an e
xisting unobserved attribute'); | 261 }, name + ' must not enqueue an attributeChanged reaction when removing an e
xisting unobserved attribute'); |
262 } | 262 } |
| 263 |
| 264 function test_mutating_style_property_value(testFunction, name, options) { |
| 265 const propertyName = (options || {}).propertyName || 'color'; |
| 266 const idlName = (options || {}).idlName || 'color'; |
| 267 const value1 = (options || {}).value1 || 'blue'; |
| 268 const rule1 = `${propertyName}: ${value1};`; |
| 269 const value2 = (options || {}).value2 || 'red'; |
| 270 const rule2 = `${propertyName}: ${value2};`; |
| 271 |
| 272 test(function () { |
| 273 var element = define_new_custom_element(['style']); |
| 274 var instance = document.createElement(element.name); |
| 275 assert_array_equals(element.takeLog().types(), ['constructed']); |
| 276 testFunction(instance, propertyName, idlName, value1); |
| 277 assert_equals(instance.getAttribute('style'), rule1); |
| 278 var logEntries = element.takeLog(); |
| 279 assert_array_equals(logEntries.types(), ['attributeChanged']); |
| 280 assert_attribute_log_entry(logEntries.last(), {name: 'style', oldValue:
null, newValue: rule1, namespace: null}); |
| 281 }, name + ' must enqueue an attributeChanged reaction when it adds the obser
ved style attribute'); |
| 282 |
| 283 test(function () { |
| 284 var element = define_new_custom_element(['title']); |
| 285 var instance = document.createElement(element.name); |
| 286 assert_array_equals(element.takeLog().types(), ['constructed']); |
| 287 testFunction(instance, propertyName, idlName, value1); |
| 288 assert_equals(instance.getAttribute('style'), rule1); |
| 289 assert_array_equals(element.takeLog().types(), []); |
| 290 }, name + ' must not enqueue an attributeChanged reaction when it adds the s
tyle attribute but the style attribute is not observed'); |
| 291 |
| 292 test(function () { |
| 293 var element = define_new_custom_element(['style']); |
| 294 var instance = document.createElement(element.name); |
| 295 testFunction(instance, propertyName, idlName, value1); |
| 296 assert_array_equals(element.takeLog().types(), ['constructed', 'attribut
eChanged']); |
| 297 testFunction(instance, propertyName, idlName, value2); |
| 298 assert_equals(instance.getAttribute('style'), rule2); |
| 299 var logEntries = element.takeLog(); |
| 300 assert_array_equals(logEntries.types(), ['attributeChanged']); |
| 301 assert_attribute_log_entry(logEntries.last(), {name: 'style', oldValue:
rule1, newValue: rule2, namespace: null}); |
| 302 }, name + ' must enqueue an attributeChanged reaction when it mutates the ob
served style attribute'); |
| 303 |
| 304 test(function () { |
| 305 var element = define_new_custom_element([]); |
| 306 var instance = document.createElement(element.name); |
| 307 testFunction(instance, propertyName, idlName, value1); |
| 308 assert_array_equals(element.takeLog().types(), ['constructed']); |
| 309 testFunction(instance, propertyName, idlName, value2); |
| 310 assert_equals(instance.getAttribute('style'), rule2); |
| 311 assert_array_equals(element.takeLog().types(), []); |
| 312 }, name + ' must not enqueue an attributeChanged reaction when it mutates th
e style attribute but the style attribute is not observed'); |
| 313 } |
| 314 |
| 315 function test_removing_style_property_value(testFunction, name) { |
| 316 test(function () { |
| 317 var element = define_new_custom_element(['style']); |
| 318 var instance = document.createElement(element.name); |
| 319 instance.setAttribute('style', 'color: red; display: none;'); |
| 320 assert_array_equals(element.takeLog().types(), ['constructed', 'attribut
eChanged']); |
| 321 testFunction(instance, 'color', 'color'); |
| 322 assert_equals(instance.getAttribute('style'), 'display: none;'); // Don'
t make this empty since browser behaviors are inconsistent now. |
| 323 var logEntries = element.takeLog(); |
| 324 assert_array_equals(logEntries.types(), ['attributeChanged']); |
| 325 assert_attribute_log_entry(logEntries.last(), {name: 'style', oldValue:
'color: red; display: none;', newValue: 'display: none;', namespace: null}); |
| 326 }, name + ' must enqueue an attributeChanged reaction when it removes a prop
erty from the observed style attribute'); |
| 327 |
| 328 test(function () { |
| 329 var element = define_new_custom_element(['class']); |
| 330 var instance = document.createElement(element.name); |
| 331 instance.setAttribute('style', 'color: red; display: none;'); |
| 332 assert_array_equals(element.takeLog().types(), ['constructed']); |
| 333 testFunction(instance, 'color', 'color'); |
| 334 assert_equals(instance.getAttribute('style'), 'display: none;'); // Don'
t make this empty since browser behaviors are inconsistent now. |
| 335 assert_array_equals(element.takeLog().types(), []); |
| 336 }, name + ' must not enqueue an attributeChanged reaction when it removes a
property from the style attribute but the style attribute is not observed'); |
| 337 } |
| 338 |
| 339 function test_mutating_style_property_priority(testFunction, name) { |
| 340 test(function () { |
| 341 var element = define_new_custom_element(['style']); |
| 342 var instance = document.createElement(element.name); |
| 343 instance.setAttribute('style', 'color: red'); |
| 344 assert_array_equals(element.takeLog().types(), ['constructed', 'attribut
eChanged']); |
| 345 testFunction(instance, 'color', 'color', true); |
| 346 assert_equals(instance.getAttribute('style'), 'color: red !important;'); |
| 347 var logEntries = element.takeLog(); |
| 348 assert_array_equals(logEntries.types(), ['attributeChanged']); |
| 349 assert_attribute_log_entry(logEntries.last(), {name: 'style', oldValue:
'color: red', newValue: 'color: red !important;', namespace: null}); |
| 350 }, name + ' must enqueue an attributeChanged reaction when it makes a proper
ty important and the style attribute is observed'); |
| 351 |
| 352 test(function () { |
| 353 var element = define_new_custom_element(['id']); |
| 354 var instance = document.createElement(element.name); |
| 355 instance.setAttribute('style', 'color: red'); |
| 356 assert_array_equals(element.takeLog().types(), ['constructed']); |
| 357 testFunction(instance, 'color', 'color', true); |
| 358 assert_equals(instance.getAttribute('style'), 'color: red !important;'); |
| 359 assert_array_equals(element.takeLog().types(), []); |
| 360 }, name + ' must enqueue an attributeChanged reaction when it makes a proper
ty important but the style attribute is not observed'); |
| 361 } |
OLD | NEW |