tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

scoped-registry-append-does-not-upgrade.html (6419B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 </head>
      8 <body>
      9 <script>
     10 
     11 test(() => {
     12    assert_equals((new Document).createElement('a-b').customElementRegistry, null);
     13    assert_equals(document.implementation.createHTMLDocument().createElement('a-b').customElementRegistry, null);
     14    assert_equals(document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null).createElement('a-b').customElementRegistry, null);
     15 }, 'customElementRegistry of an upgrade candidate created in a document without a browsing context uses null regsitry by default');
     16 
     17 function makeIframe(test) {
     18    const iframe = document.createElement('iframe');
     19    document.body.appendChild(iframe);
     20    test.add_cleanup(() => iframe.remove());
     21    return [iframe.contentDocument, iframe.contentWindow];
     22 }
     23 
     24 test((test) => {
     25    const [doc, win] = makeIframe(test);
     26    doc.documentElement.setHTMLUnsafe('<div id="host"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><a-b></a-b></template></div>');
     27    const hostClone = doc.getElementById('host').cloneNode(true);
     28    assert_equals(hostClone.shadowRoot.customElementRegistry, null);
     29    assert_equals(hostClone.shadowRoot.querySelector('a-b').customElementRegistry, null);
     30 }, 'Connecting a custom element candiate in a shadow root with a scoped custom element registry has null registry by default');
     31 
     32 test((test) => {
     33    const [doc, win] = makeIframe(test);
     34    doc.documentElement.setHTMLUnsafe('<div id="host"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><a-b></a-b></template></div>');
     35    win.customElements.define('a-b', class ABElement extends win.HTMLElement { });
     36    const hostClone = doc.getElementById('host').cloneNode(true);
     37    assert_equals(hostClone.shadowRoot.customElementRegistry, null);
     38    const candidate = hostClone.shadowRoot.querySelector('a-b');
     39    assert_equals(candidate.customElementRegistry, null);
     40    doc.body.appendChild(candidate);
     41    assert_equals(candidate.customElementRegistry, null);
     42 }, 'Connecting a custom element candiate with null registry does not set the registry');
     43 
     44 test((test) => {
     45    const [doc, win] = makeIframe(test);
     46    doc.documentElement.setHTMLUnsafe('<div id="host"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><a-b></a-b></template></div>');
     47    win.customElements.define('a-b', class ABElement extends win.HTMLElement { });
     48    const hostClone = doc.getElementById('host').cloneNode(true);
     49    const candidate = hostClone.shadowRoot.querySelector('a-b');
     50    const registry = new CustomElementRegistry;
     51    assert_equals(candidate.customElementRegistry, null);
     52    registry.initialize(hostClone.shadowRoot);
     53    assert_equals(candidate.customElementRegistry, registry);
     54    doc.body.appendChild(candidate);
     55    assert_equals(candidate.customElementRegistry, registry);
     56 
     57    const element = doc.createElement('host', {customElementRegistry: registry});
     58    assert_equals(element.customElementRegistry, registry);
     59    doc.body.appendChild(element);
     60    assert_equals(element.customElementRegistry, registry);
     61 }, 'Connecting a custom element candiate with a scoped custom element registry does not change the registry');
     62 
     63 test((test) => {
     64    const [doc, win] = makeIframe(test);
     65    doc.documentElement.setHTMLUnsafe('<div id="host1"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><a-b></a-b></template></div>'
     66        + '<div id="host2"><template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry><c-d></c-d></template></div>');
     67    win.customElements.define('a-b', class ABElement extends win.HTMLElement { });
     68    const clone1 = doc.getElementById('host1').cloneNode(true);
     69    const clone2 = doc.getElementById('host2').cloneNode(true);
     70    const candidate = clone1.shadowRoot.querySelector('a-b');
     71    assert_equals(candidate.customElementRegistry, null);
     72    assert_equals(clone2.shadowRoot.querySelector('c-d').customElementRegistry, null);
     73    const registry = new CustomElementRegistry;
     74    registry.initialize(clone2.shadowRoot);
     75    assert_equals(clone2.shadowRoot.querySelector('c-d').customElementRegistry, registry);
     76    clone2.shadowRoot.appendChild(candidate);
     77    assert_equals(candidate.customElementRegistry, null);
     78 }, 'Inserting a custom element candiate with null registry does not change the registry');
     79 
     80 test((test) => {
     81    const [doc, win] = makeIframe(test);
     82    const registry = new CustomElementRegistry;
     83    const host = doc.createElement('div');
     84    const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: registry});
     85    assert_equals(shadowRoot.customElementRegistry, registry);
     86    doc.body.appendChild(host);
     87    assert_equals(shadowRoot.customElementRegistry, registry);
     88 }, 'Inserting the shadow host of a shadow root with a scoped custom element registry does not change the registry');
     89 
     90 test((test) => {
     91    const [doc1, win1] = makeIframe(test);
     92    const [doc2, win2] = makeIframe(test);
     93    win2.customElements.define('a-b', class ABElement extends win2.HTMLElement { });
     94    const elementFromDoc1 = doc1.createElement('a-b');
     95    assert_equals(elementFromDoc1.customElementRegistry, win1.customElements);
     96    doc2.body.appendChild(elementFromDoc1);
     97    assert_equals(elementFromDoc1.customElementRegistry, win2.customElements);
     98    assert_true(elementFromDoc1 instanceof ABElement);
     99 }, 'Inserting a node from another document with global registry results in the custom element registry to be set and upgraded.');
    100 
    101 test((test) => {
    102    const contentDocument = document.implementation.createHTMLDocument();
    103    class ABElement extends HTMLElement { }
    104    customElements.define('a-b', ABElement);
    105    const elementFromContentDoc = contentDocument.createElement('a-b');
    106    assert_equals(elementFromContentDoc.customElementRegistry, null);
    107    document.body.appendChild(elementFromContentDoc);
    108    assert_equals(elementFromContentDoc.customElementRegistry, customElements);
    109    assert_true(elementFromContentDoc instanceof ABElement);
    110 }, 'Inserting a node from another document with null registry results in the custom element registry to be set and upgraded.');
    111 
    112 </script>
    113 </body>
    114 </html>