107 lines
3.4 KiB
HTML
107 lines
3.4 KiB
HTML
<html>
|
|
<head>
|
|
<script>
|
|
function debug(str) {
|
|
var c = document.getElementById('console')
|
|
c.appendChild(document.createTextNode(str + '\n'));
|
|
}
|
|
|
|
function print(message, color)
|
|
{
|
|
var paragraph = document.createElement("div");
|
|
paragraph.appendChild(document.createTextNode(message));
|
|
paragraph.style.fontFamily = "monospace";
|
|
if (color)
|
|
paragraph.style.color = color;
|
|
document.getElementById("console").appendChild(paragraph);
|
|
}
|
|
|
|
var element, range, nodeFilter, cssRule, cssPrimitiveValue, cssStyleDeclaration, event;
|
|
var originalNodeConstructor;
|
|
|
|
function shouldBe(a, b)
|
|
{
|
|
var evalA;
|
|
try {
|
|
evalA = eval(a);
|
|
} catch(e) {
|
|
evalA = e;
|
|
}
|
|
if (evalA == b)
|
|
print("PASS: " + a + " should be " + b + " and is.", "green");
|
|
else
|
|
print("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
|
|
}
|
|
|
|
function runTests() {
|
|
if (window.testRunner)
|
|
testRunner.dumpAsText();
|
|
|
|
var src = '<root xmlns:foo="http://www.example.com" attr="test2" foo:attr="test" />';
|
|
var doc = (new DOMParser()).parseFromString(src, 'text/xml')
|
|
docElem = doc.documentElement;
|
|
|
|
// Test getAttribute
|
|
shouldBe("docElem.getAttribute('foo:attr')", "test");
|
|
shouldBe("docElem.getAttribute('attr')", "test2");
|
|
shouldBe("docElem.getAttribute('bar:attr')", null)
|
|
|
|
// Test hasAttribute
|
|
shouldBe("docElem.hasAttribute('foo:attr')", true);
|
|
shouldBe("docElem.hasAttribute('attr')", true);
|
|
shouldBe("docElem.hasAttribute('bar:attr')", false);
|
|
|
|
// Test getAttributeNode
|
|
shouldBe("docElem.getAttributeNode('foo:attr').value", "test");
|
|
shouldBe("docElem.getAttributeNode('bar:attr')", null);
|
|
|
|
// Test setAttribute
|
|
shouldBe("docElem.attributes.length", 3);
|
|
docElem.setAttribute("foo:attr", "new");
|
|
shouldBe("docElem.attributes.length", 3);
|
|
shouldBe("docElem.getAttribute('foo:attr')", "new");
|
|
|
|
docElem.setAttribute("bar:attr", "new2");
|
|
shouldBe("docElem.attributes.length", 4);
|
|
shouldBe("docElem.getAttribute('bar:attr')", "new2");
|
|
shouldBe("docElem.getAttributeNode('bar:attr').prefix", null);
|
|
shouldBe("docElem.getAttributeNode('bar:attr').localName", "bar:attr");
|
|
|
|
// Test removeAttribute
|
|
docElem.removeAttribute('foo:attr');
|
|
shouldBe("docElem.getAttribute('foo:attr')", null);
|
|
shouldBe("docElem.attributes.length", 3);
|
|
docElem.removeAttribute('bar:attr');
|
|
shouldBe("docElem.getAttribute('bar:attr')", null);
|
|
shouldBe("docElem.attributes.length", 2);
|
|
docElem.removeAttribute('attr');
|
|
shouldBe("docElem.getAttribute('attr')", null);
|
|
shouldBe("docElem.attributes.length", 1);
|
|
|
|
// Re-parse the document so we can test NamedNodeMap
|
|
doc = (new DOMParser()).parseFromString(src, 'text/xml');
|
|
attributes = doc.documentElement.attributes;
|
|
|
|
// Test getNamedItem
|
|
shouldBe("attributes.getNamedItem('foo:attr').value", "test");
|
|
shouldBe("attributes.getNamedItem('attr').value", "test2");
|
|
shouldBe("attributes.getNamedItem('bar:attr')", null);
|
|
|
|
// Test removeNamedItem
|
|
shouldBe("attributes.length", 3);
|
|
attributes.removeNamedItem('foo:attr');
|
|
shouldBe("attributes.getNamedItem('foo:attr')", null);
|
|
shouldBe("attributes.length", 2);
|
|
attributes.removeNamedItem('attr');
|
|
shouldBe("attributes.getNamedItem('attr')", null);
|
|
shouldBe("attributes.length", 1);
|
|
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body onload="runTests();">
|
|
<pre id="console">
|
|
</pre>
|
|
</body>
|
|
</html> |