2 <script src=
"../../resources/js-test.js"></script>
4 description('Tests the serialization of special XML namespaces on attributes, as reported in <a href="http://crbug.com/395950">bug 395950</a>.');
6 var xmlDocument
= (new DOMParser()).parseFromString('<outer />', 'text/xml');
8 var inner1
= xmlDocument
.createElementNS(null, 'inner1');
9 // The xlink's namespace prefix is xlink by default, not auto-generated.
10 inner1
.setAttributeNS('http://www.w3.org/1999/xlink', 'href', 'http://www.google.com');
11 // The xml namespace is automatically bound to the xml prefix, no definition needed.
12 inner1
.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'attr', 'value');
13 xmlDocument
.firstChild
.appendChild(inner1
);
15 var inner2
= xmlDocument
.createElementNS(null, 'inner2');
16 // The xlink's namespace prefix should not be forced to xlink.
17 inner2
.setAttributeNS('http://www.w3.org/1999/xlink', 'xl:href', 'http://www.google.com');
18 // The xml namespace is automatically bound to the xml prefix, no definition needed.
19 inner2
.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:attr', 'value');
20 xmlDocument
.firstChild
.appendChild(inner2
);
22 // Check the DOM construction.
23 shouldBeEqualToString('xmlDocument.querySelector("inner1").getAttributeNS("http://www.w3.org/1999/xlink", "href")', 'http://www.google.com');
24 shouldBeEqualToString('xmlDocument.querySelector("inner1").getAttributeNS("http://www.w3.org/XML/1998/namespace", "attr")', 'value');
25 shouldBeEqualToString('xmlDocument.querySelector("inner2").getAttributeNS("http://www.w3.org/1999/xlink", "href")', 'http://www.google.com');
26 shouldBeEqualToString('xmlDocument.querySelector("inner2").getAttribute("xl:href")', 'http://www.google.com');
27 shouldBeEqualToString('xmlDocument.querySelector("inner2").getAttributeNS("http://www.w3.org/XML/1998/namespace", "attr")', 'value');
28 shouldBeEqualToString('xmlDocument.querySelector("inner2").getAttribute("xml:attr")', 'value');
30 var xmlString
= (new XMLSerializer()).serializeToString(xmlDocument
);
32 // Check the serialization result.
33 var parsedDoc
= (new DOMParser()).parseFromString(xmlString
, 'text/xml');
34 shouldBeEqualToString('parsedDoc.querySelector("inner1").getAttributeNS("http://www.w3.org/1999/xlink", "href")', 'http://www.google.com');
35 shouldBeEqualToString('parsedDoc.querySelector("inner1").getAttributeNS("http://www.w3.org/XML/1998/namespace", "attr")', 'value');
36 shouldBeEqualToString('parsedDoc.querySelector("inner2").getAttributeNS("http://www.w3.org/1999/xlink", "href")', 'http://www.google.com');
37 shouldBeEqualToString('parsedDoc.querySelector("inner2").getAttribute("xl:href")', 'http://www.google.com');
38 shouldBeEqualToString('parsedDoc.querySelector("inner2").getAttributeNS("http://www.w3.org/XML/1998/namespace", "attr")', 'value');
39 shouldBeEqualToString('parsedDoc.querySelector("inner2").getAttribute("xml:attr")', 'value');
41 // Check that the correct xmlns definitions were emitted.
42 shouldBeEqualToNumber('xmlString.indexOf("xmlns:xml")', -1);
43 shouldNotBe('xmlString.indexOf("xmlns:xlink")', '-1');
44 shouldNotBe('xmlString.indexOf("xmlns:xl")', '-1');