| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Custom Elements: Insert a node should try to upgrade</title> | 2 <title>Custom Elements: Insert a node should try to upgrade</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 function assert_invocations(invocations, element, length, i) { |
| 11 assert_equals(invocations.length, length, length == 2 ? 'inserting into differ
ent node should enqueue connectedCallback again' : 'inserting an element should
enqueue connectedCallback reaction'); |
| 12 assert_array_equals(invocations[i].slice(0, 2), ['connected', element], 'inser
ting "custom" element should enqueue a connectedCallback reaction'); |
| 13 assert_array_equals(invocations[i][2], [], 'connectedCallback should be invoke
d with empty argument list'); |
| 14 } |
| 15 |
| 10 // Insert a node | 16 // Insert a node |
| 11 // https://dom.spec.whatwg.org/#concept-node-insert | 17 // https://dom.spec.whatwg.org/#concept-node-insert |
| 18 // 6.5.2.1 If inclusiveDescendant is custom, then enqueue a custom element callb
ack reaction |
| 19 // with inclusiveDescendant, callback name "connectedCallback", and an empty arg
ument list. |
| 20 test_with_window(w => { |
| 21 let element = w.document.createElement('a-a'); |
| 22 let invocations = []; |
| 23 w.customElements.define('a-a', class extends w.HTMLElement { |
| 24 connectedCallback() { invocations.push(['connected', this, arguments]); } |
| 25 }); |
| 26 w.document.body.appendChild(element); |
| 27 assert_invocations(invocations, element, 1, 0); |
| 28 w.document.head.appendChild(element); |
| 29 assert_invocations(invocations, element, 2, 1); |
| 30 }, 'Insert a node that is "custom" should enqueue connectedCallback'); |
| 31 |
| 12 // 6.5.2.2. try to upgrade inclusiveDescendant. | 32 // 6.5.2.2. try to upgrade inclusiveDescendant. |
| 13 // Try to upgrade an element | 33 // Try to upgrade an element |
| 14 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade | 34 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade |
| 15 test_with_window(w => { | 35 test_with_window(w => { |
| 16 let element = w.document.createElement('a-a'); | 36 let element = w.document.createElement('a-a'); |
| 17 | 37 |
| 18 w.customElements.define('a-a', class extends w.HTMLElement { | 38 w.customElements.define('a-a', class extends w.HTMLElement { |
| 19 constructor() { | 39 constructor() { |
| 20 super(); | 40 super(); |
| 21 this.is_upgraded = true; | 41 this.is_upgraded = true; |
| 22 } | 42 } |
| 23 }); | 43 }); |
| 24 assert_false('is_upgraded' in element); | 44 assert_false('is_upgraded' in element); |
| 25 assert_false(element.matches(':defined')); | 45 assert_false(element.matches(':defined')); |
| 26 | 46 |
| 27 w.document.body.appendChild(element); | 47 w.document.body.appendChild(element); |
| 28 assert_true(element.is_upgraded); | 48 assert_true(element.is_upgraded); |
| 29 assert_true(element.matches(':defined')); | 49 assert_true(element.matches(':defined')); |
| 30 }, 'Insert a node should try to upgrade'); | 50 }, 'Insert a node should try to upgrade'); |
| 31 </script> | 51 </script> |
| 32 </body> | 52 </body> |
| OLD | NEW |