| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <link id="import1" rel="import" href="resources/adopted-nodes.html"> |
| 5 <body> |
| 6 <b-b id="x"></b-b> |
| 7 <b-b id="y"></b-b> |
| 8 <b-b id="z"></b-b> |
| 9 </body> |
| 10 <script> |
| 11 'use strict'; |
| 12 |
| 13 test(() => { |
| 14 let reactions = []; |
| 15 |
| 16 customElements.define('a-a', class extends HTMLElement { |
| 17 adoptedCallback() { |
| 18 reactions.push(this); |
| 19 } |
| 20 }); |
| 21 |
| 22 let importDoc = import1.import; |
| 23 |
| 24 let a = importDoc.querySelector('#a'); |
| 25 assert_equals(a.ownerDocument, importDoc); |
| 26 document.body.appendChild(a); |
| 27 assert_equals(a.ownerDocument, document, 'After appendChild(), node document s
hould change.'); |
| 28 |
| 29 let b = importDoc.querySelector('#b'); |
| 30 assert_equals(b.ownerDocument, importDoc); |
| 31 let b2 = document.importNode(b); |
| 32 assert_equals(b.ownerDocument, importDoc, 'importNode() should not change node
document.'); |
| 33 assert_equals(b2.ownerDocument, document, |
| 34 'importNode() should copy node from one document to another.'); |
| 35 |
| 36 let c = importDoc.querySelector('#c'); |
| 37 assert_equals(c.ownerDocument, importDoc); |
| 38 let c2 = document.adoptNode(c); |
| 39 assert_equals(c.ownerDocument, document, 'adoptNode should have changed node d
ocument.'); |
| 40 assert_equals(c, c2, 'adoptNode() should move node from another document.'); |
| 41 |
| 42 assert_array_equals(importDoc.querySelectorAll('a-a'), [b], |
| 43 'Only <a-a#b> should remain in the imported document.'); |
| 44 assert_array_equals(reactions, [a, c], |
| 45 'appendChild() and adoptNode() should cause adoptedCallbac
k.'); |
| 46 }, 'adoptedCallback should be invoked when moving custom element from import to
master document'); |
| 47 |
| 48 test(() => { |
| 49 let reactions = []; |
| 50 |
| 51 customElements.define('b-b', class extends HTMLElement { |
| 52 adoptedCallback() { |
| 53 reactions.push(this); |
| 54 } |
| 55 }); |
| 56 |
| 57 let importDoc = import1.import; |
| 58 |
| 59 let x = document.querySelector('#x'); |
| 60 assert_equals(x.ownerDocument, document); |
| 61 importDoc.body.appendChild(x); |
| 62 assert_equals(x.ownerDocument, importDoc, 'After appendChild(), node document
should change.'); |
| 63 |
| 64 let y = document.querySelector('#y'); |
| 65 assert_equals(y.ownerDocument, document); |
| 66 let y2 = importDoc.importNode(y); |
| 67 assert_equals(y.ownerDocument, document, 'importNode() should not change node
document.'); |
| 68 assert_equals(y2.ownerDocument, importDoc, |
| 69 'importNode() should copy node from one document to another.'); |
| 70 |
| 71 let z = document.querySelector('#z'); |
| 72 assert_equals(z.ownerDocument, document); |
| 73 let z2 = importDoc.adoptNode(z); |
| 74 assert_equals(z.ownerDocument, importDoc, 'adoptNode should have changed node
document.'); |
| 75 assert_equals(z, z2, 'adoptNode() should move node from another document.'); |
| 76 |
| 77 assert_array_equals(document.querySelectorAll('b-b'), [y], |
| 78 'Only <b-b#y> should remain in the imported document.'); |
| 79 assert_array_equals(reactions, [x, z], |
| 80 'appendChild() and adoptNode() should cause adoptedCallbac
k.'); |
| 81 }, 'adoptedCallback should be invoked when moving custom element from master doc
ument to import'); |
| 82 </script> |
| OLD | NEW |