Bug 1528722 [wpt PR 15410] - domparsing: Apply parse(), serialize(), and XMLNS_URI, a=testonly
authorKent Tamura <tkent@chromium.org>
Tue, 05 Mar 2019 12:15:33 +0000
changeset 522450 d04acd61397bb9e78d0397294931e47d758d7fcf
parent 522449 d1afd891ac348c1df050feb96de8b67419b34a72
child 522451 289af7fabdef4962814a42983c5a1f88710fcaee
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)
reviewerstestonly
bugs1528722, 15410, 1475021, 632528
milestone67.0a1
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 1528722 [wpt PR 15410] - domparsing: Apply parse(), serialize(), and XMLNS_URI, a=testonly Automatic update from web-platform-tests domparsing: Apply parse(), serialize(), and XMLNS_URI This change has no behavior changes. Change-Id: I4618f6d5afb5d0b269c18d4cff7901913558f739 Reviewed-on: https://chromium-review.googlesource.com/c/1475021 Commit-Queue: Yoshifumi Inoue <yosin@chromium.org> Auto-Submit: Kent Tamura <tkent@chromium.org> Reviewed-by: Yoshifumi Inoue <yosin@chromium.org> Cr-Commit-Position: refs/heads/master@{#632528} -- wpt-commits: 4a90b84e984bcd83978317b86031ed4e4aa8600e wpt-pr: 15410
testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
--- a/testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
+++ b/testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
@@ -22,38 +22,32 @@ function parse(xmlString) {
   return (new DOMParser()).parseFromString(xmlString, 'text/xml').documentElement;
 }
 
 function serialize(node) {
   return (new XMLSerializer()).serializeToString(node);
 }
 
 test(function() {
-  var serializer = new XMLSerializer();
   var root = createXmlDoc().documentElement;
-  var xmlString = serializer.serializeToString(root);
-  assert_equals(xmlString, '<root><child1>value1</child1></root>');
+  assert_equals(serialize(root), '<root><child1>value1</child1></root>');
 }, 'check XMLSerializer.serializeToString method could parsing xmldoc to string');
 
 test(function() {
-  var serializer = new XMLSerializer();
   var root = createXmlDoc().documentElement;
   var element = root.ownerDocument.createElementNS('urn:foo', 'another');
   var child1 = root.firstChild;
   root.replaceChild(element, child1);
   element.appendChild(child1);
-  var xmlString = serializer.serializeToString(root);
-  assert_equals(xmlString, '<root><another xmlns="urn:foo"><child1 xmlns="">value1</child1></another></root>');
+  assert_equals(serialize(root), '<root><another xmlns="urn:foo"><child1 xmlns="">value1</child1></another></root>');
 }, 'Check if the default namespace is correctly reset.');
 
 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>');
+  var root = parse('<root xmlns="urn:bar"><outer xmlns=""><inner>value1</inner></outer></root>');
+  assert_equals(serialize(root), '<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');
@@ -119,44 +113,39 @@ test(function() {
 test(function() {
   let root = parse('<r xmlns:xx="uri"></r>');
   root.setAttributeNS('uri2', 'xx:name', 'value');
   assert_equals(serialize(root),
                 '<r xmlns:xx="uri" xmlns:ns1="uri2" ns1:name="value"/>');
 }, 'Check if the prefix of an attribute is replaced with a generated one in a case where the prefix is already mapped to a different namespace URI.');
 
 test(function() {
-  var serializer = new XMLSerializer();
-  var parser = new DOMParser();
-  var root = parser.parseFromString('<root />', 'text/xml').documentElement;
+  var root = parse('<root />');
   root.setAttribute('attr', '\t');
-  assert_in_array(serializer.serializeToString(root), [
+  assert_in_array(serialize(root), [
     '<root attr="&#9;"/>', '<root attr="&#x9;"/>']);
   root.setAttribute('attr', '\n');
-  assert_in_array(serializer.serializeToString(root), [
+  assert_in_array(serialize(root), [
     '<root attr="&#xA;"/>', '<root attr="&#10;"/>']);
   root.setAttribute('attr', '\r');
-  assert_in_array(serializer.serializeToString(root), [
+  assert_in_array(serialize(root), [
     '<root attr="&#xD;"/>', '<root attr="&#13;"/>']);
 }, 'check XMLSerializer.serializeToString escapes attribute values for roundtripping');
 
 test(function() {
   const root = (new Document()).createElement('root');
   root.setAttributeNS('uri1', 'p:foobar', 'value1');
-  root.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:p', 'uri2');
-  const xmlString = (new XMLSerializer()).serializeToString(root);
-  assert_equals(xmlString, '<root xmlns:ns1="uri1" ns1:foobar="value1" xmlns:p="uri2"/>');
+  root.setAttributeNS(XMLNS_URI, 'xmlns:p', 'uri2');
+  assert_equals(serialize(root), '<root xmlns:ns1="uri1" ns1:foobar="value1" xmlns:p="uri2"/>');
 }, 'Check if attribute serialization takes into account of following xmlns:* attributes');
 
 test(function() {
-  const input = '<root xmlns:p="uri1"><child/></root>';
-  const root = (new DOMParser()).parseFromString(input, 'text/xml').documentElement;
+  const root = parse('<root xmlns:p="uri1"><child/></root>');
   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>');
+  assert_equals(serialize(root), '<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.');
@@ -171,40 +160,36 @@ test(function() {
 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');
+  root.setAttributeNS(XMLNS_URI, '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;
+  const root = parse('<root><child1/><child2/></root>');
   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>');
+  assert_equals(serialize(root), '<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}".');
 
 test(function() {
-  const input = '<root xmlns:ns2="uri2"><child xmlns:ns1="uri1"/></root>';
-  const root = (new DOMParser()).parseFromString(input, 'text/xml').documentElement;
+  const root = parse('<root xmlns:ns2="uri2"><child xmlns:ns1="uri1"/></root>');
   root.firstChild.setAttributeNS('uri3', 'attr1', 'value1');
-  const xmlString = (new XMLSerializer()).serializeToString(root);
   // According to 'DOM Parsing and Serialization' draft as of 2018-12-11,
   // 'generate a prefix' result can conflict with an existing xmlns:ns* declaration.
-  assert_equals(xmlString, '<root xmlns:ns2="uri2"><child xmlns:ns1="uri1" xmlns:ns1="uri3" ns1:attr1="value1"/></root>');
+  assert_equals(serialize(root), '<root xmlns:ns2="uri2"><child xmlns:ns1="uri1" xmlns:ns1="uri3" ns1:attr1="value1"/></root>');
 }, 'Check if "ns1" is generated even if the element already has xmlns:ns1.');
 
 test(function() {
   const root = (new Document()).createElement('root');
   root.setAttributeNS('http://www.w3.org/1999/xlink', 'href', 'v');
   assert_equals(serialize(root), '<root xmlns:ns1="http://www.w3.org/1999/xlink" ns1:href="v"/>');
 
   const root2 = (new Document()).createElement('root');