AriaMixin-element-attributes.html (3595B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Custom Elements: CEReactions on Element interface</title> 5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> 6 <meta name="assert" content="Element attributes of AriaAttributes interface must have CEReactions"> 7 <meta name="help" content="https://dom.spec.whatwg.org/#element"> 8 <meta name="help" content="https://w3c.github.io/DOM-Parsing/"> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script src="../resources/custom-elements-helpers.js"></script> 12 <script src="./resources/reactions.js"></script> 13 </head> 14 <body> 15 <div id="log"></div> 16 <div id="parentElement"></div> 17 <script> 18 19 function testElementReflectAttribute(jsAttributeName, contentAttributeName, validValue1, validValue2, name, getParentElement) { 20 test(function () { 21 let element = define_new_custom_element([contentAttributeName]); 22 let instance = document.createElement(element.name); 23 assert_array_equals(element.takeLog().types(), ['constructed']); 24 parentElement.appendChild(instance); 25 assert_array_equals(element.takeLog().types(), ['connected']); 26 instance[jsAttributeName] = validValue1; 27 let logEntries = element.takeLog(); 28 assert_array_equals(logEntries.types(), ['attributeChanged']); 29 30 assert_attribute_log_entry(logEntries.last(), {name: contentAttributeName, oldValue: null, newValue: "", namespace: null}); 31 }, name + ' must enqueue an attributeChanged reaction when adding ' + contentAttributeName + ' content attribute'); 32 33 test(function () { 34 let element = define_new_custom_element([contentAttributeName]); 35 let instance = document.createElement(element.name); 36 parentElement.appendChild(instance); 37 instance[jsAttributeName] = validValue1; 38 assert_array_equals(element.takeLog().types(), ['constructed', 'connected', 'attributeChanged']); 39 instance[jsAttributeName] = validValue2; 40 var logEntries = element.takeLog(); 41 assert_array_equals(logEntries.types(), ['attributeChanged']); 42 assert_attribute_log_entry(logEntries.last(), {name: contentAttributeName, oldValue: "", newValue: "", namespace: null}); 43 }, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute'); 44 } 45 46 const dummy1 = document.createElement('div'); 47 dummy1.id = 'dummy1'; 48 document.body.appendChild(dummy1); 49 50 const dummy2 = document.createElement('div'); 51 dummy2.id = 'dummy2'; 52 document.body.appendChild(dummy2); 53 54 testElementReflectAttribute('ariaActiveDescendantElement', 'aria-activedescendant', dummy1, dummy2, 'ariaActiveDescendantElement in Element'); 55 testElementReflectAttribute('ariaControlsElements', 'aria-controls', [dummy1], [dummy2], 'ariaControlsElements in Element'); 56 testElementReflectAttribute('ariaDescribedByElements', 'aria-describedby', [dummy1], [dummy2], 'ariaDescribedByElements in Element'); 57 testElementReflectAttribute('ariaDetailsElements', 'aria-details', [dummy1], [dummy2], 'ariaDetailsElements in Element'); 58 testElementReflectAttribute('ariaErrorMessageElements', 'aria-errormessage', [dummy1], [dummy2], 'ariaErrorMessageElements in Element'); 59 testElementReflectAttribute('ariaFlowToElements', 'aria-flowto', [dummy1], [dummy2], 'ariaFlowToElements in Element'); 60 testElementReflectAttribute('ariaLabelledByElements', 'aria-labelledby', [dummy1], [dummy2], 'ariaLabelledByElements in Element') 61 testElementReflectAttribute('ariaOwnsElements', 'aria-owns', [dummy1], [dummy2], 'ariaOwnsElements in Element') 62 63 </script> 64 </body> 65 </html>