| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Custom Elements: Custom Element State "Failed" in Upgrades</title> | 2 <title>Custom Elements: Custom Element State "Failed" in Upgrades</title> |
| 3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="resources/custom-elements-helpers.js"></script> | 5 <script src="resources/custom-elements-helpers.js"></script> |
| 6 <body> | 6 <body> |
| 7 <script> | 7 <script> |
| 8 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 // Custom Element State | 10 // Custom Element State |
| 11 // https://dom.spec.whatwg.org/#concept-element-custom-element-state | 11 // https://dom.spec.whatwg.org/#concept-element-custom-element-state |
| 12 | 12 |
| 13 test_with_window(w => { | 13 test_with_window(w => { |
| 14 let document = w.document; | 14 let document = w.document; |
| 15 let element = document.createElement('a-a'); | 15 let element = document.createElement('a-a'); |
| 16 | 16 |
| 17 let constructorCount = 0; | 17 let constructorCount = 0; |
| 18 w.customElements.define('a-a', class extends w.HTMLElement { | 18 w.customElements.define('a-a', class extends w.HTMLElement { |
| 19 constructor() { | 19 constructor() { |
| 20 constructorCount++; | 20 constructorCount++; |
| 21 throw new Error(); | 21 throw new Error(); |
| 22 } | 22 } |
| 23 connectedCallback() { | 23 connectedCallback() { |
| 24 // TODO(davaajav): remove the failure expectation when this issue is close
d |
| 25 // https://github.com/w3c/webcomponents/issues/563 |
| 24 assert_unreached('connectedCallback should not be invoked if constructor t
hrew'); | 26 assert_unreached('connectedCallback should not be invoked if constructor t
hrew'); |
| 25 } | 27 } |
| 26 }); | 28 }); |
| 27 | 29 |
| 28 // Upgrade calls the constructor. | 30 // Upgrade calls the constructor. |
| 29 // 9. If constructResult is an abrupt completion, then | 31 // 9. If constructResult is an abrupt completion, then |
| 30 // Set element's custom element state to "failed". | 32 // Set element's custom element state to "failed". |
| 31 // https://html.spec.whatwg.org/multipage/scripting.html#upgrades | 33 // https://html.spec.whatwg.org/multipage/scripting.html#upgrades |
| 32 let container = document.body; | 34 let container = document.body; |
| 33 container.appendChild(element); | 35 container.appendChild(element); |
| 34 assert_equals(constructorCount, 1, 'constructor should be invoked once'); | 36 assert_equals(constructorCount, 1, 'constructor should be invoked once'); |
| 35 | 37 |
| 36 // "failed" is not "defined" | 38 // "failed" is not "defined" |
| 37 // https://dom.spec.whatwg.org/#concept-element-defined | 39 // https://dom.spec.whatwg.org/#concept-element-defined |
| 38 assert_false(element.matches(':defined')); | 40 assert_false(element.matches(':defined')); |
| 41 |
| 42 // "failed" element should implement HTMLUnknownElement only in "creating an e
lement for a token" |
| 43 // https://html.spec.whatwg.org/#create-an-element-for-the-token |
| 44 assert_equals(Object.getPrototypeOf(element), w.HTMLElement.prototype); |
| 45 |
| 46 // 2. If element's custom element state is "failed", then abort these steps. |
| 47 // https://html.spec.whatwg.org/multipage/scripting.html#upgrades |
| 48 container.appendChild(element); |
| 49 assert_equals(constructorCount, 1, 'constructor should be invoked once'); |
| 39 }); | 50 }); |
| 40 </script> | 51 </script> |
| 41 </body> | 52 </body> |
| OLD | NEW |