Document-importNode.html (1484B)
1 <!DOCTYPE html> 2 <link rel="help" href="https://dom.spec.whatwg.org/#dom-document-importnode"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="../resources/custom-elements-helpers.js"></script> 6 <body> 7 <script> 8 test_with_window((w, doc) => { 9 class MyElement extends HTMLElement {} 10 class MyElement2 extends w.HTMLElement {} 11 customElements.define('my-element', MyElement); 12 w.customElements.define('my-element', MyElement2); 13 14 let original = document.createElement('my-element'); 15 assert_true(original instanceof MyElement); 16 assert_equals(original.customElementRegistry, customElements); 17 18 let imported = doc.importNode(original); 19 assert_true(imported instanceof MyElement2); 20 assert_false(imported instanceof MyElement); 21 assert_equals(imported.customElementRegistry, w.customElements); 22 }, 'autonomous: document.importNode() should import custom elements successfully'); 23 24 test_with_window((w, doc) => { 25 class MyElement3 extends w.HTMLElement {} 26 w.customElements.define('my-element3', MyElement3); 27 28 let original = document.createElement('my-element3'); 29 assert_equals(original.constructor, HTMLElement); 30 assert_equals(original.customElementRegistry, customElements); 31 32 let imported = doc.importNode(original); 33 assert_equals(imported.customElementRegistry, w.customElements); 34 }, 'autonomous: document.importNode() should import "undefined" custom elements successfully'); 35 </script> 36 </body>