| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../resources/js-test.js"></script> | |
| 3 <script> | |
| 4 description('Tests the serialization of XML namespaces on attributes, as reporte
d in <a href="http://crbug.com/248044">bug 248044</a>.'); | |
| 5 window.doc = (new DOMParser()).parseFromString('<outer attr1="value1" xmlns="htt
p://www.example.com"/>', 'text/xml'); | |
| 6 // XML-namespaced attributes should get the "xml" prefix. | |
| 7 doc.documentElement.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'id',
'outer'); | |
| 8 // Attributes with the same namespace as the element should get a prefix. | |
| 9 doc.documentElement.setAttributeNS('http://www.example.com', 'foo', 'bar'); | |
| 10 doc.documentElement.setAttributeNS('http://www.example.com', 'foo2', 'bar2'); | |
| 11 // Two attributes with the same namespace and different prefixes shouldn't confu
se the serializer. | |
| 12 doc.documentElement.setAttributeNS('http://www.example.com/ns1', 'fizz', 'buzz')
; | |
| 13 // A prefix declared in an xmlns attribute (coming soon) shouldn't get another x
mlns attribute. | |
| 14 doc.documentElement.setAttributeNS('http://www.example.com/ns1', 'prefix1:fizz2'
, 'buzz2'); | |
| 15 // A prefix without a matching xmlns attribute should get one during serializati
on. | |
| 16 doc.documentElement.setAttributeNS('http://www.example.com/ns2', 'prefix2:name',
'value'); | |
| 17 doc.documentElement.setAttributeNS('http://www.example.com/ns2', 'name2', 'value
2'); | |
| 18 // Namespace declaration for the prefix1:fizz attribute. | |
| 19 doc.documentElement.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:prefi
x1', 'http://www.example.com/ns1'); | |
| 20 // Element with the same namespace as the parent. | |
| 21 var innerElement = doc.createElementNS("http://www.example.com", 'inner'); | |
| 22 doc.documentElement.appendChild(innerElement); | |
| 23 // An attribute with no namespace doesn't need a prefix. | |
| 24 innerElement.setAttributeNS(null, 'id', 'inner'); | |
| 25 | |
| 26 // Check the DOM construction. | |
| 27 shouldBe('doc.documentElement.getAttributeNS(null, "attr1")', '"value1"'); | |
| 28 shouldBe('doc.documentElement.getAttributeNS("http://www.example.com", "foo")',
'"bar"'); | |
| 29 shouldBe('doc.documentElement.getAttributeNS("http://www.example.com", "foo2")',
'"bar2"'); | |
| 30 shouldBe('doc.documentElement.getAttributeNS("http://www.example.com/ns1", "fizz
")', '"buzz"'); | |
| 31 shouldBe('doc.documentElement.getAttributeNS("http://www.example.com/ns1", "fizz
2")', '"buzz2"'); | |
| 32 shouldBe('doc.documentElement.getAttributeNS("http://www.example.com/ns2", "name
")', '"value"'); | |
| 33 shouldBe('doc.documentElement.getAttributeNS("http://www.example.com/ns2", "name
2")', '"value2"'); | |
| 34 shouldBe('doc.documentElement.getAttributeNS("http://www.w3.org/XML/1998/namespa
ce", "id")', '"outer"'); | |
| 35 shouldBe('doc.querySelector("inner").localName', '"inner"'); | |
| 36 shouldBe('doc.querySelector("inner").namespaceURI', '"http://www.example.com"'); | |
| 37 shouldBe('doc.querySelector("inner").getAttributeNS(null, "id")', '"inner"'); | |
| 38 | |
| 39 window.xmlText = (new XMLSerializer()).serializeToString(doc); // exported for d
ebugging | |
| 40 window.parsedDoc = (new DOMParser()).parseFromString(xmlText, 'text/xml'); | |
| 41 | |
| 42 // Check the serialization result. | |
| 43 shouldBe('parsedDoc.documentElement.getAttributeNS(null, "attr1")', '"value1"'); | |
| 44 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.example.com", "fo
o")', '"bar"'); | |
| 45 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.example.com", "fo
o2")', '"bar2"'); | |
| 46 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.example.com/ns1",
"fizz")', '"buzz"'); | |
| 47 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.example.com/ns1",
"fizz2")', '"buzz2"'); | |
| 48 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.example.com/ns2",
"name")', '"value"'); | |
| 49 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.example.com/ns2",
"name2")', '"value2"'); | |
| 50 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.w3.org/XML/1998/n
amespace", "id")', '"outer"'); | |
| 51 shouldBe('parsedDoc.querySelector("inner").localName', '"inner"'); | |
| 52 shouldBe('parsedDoc.querySelector("inner").namespaceURI', '"http://www.example.c
om"'); | |
| 53 shouldBe('parsedDoc.querySelector("inner").getAttributeNS(null, "id")', '"inner"
'); | |
| 54 </script> | |
| OLD | NEW |