blob: 6c5e2a0f0a273611ff351c12d87a08710e1ddd67 [file] [log] [blame]
<html>
<head>
<script>
function write(str) {
pre = document.getElementById('console');
text = document.createTextNode(str + '\n');
pre.appendChild(text);
}
function runTests() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
elem = document.createElement('test');
elem.setAttribute('attr_name', 'attr_value');
write("Add an attribute:");
write("");
write(" setAttribute(attr_name)");
write("");
write("The following should be non-empty, true, or non-null.");
write("");
write(" getAttribute(attr_name) = " + elem.getAttribute('attr_name'));
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
write(" getAttributeNode(attr_name) = " + elem.getAttributeNode('attr_name'));
write(" attributes.getNamedItem(attr_name) = " + elem.attributes.getNamedItem('attr_name'));
write("");
write(" getAttributeNS(attr_name) = " + elem.getAttributeNS(null, 'attr_name'));
write(" hasAttributeNS(attr_name) = " + elem.hasAttributeNS(null, 'attr_name'));
write(" getAttributeNodeNS(attr_name) = " + elem.getAttributeNodeNS(null, 'attr_name'));
write(" attributes.getNamedItemNS(attr_name) = " + elem.attributes.getNamedItemNS(null, 'attr_name'));
write("");
write(" getAttribute(ATTR_NAME) = " + elem.getAttribute('ATTR_NAME'));
write(" hasAttribute(ATTR_NAME) = " + elem.hasAttribute('ATTR_NAME'));
write(" getAttributeNode(ATTR_NAME) = " + elem.getAttributeNode('ATTR_NAME'));
write(" attributes.getNamedItem(ATTR_NAME) = " + elem.attributes.getNamedItem('ATTR_NAME'));
write("");
write("The following should be empty, false, or null.");
write("");
write(" getAttributeNS(ATTR_NAME) = " + elem.getAttributeNS(null, 'ATTR_NAME'));
write(" hasAttributeNS(ATTR_NAME) = " + elem.hasAttributeNS(null, 'ATTR_NAME'));
write(" getAttributeNodeNS(ATTR_NAME) = " + elem.getAttributeNodeNS(null, 'ATTR_NAME'));
write(" attributes.getNamedItemNS(ATTR_NAME) = " + elem.attributes.getNamedItemNS(null, 'ATTR_NAME'));
write("");
write("The following should successfully remove the attribute.");
write("");
elem.setAttribute('attr_name', 'attr_value');
elem.removeAttribute('attr_name');
write(" setAttribute(attr_name); removeAttribute(attr_name)")
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
elem.setAttribute('attr_name', 'attr_value');
elem.removeAttributeNS(null, 'attr_name');
write(" setAttribute(attr_name); removeAttributeNS(attr_name)")
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
elem.setAttribute('attr_name', 'attr_value');
elem.attributes.removeNamedItem('attr_name');
write(" setAttribute(attr_name); attributes.removeNamedItem(attr_name)")
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
elem.setAttribute('attr_name', 'attr_value');
elem.attributes.removeNamedItemNS(null, 'attr_name');
write(" setAttribute(attr_name); attributes.removeNamedItemNS(null, attr_name)")
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
write("");
elem.setAttribute('attr_name', 'attr_value');
elem.removeAttribute('ATTR_NAME');
write(" setAttribute(attr_name); removeAttribute(ATTR_NAME)")
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
elem.setAttribute('attr_name', 'attr_value');
elem.attributes.removeNamedItem('ATTR_NAME');
write(" setAttribute(attr_name); attributes.removeNamedItem(ATTR_NAME)")
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
write("");
write("The following should fail to remove the attribute.");
write("");
elem.setAttribute('attr_name', 'attr_value');
elem.removeAttributeNS(null, 'ATTR_NAME');
write(" setAttribute(attr_name); removeAttributeNS(ATTR_NAME)")
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
write("");
write("The following should fail to remove the attribute with an exception.");
write("");
elem.setAttribute('attr_name', 'attr_value');
try {
elem.attributes.removeNamedItemNS(null, 'ATTR_NAME');
write(" attributes.removeNamedItemNS(ATTR_NAME) was expected to raise an exception but did not");
} catch (e) {
write(" attributes.removeNamedItemNS(ATTR_NAME) raised an exception as expected");
}
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
write("");
write("The following should set a lowercase attribute, so the result should be true.");
write("");
elem.setAttributeNS(null, 'attr_name', 'attr_value');
write(" setAttributeNS(attr_name)");
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
elem.removeAttributeNS(null, 'attr_name');
write("");
write("The following should set an uppercase attribute, so the result should be false.");
write("");
elem.setAttributeNS(null, 'ATTR_NAME', 'attr_value');
write(" setAttributeNS(ATTR_NAME)");
write(" hasAttribute(attr_name) = " + elem.hasAttribute('attr_name'));
elem.removeAttributeNS(null, 'ATTR_NAME');
}
</script>
</head>
<body onload="runTests();">
<pre id="console">This test checks whether attribute names with uppercase work properly in HTML documents.
</pre>
</body>
</html>