summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/custom-element-registry/define-customized-builtins.html
blob: b691033871c05b680c13dca7e7cae0f25962f2af (plain)
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
83
84
85
86
87
88
<!DOCTYPE html>
<title>Custom Elements: Element Definition Customized Builtins</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="log"></div>
<iframe id="iframe"></iframe>
<script>
'use strict';
(() =>  {
  // 2. If name is not a valid custom element name,
  // then throw a SyntaxError and abort these steps.
  let validCustomElementNames = [
    // [a-z] (PCENChar)* '-' (PCENChar)*
    // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name
    'a-',
    'a-a',
    'aa-',
    'aa-a',
    'a-.-_',
    'a-0123456789',
    'a-\u6F22\u5B57', // Two CJK Unified Ideographs
    'a-\uD840\uDC0B', // Surrogate pair U+2000B
  ];
  let invalidCustomElementNames = [
    undefined,
    null,
    '',
    '-',
    'a',
    'input',
    'mycustomelement',
    'A',
    'A-',
    '0-',
    'a-A',
    'a-Z',
    'A-a',
    'a-a\u00D7',
    'a-a\u3000',
    'a-a\uDB80\uDC00', // Surrogate pair U+F0000
    // name must not be any of the hyphen-containing element names.
    'annotation-xml',
    'color-profile',
    'font-face',
    'font-face-src',
    'font-face-uri',
    'font-face-format',
    'font-face-name',
    'missing-glyph',
  ];

  const iframe = document.getElementById("iframe");
  const testWindow = iframe.contentDocument.defaultView;
  const customElements = testWindow.customElements;

  // 9.1. If extends is a valid custom element name,
  // then throw a NotSupportedError.
  validCustomElementNames.forEach(name =>  {
    test(() =>  {
      assert_throws_dom('NOT_SUPPORTED_ERR', testWindow.DOMException, () =>  {
        customElements.define('test-define-extend-valid-name', class {}, { extends: name });
      });
    }, `If extends is ${name}, should throw a NotSupportedError`);
  });

  // 9.2. If the element interface for extends and the HTML namespace is HTMLUnknownElement
  // (e.g., if extends does not indicate an element definition in this specification),
  // then throw a NotSupportedError.
  [
    // https://html.spec.whatwg.org/multipage/dom.html#elements-in-the-dom:htmlunknownelement
    'bgsound',
    'blink',
    'isindex',
    'multicol',
    'nextid',
    'spacer',
    'elementnametobeunknownelement',
  ].forEach(name =>  {
    test(() =>  {
      assert_throws_dom('NOT_SUPPORTED_ERR', testWindow.DOMException, () =>  {
        customElements.define('test-define-extend-' + name, class {}, { extends: name });
      });
    }, `If extends is ${name}, should throw a NotSupportedError`);
  });
})();
</script>
</body>