mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 12:15:33 +00:00
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
This commit is contained in:
parent
d82606141d
commit
525e1e2878
@ -27,28 +27,22 @@ function serialize(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() {
|
||||
@ -124,34 +118,29 @@ test(function() {
|
||||
}, '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="	"/>', '<root attr="	"/>']);
|
||||
root.setAttribute('attr', '\n');
|
||||
assert_in_array(serializer.serializeToString(root), [
|
||||
assert_in_array(serialize(root), [
|
||||
'<root attr="
"/>', '<root attr=" "/>']);
|
||||
root.setAttribute('attr', '\r');
|
||||
assert_in_array(serializer.serializeToString(root), [
|
||||
assert_in_array(serialize(root), [
|
||||
'<root attr="
"/>', '<root attr=" "/>']);
|
||||
}, '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() {
|
||||
@ -176,30 +165,26 @@ test(function() {
|
||||
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user