File: HTMLElement-attachInternals.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (82 lines) | stat: -rw-r--r-- 3,433 bytes parent folder | download | duplicates (27)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" content="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals">
<div id="container"></div>
<script>
test(() => {
  class MyElement1 extends HTMLElement {
  }
  customElements.define('my-element1', MyElement1);
  const container = document.querySelector('#container');

  let element = new MyElement1();
  assert_true(element.attachInternals() instanceof ElementInternals,
              'New - 1st call');
  assert_throws_dom('NotSupportedError', () => { element.attachInternals(); },
                    'New - 2nd call');

  element = document.createElement('my-element1');
  assert_true(element.attachInternals() instanceof ElementInternals,
              'createElement - 1st call');
  assert_throws_dom('NotSupportedError', () => { element.attachInternals(); },
                    'createElement - 2nd call');

  container.innerHTML = '<my-element1></my-element1>';
  assert_true(container.firstChild.attachInternals() instanceof ElementInternals,
              'Parser - 1st call');
  assert_throws_dom('NotSupportedError', () => {
    container.firstChild.attachInternals();
  }, 'Parser - 2nd call');
}, 'Successful attachInternals() and the second call.');

test(() => {
  class MyDiv extends HTMLDivElement {}
  customElements.define('my-div', MyDiv, { extends: 'div' });
  const customizedBuiltin = document.createElement('div', { is: 'my-div'});
  assert_throws_dom('NotSupportedError', () => { customizedBuiltin.attachInternals() });
}, 'attachInternals() throws a NotSupportedError if it is called for ' +
     'a customized built-in element');

test(() => {
  const builtin = document.createElement('div');
  assert_throws_dom('NotSupportedError', () => { builtin.attachInternals() });

  const doc = document.implementation.createDocument('foo', null);
  const span = doc.appendChild(doc.createElementNS('http://www.w3.org/1999/xhtml', 'html:span'));
  assert_true(span instanceof HTMLElement);
  assert_throws_dom('NotSupportedError', () => { span.attachInternals(); });

  const undefinedCustom = document.createElement('undefined-element');
  assert_throws_dom('NotSupportedError', () => { undefinedCustom.attachInternals() });
}, 'If a custom element definition for the local name of the element doesn\'t' +
     ' exist, throw an NotSupportedError');

test(() => {
  class MyElement2 extends HTMLElement {
    static get disabledFeatures() { return ['internals']; }
  }
  customElements.define('my-element2', MyElement2);
  const container = document.querySelector('#container');

  assert_throws_dom('NotSupportedError', () => {
    (new MyElement2).attachInternals();
  });
  assert_throws_dom('NotSupportedError', () => {
    document.createElement('my-element2').attachInternals();
  });
  assert_throws_dom('NotSupportedError', () => {
    container.innerHTML = '<my-element2></my-element2>';
    container.firstChild.attachInternals();
  });

  class MyElement3 extends HTMLElement {
    static get disabledFeatures() { return ['INTERNALS']; }
  }
  customElements.define('my-element3', MyElement3);
  assert_true((new MyElement3).attachInternals() instanceof ElementInternals);
}, 'If a custom element definition for the local name of the element has ' +
     'disable internals flag, throw a NotSupportedError');
</script>
</body>