Bug 1528721 [wpt PR 15403] - XMLSerializer: Support element prefix rewriting., a=testonly
authorKent Tamura <tkent@chromium.org>
Tue, 05 Mar 2019 12:15:16 +0000
changeset 525447 d1afd891ac348c1df050feb96de8b67419b34a72
parent 525446 22da78af2c327e3296ca94ce093bedff27ca865e
child 525448 d04acd61397bb9e78d0397294931e47d758d7fcf
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1528721, 15403, 929035, 1473090, 632459
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1528721 [wpt PR 15403] - XMLSerializer: Support element prefix rewriting., a=testonly Automatic update from web-platform-tests XMLSerializer: Support element prefix rewriting. We need to change the prefix of an element if: - The element's namespace is same as the inherited default namespace, and the element prefix is not empty, - The prefix-namespace pair of an element is not declared, and there is another prefix associated to the namespace, or - The namespace of an element is not associated to any prefixes, and the element's prefix is declared for another namespace in the element. This CL implements Step 11, 12.1 to 12.5 of [1]. * Add capability to serialize prefix which is not element.prefix() to MarkupFormatter * MarkupAccumulator::AppendElement() returns a serialized prefix, and AppendEndTag() takes it as an argument. * MarkupAccumulator::AppendStartTagOpen() implements the steps, and returns a serialized prefix as well as 'ignore namespace definition attribute' flag. * MarkupAccumulator::RetrievePreferredPrefixString(): Remove the code for empty prefix for elements. Empty prefix is handled in the callsite. * MarkupAccumulator::ShouldAddNamespaceElement(): Removed. It's not used any longer. * dom/domparsing/xmlserializer-xml-namespace-expected.txt: The new behavior is expected. We successfully find 'xml' prefix. [1] https://w3c.github.io/DOM-Parsing/#xml-serializing-an-element-node Bug: 929035 Change-Id: Icf63cb40b120d29a4b8678104592739d773f3a48 Reviewed-on: https://chromium-review.googlesource.com/c/1473090 Reviewed-by: Yoshifumi Inoue <yosin@chromium.org> Commit-Queue: Kent Tamura <tkent@chromium.org> Cr-Commit-Position: refs/heads/master@{#632459} -- wpt-commits: 2767f92702b54d58cd8b4c289f00a7bc028c10fb wpt-pr: 15403
--- a/testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
+++ b/testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
@@ -150,16 +150,44 @@ test(function() {
   const input = '<root xmlns:p="uri1"><child/></root>';
   const root = (new DOMParser()).parseFromString(input, 'text/xml').documentElement;
   root.firstChild.setAttributeNS('uri2', 'p:foobar', 'v');
   const xmlString = (new XMLSerializer()).serializeToString(root);
   assert_equals(xmlString, '<root xmlns:p="uri1"><child xmlns:ns1="uri2" ns1:foobar="v"/></root>');
 }, 'Check if attribute serialization takes into account of the same prefix declared in an ancestor element');
 test(function() {
+  assert_equals(serialize(parse('<root><child/></root>')), '<root><child/></root>');
+  assert_equals(serialize(parse('<root><child xmlns=""/></root>')), '<root><child/></root>');
+  assert_equals(serialize(parse('<root xmlns="u1"><child xmlns="u1"/></root>')), '<root xmlns="u1"><child/></root>');
+  assert_equals(serialize(parse('<root xmlns="u1"><p:child xmlns:p="u1"/></root>')), '<root xmlns="u1"><child xmlns:p="u1"/></root>');
+}, 'Check if start tag serialization drops element prefix if the namespace is same as inherited default namespace.');
+test(function() {
+  const root = parse('<root xmlns:p1="u1"><child xmlns:p2="u1"/></root>');
+  const child2 = root.ownerDocument.createElementNS('u1', 'child2');
+  root.firstChild.appendChild(child2);
+  assert_equals(serialize(root), '<root xmlns:p1="u1"><child xmlns:p2="u1"><p2:child2/></child></root>');
+}, 'Check if start tag serialization finds an appropriate prefix.');
+test(function() {
+  const root = (new Document()).createElementNS('uri1', 'p:root');
+  root.setAttributeNS(XMLNS_URI, 'xmlns:p', 'uri2');
+  assert_equals(serialize(root), '<ns1:root xmlns:ns1="uri1" xmlns:p="uri2"/>');
+}, 'Check if start tag serialization takes into account of its xmlns:* attributes');
+test(function() {
+  const root = (new Document()).createElement('root');
+  root.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:p', 'uri2');
+  const child = root.ownerDocument.createElementNS('uri1', 'p:child');
+  root.appendChild(child);
+  assert_equals(serialize(root), '<root xmlns:p="uri2"><p:child xmlns:p="uri1"/></root>');
+}, 'Check if start tag serialization applied the original prefix even if it is declared in an ancestor element.');
+test(function() {
   const input = '<root><child1/><child2/></root>';
   const root = (new DOMParser()).parseFromString(input, 'text/xml').documentElement;
   root.firstChild.setAttributeNS('uri1', 'attr1', 'value1');
   root.firstChild.setAttributeNS('uri2', 'attr2', 'value2');
   root.lastChild.setAttributeNS('uri3', 'attr3', 'value3');
   const xmlString = (new XMLSerializer()).serializeToString(root);
   assert_equals(xmlString, '<root><child1 xmlns:ns1="uri1" ns1:attr1="value1" xmlns:ns2="uri2" ns2:attr2="value2"/><child2 xmlns:ns3="uri3" ns3:attr3="value3"/></root>');
 }, 'Check if generated prefixes match to "ns${index}".');