Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html |
| diff --git a/third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html b/third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f167ae8ff467c5450302292d915be59abb94bbab |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html |
| @@ -0,0 +1,85 @@ |
| +<!DOCTYPE html> |
| +<title>Custom Elements defineElement Tests</title> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharness-helpers.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="resources/custom-elements-helpers.js"></script> |
| +<body> |
| +<script> |
| +// https://html.spec.whatwg.org/multipage/scripting.html#customelementsregistry |
| +// "Element definition" process |
| + |
|
domenic
2016/05/05 19:15:27
Koji wrote a bunch of tests for this already: http
|
| +test_with_window((w) => { |
| + assert_throws(TypeError.prototype, () => { |
| + w.customElements.define('a-a', 42); |
| + }, 'defining a non-constructor should throw a TypeError'); |
| +}, 'A "constructor" that is not a constructor'); |
| + |
| +test_with_window((w) => { |
| + // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name |
| + let invalid_names = [ |
| + 'annotation-xml', |
| + 'color-profile', |
| + 'font-face', |
| + 'font-face-src', |
| + 'font-face-uri', |
| + 'font-face-format', |
| + 'font-face-name', |
| + 'missing-glyph', |
| + 'div', 'p', |
| + 'nothtmlbutnohyphen', |
| + '-not-initial-a-z', '0not-initial-a-z', 'Not-initial-a-z', |
| + 'intermediate-UPPERCASE-letters', |
| + 'bad-\u00b6', 'bad-\u00b8', 'bad-\u00bf', 'bad-\u00d7', 'bad-\u00f7', |
| + 'bad-\u037e', 'bad-\u037e', 'bad-\u2000', 'bad-\u200e', 'bad-\u203e', |
| + 'bad-\u2041', 'bad-\u206f', 'bad-\u2190', 'bad-\u2bff', 'bad-\u2ff0', |
| + 'bad-\u3000', 'bad-\ud800', 'bad-\uf8ff', 'bad-\ufdd0', 'bad-\ufdef', |
| + 'bad-\ufffe', 'bad-\uffff', 'bad-' + String.fromCodePoint(0xf0000) |
| + ]; |
| + class X extends w.HTMLElement {} |
| + invalid_names.forEach((name) => { |
| + assert_throws(SyntaxError.prototype, () => { |
| + w.customElements.define(name, X); |
| + }, `defining an element named "${name}" should throw a SyntaxError`); |
| + }); |
| +}, 'Invalid names'); |
| + |
| +test_with_window((w) => { |
| + class X extends w.HTMLElement {} |
| + class Y extends w.HTMLElement {} |
| + w.customElements.define('a-a', X); |
| + assert_throws('NotSupportedError', () => { |
| + w.customElements.define('a-a', Y); |
| + }, 'defining an element with a name that is already defined should throw ' + |
| + 'a NotSupportedError'); |
| +}, 'Duplicate name'); |
| + |
| +test_with_window((w) => { |
| + class X extends w.HTMLElement {} |
| + w.customElements.define('a-a', X); |
| + assert_throws('NotSupportedError', () => { |
| + w.customElements.define('a-b', X); |
| + }, 'defining an element with a constructor that is already in the ' + |
| + 'registry should throw a NotSupportedError'); |
| +}, 'Reused constructor'); |
| + |
| +test_with_window((w) => { |
|
domenic
2016/05/05 19:15:27
His tests did not generally test the order of the
|
| + assert_throws(TypeError.prototype, () => { |
| + let not_a_constructor = new Object(); |
| + let invalid_name = 'annotation-xml'; |
| + // TODO(dominicc): When V8 supports IsConstructor, replace this with a |
| + // function. |
| + w.customElements.define(invalid_name, not_a_constructor); |
| + }, 'Defining an element with an invalid name and invalid constructor ' + |
| + 'should throw a TypeError for the constructor and not a SyntaxError'); |
| + |
| + class C extends w.HTMLElement {} |
| + w.customElements.define('a-a', C); |
| + assert_throws(SyntaxError.prototype, () => { |
| + let invalid_name = 'annotation-xml'; |
| + let reused_constructor = C; |
| + w.customElements.define(invalid_name, reused_constructor); |
| + }, 'Defining an element with an invalid name and a reused constructor ' + |
| + 'should throw a SyntaxError for the name and not a NotSupportedError'); |
| +}, 'Order of checks'); |
| +</script> |