diff --git a/custom-elements/adopted-callback.html b/custom-elements/adopted-callback.html
index 5c08a04a4210d7..1ed4634dba9ff8 100644
--- a/custom-elements/adopted-callback.html
+++ b/custom-elements/adopted-callback.html
@@ -117,6 +117,38 @@
});
}, 'Moving the shadow host of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');
+ promise_test(function () {
+ return getDocument().then(function (doc) {
+ const instance = document.createElement('my-custom-element');
+ const host = document.createElement('div');
+ const shadowRoot = host.attachShadow({mode: 'closed'});
+ shadowRoot.appendChild(instance);
+ document.body.appendChild(host);
+
+ calls = [];
+ doc.documentElement.appendChild(shadowRoot);
+ assert_array_equals(calls, ['disconnected', 'adopted', document, doc, 'connected']);
+ });
+ }, 'Moving the shadow host\'s shadow of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');
+
+ promise_test(function () {
+ return getDocument().then(function (doc) {
+ const instance = document.createElement('my-custom-element');
+ const template = document.createElement('template');
+ const templateContent = template.content;
+ templateContent.appendChild(instance);
+ document.body.appendChild(template);
+
+ calls = [];
+ doc.documentElement.appendChild(templateContent);
+ if (doc === templateContent.ownerDocument) {
+ assert_array_equals(calls, ['connected']);
+ } else {
+ assert_array_equals(calls, ['adopted', templateContent.ownerDocument, doc, 'connected']);
+ }
+ });
+ }, 'Moving the \'s content of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');
+
promise_test(function () {
return getDocument().then(function (doc) {
var instance = document.createElement('my-custom-element');
diff --git a/dom/nodes/adoption.window.js b/dom/nodes/adoption.window.js
new file mode 100644
index 00000000000000..86893a4ae770e4
--- /dev/null
+++ b/dom/nodes/adoption.window.js
@@ -0,0 +1,58 @@
+// Testing DocumentFragment with host separately as it has a different node document by design
+test(() => {
+ const df = document.createElement("template").content;
+ const child = df.appendChild(new Text('hi'));
+ assert_not_equals(df.ownerDocument, document);
+ const nodeDocument = df.ownerDocument;
+ document.body.appendChild(df);
+ assert_equals(df.childNodes.length, 0);
+ assert_equals(child.ownerDocument, document);
+ assert_equals(df.ownerDocument, nodeDocument);
+}, `appendChild() and DocumentFragment with host`);
+
+test(() => {
+ const df = document.createElement("template").content;
+ const child = df.appendChild(new Text('hi'));
+ const nodeDocument = df.ownerDocument;
+ document.adoptNode(df);
+ assert_equals(df.childNodes.length, 1);
+ assert_equals(child.ownerDocument, nodeDocument);
+ assert_equals(df.ownerDocument, nodeDocument);
+}, `adoptNode() and DocumentFragment with host`);
+
+[
+ {
+ "name": "DocumentFragment",
+ "creator": doc => doc.createDocumentFragment()
+ },
+ {
+ "name": "ShadowRoot",
+ "creator": doc => doc.createElementNS("http://www.w3.org/1999/xhtml", "div").attachShadow({mode: "closed"})
+ }
+].forEach(dfTest => {
+ test(() => {
+ const doc = new Document();
+ const df = dfTest.creator(doc);
+ const child = df.appendChild(new Text('hi'));
+ assert_equals(df.ownerDocument, doc);
+
+ document.body.appendChild(df);
+ assert_equals(df.childNodes.length, 0);
+ assert_equals(child.ownerDocument, document);
+ assert_equals(df.ownerDocument, doc);
+ }, `appendChild() and ${dfTest.name}`);
+
+ test(() => {
+ const doc = new Document();
+ const df = dfTest.creator(doc);
+ const child = df.appendChild(new Text('hi'));
+ if (dfTest.name === "ShadowRoot") {
+ assert_throws("HierarchyRequestError", () => document.adoptNode(df));
+ } else {
+ document.adoptNode(df);
+ assert_equals(df.childNodes.length, 1);
+ assert_equals(child.ownerDocument, document);
+ assert_equals(df.ownerDocument, document);
+ }
+ }, `adoptNode() and ${dfTest.name}`);
+});
diff --git a/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy.html b/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy.html
index 1f33b96b342c4a..046395ac7c728a 100644
--- a/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy.html
+++ b/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy.html
@@ -1,19 +1,11 @@
-
-
-
-
-
-
-
-
+
Happy Templating!
-
-