tor-browser

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

HTMLElement-attachInternals.html (3433B)


      1 <!DOCTYPE html>
      2 <body>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <link rel="help" content="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals">
      6 <div id="container"></div>
      7 <script>
      8 test(() => {
      9  class MyElement1 extends HTMLElement {
     10  }
     11  customElements.define('my-element1', MyElement1);
     12  const container = document.querySelector('#container');
     13 
     14  let element = new MyElement1();
     15  assert_true(element.attachInternals() instanceof ElementInternals,
     16              'New - 1st call');
     17  assert_throws_dom('NotSupportedError', () => { element.attachInternals(); },
     18                    'New - 2nd call');
     19 
     20  element = document.createElement('my-element1');
     21  assert_true(element.attachInternals() instanceof ElementInternals,
     22              'createElement - 1st call');
     23  assert_throws_dom('NotSupportedError', () => { element.attachInternals(); },
     24                    'createElement - 2nd call');
     25 
     26  container.innerHTML = '<my-element1></my-element1>';
     27  assert_true(container.firstChild.attachInternals() instanceof ElementInternals,
     28              'Parser - 1st call');
     29  assert_throws_dom('NotSupportedError', () => {
     30    container.firstChild.attachInternals();
     31  }, 'Parser - 2nd call');
     32 }, 'Successful attachInternals() and the second call.');
     33 
     34 test(() => {
     35  class MyDiv extends HTMLDivElement {}
     36  customElements.define('my-div', MyDiv, { extends: 'div' });
     37  const customizedBuiltin = document.createElement('div', { is: 'my-div'});
     38  assert_throws_dom('NotSupportedError', () => { customizedBuiltin.attachInternals() });
     39 }, 'attachInternals() throws a NotSupportedError if it is called for ' +
     40     'a customized built-in element');
     41 
     42 test(() => {
     43  const builtin = document.createElement('div');
     44  assert_throws_dom('NotSupportedError', () => { builtin.attachInternals() });
     45 
     46  const doc = document.implementation.createDocument('foo', null);
     47  const span = doc.appendChild(doc.createElementNS('http://www.w3.org/1999/xhtml', 'html:span'));
     48  assert_true(span instanceof HTMLElement);
     49  assert_throws_dom('NotSupportedError', () => { span.attachInternals(); });
     50 
     51  const undefinedCustom = document.createElement('undefined-element');
     52  assert_throws_dom('NotSupportedError', () => { undefinedCustom.attachInternals() });
     53 }, 'If a custom element definition for the local name of the element doesn\'t' +
     54     ' exist, throw an NotSupportedError');
     55 
     56 test(() => {
     57  class MyElement2 extends HTMLElement {
     58    static get disabledFeatures() { return ['internals']; }
     59  }
     60  customElements.define('my-element2', MyElement2);
     61  const container = document.querySelector('#container');
     62 
     63  assert_throws_dom('NotSupportedError', () => {
     64    (new MyElement2).attachInternals();
     65  });
     66  assert_throws_dom('NotSupportedError', () => {
     67    document.createElement('my-element2').attachInternals();
     68  });
     69  assert_throws_dom('NotSupportedError', () => {
     70    container.innerHTML = '<my-element2></my-element2>';
     71    container.firstChild.attachInternals();
     72  });
     73 
     74  class MyElement3 extends HTMLElement {
     75    static get disabledFeatures() { return ['INTERNALS']; }
     76  }
     77  customElements.define('my-element3', MyElement3);
     78  assert_true((new MyElement3).attachInternals() instanceof ElementInternals);
     79 }, 'If a custom element definition for the local name of the element has ' +
     80     'disable internals flag, throw a NotSupportedError');
     81 </script>
     82 </body>