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

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

Issue 2029923003: Recursively defining custom elements should not lead to redefinition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Custom Elements: defineElement</title> 2 <title>Custom Elements: defineElement</title>
3 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#cus tomelementsregistry"> 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"> 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org">
5 <script src="../../resources/testharness.js"></script> 5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharness-helpers.js"></script> 6 <script src="../../resources/testharness-helpers.js"></script>
7 <script src="../../resources/testharnessreport.js"></script> 7 <script src="../../resources/testharnessreport.js"></script>
8 <script src="resources/custom-elements-helpers.js"></script> 8 <script src="resources/custom-elements-helpers.js"></script>
9 <body> 9 <body>
10 <script> 10 <script>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 test_with_window((w) => { 57 test_with_window((w) => {
58 class X extends w.HTMLElement {} 58 class X extends w.HTMLElement {}
59 class Y extends w.HTMLElement {} 59 class Y extends w.HTMLElement {}
60 w.customElements.define('a-a', X); 60 w.customElements.define('a-a', X);
61 assert_throws('NotSupportedError', () => { 61 assert_throws('NotSupportedError', () => {
62 w.customElements.define('a-a', Y); 62 w.customElements.define('a-a', Y);
63 }, 'defining an element with a name that is already defined should throw ' + 63 }, 'defining an element with a name that is already defined should throw ' +
64 'a NotSupportedError'); 64 'a NotSupportedError');
65 }, 'Duplicate name'); 65 }, 'Duplicate name');
66 66
67 // TODO(dominicc): Update this (perhaps by removing this comment) when
68 // https://github.com/whatwg/html/pull/1333 lands/issue
69 // https://github.com/whatwg/html/issues/1329 is closed.
70 test_with_window((w) => {
71 class Y extends w.HTMLElement {}
72 let X = (function () {}).bind({});
73 Object.defineProperty(X, 'prototype', {
74 get() {
75 assert_throws('NotSupportedError', () => {
76 w.customElements.define('a-a', Y);
77 }, 'defining an element with a name that is being defined should ' +
78 'throw a NotSupportedError');
79 return new Object();
80 }
81 });
82 // TODO(dominicc): When callback retrieval is implemented, change this
83 // to pass a valid constructor and recursively call define when retrieving
84 // callbacks instead; then it is possible to assert the first definition
85 // worked:
86 // let element = Reflect.construct(HTMLElement, [], X);
87 // assert_equals(element.localName, 'a-a');
88 w.customElements.define('a-a', X);
89 }, 'Duplicate name defined recursively');
90
67 test_with_window((w) => { 91 test_with_window((w) => {
68 class X extends w.HTMLElement {} 92 class X extends w.HTMLElement {}
69 w.customElements.define('a-a', X); 93 w.customElements.define('a-a', X);
70 assert_throws('NotSupportedError', () => { 94 assert_throws('NotSupportedError', () => {
71 w.customElements.define('a-b', X); 95 w.customElements.define('a-b', X);
72 }, 'defining an element with a constructor that is already in the ' + 96 }, 'defining an element with a constructor that is already in the ' +
73 'registry should throw a NotSupportedError'); 97 'registry should throw a NotSupportedError');
74 }, 'Reused constructor'); 98 }, 'Reused constructor');
75 99
100 // TODO(dominicc): Update this (perhaps by removing this comment) when
101 // https://github.com/whatwg/html/pull/1333 lands/issue
102 // https://github.com/whatwg/html/issues/1329 is closed.
103 test_with_window((w) => {
104 let X = (function () {}).bind({});
105 Object.defineProperty(X, 'prototype', {
106 get() {
107 assert_throws('NotSupportedError', () => {
108 w.customElements.define('second-name', X);
109 }, 'defining an element with a constructor that is being defined ' +
110 'should throw a NotSupportedError');
111 return new Object();
112 }
113 });
114 // TODO(dominicc): When callback retrieval is implemented, change this
115 // to pass a valid constructor and recursively call define when retrieving
116 // callbacks instead; then it is possible to assert the first definition
117 // worked:
118 // let element = Reflect.construct(HTMLElement, [], X);
119 // assert_equals(element.localName, 'a-a');
120 w.customElements.define('first-name', X);
121 }, 'Reused constructor recursively');
122
76 test_with_window((w) => { 123 test_with_window((w) => {
77 function F() {} 124 function F() {}
78 F.prototype = 42; 125 F.prototype = 42;
79 assert_throws(TypeError.prototype, () => { 126 assert_throws(TypeError.prototype, () => {
80 w.customElements.define('a-a', F); 127 w.customElements.define('a-a', F);
81 }, 'defining an element with a constructor with a prototype that is not an ' + 128 }, 'defining an element with a constructor with a prototype that is not an ' +
82 'object should throw a TypeError'); 129 'object should throw a TypeError');
83 }, 'Retrieved prototype is a non-object'); 130 }, 'Retrieved prototype is a non-object');
84 131
85 test_with_window((w) => { 132 test_with_window((w) => {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 super(); 203 super();
157 invocations.push(this); 204 invocations.push(this);
158 } 205 }
159 } 206 }
160 w.customElements.define('a-a', C); 207 w.customElements.define('a-a', C);
161 assert_array_equals([a], invocations, 208 assert_array_equals([a], invocations,
162 'the constructor should have been invoked once for the ' + 209 'the constructor should have been invoked once for the ' +
163 'elements in the shadow tree'); 210 'elements in the shadow tree');
164 }, 'Upgrade: shadow tree'); 211 }, 'Upgrade: shadow tree');
165 </script> 212 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698