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

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

Issue 2320553002: Custom Elements: HTMLElement constructor tests (Closed)
Patch Set: wraping up long stringl literal Created 4 years, 3 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/LayoutTests/custom-elements/spec/define-element.html » ('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: Constructor Tests</title> 2 <title>Custom Elements: Constructor Tests</title>
3 <link rel="help" href="https://html.spec.whatwg.org/multipage/dom.html#elements- in-the-dom"> 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/dom.html#elements- in-the-dom">
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/testharnessreport.js"></script> 6 <script src="../../resources/testharnessreport.js"></script>
7 <script src="resources/custom-elements-helpers.js"></script> 7 <script src="resources/custom-elements-helpers.js"></script>
8 <body> 8 <body>
9 <script> 9 <script>
10 'use strict'; 10 'use strict';
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 assert_equals(e.prefix, 51 assert_equals(e.prefix,
52 null, 52 null,
53 'the element name should not have a prefix'); 53 'the element name should not have a prefix');
54 assert_equals(e.ownerDocument, 54 assert_equals(e.ownerDocument,
55 w.document, 55 w.document,
56 'the element should be owned by the registry\'s associated ' + 56 'the element should be owned by the registry\'s associated ' +
57 'document'); 57 'document');
58 assert_equals(num_constructor_invocations, 58 assert_equals(num_constructor_invocations,
59 1, 59 1,
60 'the constructor should have been invoked once'); 60 'the constructor should have been invoked once');
61 assert_true(e.matches(':defined'), 'custom element constructed with new should be "custom"');
61 }, 'Custom element constructor, construct'); 62 }, 'Custom element constructor, construct');
62 63
63 test_with_window((w) => { 64 test_with_window((w) => {
64 class C extends w.HTMLElement { } 65 class C extends w.HTMLElement { }
65 class D extends C {} 66 class D extends C {}
66 w.customElements.define('a-a', C); // Note: Not D. 67 w.customElements.define('a-a', C); // Note: Not D.
67 assert_throws(TypeError.prototype, () => { 68 assert_throws(TypeError.prototype, () => {
68 new D(); 69 new D();
69 }, 'constructing a custom element with a new.target with no registry ' + 70 }, 'constructing a custom element with a new.target with no registry ' +
70 'entry should throw a TypeError'); 71 'entry should throw a TypeError');
71 72
72 assert_throws(TypeError.prototype, () => { 73 assert_throws(TypeError.prototype, () => {
73 Reflect.construct(C, [], 42); 74 Reflect.construct(C, [], 42);
74 }, 'constructing a custom element with a non-object new.target should ' + 75 }, 'constructing a custom element with a non-object new.target should ' +
75 'throw a TypeError'); 76 'throw a TypeError');
76 }, 'Custom element constructor, construct invalid new.target'); 77 }, 'Custom element constructor, construct invalid new.target');
78
79 test_with_window((w) => {
80 w.customElements.define('a-a', w.HTMLButtonElement);
81 assert_throws(TypeError.prototype, () => {
82 w.document.createElement('a-a');
83 }, 'If NewTarget is equal to active function object, TypeError should be throw n');
84 }, 'Custom element constructor, NewTarget is equal to active function object');
85
86 test_with_window((w) => {
87 w.customElements.define('a-a', class extends w.HTMLButtonElement {} );
88 assert_throws(TypeError.prototype, () => {
89 w.document.createElement('a-a');
90 }, 'If NewTarget is equal to active function object, TypeError should be throw n');
91 }, 'Custom element constructor, active function object is not equal to HTMLEleme nt');
92
93 test_with_window((w) => {
94 let flag = true;
95 class A extends w.HTMLElement {
96 constructor() {
97 if (flag) {
98 flag = false;
99 new A();
100 }
101 super();
102 }
103 }
104 w.customElements.define('a-a', A);
105 let e = new A();
106 assert_true(e.matches(':defined'),
107 'constructing a custom element with new should not throw InvalidStateError ' +
108 'and should return a "custom" element');
109 }, 'Already constructed marker, construct with new');
110
111 test_with_window((w) => {
112 let flag = true;
113 class A extends w.HTMLElement {
114 constructor() {
115 if (flag) {
116 flag = false;
117 new A();
118 }
119 super();
120 }
121 }
122 w.customElements.define('a-a', A);
123 assert_throws_dom_exception(w, 'INVALID_STATE_ERR', () => {
124 w.document.createElement('a-a');
125 }, 'Creating an element that is already constructed marker should throw Invali dStateError');
126 }, 'Already constructed marker, create element');
127
128 test_with_window((w) => {
129 let errors = [];
130 w.onerror = function (event, source, lineno, colno, error) {
131 errors.push(error.name);
132 return true;
133 };
134 let flag = true;
135 let e = w.document.createElement('a-a');
136 class A extends w.HTMLElement {
137 constructor() {
138 if (flag) {
139 flag = false;
140 new A();
141 }
142 super();
143 }
144 }
145 w.customElements.define('a-a', A);
146 w.document.body.appendChild(e);
147 assert_array_equals(errors, ['InvalidStateError'], 'Upgrading an element ' +
148 'that is already constructed marker should throw InvalidStateError');
149 }, 'Already constructed marker, upgrade element');
77 </script> 150 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698