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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/upgrading-parser-created-element.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: Upgrading unresolved elements</title>
5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
6 <meta name="assert" content="HTML parser must add an unresolved custom element t o the upgrade candidates map">
7 <link rel="help" href="https://html.spec.whatwg.org/#upgrades">
8 <script src="/resources/testharness.js"></script>
9 <script src="/resources/testharnessreport.js"></script>
10 </head>
11 <body>
12 <div id="log"></div>
13 <my-custom-element></my-custom-element>
14 <instantiates-itself-after-super></instantiates-itself-after-super>
15 <instantiates-itself-before-super></instantiates-itself-before-super>
16 <my-other-element id="instance"></my-other-element>
17 <my-other-element id="otherInstance"></my-other-element>
18 <script>
19
20 setup({allow_uncaught_exception:true});
21
22 test(function () {
23 class MyCustomElement extends HTMLElement { }
24
25 var instance = document.querySelector('my-custom-element');
26 assert_true(instance instanceof HTMLElement);
27 assert_false(instance instanceof HTMLUnknownElement,
28 'an unresolved custom element should not be an instance of HTMLUnknownEl ement');
29 assert_false(instance instanceof MyCustomElement);
30
31 customElements.define('my-custom-element', MyCustomElement);
32
33 assert_true(instance instanceof HTMLElement);
34 assert_true(instance instanceof MyCustomElement,
35 'Calling customElements.define must upgrade existing custom elements');
36
37 }, 'Element.prototype.createElement must add an unresolved custom element to the upgrade candidates map');
38
39 test(function () {
40 class InstantiatesItselfAfterSuper extends HTMLElement {
41 constructor(doNotCreateItself) {
42 super();
43 if (!doNotCreateItself)
44 new InstantiatesItselfAfterSuper(true);
45 }
46 }
47
48 var uncaughtError;
49 window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
50 customElements.define('instantiates-itself-after-super', InstantiatesItselfA fterSuper);
51 assert_equals(uncaughtError.name, 'InvalidStateError');
52 }, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
53 + ' due to a custom element constructor constructing itself after super() ca ll');
54
55 test(function () {
56 class InstantiatesItselfBeforeSuper extends HTMLElement {
57 constructor(doNotCreateItself) {
58 if (!doNotCreateItself)
59 new InstantiatesItselfBeforeSuper(true);
60 super();
61 }
62 }
63
64 var uncaughtError;
65 window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
66 customElements.define('instantiates-itself-before-super', InstantiatesItself BeforeSuper);
67 assert_equals(uncaughtError.name, 'InvalidStateError');
68 }, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
69 + ' due to a custom element constructor constructing itself before super() c all');
70
71 test(function () {
72 class MyOtherElement extends HTMLElement {
73 constructor() {
74 super();
75 if (this == instance)
76 return otherInstance;
77 }
78 }
79 var instance = document.getElementById('instance');
80 var otherInstance = document.getElementById('otherInstance');
81
82 assert_false(instance instanceof MyOtherElement);
83 assert_false(otherInstance instanceof MyOtherElement);
84
85 var uncaughtError;
86 window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
87 customElements.define('my-other-element', MyOtherElement);
88 assert_equals(uncaughtError.name, 'InvalidStateError');
89
90 assert_true(document.createElement('my-other-element') instanceof MyOtherEle ment,
91 'Upgrading of custom elements must happen after the definition was added to the registry.');
92
93 }, 'Upgrading a custom element must throw an InvalidStateError when the returned element is not SameValue as the upgraded element');
94
95 </script>
96 </body>
97 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698