Bug 1527283 [wpt PR 15340] - XMLSerializer: Fix prefixed attribute serialization, a=testonly
authorKent Tamura <tkent@chromium.org>
Tue, 19 Feb 2019 14:39:29 +0000
changeset 519250 4fce8beb3c9e5c1ff467c988cdc2cf379d99355c
parent 519249 d20202f2766ffb670cc9e55d0a1a17d4813b5925
child 519251 8196d285222a5994380b23d9887dca0d38c2efd1
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1527283, 15340, 929035, 1460643, 631058
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 1527283 [wpt PR 15340] - XMLSerializer: Fix prefixed attribute serialization, a=testonly Automatic update from web-platform-tests XMLSerializer: Fix prefixed attribute serialization ... in a case where its owner element has xmlns:prefix of which prefix is same as the attribute and namespace is not same as the attribute. e.g. el.setAttributeNS("uri1", "p:n", "v"); el.setAttributeNS(XMLNS_URI, "xmlns:p", "uri2"); ShouldAddNamespaceAttribute() checked only existence of xmlns:prefix in the element, but we should check existence of (prefix, namespace URI) pair in the scope according to the specification. So, this CL adds 'recording the namespace information' step [1] defined by the specification, and ShouldAddNamespaceAttribute() checks all available prefixes in the scope. [1] https://w3c.github.io/DOM-Parsing/#recording-the-namespace Bug: 929035 Change-Id: I575e8f652ae45f7583202443cc72d5afe5faf59d Reviewed-on: https://chromium-review.googlesource.com/c/1460643 Reviewed-by: Yoshifumi Inoue <yosin@chromium.org> Commit-Queue: Kent Tamura <tkent@chromium.org> Cr-Commit-Position: refs/heads/master@{#631058} -- wpt-commits: 265330b7d26194cb60157a18ac399127d21f6b99 wpt-pr: 15340
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
@@ -51,16 +51,32 @@ test(function() {
   assert_in_array(serializer.serializeToString(root), [
     '<root attr="&#xA;"/>', '<root attr="&#10;"/>']);
   root.setAttribute('attr', '\r');
   assert_in_array(serializer.serializeToString(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"/>');
+}, '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;
+  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() {
   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}".');