define-customized-builtins.html (2570B)
1 <!DOCTYPE html> 2 <title>Custom Elements: Element Definition Customized Builtins</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <body> 6 <div id="log"></div> 7 <iframe id="iframe"></iframe> 8 <script> 9 'use strict'; 10 (() => { 11 // 2. If name is not a valid custom element name, 12 // then throw a SyntaxError and abort these steps. 13 let validCustomElementNames = [ 14 // [a-z] (PCENChar)* '-' (PCENChar)* 15 // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name 16 'a-', 17 'a-a', 18 'aa-', 19 'aa-a', 20 'a-.-_', 21 'a-0123456789', 22 'a-\u6F22\u5B57', // Two CJK Unified Ideographs 23 'a-\uD840\uDC0B', // Surrogate pair U+2000B 24 ]; 25 let invalidCustomElementNames = [ 26 undefined, 27 null, 28 '', 29 '-', 30 'a', 31 'input', 32 'mycustomelement', 33 'A', 34 'A-', 35 '0-', 36 'a-A', 37 'a-Z', 38 'A-a', 39 'a-a\u00D7', 40 'a-a\u3000', 41 'a-a\uDB80\uDC00', // Surrogate pair U+F0000 42 // name must not be any of the hyphen-containing element names. 43 'annotation-xml', 44 'color-profile', 45 'font-face', 46 'font-face-src', 47 'font-face-uri', 48 'font-face-format', 49 'font-face-name', 50 'missing-glyph', 51 ]; 52 53 const iframe = document.getElementById("iframe"); 54 const testWindow = iframe.contentDocument.defaultView; 55 const customElements = testWindow.customElements; 56 57 // 9.1. If extends is a valid custom element name, 58 // then throw a NotSupportedError. 59 validCustomElementNames.forEach(name => { 60 test(() => { 61 assert_throws_dom('NOT_SUPPORTED_ERR', testWindow.DOMException, () => { 62 customElements.define('test-define-extend-valid-name', class {}, { extends: name }); 63 }); 64 }, `If extends is ${name}, should throw a NotSupportedError`); 65 }); 66 67 // 9.2. If the element interface for extends and the HTML namespace is HTMLUnknownElement 68 // (e.g., if extends does not indicate an element definition in this specification), 69 // then throw a NotSupportedError. 70 [ 71 // https://html.spec.whatwg.org/multipage/dom.html#elements-in-the-dom:htmlunknownelement 72 'bgsound', 73 'blink', 74 'isindex', 75 'multicol', 76 'nextid', 77 'spacer', 78 'elementnametobeunknownelement', 79 ].forEach(name => { 80 test(() => { 81 assert_throws_dom('NOT_SUPPORTED_ERR', testWindow.DOMException, () => { 82 customElements.define('test-define-extend-' + name, class {}, { extends: name }); 83 }); 84 }, `If extends is ${name}, should throw a NotSupportedError`); 85 }); 86 })(); 87 </script> 88 </body>