<!DOCTYPE html>
<title>Tests the serialization of special XML namespaces on attributes, as reported in http://crbug.com/395950, bug 395950</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
var xmlDocument = (new DOMParser()).parseFromString('<outer />', 'text/xml');
var inner1 = xmlDocument.createElementNS(null, 'inner1');
// The xml namespace is automatically bound to the xml prefix, no definition needed.
inner1.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'attr', 'value');
xmlDocument.firstChild.appendChild(inner1);
var inner2 = xmlDocument.createElementNS(null, 'inner2');
// The xml namespace is automatically bound to the xml prefix, no definition needed.
inner2.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:attr', 'value');
xmlDocument.firstChild.appendChild(inner2);
// Check the DOM construction.
assert_equals(xmlDocument.querySelector("inner1").getAttributeNS("http://www.w3.org/XML/1998/namespace", "attr"), 'value');
assert_equals(xmlDocument.querySelector("inner2").getAttributeNS("http://www.w3.org/XML/1998/namespace", "attr"), 'value');
assert_equals(xmlDocument.querySelector("inner2").getAttribute("xml:attr"), 'value');
var xmlString = (new XMLSerializer()).serializeToString(xmlDocument);
// Check the serialization result.
var parsedDoc = (new DOMParser()).parseFromString(xmlString, 'text/xml');
assert_equals(parsedDoc.querySelector("inner1").getAttributeNS("http://www.w3.org/XML/1998/namespace", "attr"), 'value');
assert_equals(parsedDoc.querySelector("inner2").getAttributeNS("http://www.w3.org/XML/1998/namespace", "attr"), 'value');
assert_equals(parsedDoc.querySelector("inner2").getAttribute("xml:attr"), 'value');
// Check that the correct xmlns definitions were emitted.
assert_equals(xmlString.indexOf("xmlns:xml"), -1);
done();
</script>