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";
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
)
31 print("PASS: " + a
+ " should be " + b
+ " and is.", "green");
33 print("FAIL: " + a
+ " should be " + b
+ " but instead is " + evalA
, "red");
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
;
45 shouldBe("docElem.getAttribute('foo:attr')", "test");
46 shouldBe("docElem.getAttribute('attr')", "test2");
47 shouldBe("docElem.getAttribute('bar:attr')", null)
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);
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
;
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);
103 <body onload=
"runTests();">