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

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

Issue 2320553002: Custom Elements: HTMLElement constructor tests (Closed)
Patch Set: patch update 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/construct-expected.txt » ('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 assert_throws_dom_exception(w, 'INVALID_STATE_ERR', () => {
106 new A();
107 }, 'Constructing an element that is already constructed marker should throw In validStateError');
108 }, 'Already constructed marker, construct with new');
dominicc (has gone to gerrit) 2016/09/08 04:13:22 Can you point to the key points in the spec that m
109
110 test_with_window((w) => {
111 let flag = true;
112 class A extends w.HTMLElement {
113 constructor() {
114 if (flag) {
115 flag = false;
116 new A();
117 }
118 super();
119 }
120 }
121 w.customElements.define('a-a', A);
122 assert_throws_dom_exception(w, 'INVALID_STATE_ERR', () => {
123 w.document.createElement('a-a');
124 }, 'Creating an element that is already constructed marker should throw Invali dStateError');
125 }, 'Already constructed marker, create element');
126
127 test_with_window((w) => {
128 let errors = [];
129 w.onerror = function (event, source, lineno, colno, error) {
130 errors.push(error.name);
131 return true;
132 };
133 let flag = true;
134 let e = w.document.createElement('a-a');
135 class A extends w.HTMLElement {
136 constructor() {
137 if (flag) {
138 flag = false;
139 new A();
140 }
141 super();
142 }
143 }
144 w.customElements.define('a-a', A);
145 w.document.body.appendChild(e);
146 assert_array_equals(errors, ['InvalidStateError'], 'Upgrading an element that is already constructed marker should throw InvalidStateError');
147 }, 'Already constructed marker, upgrade element');
77 </script> 148 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/custom-elements/spec/construct-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698