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

Unified Diff: third_party/WebKit/LayoutTests/custom-elements/imports/adopted-callback.html

Issue 2296663002: Add a test for adoptedCallback for custom elements in imports (Closed)
Patch Set: Add document->import move test. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/custom-elements/imports/resources/adopted-nodes.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/custom-elements/imports/adopted-callback.html
diff --git a/third_party/WebKit/LayoutTests/custom-elements/imports/adopted-callback.html b/third_party/WebKit/LayoutTests/custom-elements/imports/adopted-callback.html
new file mode 100644
index 0000000000000000000000000000000000000000..febf72506b803a16df5fd46f850e6058a246d88a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/custom-elements/imports/adopted-callback.html
@@ -0,0 +1,82 @@
+<!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>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/custom-elements/imports/resources/adopted-nodes.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698