Bug 489925. getElementById should not return anonymous nodes. r=jst

This commit is contained in:
Boris Zbarsky 2009-09-02 11:32:02 -04:00
parent 86994c8fce
commit 182d27a809
3 changed files with 113 additions and 0 deletions

View File

@ -2374,6 +2374,11 @@ nsDocument::ContentAppended(nsIDocument* aDocument,
{
NS_ASSERTION(aDocument == this, "unexpected doc");
if (aContainer->GetBindingParent()) {
// Anonymous node; bail out
return;
}
for (nsINode::ChildIterator iter(aContainer, aNewIndexInContainer);
!iter.IsDone();
iter.Next()) {
@ -2391,6 +2396,11 @@ nsDocument::ContentInserted(nsIDocument* aDocument,
NS_ABORT_IF_FALSE(aContent, "Null content!");
if (aContent->GetBindingParent()) {
// Anonymous node; bail out
return;
}
RegisterNamedItems(aContent);
}
@ -2404,6 +2414,11 @@ nsDocument::ContentRemoved(nsIDocument* aDocument,
NS_ABORT_IF_FALSE(aChild, "Null content!");
if (aChild->GetBindingParent()) {
// Anonymous node; bail out
return;
}
UnregisterNamedItems(aChild);
}
@ -2415,6 +2430,11 @@ nsDocument::AttributeWillChange(nsIDocument* aDocument,
NS_ABORT_IF_FALSE(aContent, "Null content!");
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
if (aContent->GetBindingParent()) {
// Anonymous node; bail out
return;
}
if (aNameSpaceID != kNameSpaceID_None)
return;
if (aAttribute == nsGkAtoms::name) {
@ -2435,6 +2455,11 @@ nsDocument::AttributeChanged(nsIDocument* aDocument,
NS_ABORT_IF_FALSE(aContent, "Null content!");
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
if (aContent->GetBindingParent()) {
// Anonymous node; bail out
return;
}
if (aNameSpaceID != kNameSpaceID_None)
return;
if (aAttribute == nsGkAtoms::name) {

View File

@ -314,6 +314,7 @@ _TEST_FILES = test_bug5141.html \
bug466409-empty.css \
test_bug466409.html \
test_classList.html \
test_bug489925.xhtml \
$(NULL)
# Disabled; see bug 492181
# test_plugin_freezing.html

View File

@ -0,0 +1,87 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=489925
-->
<head>
<title>Test for Bug 489925</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<bindings xmlns="http://www.mozilla.org/xbl">
<binding id="t1">
<content>
<h:span anonid="test" xmlns:h="http://www.w3.org/1999/xhtml">
<children/>
</h:span>
</content>
<implementation>
<constructor>
document.getAnonymousElementByAttribute(this, "anonid", "test").id = "test1";
</constructor>
</implementation>
</binding>
<binding id="t2">
<content>
<h:span anonid="test" xmlns:h="http://www.w3.org/1999/xhtml">
<children/>
</h:span>
</content>
<implementation>
<constructor>
var s = document.createElement("span");
s.id = "test2";
document.getAnonymousElementByAttribute(this, "anonid", "test").appendChild(s);
</constructor>
</implementation>
</binding>
<binding id="t3">
<content>
<h:span anonid="test" xmlns:h="http://www.w3.org/1999/xhtml">
<children/>
</h:span>
</content>
<implementation>
<constructor>
var s = document.createElement("span");
s.id = "test3";
var p = document.getAnonymousElementByAttribute(this, "anonid", "test");
p.appendChild(document.createTextNode("testing"));
p.insertBefore(s, p.lastChild);
</constructor>
</implementation>
</binding>
</bindings>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=489925">Mozilla Bug 489925</a>
<p id="display">
<span style="-moz-binding: url(#t1)"/>
<span style="-moz-binding: url(#t2)"/>
<span style="-moz-binding: url(#t3)"/>
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
<![CDATA[
/** Test for Bug 489925 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
is($("test1"), null, "Setting id should not add anonymous element to table");
is($("test2"), null, "Append should not add anonymous element to table");
is($("test3"), null, "Insert should not add anonymous element to table");
SimpleTest.finish();
});
]]>
</script>
</pre>
</body>
</html>