Bug 514487 - Cloning a document doesn't update the ID map, r=bz

--HG--
extra : rebase_source : 5b3003c47cdc47a3a9998dc4bfbe374c096a8690
This commit is contained in:
Olli Pettay 2009-09-10 16:23:40 +03:00
Родитель a615a3878f
Коммит b8b8c34ba3
4 изменённых файлов: 62 добавлений и 1 удалений

Просмотреть файл

@ -1010,7 +1010,7 @@ public:
virtual void MaybePreLoadImage(nsIURI* uri);
protected:
friend class nsNodeUtils;
void RegisterNamedItems(nsIContent *aContent);
void UnregisterNamedItems(nsIContent *aContent);
void UpdateNameTableEntry(nsIContent *aContent);

Просмотреть файл

@ -50,6 +50,7 @@
#include "nsIDOMAttr.h"
#include "nsCOMArray.h"
#include "nsPIDOMWindow.h"
#include "nsDocument.h"
#ifdef MOZ_XUL
#include "nsXULElement.h"
#endif
@ -557,6 +558,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
nsnull;
nsCOMPtr<nsINode> clone;
PRBool isDeepDocumentClone = PR_FALSE;
if (aClone) {
rv = aNode->Clone(nodeInfo, getter_AddRefs(clone));
NS_ENSURE_SUCCESS(rv, rv);
@ -571,6 +573,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
NS_ENSURE_SUCCESS(rv, rv);
}
else if (aDeep && clone->IsNodeOfType(nsINode::eDOCUMENT)) {
isDeepDocumentClone = PR_TRUE;
// After cloning the document itself, we want to clone the children into
// the cloned document (somewhat like cloning and importing them into the
// cloned document).
@ -675,6 +678,13 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
aCx, aOldScope, aNewScope, aNodesWithProperties,
clone, getter_AddRefs(child));
NS_ENSURE_SUCCESS(rv, rv);
if (isDeepDocumentClone) {
nsCOMPtr<nsIContent> content = do_QueryInterface(child);
if (content) {
static_cast<nsDocument*>(clone.get())->
RegisterNamedItems(content);
}
}
}
}

Просмотреть файл

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

Просмотреть файл

@ -0,0 +1,50 @@
<!DOCTYPE HTML>
<html id="root">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=514487
-->
<head id="child">
<title>Test for Bug 514487</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"/>
</head>
<body onload="runTests()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=514487">Mozilla Bug 514487</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 514487 **/
SimpleTest.waitForExplicitFinish();
function runTests() {
// Test XML document cloning.
var d = (new DOMParser()).parseFromString(
"<html xmlns='http://www.w3.org/1999/xhtml' id='root'><foo id='child'/></html>",
"text/xml");
var cloneDoc = d.cloneNode(true);
ok(cloneDoc.getElementById("root"),
"XML document should have an element with ID 'root'");
ok(cloneDoc.getElementById("child"),
"XML document should have an element with ID 'child'");
// Test HTML cloning.
cloneDoc = document.cloneNode(true);
ok(cloneDoc.getElementById("root"),
"HTML document should have an element with ID 'root'");
ok(cloneDoc.getElementById("child"),
"HTML document should have an element with ID 'child'");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>