Serialization algorithms should not be changed in the middle of a serialization

Our serializer detected serialization type with |node.GetDocument()
.IsHTMLDocument()|.  Usually it stays with a single value during a single
serializer call. However, <template>'s content can be owned by a document
different from the <template>.  We should store serialization type detected
with the specified node.

* Change SerializationType enum items:
  kAsOwnerDocument / kForceXML ==> kHTML / kXML

* SerializeAsHTMLDocument() doesn't need an argument.
  Also, rename it to SerializeAsHTML() for simplicity.

Bug: 968079
Change-Id: I4e7b20068eb4518a53d0fbf0341fd114498a3231
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1640584
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665811}
diff --git a/html/syntax/serializing-html-fragments/template.html b/html/syntax/serializing-html-fragments/template.html
new file mode 100644
index 0000000..ea05038
--- /dev/null
+++ b/html/syntax/serializing-html-fragments/template.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<script>
+test(() => {
+  document.body.insertAdjacentHTML('afterbegin', '<div><template><table><td></table></template></div>');
+  let t = document.querySelector('template');
+  assert_equals(t.innerHTML, '<table><tbody><tr><td></td></tr></tbody></table>');
+  assert_equals(t.parentNode.innerHTML, '<template><table><tbody><tr><td></td></tr></tbody></table></template>');
+}, 'Template element content is correctly serialized');
+
+test(() => {
+  let t = document.createElement('template');
+  let c = t.content.appendChild(document.createElementNS("xx", "div"));
+  c.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'en-us');
+  c.setAttributeNS('uri2', 'p:attr', 'v');
+  let doc = new Document();
+  doc.adoptNode(t.content);
+  assert_equals(t.innerHTML, '<div xml:lang="en-us" p:attr="v"></div>');
+}, 'HTML fragment serialization algorithm should be applied to the template content');
+</script>
+</body>