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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading.html

Issue 2446483002: Import wpt@c5a14f553cba5f197743b9af605a84eddd8692a2 (Closed)
Patch Set: Created 4 years, 1 month 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 <html>
3 <head>
4 <title>Custom Elements: Enqueue a custom element upgrade reaction</title>
5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
6 <meta name="assert" content="Enqueue a custom element upgrade reaction must upgr ade a custom element">
7 <link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element">
8 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#con cept-try-upgrade">
9 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#enq ueue-a-custom-element-upgrade-reaction">
10 <script src="/resources/testharness.js"></script>
11 <script src="/resources/testharnessreport.js"></script>
12 <script src="resources/custom-elements-helpers.js"></script>
13 </head>
14 <body>
15 <div id="log"></div>
16 <script>
17
18 class PredefinedCustomElement extends HTMLElement {}
19 customElements.define('predefined-custom-element', PredefinedCustomElement);
20
21 var customElementNumber = 1;
22 function generateNextCustomElementName() { return 'custom-' + customElementNumbe r++; }
23
24 // Tests for documents without a browsing context.
25 document_types().filter(function (entry) { return !entry.isOwner && !entry.hasBr owsingContext; }).forEach(function (entry) {
26 var documentName = entry.name;
27 var getDocument = entry.create;
28
29 promise_test(function () {
30 return getDocument().then(function (doc) {
31 assert_false(doc.createElement('predefined-custom-element') instance of PredefinedCustomElement);
32 });
33 }, 'Creating an element in ' + documentName + ' must not enqueue a custom el ement upgrade reaction'
34 + ' because the document does not have a browsing context');
35
36 promise_test(function () {
37 var name = generateNextCustomElementName();
38 var unresolvedElement = document.createElement(name);
39
40 assert_equals(unresolvedElement.__proto__, HTMLElement.prototype,
41 '[[Prototype]] internal slot of the unresolved custom element must b e the HTMLElement prototype');
42
43 return getDocument().then(function (doc) {
44 var unresolvedElementInDoc = doc.createElement(name);
45 var prototype = (unresolvedElementInDoc.namespaceURI == 'http://www. w3.org/1999/xhtml' ? HTMLElement : Element).prototype;
46
47 assert_equals(unresolvedElementInDoc.__proto__, prototype,
48 '[[Prototype]] internal slot of the unresolved custom element mu st be the ' + prototype.toString() + ' prototype');
49 var someCustomElement = class extends HTMLElement {};
50 customElements.define(name, someCustomElement);
51 assert_equals(unresolvedElementInDoc.__proto__, prototype, '"define" must not upgrade a disconnected unresolved custom elements');
52 doc.documentElement.appendChild(unresolvedElementInDoc);
53 assert_equals(unresolvedElementInDoc.__proto__, prototype,
54 'Inserting an element into a document without a browsing context must not enqueue a custom element upgrade reaction');
55 });
56 }, 'Creating an element in ' + documentName + ' and inserting into the docum ent must not enqueue a custom element upgrade reaction');
57
58 promise_test(function () {
59 var name = generateNextCustomElementName();
60 var unresolvedElement = document.createElement(name);
61
62 assert_equals(unresolvedElement.__proto__, HTMLElement.prototype,
63 '[[Prototype]] internal slot of the unresolved custom element must b e the HTMLElement prototype');
64
65 return getDocument().then(function (doc) {
66 var unresolvedElementInDoc = doc.createElement(name);
67 var prototype = (unresolvedElementInDoc.namespaceURI == 'http://www. w3.org/1999/xhtml' ? HTMLElement : Element).prototype;
68
69 assert_equals(unresolvedElementInDoc.__proto__, prototype,
70 '[[Prototype]] internal slot of the unresolved custom element mu st be the ' + prototype.toString() + ' prototype');
71 var someCustomElement = class extends HTMLElement {};
72 customElements.define(name, someCustomElement);
73 assert_equals(unresolvedElementInDoc.__proto__, prototype, '"define" must not upgrade a disconnected unresolved custom elements');
74 document.body.appendChild(unresolvedElementInDoc);
75
76 if (unresolvedElementInDoc.namespaceURI == 'http://www.w3.org/1999/x html') {
77 assert_equals(unresolvedElementInDoc.__proto__, someCustomElemen t.prototype,
78 'Inserting an element into a document with a browsing contex t must enqueue a custom element upgrade reaction');
79 } else {
80 assert_equals(unresolvedElementInDoc.__proto__, prototype,
81 'Looking up a custom element definition must return null if the element is not in the HTML namespace');
82 }
83 });
84 }, 'Creating an element in ' + documentName + ' and adopting back to a docum ent with browsing context must enqueue a custom element upgrade reaction');
85
86 });
87
88 // Tests for documents with a browsing context.
89 document_types().filter(function (entry) { return !entry.isOwner && entry.hasBro wsingContext; }).forEach(function (entry) {
90 var documentName = entry.name;
91 var getDocument = entry.create;
92
93 promise_test(function () {
94 return getDocument().then(function (doc) {
95 assert_false(doc.createElement('predefined-custom-element') instance of PredefinedCustomElement);
96 });
97 }, 'Creating an element in ' + documentName + ' must not enqueue a custom el ement upgrade reaction if there is no matching definition');
98
99 promise_test(function () {
100 return getDocument().then(function (doc) {
101 var docWindow = doc.defaultView;
102 class DistinctPredefinedCustomElement extends docWindow.HTMLElement { };
103 docWindow.customElements.define('predefined-custom-element', Distinc tPredefinedCustomElement);
104 assert_true(doc.createElement('predefined-custom-element') instanceo f DistinctPredefinedCustomElement);
105 });
106 }, 'Creating an element in ' + documentName + ' must enqueue a custom elemen t upgrade reaction if there is a matching definition');
107
108 promise_test(function () {
109 var unresolvedElement = document.createElement('unresolved-element');
110 return getDocument().then(function (doc) {
111 var docWindow = doc.defaultView;
112 class UnresolvedElement extends docWindow.HTMLElement { };
113 var unresolvedElementInDoc = doc.createElement('unresolved-element') ;
114
115 assert_equals(unresolvedElement.__proto__, HTMLElement.prototype);
116 assert_equals(unresolvedElementInDoc.__proto__, docWindow.HTMLElemen t.prototype);
117
118 docWindow.customElements.define('unresolved-element', UnresolvedElem ent);
119
120 assert_equals(unresolvedElement.__proto__, HTMLElement.prototype);
121 assert_equals(unresolvedElementInDoc.__proto__, docWindow.HTMLElemen t.prototype);
122
123 });
124 }, '"define" in ' + documentName + ' must not enqueue a custom element upgra de reaction on a disconnected unresolved custom element');
125
126 promise_test(function () {
127 var unresolvedElement = document.createElement('unresolved-element');
128 return getDocument().then(function (doc) {
129 var docWindow = doc.defaultView;
130 class UnresolvedElement extends docWindow.HTMLElement { };
131 var unresolvedElementInDoc = doc.createElement('unresolved-element') ;
132
133 assert_equals(unresolvedElement.__proto__, HTMLElement.prototype);
134 assert_equals(unresolvedElementInDoc.__proto__, docWindow.HTMLElemen t.prototype);
135
136 docWindow.customElements.define('unresolved-element', UnresolvedElem ent);
137 doc.documentElement.appendChild(unresolvedElementInDoc);
138
139 assert_equals(unresolvedElement.__proto__, HTMLElement.prototype);
140 assert_equals(unresolvedElementInDoc.__proto__, UnresolvedElement.pr ototype);
141 });
142 }, 'Inserting an unresolved custom element into ' + documentName + ' must en queue a custom element upgrade reaction');
143
144 promise_test(function () {
145 var unresolvedElement = document.createElement('unresolved-element');
146 return getDocument().then(function (doc) {
147 var docWindow = doc.defaultView;
148 class UnresolvedElement extends docWindow.HTMLElement { };
149 var unresolvedElementInDoc = doc.createElement('unresolved-element') ;
150 doc.documentElement.appendChild(unresolvedElementInDoc);
151
152 assert_equals(unresolvedElement.__proto__, HTMLElement.prototype);
153 assert_equals(unresolvedElementInDoc.__proto__, docWindow.HTMLElemen t.prototype);
154
155 docWindow.customElements.define('unresolved-element', UnresolvedElem ent);
156
157 assert_equals(unresolvedElement.__proto__, HTMLElement.prototype);
158 assert_equals(unresolvedElementInDoc.__proto__, UnresolvedElement.pr ototype);
159 });
160 }, '"define" in ' + documentName + ' must enqueue a custom element upgrade r eaction on a connected unresolved custom element');
161
162 promise_test(function () {
163 var unresolvedElement = document.createElement('unresolved-element');
164 return getDocument().then(function (doc) {
165 var docWindow = doc.defaultView;
166 class UnresolvedElement extends docWindow.HTMLElement { };
167 assert_false(unresolvedElement instanceof UnresolvedElement);
168 docWindow.customElements.define('unresolved-element', UnresolvedElem ent);
169 doc.adoptNode(unresolvedElement);
170 assert_false(unresolvedElement instanceof UnresolvedElement);
171 });
172 }, 'Adopting (and leaving disconnceted) an unresolved custom element into ' + documentName + ' must not enqueue a custom element upgrade reaction');
173
174 promise_test(function () {
175 var unresolvedElement = document.createElement('unresolved-element');
176 return getDocument().then(function (doc) {
177 var docWindow = doc.defaultView;
178 class UnresolvedElement extends docWindow.HTMLElement { };
179 assert_false(unresolvedElement instanceof UnresolvedElement);
180 docWindow.customElements.define('unresolved-element', UnresolvedElem ent);
181 doc.documentElement.appendChild(unresolvedElement);
182 assert_true(unresolvedElement instanceof UnresolvedElement);
183 });
184 }, 'Adopting and inserting an unresolved custom element into ' + documentNam e + ' must enqueue a custom element upgrade reaction');
185
186 });
187
188 </script>
189 </body>
190 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698