Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>Custom Elements defineElement Tests</title> | |
| 3 <script src="../../resources/testharness.js"></script> | |
| 4 <script src="../../resources/testharness-helpers.js"></script> | |
| 5 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <script src="resources/custom-elements-helpers.js"></script> | |
| 7 <body> | |
| 8 <script> | |
| 9 // https://html.spec.whatwg.org/multipage/scripting.html#customelementsregistry | |
| 10 // "Element definition" process | |
| 11 | |
|
domenic
2016/05/05 19:15:27
Koji wrote a bunch of tests for this already: http
| |
| 12 test_with_window((w) => { | |
| 13 assert_throws(TypeError.prototype, () => { | |
| 14 w.customElements.define('a-a', 42); | |
| 15 }, 'defining a non-constructor should throw a TypeError'); | |
| 16 }, 'A "constructor" that is not a constructor'); | |
| 17 | |
| 18 test_with_window((w) => { | |
| 19 // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element- name | |
| 20 let invalid_names = [ | |
| 21 'annotation-xml', | |
| 22 'color-profile', | |
| 23 'font-face', | |
| 24 'font-face-src', | |
| 25 'font-face-uri', | |
| 26 'font-face-format', | |
| 27 'font-face-name', | |
| 28 'missing-glyph', | |
| 29 'div', 'p', | |
| 30 'nothtmlbutnohyphen', | |
| 31 '-not-initial-a-z', '0not-initial-a-z', 'Not-initial-a-z', | |
| 32 'intermediate-UPPERCASE-letters', | |
| 33 'bad-\u00b6', 'bad-\u00b8', 'bad-\u00bf', 'bad-\u00d7', 'bad-\u00f7', | |
| 34 'bad-\u037e', 'bad-\u037e', 'bad-\u2000', 'bad-\u200e', 'bad-\u203e', | |
| 35 'bad-\u2041', 'bad-\u206f', 'bad-\u2190', 'bad-\u2bff', 'bad-\u2ff0', | |
| 36 'bad-\u3000', 'bad-\ud800', 'bad-\uf8ff', 'bad-\ufdd0', 'bad-\ufdef', | |
| 37 'bad-\ufffe', 'bad-\uffff', 'bad-' + String.fromCodePoint(0xf0000) | |
| 38 ]; | |
| 39 class X extends w.HTMLElement {} | |
| 40 invalid_names.forEach((name) => { | |
| 41 assert_throws(SyntaxError.prototype, () => { | |
| 42 w.customElements.define(name, X); | |
| 43 }, `defining an element named "${name}" should throw a SyntaxError`); | |
| 44 }); | |
| 45 }, 'Invalid names'); | |
| 46 | |
| 47 test_with_window((w) => { | |
| 48 class X extends w.HTMLElement {} | |
| 49 class Y extends w.HTMLElement {} | |
| 50 w.customElements.define('a-a', X); | |
| 51 assert_throws('NotSupportedError', () => { | |
| 52 w.customElements.define('a-a', Y); | |
| 53 }, 'defining an element with a name that is already defined should throw ' + | |
| 54 'a NotSupportedError'); | |
| 55 }, 'Duplicate name'); | |
| 56 | |
| 57 test_with_window((w) => { | |
| 58 class X extends w.HTMLElement {} | |
| 59 w.customElements.define('a-a', X); | |
| 60 assert_throws('NotSupportedError', () => { | |
| 61 w.customElements.define('a-b', X); | |
| 62 }, 'defining an element with a constructor that is already in the ' + | |
| 63 'registry should throw a NotSupportedError'); | |
| 64 }, 'Reused constructor'); | |
| 65 | |
| 66 test_with_window((w) => { | |
|
domenic
2016/05/05 19:15:27
His tests did not generally test the order of the
| |
| 67 assert_throws(TypeError.prototype, () => { | |
| 68 let not_a_constructor = new Object(); | |
| 69 let invalid_name = 'annotation-xml'; | |
| 70 // TODO(dominicc): When V8 supports IsConstructor, replace this with a | |
| 71 // function. | |
| 72 w.customElements.define(invalid_name, not_a_constructor); | |
| 73 }, 'Defining an element with an invalid name and invalid constructor ' + | |
| 74 'should throw a TypeError for the constructor and not a SyntaxError'); | |
| 75 | |
| 76 class C extends w.HTMLElement {} | |
| 77 w.customElements.define('a-a', C); | |
| 78 assert_throws(SyntaxError.prototype, () => { | |
| 79 let invalid_name = 'annotation-xml'; | |
| 80 let reused_constructor = C; | |
| 81 w.customElements.define(invalid_name, reused_constructor); | |
| 82 }, 'Defining an element with an invalid name and a reused constructor ' + | |
| 83 'should throw a SyntaxError for the name and not a NotSupportedError'); | |
| 84 }, 'Order of checks'); | |
| 85 </script> | |
| OLD | NEW |