blob: a8b62eb184d9937c2da647ce81a10d6671806843 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>Attr empty value tests</title>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
}
function isReallyEmpty(attr) {
return attr.value === ""
&& attr.nodeValue === ""
&& attr.textContent === ""
&& attr.hasChildNodes() === false
&& attr.firstChild === null
&& attr.lastChild === null
&& attr.childNodes.length === 0;
}
window.onload = function() {
var tests = [];
var dynamicAttr = document.createAttribute("foo");
tests[0] = isReallyEmpty(dynamicAttr);
dynamicAttr.value = "";
tests[1] = isReallyEmpty(dynamicAttr);
dynamicAttr.value = "bar";
dynamicAttr.value = "";
tests[2] = isReallyEmpty(dynamicAttr);
dynamicAttr.textContent = "bar";
dynamicAttr.textContent = "";
tests[3] = isReallyEmpty(dynamicAttr);
var parsedAttr = document.body.getAttributeNode("id");
tests[4] = isReallyEmpty(parsedAttr);
parsedAttr.value = "";
tests[5] = isReallyEmpty(parsedAttr);
parsedAttr.value = "bar";
parsedAttr.value = "";
tests[6] = isReallyEmpty(parsedAttr);
parsedAttr.textContent = "bar";
parsedAttr.textContent = "";
tests[7] = isReallyEmpty(parsedAttr);
var parsedAttrIntitiallyNonEmpty = document.body.getAttributeNode("class");
parsedAttrIntitiallyNonEmpty.value = "";
tests[8] = isReallyEmpty(parsedAttrIntitiallyNonEmpty);
parsedAttrIntitiallyNonEmpty.textContent = "bar";
parsedAttrIntitiallyNonEmpty.textContent = "";
tests[9] = isReallyEmpty(parsedAttrIntitiallyNonEmpty);
document.body.setAttribute("title", "");
var parsedAttrNodeChangedToEmptyBySetAttribute = document.body.getAttributeNode("title");
tests[10] = isReallyEmpty(parsedAttrNodeChangedToEmptyBySetAttribute);
parsedAttrNodeChangedToEmptyBySetAttribute.textContent = "bar";
parsedAttrNodeChangedToEmptyBySetAttribute.textContent = "";
tests[11] = isReallyEmpty(parsedAttrNodeChangedToEmptyBySetAttribute);
var results = document.getElementsByTagName("p")[1];
while (results.hasChildNodes()) {
results.removeChild(results.lastChild);
}
for (var i = 0; i < tests.length; ++i) {
var pass = tests[i] ? "PASS" : "FAIL";
results.appendChild(document.createTextNode("SubTest " + (i + 1) + " = " + pass));
results.appendChild(document.createElement("br"));
}
var completely = "PASS";
for (var i = 0; i < tests.length; ++i) {
if (tests[i] === false) {
completely = "FAIL";
break;
}
}
results.appendChild(document.createTextNode("Complete Test = " + completely));
};
</script>
</head>
<body id="" class="test" title="test">
<h1>Attr empty value tests <a href="https://bugs.webkit.org/show_bug.cgi?id=16923">Bug 16923</a></h1>
<p>In Opera, Firefox and IE, when an Attr's value is an empty string, the Attr node won't have any childNodes. The following 12 tests will see if this is true for WebKit for both parsed and dynamically-created Attr nodes. The tests use multiple methods of changing the Attr's value and even test reverting from a non-empty value to an empty one to check that all childNodes were removed. Some of the tests make use of .textContent, so this test is not compatible with IE. Opera and Firefox both completely pass this test.</p>
<p>This test requires Javascript.</p>
</body>
</html>