scoped-registry-initialize.html (4335B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> 5 <link rel="help" href="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-initialize"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 </head> 9 <body> 10 <script> 11 12 function runTest(title, makeDocument, customElementRegistry) { 13 test(() => { 14 assert_equals(makeDocument().createElement('a-b').customElementRegistry, null); 15 }, `${title}: customElementRegistry of an upgrade candidate created with a document without a browsing context uses null regsitry by default`); 16 17 test(() => { 18 const element = makeDocument().createElement('a-b'); 19 customElementRegistry.initialize(element); 20 assert_equals(element.customElementRegistry, customElementRegistry); 21 }, `${title}: customElementRegistry of an upgrade candidate after calling CustomElementRegistry.prototype.initialize should return the registry`); 22 23 test(() => { 24 const element = makeDocument().createElement('a-b', {customElementRegistry}); 25 customElementRegistry.initialize(element); 26 assert_equals(element.customElementRegistry, customElementRegistry); 27 }, `${title}: customElementRegistry of an upgrade candidate created with an explicit customElementRegistry argument should return the registry`); 28 29 test(() => { 30 const element = makeDocument().createElement('foo'); 31 assert_equals(element.customElementRegistry, null); 32 }, `${title}: customElementRegistry of an unknown element created with a document without a browsing context uses null regsitry by default`); 33 34 test(() => { 35 const element = makeDocument().createElement('foo'); 36 customElementRegistry.initialize(element); 37 assert_equals(element.customElementRegistry, customElementRegistry); 38 }, `${title}: customElementRegistry of an unknown element after calling CustomElementRegistry.prototype.initialize should return the registry`); 39 40 test(() => { 41 const element = makeDocument().createElement('foo', {customElementRegistry}); 42 assert_equals(element.customElementRegistry, customElementRegistry); 43 }, `${title}: customElementRegistry of an unknown element created with an explicit customElementRegistry argument should return the registry`); 44 45 const addElement = (doc) => { 46 const element = doc.createElement('b-c'); 47 if (doc.body) 48 doc.body.appendChild(element); 49 else if (doc.documentElement) 50 doc.documentElement.appendChild(element); 51 else 52 doc.appendChild(element); 53 return element; 54 } 55 56 test(() => { 57 assert_equals(addElement(makeDocument()).customElementRegistry, null); 58 }, `${title}: customElementRegistry of an upgrade candidate connected to a document without a browsing context uses null regsitry by default`); 59 60 test(() => { 61 const doc = makeDocument(); 62 const element = addElement(doc); 63 customElementRegistry.initialize(doc); 64 assert_equals(doc.customElementRegistry, customElementRegistry); 65 assert_equals(element.customElementRegistry, customElementRegistry); 66 }, `${title}: customElementRegistry of document and an upgrade candidate after calling CustomElementRegistry.prototype.initialize should return the registry`); 67 68 test(() => { 69 const doc = makeDocument(); 70 const element = addElement(doc); 71 customElementRegistry.initialize(doc); 72 assert_equals(doc.customElementRegistry, customElementRegistry); 73 assert_equals(element.customElementRegistry, customElementRegistry); 74 element.innerHTML = '<a-b></a-b>'; 75 assert_equals(element.querySelector('a-b').customElementRegistry, customElementRegistry); 76 }, `${title}: customElementRegistry of an element created after calling CustomElementRegistry.prototype.initialize should return the registry`); 77 } 78 79 runTest('Document', () => new Document, new CustomElementRegistry); 80 runTest('HTMLDocument', () => document.implementation.createHTMLDocument(), new CustomElementRegistry); 81 runTest('XHTMLDocument', () => document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null), new CustomElementRegistry); 82 83 </script> 84 </body> 85 </html>