Bug 1528705 [wpt PR 15389] - XMLSerializer should drop xmlns="..." in some cases, a=testonly
authorKent Tamura <tkent@chromium.org>
Tue, 05 Mar 2019 12:14:01 +0000
changeset 522438 db38aa6ecb1650383ada623fb3f6138a04aeb449
parent 522437 c8eeaabc6e7804b4c59ccd205131a6556caf3db4
child 522439 054360de14538a69798029c4918dc5c58e9e7f72
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1528705, 15389, 929035, 1471671, 632142
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 1528705 [wpt PR 15389] - XMLSerializer should drop xmlns="..." in some cases, a=testonly Automatic update from web-platform-tests XMLSerializer should drop xmlns="..." in some cases If an element has no prefix and its namespace is different from the current default namespace, the element needs to add xmlns="<elements-namesapce-uri>". In such case, we need to drop existing xmlns="<other-uri>" and need to take care of existing xmlns="<elements-namespace-uri>". Implementation: Follow the specification in the following points: - Stop registering default namespace to prefix-namespace / namespace-prefixes maps. - The default namespace is tracked by NamespaceContext:: context_namespace_. - 'local default namespace' is computed in 'recording the namespace information' algorithm. * NamespaceContext::Add(): Make sure arguments are not empty. * Move MarkupAccumulator::RecordNamespacInformation to NamespaceContext, and update the default namespace handling. * AppendElement() respects to 'ignore namespace definition attribute' flag. * Implement some parts of the specification to - keep track the default namespace - return correct 'ignore namespace definition attribute' value - add an appropriate xmlns="..." Bug: 929035 Change-Id: Id5f0090d5dc08334c202e6ef9b107f1645fb3120 Reviewed-on: https://chromium-review.googlesource.com/c/1471671 Commit-Queue: Kent Tamura <tkent@chromium.org> Auto-Submit: Kent Tamura <tkent@chromium.org> Reviewed-by: Yoshifumi Inoue <yosin@chromium.org> Cr-Commit-Position: refs/heads/master@{#632142} -- wpt-commits: 1b2808938937c9e992eb469b345ca64f99182c29 wpt-pr: 15389
--- a/testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
+++ b/testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
@@ -4,16 +4,18 @@
   <title>domparsing Test: XMLSerializer.serializeToString</title>
   <script src="/resources/testharness.js"></script>
   <script src="/resources/testharnessreport.js"></script>
+const XMLNS_URI = 'http://www.w3.org/2000/xmlns/';
 function createXmlDoc(){
   var input = '<?xml version="1.0" encoding="UTF-8"?><root><child1>value1</child1></root>';
   var parser = new DOMParser();
   return parser.parseFromString(input, 'text/xml');
 // Returns the root element.
 function parse(xmlString) {
@@ -45,16 +47,36 @@ test(function() {
 test(function() {
   var input = '<root xmlns="urn:bar"><outer xmlns=""><inner>value1</inner></outer></root>';
   var root = (new DOMParser()).parseFromString(input, 'text/xml').documentElement;
   var xmlString = (new XMLSerializer()).serializeToString(root);
   assert_equals(xmlString, '<root xmlns="urn:bar"><outer xmlns=""><inner>value1</inner></outer></root>');
 }, 'Check if there is no redundant empty namespace declaration.');
 test(function() {
+  const root = parse('<root xmlns="uri1"/>');
+  const child = root.ownerDocument.createElement('child');
+  child.setAttributeNS(XMLNS_URI, 'xmlns', 'FAIL1');
+  root.appendChild(child);
+  const child2 = root.ownerDocument.createElementNS('uri2', 'child2');
+  child2.setAttributeNS(XMLNS_URI, 'xmlns', 'FAIL2');
+  root.appendChild(child2);
+  const child3 = root.ownerDocument.createElementNS('uri1', 'child3');
+  child3.setAttributeNS(XMLNS_URI, 'xmlns', 'FAIL3');
+  root.appendChild(child3);
+  const child4 = root.ownerDocument.createElementNS('uri4', 'child4');
+  child4.setAttributeNS(XMLNS_URI, 'xmlns', 'uri4');
+  root.appendChild(child4);
+  const child5 = root.ownerDocument.createElement('child5');
+  child5.setAttributeNS(XMLNS_URI, 'xmlns', '');
+  root.appendChild(child5);
+  assert_equals(serialize(root), '<root xmlns="uri1"><child xmlns=""/><child2 xmlns="uri2"/><child3/><child4 xmlns="uri4"/><child5 xmlns=""/></root>');
+}, 'Check if inconsistent xmlns="..." is dropped.');
+test(function() {
   let root = parse('<r xmlns:xx="uri"></r>');
   root.setAttributeNS('uri', 'name', 'v');
   assert_equals(serialize(root), '<r xmlns:xx="uri" xx:name="v"/>');
   let root2 = parse('<r xmlns:xx="uri"><b/></r>');
   let child = root2.firstChild;
   child.setAttributeNS('uri', 'name', 'v');
   assert_equals(serialize(root2), '<r xmlns:xx="uri"><b xx:name="v"/></r>');