Commit 248f5a13 authored by ap@webkit.org's avatar ap@webkit.org

2008-05-14 Michael A. Puls II <shadow2531@gmail.com>

        Reviewed by Alexey.

        Fix for https://bugs.webkit.org/show_bug.cgi?id=16923 
        Attr nodes with a value of "" should not have any childNodes
        
        In Opera, Firefox and IE, when an attribute node has a value
        of "", the attribute node doesn't have any childNodes. This
        is true in WebKit also, but not when you assign "" to the
        Attr's value when the existing value is non-empty.
        
        Test: fast/dom/attribute-empty-value-no-children.html

        * dom/Attr.cpp: (WebCore::Attr::setValue): Use createTextChild(), which only appends
        a child text node if the value being assigned is not empty.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33442 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 660eccc3
2008-05-14 Michael A. Puls II <shadow2531@gmail.com>
Reviewed by Alexey.
Test for https://bugs.webkit.org/show_bug.cgi?id=16923
Test that Attr nodes with a value of "" don't have any
childNodes like Firefox, Opera and IE.
* fast/dom/attribute-empty-value-no-children-expected.txt: Added.
* fast/dom/attribute-empty-value-no-children.html: Added.
2008-05-13 Dan Bernstein <mitz@apple.com>
Reviewed by John Sullivan.
Attr empty value tests Bug 16923
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.
SubTest 1 = PASS
SubTest 2 = PASS
SubTest 3 = PASS
SubTest 4 = PASS
SubTest 5 = PASS
SubTest 6 = PASS
SubTest 7 = PASS
SubTest 8 = PASS
SubTest 9 = PASS
SubTest 10 = PASS
SubTest 11 = PASS
SubTest 12 = PASS
Complete Test = PASS
<!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>
2008-05-14 Michael A. Puls II <shadow2531@gmail.com>
Reviewed by Alexey.
Fix for https://bugs.webkit.org/show_bug.cgi?id=16923
Attr nodes with a value of "" should not have any childNodes
In Opera, Firefox and IE, when an attribute node has a value
of "", the attribute node doesn't have any childNodes. This
is true in WebKit also, but not when you assign "" to the
Attr's value when the existing value is non-empty.
Test: fast/dom/attribute-empty-value-no-children.html
* dom/Attr.cpp: (WebCore::Attr::setValue): Use createTextChild(), which only appends
a child text node if the value being assigned is not empty.
2008-05-14 Julien Chaffraix <jchaffraix@webkit.org>
Reviewed by Eric.
......@@ -105,7 +105,7 @@ void Attr::setValue( const String& v, ExceptionCode& ec)
{
ec = 0;
// do not interprete entities in the string, its literal!
// do not interpret entities in the string, it's literal!
// NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
if (isReadOnlyNode()) {
......@@ -113,13 +113,12 @@ void Attr::setValue( const String& v, ExceptionCode& ec)
return;
}
int e = 0;
m_ignoreChildrenChanged++;
removeChildren();
appendChild(document()->createTextNode(v), e);
m_ignoreChildrenChanged--;
m_attribute->setValue(v.impl());
createTextChild();
m_ignoreChildrenChanged--;
if (m_element)
m_element->attributeChanged(m_attribute.get());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment