2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / LayoutTests / fast / dom / attribute-namespaces-get-set.html
blob193f9bab83636c106e34616f973b797e1565151b
1 <html>
2 <head>
3 <script>
4 function debug(str) {
5 var c = document.getElementById('console')
6 c.appendChild(document.createTextNode(str + '\n'));
9 function print(message, color)
11 var paragraph = document.createElement("div");
12 paragraph.appendChild(document.createTextNode(message));
13 paragraph.style.fontFamily = "monospace";
14 if (color)
15 paragraph.style.color = color;
16 document.getElementById("console").appendChild(paragraph);
19 var element, range, nodeFilter, cssRule, cssPrimitiveValue, cssStyleDeclaration, event;
20 var originalNodeConstructor;
22 function shouldBe(a, b)
24 var evalA;
25 try {
26 evalA = eval(a);
27 } catch(e) {
28 evalA = e;
30 if (evalA == b)
31 print("PASS: " + a + " should be " + b + " and is.", "green");
32 else
33 print("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
36 function runTests() {
37 if (window.layoutTestController)
38 layoutTestController.dumpAsText();
40 var src = '<root xmlns:foo="http://www.example.com" attr="test2" foo:attr="test" />';
41 var doc = (new DOMParser()).parseFromString(src, 'text/xml')
42 docElem = doc.documentElement;
44 // Test getAttribute
45 shouldBe("docElem.getAttribute('foo:attr')", "test");
46 shouldBe("docElem.getAttribute('attr')", "test2");
47 shouldBe("docElem.getAttribute('bar:attr')", null)
49 // Test hasAttribute
50 shouldBe("docElem.hasAttribute('foo:attr')", true);
51 shouldBe("docElem.hasAttribute('attr')", true);
52 shouldBe("docElem.hasAttribute('bar:attr')", false);
54 // Test getAttributeNode
55 shouldBe("docElem.getAttributeNode('foo:attr').value", "test");
56 shouldBe("docElem.getAttributeNode('bar:attr')", null);
58 // Test setAttribute
59 shouldBe("docElem.attributes.length", 3);
60 docElem.setAttribute("foo:attr", "new");
61 shouldBe("docElem.attributes.length", 3);
62 shouldBe("docElem.getAttribute('foo:attr')", "new");
64 docElem.setAttribute("bar:attr", "new2");
65 shouldBe("docElem.attributes.length", 4);
66 shouldBe("docElem.getAttribute('bar:attr')", "new2");
67 shouldBe("docElem.getAttributeNode('bar:attr').prefix", null);
68 shouldBe("docElem.getAttributeNode('bar:attr').localName", "bar:attr");
70 // Test removeAttribute
71 docElem.removeAttribute('foo:attr');
72 shouldBe("docElem.getAttribute('foo:attr')", null);
73 shouldBe("docElem.attributes.length", 3);
74 docElem.removeAttribute('bar:attr');
75 shouldBe("docElem.getAttribute('bar:attr')", null);
76 shouldBe("docElem.attributes.length", 2);
77 docElem.removeAttribute('attr');
78 shouldBe("docElem.getAttribute('attr')", null);
79 shouldBe("docElem.attributes.length", 1);
81 // Re-parse the document so we can test NamedNodeMap
82 doc = (new DOMParser()).parseFromString(src, 'text/xml');
83 attributes = doc.documentElement.attributes;
85 // Test getNamedItem
86 shouldBe("attributes.getNamedItem('foo:attr').value", "test");
87 shouldBe("attributes.getNamedItem('attr').value", "test2");
88 shouldBe("attributes.getNamedItem('bar:attr')", null);
90 // Test removeNamedItem
91 shouldBe("attributes.length", 3);
92 attributes.removeNamedItem('foo:attr');
93 shouldBe("attributes.getNamedItem('foo:attr')", null);
94 shouldBe("attributes.length", 2);
95 attributes.removeNamedItem('attr');
96 shouldBe("attributes.getNamedItem('attr')", null);
97 shouldBe("attributes.length", 1);
101 </script>
102 </head>
103 <body onload="runTests();">
104 <pre id="console">
105 </pre>
106 </body>
107 </html>