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