Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / XMLSerializer-attribute-namespaces.html
blobbe727ee16e1e12d84ef30469d50cfd66cfe6c65d
1 <!DOCTYPE html>
2 <script src="../../resources/js-test.js"></script>
3 <script>
4 description('Tests the serialization of XML namespaces on attributes, as reported in <a href="http://crbug.com/248044">bug 248044</a>.');
5 window.doc = (new DOMParser()).parseFromString('<outer attr1="value1" xmlns="http://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 confuse 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 xmlns 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 serialization.
16 doc.documentElement.setAttributeNS('http://www.example.com/ns2', 'prefix2:name', 'value');
17 doc.documentElement.setAttributeNS('http://www.example.com/ns2', 'name2', 'value2');
18 // Namespace declaration for the prefix1:fizz attribute.
19 doc.documentElement.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:prefix1', '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');
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", "fizz2")', '"buzz2"');
32 shouldBe('doc.documentElement.getAttributeNS("http://www.example.com/ns2", "name")', '"value"');
33 shouldBe('doc.documentElement.getAttributeNS("http://www.example.com/ns2", "name2")', '"value2"');
34 shouldBe('doc.documentElement.getAttributeNS("http://www.w3.org/XML/1998/namespace", "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"');
39 window.xmlText = (new XMLSerializer()).serializeToString(doc); // exported for debugging
40 window.parsedDoc = (new DOMParser()).parseFromString(xmlText, 'text/xml');
42 // Check the serialization result.
43 shouldBe('parsedDoc.documentElement.getAttributeNS(null, "attr1")', '"value1"');
44 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.example.com", "foo")', '"bar"');
45 shouldBe('parsedDoc.documentElement.getAttributeNS("http://www.example.com", "foo2")', '"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/namespace", "id")', '"outer"');
51 shouldBe('parsedDoc.querySelector("inner").localName', '"inner"');
52 shouldBe('parsedDoc.querySelector("inner").namespaceURI', '"http://www.example.com"');
53 shouldBe('parsedDoc.querySelector("inner").getAttributeNS(null, "id")', '"inner"');
54 </script>