tor-browser

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

ShadowRoot-init-customElementRegistry.html (4502B)


      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://github.com/whatwg/html/issues/10854">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 </head>
      9 <body>
     10 <script>
     11 
     12 class GlobalABElement extends HTMLElement {};
     13 customElements.define('a-b', GlobalABElement);
     14 
     15 test(() => {
     16    const shadowRoot = document.createElement('div').attachShadow({mode: 'closed'});
     17    assert_equals(shadowRoot.customElementRegistry, window.customElements);
     18 }, 'A newly attached disconnected ShadowRoot should use the global registry by default');
     19 
     20 test(() => {
     21    const host = document.body.appendChild(document.createElement('div'));
     22    const shadowRoot = host.attachShadow({mode: 'closed'});
     23    assert_equals(shadowRoot.customElementRegistry, window.customElements);
     24 }, 'A newly attached connected ShadowRoot should use the global registry by default');
     25 
     26 test(() => {
     27    const registry = new CustomElementRegistry;
     28    const shadowRoot = document.createElement('div').attachShadow({mode: 'closed', customElementRegistry: registry});
     29    assert_equals(shadowRoot.customElementRegistry, registry);
     30 }, 'A newly attached disconnected ShadowRoot should use the scoped registry if explicitly specified in attachShadow');
     31 
     32 test(() => {
     33    const registry = new CustomElementRegistry;
     34    const host = document.body.appendChild(document.createElement('div'));
     35    const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: registry});
     36    assert_equals(shadowRoot.customElementRegistry, registry);
     37 }, 'A newly attached connected ShadowRoot should use the scoped registry if explicitly specified in attachShadow');
     38 
     39 test(() => {
     40    const host = document.body.appendChild(document.createElement('div'));
     41    const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
     42    assert_equals(shadowRoot.customElementRegistry, null);
     43 }, 'attachShadow() should use null registry when customElementRegistry is null (host uses global registry)');
     44 
     45 test(() => {
     46    const registry = new CustomElementRegistry;
     47    const host = document.body.appendChild(document.createElement('div', {customElementRegistry: registry}));
     48    const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
     49    assert_equals(shadowRoot.customElementRegistry, null);
     50 }, 'attachShadow() should use null registry when customElementRegistry is null (host uses custom registry)');
     51 
     52 test((test) => {
     53    const host = document.createElement('div');
     54    const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
     55    assert_equals(shadowRoot.customElementRegistry, null);
     56 }, `attchShadow on a builtin element with null customElementRegistry should create a ShadowRoot with null registry`);
     57 
     58 test((test) => {
     59    const host = document.createElement('c-d');
     60    const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
     61    assert_equals(shadowRoot.customElementRegistry, null);
     62 }, `attchShadow on a custom elememnt candidate with null customElementRegistry should create a ShadowRoot with null registry`);
     63 
     64 test((test) => {
     65    const host = document.createElement('a-b');
     66    const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
     67    assert_equals(shadowRoot.customElementRegistry, null);
     68 }, `attchShadow on a custom elememnt with null customElementRegistry should create a ShadowRoot with null registry`);
     69 
     70 test(() => {
     71    const registry = new CustomElementRegistry;
     72    const template = document.createElement('template');
     73    template.innerHTML = '<div></div>';
     74    const host = template.content.cloneNode(true).firstChild;
     75    assert_equals(host.customElementRegistry, null);
     76    const shadowRoot = host.attachShadow({mode: 'open', customElementRegistry: null, clonable: true});
     77    assert_equals(shadowRoot.customElementRegistry, null);
     78    shadowRoot.innerHTML = '<span></span>';
     79    assert_equals(shadowRoot.querySelector('span').customElementRegistry, null);
     80    const cloneHost = host.cloneNode(true);
     81    assert_equals(cloneHost.customElementRegistry, null);
     82    assert_equals(cloneHost.shadowRoot.customElementRegistry, null);
     83    assert_equals(cloneHost.shadowRoot.querySelector('span').customElementRegistry, null);
     84 }, 'attachShadow() should use the null registry when the shadow host uses null registry and customElementRegistry is null');
     85 
     86 </script>
     87 </body>
     88 </html>