| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Custom Elements: create an element inside a template </title> |
| 3 <link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element"> |
| 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="resources/custom-elements-helpers.js"></script> |
| 7 <iframe id="iframe"></iframe> |
| 8 <script> |
| 9 'use strict'; |
| 10 |
| 11 // A document`s browsing context only afffects the look up result of custom elem
ent definition |
| 12 // https://html.spec.whatwg.org/#look-up-a-custom-element-definition |
| 13 // There are two places where we need to look up a custom element definition: |
| 14 // 1. creating an element |
| 15 // https://dom.spec.whatwg.org/#concept-create-element |
| 16 // 2. trying to upgrade an element |
| 17 // https://html.spec.whatwg.org/#concept-try-upgrade |
| 18 // The previous observation leads to the following behaviours: |
| 19 // 1. an element in a document without browsing context should not be upgraded |
| 20 // 2. a custom element cannot be created in a document without browsing context |
| 21 // 3. an already "defined" custom element should remain "defined" after being in
serted |
| 22 // into a document without browsing context |
| 23 |
| 24 test_with_window(w => { |
| 25 let doc_without_browsing_context = w.document.implementation.createHTMLDocumen
t(); |
| 26 let element = doc_without_browsing_context.createElement('a-a'); |
| 27 w.customElements.define('a-a', class extends w.HTMLElement {}); |
| 28 doc_without_browsing_context.body.appendChild(element); |
| 29 assert_true(element.matches(':not(:defined)')); |
| 30 w.document.body.appendChild(element); |
| 31 assert_true(element.matches(':defined')); |
| 32 }, 'An element should not upgraded in a document without browsing context'); |
| 33 |
| 34 test_with_window(w => { |
| 35 let doc_without_browsing_context = w.document.implementation.createHTMLDocumen
t(); |
| 36 w.customElements.define('b-b', class extends w.HTMLElement {}); |
| 37 let e1 = doc_without_browsing_context.createElement('b-b'); |
| 38 assert_true(e1.matches(':not(:defined)')); |
| 39 let e2 = w.document.createElement('b-b'); |
| 40 assert_true(e2.matches(':defined')); |
| 41 }, 'Custom element should not be created in a document without browsing context'
); |
| 42 |
| 43 test_with_window(w => { |
| 44 w.customElements.define('a-a', class extends w.HTMLElement {}); |
| 45 let element = w.document.createElement('a-a'); |
| 46 assert_true(element.matches(':defined')); |
| 47 let doc_without_browsing_context = w.document.implementation.createHTMLDocumen
t(); |
| 48 doc_without_browsing_context.body.appendChild(element); |
| 49 let inserted_element = doc_without_browsing_context.body.querySelector('a-a'); |
| 50 assert_true(inserted_element.matches(':defined')); |
| 51 }, 'Inserting an already defined custom element into a document without browsing
context ' + |
| 52 'should not change its state'); |
| 53 </script> |
| OLD | NEW |