Commit 93d0aedd authored by weinig@apple.com's avatar weinig@apple.com

WebCore: Patch for https://bugs.webkit.org/show_bug.cgi?id=42021

isEqualNode should work for DocumentType nodes

Reviewed by Anders Carlsson.

Test: fast/dom/Node/isEqualNode.html

* dom/Node.cpp:
(WebCore::Node::isEqualNode): Add DocumentType logic from the DOM3 spec.

LayoutTests: Test for https://bugs.webkit.org/show_bug.cgi?id=42021
isEqualNode should work for DocumentType nodes

Reviewed by Anders Carlsson.

* fast/dom/Node/isEqualNode-expected.txt: Added.
* fast/dom/Node/isEqualNode.html: Added.
* fast/dom/Node/script-tests/isEqualNode.js: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63051 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c4737d8b
2010-07-10 Sam Weinig <sam@webkit.org>
Reviewed by Anders Carlsson.
Test for https://bugs.webkit.org/show_bug.cgi?id=42021
isEqualNode should work for DocumentType nodes
* fast/dom/Node/isEqualNode-expected.txt: Added.
* fast/dom/Node/isEqualNode.html: Added.
* fast/dom/Node/script-tests/isEqualNode.js: Added.
2010-07-10 Dan Bernstein <mitz@apple.com>
Reviewed by Anders Carlsson.
Test the isEqualNode API.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Test isEqualNode for DocumentType nodes.
PASS docTypeAllSet.isEqualNode(docTypeAllSet2) is true
PASS docTypeAllSet.isEqualNode(docTypeDifferentPublicID) is false
PASS docTypeAllSet.isEqualNode(docTypeDifferentSystemID) is false
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../js/resources/js-test-style.css">
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="script-tests/isEqualNode.js"></script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
description("Test the isEqualNode API.");
debug("Test isEqualNode for DocumentType nodes.");
var docTypeAllSet = document.implementation.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
var docTypeAllSet2 = document.implementation.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
var docTypeDifferentPublicID = document.implementation.createDocumentType('html', 'foo', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
var docTypeDifferentSystemID = document.implementation.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'bar');
shouldBeTrue("docTypeAllSet.isEqualNode(docTypeAllSet2)");
shouldBeFalse("docTypeAllSet.isEqualNode(docTypeDifferentPublicID)");
shouldBeFalse("docTypeAllSet.isEqualNode(docTypeDifferentSystemID)");
var successfullyParsed = true;
2010-07-10 Sam Weinig <sam@webkit.org>
Reviewed by Anders Carlsson.
Patch for https://bugs.webkit.org/show_bug.cgi?id=42021
isEqualNode should work for DocumentType nodes
Test: fast/dom/Node/isEqualNode.html
* dom/Node.cpp:
(WebCore::Node::isEqualNode): Add DocumentType logic from the DOM3 spec.
2010-07-10 Daniel Bates <dbates@rim.com>
Reviewed by Adam Barth.
......@@ -40,6 +40,7 @@
#include "ContextMenuController.h"
#include "DOMImplementation.h"
#include "Document.h"
#include "DocumentType.h"
#include "DynamicNodeList.h"
#include "Element.h"
#include "Event.h"
......@@ -1731,12 +1732,13 @@ KURL Node::baseURI() const
return parentNode() ? parentNode()->baseURI() : KURL();
}
bool Node::isEqualNode(Node *other) const
bool Node::isEqualNode(Node* other) const
{
if (!other)
return false;
if (nodeType() != other->nodeType())
NodeType nodeType = this->nodeType();
if (nodeType != other->nodeType())
return false;
if (nodeName() != other->nodeName())
......@@ -1754,17 +1756,17 @@ bool Node::isEqualNode(Node *other) const
if (nodeValue() != other->nodeValue())
return false;
NamedNodeMap *attrs = attributes();
NamedNodeMap *otherAttrs = other->attributes();
NamedNodeMap* attributes = this->attributes();
NamedNodeMap* otherAttributes = other->attributes();
if (!attrs && otherAttrs)
if (!attributes && otherAttributes)
return false;
if (attrs && !attrs->mapsEquivalent(otherAttrs))
if (attributes && !attributes->mapsEquivalent(otherAttributes))
return false;
Node *child = firstChild();
Node *otherChild = other->firstChild();
Node* child = firstChild();
Node* otherChild = other->firstChild();
while (child) {
if (!child->isEqualNode(otherChild))
......@@ -1777,8 +1779,33 @@ bool Node::isEqualNode(Node *other) const
if (otherChild)
return false;
// FIXME: For DocumentType nodes we should check equality on
// the entities and notations NamedNodeMaps as well.
if (nodeType == DOCUMENT_TYPE_NODE) {
const DocumentType* documentTypeThis = static_cast<const DocumentType*>(this);
const DocumentType* documentTypeOther = static_cast<const DocumentType*>(other);
if (documentTypeThis->publicId() != documentTypeOther->publicId())
return false;
if (documentTypeThis->systemId() != documentTypeOther->systemId())
return false;
if (documentTypeThis->internalSubset() != documentTypeOther->internalSubset())
return false;
NamedNodeMap* entities = documentTypeThis->entities();
NamedNodeMap* otherEntities = documentTypeOther->entities();
if (!entities && otherEntities)
return false;
if (entities && !entities->mapsEquivalent(otherEntities))
return false;
NamedNodeMap* notations = documentTypeThis->notations();
NamedNodeMap* otherNotations = documentTypeOther->notations();
if (!notations && otherNotations)
return false;
if (notations && !notations->mapsEquivalent(otherNotations))
return false;
}
return true;
}
......
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