mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Update web-platform-tests to revision ad219567030d1f99f7310f52a17546b57b70d29e
This commit is contained in:
parent
2c63d1296b
commit
a7e62acbe8
129 changed files with 4156 additions and 590 deletions
|
@ -9,12 +9,23 @@
|
|||
<body>
|
||||
<h1>domparsing_XMLSerializer_serializeToString</h1>
|
||||
<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) {
|
||||
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;
|
||||
|
@ -40,6 +51,78 @@ test(function() {
|
|||
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>');
|
||||
|
||||
let root3 = parse('<r xmlns:x0="uri" xmlns:x2="uri"><b xmlns:x1="uri"/></r>');
|
||||
let child3 = root3.firstChild;
|
||||
child3.setAttributeNS('uri', 'name', 'v');
|
||||
assert_equals(serialize(root3),
|
||||
'<r xmlns:x0="uri" xmlns:x2="uri"><b xmlns:x1="uri" x1:name="v"/></r>',
|
||||
'Should choose the nearest prefix');
|
||||
}, 'Check if an attribute with namespace and no prefix is serialized with the nearest-declared prefix');
|
||||
|
||||
test(function() {
|
||||
let root = parse('<el1 xmlns:p="u1" xmlns:q="u1"><el2 xmlns:q="u2"/></el1>');
|
||||
root.firstChild.setAttributeNS('u1', 'name', 'v');
|
||||
assert_equals(serialize(root),
|
||||
'<el1 xmlns:p="u1" xmlns:q="u1"><el2 xmlns:q="u2" q:name="v"/></el1>');
|
||||
// Maybe this is a specification error.
|
||||
}, 'Check if an attribute with namespace and no prefix is serialized with the nearest-declared prefix even if the prefix is assigned to another namespace.');
|
||||
|
||||
test(function() {
|
||||
let root = parse('<r xmlns:xx="uri"></r>');
|
||||
root.setAttributeNS('uri', 'p: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', 'p:name', 'value');
|
||||
assert_equals(serialize(root2),
|
||||
'<r xmlns:xx="uri"><b xx:name="value"/></r>');
|
||||
}, 'Check if the prefix of an attribute is replaced with another existing prefix mapped to the same namespace URI.');
|
||||
|
||||
test(function() {
|
||||
let root = parse('<r xmlns:xx="uri"></r>');
|
||||
root.setAttributeNS('uri2', 'p:name', 'value');
|
||||
assert_equals(serialize(root),
|
||||
'<r xmlns:xx="uri" xmlns:ns1="uri2" ns1:name="value"/>');
|
||||
}, 'Check if the prefix of an attribute is NOT preserved in a case where neither its prefix nor its namespace URI is not already used.');
|
||||
|
||||
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();
|
||||
|
@ -91,6 +174,16 @@ test(function() {
|
|||
assert_equals(xmlString, '<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');
|
||||
root2.setAttributeNS('http://www.w3.org/1999/xlink', 'xl:type', 'v');
|
||||
assert_equals(serialize(root2), '<root xmlns:xl="http://www.w3.org/1999/xlink" xl:type="v"/>');
|
||||
}, 'Check if no special handling for XLink namespace unlike HTML serializer.');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue