Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html

Issue 1952893003: Implement custom element construction and some 'define' checks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use DCHECK, revert RuntimeEnabledFeatures.in. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>Custom Elements: defineElement</title>
3 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#cus tomelementsregistry">
4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org">
5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharness-helpers.js"></script>
7 <script src="../../resources/testharnessreport.js"></script>
8 <script src="resources/custom-elements-helpers.js"></script>
9 <body>
10 <script>
11 // TODO(dominicc): Merge these tests with
12 // https://github.com/w3c/web-platform-tests/pull/2940
13
14 'use strict';
15
16 test_with_window((w) => {
17 assert_throws(TypeError.prototype, () => {
18 w.customElements.define('a-a', 42);
19 }, 'defining a non-constructor should throw a TypeError');
20 }, 'A "constructor" that is not a constructor');
21
22 test_with_window((w) => {
23 // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element- name
24 let invalid_names = [
25 'annotation-xml',
26 'color-profile',
27 'font-face',
28 'font-face-src',
29 'font-face-uri',
30 'font-face-format',
31 'font-face-name',
32 'missing-glyph',
33 'div', 'p',
34 'nothtmlbutnohyphen',
35 '-not-initial-a-z', '0not-initial-a-z', 'Not-initial-a-z',
36 'intermediate-UPPERCASE-letters',
37 'bad-\u00b6', 'bad-\u00b8', 'bad-\u00bf', 'bad-\u00d7', 'bad-\u00f7',
38 'bad-\u037e', 'bad-\u037e', 'bad-\u2000', 'bad-\u200e', 'bad-\u203e',
39 'bad-\u2041', 'bad-\u206f', 'bad-\u2190', 'bad-\u2bff', 'bad-\u2ff0',
40 'bad-\u3000', 'bad-\ud800', 'bad-\uf8ff', 'bad-\ufdd0', 'bad-\ufdef',
41 'bad-\ufffe', 'bad-\uffff', 'bad-' + String.fromCodePoint(0xf0000)
42 ];
43 class X extends w.HTMLElement {}
44 invalid_names.forEach((name) => {
45 assert_throws(SyntaxError.prototype, () => {
46 w.customElements.define(name, X);
47 }, `defining an element named "${name}" should throw a SyntaxError`);
48 });
49 }, 'Invalid names');
50
51 test_with_window((w) => {
52 class X extends w.HTMLElement {}
53 class Y extends w.HTMLElement {}
54 w.customElements.define('a-a', X);
55 assert_throws('NotSupportedError', () => {
56 w.customElements.define('a-a', Y);
57 }, 'defining an element with a name that is already defined should throw ' +
58 'a NotSupportedError');
59 }, 'Duplicate name');
60
61 test_with_window((w) => {
62 class X extends w.HTMLElement {}
63 w.customElements.define('a-a', X);
64 assert_throws('NotSupportedError', () => {
65 w.customElements.define('a-b', X);
66 }, 'defining an element with a constructor that is already in the ' +
67 'registry should throw a NotSupportedError');
68 }, 'Reused constructor');
69
70 test_with_window((w) => {
71 assert_throws(TypeError.prototype, () => {
72 let not_a_constructor = new Object();
73 let invalid_name = 'annotation-xml';
74 // TODO(dominicc): When V8 supports IsConstructor, replace this with a
75 // function.
76 w.customElements.define(invalid_name, not_a_constructor);
77 }, 'Defining an element with an invalid name and invalid constructor ' +
78 'should throw a TypeError for the constructor and not a SyntaxError');
79
80 class C extends w.HTMLElement {}
81 w.customElements.define('a-a', C);
82 assert_throws(SyntaxError.prototype, () => {
83 let invalid_name = 'annotation-xml';
84 let reused_constructor = C;
85 w.customElements.define(invalid_name, reused_constructor);
86 }, 'Defining an element with an invalid name and a reused constructor ' +
87 'should throw a SyntaxError for the name and not a NotSupportedError');
88 }, 'Order of checks');
89 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698