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

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

Issue 2376103007: Import wpt@09907a9c4bcee14986431d53e4381384c7c69107 (Closed)
Patch Set: update platform expectations Created 4 years, 2 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
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Custom Elements: disconnectedCallback</title>
5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
6 <meta name="assert" content="disconnectedCallback must be enqueued whenever cust om element is removed from a document">
7 <link rel="help" href="https://w3c.github.io/webcomponents/spec/custom/#dfn-conn ected-callback">
8 <script src="/resources/testharness.js"></script>
9 <script src="/resources/testharnessreport.js"></script>
10 <script src="resources/document-types.js"></script>
11 </head>
12 <body>
13 <div id="log"></div>
14 <script>
15
16 var calls = [];
17 class MyCustomElement extends HTMLElement {
18 connectedCallback() { calls.push('connected', this); }
19 disconnectedCallback() { calls.push('disconnected', this); }
20 }
21 customElements.define('my-custom-element', MyCustomElement);
22
23 DocumentTypes.forEach(function (entry) {
24 var documentName = entry.name;
25 var getDocument = entry.create;
26
27 promise_test(function () {
28 return getDocument().then(function (doc) {
29 var instance = document.createElement('my-custom-element');
30 doc.documentElement.appendChild(instance);
31 calls = [];
32 doc.documentElement.removeChild(instance);
33 assert_array_equals(calls, ['disconnected', instance]);
34 });
35 }, 'Removing a custom element from a ' + documentName + ' must enqueue and i nvoke disconnectedCallback');
36
37 promise_test(function () {
38 return getDocument().then(function (doc) {
39 var instance = document.createElement('my-custom-element');
40 var parent = document.createElement('div');
41 parent.appendChild(instance);
42 doc.documentElement.appendChild(parent);
43 calls = [];
44 doc.documentElement.removeChild(parent);
45 assert_array_equals(calls, ['disconnected', instance]);
46 });
47 }, 'Removing an ancestor of custom element from a ' + documentName + ' must enqueue and invoke disconnectedCallback');
48
49 promise_test(function () {
50 return getDocument().then(function (doc) {
51 var instance = document.createElement('my-custom-element');
52 var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div' );
53 var shadowRoot = host.attachShadow({mode: 'closed'});
54 doc.documentElement.appendChild(host);
55 shadowRoot.appendChild(instance);
56
57 calls = [];
58 shadowRoot.removeChild(instance);
59 assert_array_equals(calls, ['disconnected', instance]);
60 });
61 }, 'Removing a custom element from a shadow tree in a ' + documentName + ' m ust enqueue and invoke disconnectedCallback');
62
63 promise_test(function () {
64 return getDocument().then(function (doc) {
65 var instance = document.createElement('my-custom-element');
66 var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div' );
67 var shadowRoot = host.attachShadow({mode: 'closed'});
68 shadowRoot.appendChild(instance);
69 doc.documentElement.appendChild(host);
70
71 calls = [];
72 doc.documentElement.removeChild(host);
73 assert_array_equals(calls, ['disconnected', instance]);
74 });
75 }, 'Removing the shadow host of a custom element from a' + documentName + ' must enqueue and invoke disconnectedCallback');
76
77 promise_test(function () {
78 return getDocument().then(function (doc) {
79 var instance = document.createElement('my-custom-element');
80 var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div' );
81 var shadowRoot = host.attachShadow({mode: 'closed'});
82 shadowRoot.appendChild(instance);
83
84 calls = [];
85 shadowRoot.removeChild(instance);
86 assert_array_equals(calls, []);
87 });
88 }, 'Removing a custom element from a detached shadow tree that belongs to a ' + documentName + ' must not enqueue and invoke disconnectedCallback');
89 });
90
91 </script>
92 </body>
93 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698