blob: febf72506b803a16df5fd46f850e6058a246d88a [file] [log] [blame]
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<link id="import1" rel="import" href="resources/adopted-nodes.html">
<body>
<b-b id="x"></b-b>
<b-b id="y"></b-b>
<b-b id="z"></b-b>
</body>
<script>
'use strict';
test(() => {
let reactions = [];
customElements.define('a-a', class extends HTMLElement {
adoptedCallback() {
reactions.push(this);
}
});
let importDoc = import1.import;
let a = importDoc.querySelector('#a');
assert_equals(a.ownerDocument, importDoc);
document.body.appendChild(a);
assert_equals(a.ownerDocument, document, 'After appendChild(), node document should change.');
let b = importDoc.querySelector('#b');
assert_equals(b.ownerDocument, importDoc);
let b2 = document.importNode(b);
assert_equals(b.ownerDocument, importDoc, 'importNode() should not change node document.');
assert_equals(b2.ownerDocument, document,
'importNode() should copy node from one document to another.');
let c = importDoc.querySelector('#c');
assert_equals(c.ownerDocument, importDoc);
let c2 = document.adoptNode(c);
assert_equals(c.ownerDocument, document, 'adoptNode should have changed node document.');
assert_equals(c, c2, 'adoptNode() should move node from another document.');
assert_array_equals(importDoc.querySelectorAll('a-a'), [b],
'Only <a-a#b> should remain in the imported document.');
assert_array_equals(reactions, [a, c],
'appendChild() and adoptNode() should cause adoptedCallback.');
}, 'adoptedCallback should be invoked when moving custom element from import to master document');
test(() => {
let reactions = [];
customElements.define('b-b', class extends HTMLElement {
adoptedCallback() {
reactions.push(this);
}
});
let importDoc = import1.import;
let x = document.querySelector('#x');
assert_equals(x.ownerDocument, document);
importDoc.body.appendChild(x);
assert_equals(x.ownerDocument, importDoc, 'After appendChild(), node document should change.');
let y = document.querySelector('#y');
assert_equals(y.ownerDocument, document);
let y2 = importDoc.importNode(y);
assert_equals(y.ownerDocument, document, 'importNode() should not change node document.');
assert_equals(y2.ownerDocument, importDoc,
'importNode() should copy node from one document to another.');
let z = document.querySelector('#z');
assert_equals(z.ownerDocument, document);
let z2 = importDoc.adoptNode(z);
assert_equals(z.ownerDocument, importDoc, 'adoptNode should have changed node document.');
assert_equals(z, z2, 'adoptNode() should move node from another document.');
assert_array_equals(document.querySelectorAll('b-b'), [y],
'Only <b-b#y> should remain in the imported document.');
assert_array_equals(reactions, [x, z],
'appendChild() and adoptNode() should cause adoptedCallback.');
}, 'adoptedCallback should be invoked when moving custom element from master document to import');
</script>