LayoutTests:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 May 2006 06:33:59 +0000 (06:33 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 May 2006 06:33:59 +0000 (06:33 +0000)
        Reviewed by Darin.

        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=5624
        document.createElementNS() should not allow to insert a second <html> element

        * dom/xhtml/level3/core/documentnormalizedocument10-expected.txt:
        Updated to show a different failure.

        * dom/xhtml/level3/core/nodeappendchild02-expected.txt:
        * dom/xhtml/level3/core/nodeinsertbefore06-expected.txt:
        * dom/xhtml/level3/core/nodereplacechild39-expected.txt:
        Updated to reflect success.

        * fast/dom/createDocumentType2.html: Added.
        * fast/dom/createDocumentType2-expected.txt: Added.
        * fast/dom/createElementNS.html: Added.
        * fast/dom/createElementNS-expected.txt: Added.

WebCore:

        Reviewed by Darin.

        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=5624
        document.createElementNS() should not allow to insert a second <html> element

        Do extra checks for document nodes to detect multiple document elements
        and document types.

        * dom/Document.cpp:
        (WebCore::Document::childTypeAllowed):
        * dom/Document.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14430 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/dom/xhtml/level3/core/documentnormalizedocument10-expected.txt
LayoutTests/dom/xhtml/level3/core/nodeappendchild02-expected.txt
LayoutTests/dom/xhtml/level3/core/nodeinsertbefore06-expected.txt
LayoutTests/dom/xhtml/level3/core/nodereplacechild39-expected.txt
LayoutTests/fast/dom/createDocumentType2-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/createDocumentType2.html [new file with mode: 0644]
LayoutTests/fast/dom/createElementNS-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/createElementNS.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/Document.cpp
WebCore/dom/Document.h

index 65390471e392ce9b8418038c66f5b5553da3f8aa..97df4a4d09e85976326cff56f09a790698291dc7 100644 (file)
@@ -1,3 +1,23 @@
+2006-05-16  Rob Buis  <buis@kde.org>
+
+        Reviewed by Darin.
+
+        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=5624
+        document.createElementNS() should not allow to insert a second <html> element
+
+        * dom/xhtml/level3/core/documentnormalizedocument10-expected.txt:
+        Updated to show a different failure.
+
+        * dom/xhtml/level3/core/nodeappendchild02-expected.txt:
+        * dom/xhtml/level3/core/nodeinsertbefore06-expected.txt:
+        * dom/xhtml/level3/core/nodereplacechild39-expected.txt:
+        Updated to reflect success.
+
+        * fast/dom/createDocumentType2.html: Added.
+        * fast/dom/createDocumentType2-expected.txt: Added.
+        * fast/dom/createElementNS.html: Added.
+        * fast/dom/createElementNS-expected.txt: Added.
+
 2006-05-16  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Maciej.
index 5e597b0730c1bb857a611dd109770f13ce0f620f..5a07633cde5e54b90affd2fc7840c6f9083c2b80 100644 (file)
@@ -1,3 +1,3 @@
 Test   http://www.w3.org/2001/DOM-Test-Suite/level3/core/documentnormalizedocument10
 Status error
-Message        TypeError: Undefined value
+Message        Error: HIERARCHY_REQUEST_ERR: DOM Exception 3
index 4496ace199649c25cb00901058956244387a9e36..16bc34770a6fc79763001fd71281b3bdc9926ee5 100644 (file)
@@ -1,4 +1,3 @@
 Test   http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeappendchild02
-Status failure
-Message        throw_HIERARCHY_REQUEST_OR_NOT_SUPPORTED: fail
+Status Success
 
index 8b137891791fe96927ad78e64b0aad7bded08bdc..4b5cc9cc53082a65d876e62469633ea1180e8218 100644 (file)
@@ -1 +1,2 @@
-
+Test   http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeinsertbefore06
+Status Success
index 2ffcedbdd303ecb1af49ce5d4cf601cf6de18c59..73e9d47efac7fd2e5a69b89d43a09161c165ab15 100644 (file)
@@ -1,4 +1,3 @@
 Test   http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild39
-Status failure
-Message        throw_HIERARCHY_REQUEST_OR_NOT_SUPPORTED: fail
+Status Success
 
diff --git a/LayoutTests/fast/dom/createDocumentType2-expected.txt b/LayoutTests/fast/dom/createDocumentType2-expected.txt
new file mode 100644 (file)
index 0000000..e85b78b
--- /dev/null
@@ -0,0 +1,3 @@
+This tests that a document only supports having one doctype. If the test is successful, 'SUCCESS' will be displayed below, otherwise 'FAILURE' and a reason will be displayed.
+SUCCESS!
+
diff --git a/LayoutTests/fast/dom/createDocumentType2.html b/LayoutTests/fast/dom/createDocumentType2.html
new file mode 100644 (file)
index 0000000..cbdad3c
--- /dev/null
@@ -0,0 +1,39 @@
+<html>
+<head>
+<script>
+
+function debug(str)
+{
+    document.getElementById('console').appendChild(document.createTextNode(str))
+}
+
+function runTest()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    try {
+        // add two docType elements to test handling multiple addition of docTypes, since document has no docType initially
+        document.appendChild(document.implementation.createDocumentType("example", "http://www.example.com/", "myDoc.dtd"));
+        document.appendChild(document.implementation.createDocumentType("example", "http://www.example.com/", "myDoc.dtd"));
+        debug("FAILURE: Did not throw exception and should throw node hierarchy error.");
+        return;
+    }
+    catch (e) {
+        if (e.code != 3) {
+            debug("FAILURE: Threw an exception with a code other than 3; should throw node hierarchy error.");
+            return;
+        }
+    }
+
+    debug('SUCCESS!')
+}
+
+</script>
+</head>
+<body onload="runTest();">
+This tests that a document only supports having one doctype.
+If the test is successful, 'SUCCESS' will be displayed below, otherwise 'FAILURE' and a reason will be displayed.
+<pre id="console"></pre>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/createElementNS-expected.txt b/LayoutTests/fast/dom/createElementNS-expected.txt
new file mode 100644 (file)
index 0000000..3f0c9db
--- /dev/null
@@ -0,0 +1,3 @@
+This tests that a document only supports one document element. If the test is successful, 'SUCCESS' will be displayed below, otherwise 'FAILURE' and a reason will be displayed.
+SUCCESS!
+
diff --git a/LayoutTests/fast/dom/createElementNS.html b/LayoutTests/fast/dom/createElementNS.html
new file mode 100644 (file)
index 0000000..da5261c
--- /dev/null
@@ -0,0 +1,36 @@
+<html>
+<head>
+<script>
+
+function debug(str)
+{
+    document.getElementById('console').appendChild(document.createTextNode(str))
+}
+
+function runTest()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    try {
+        document.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "html"));
+        debug("FAILURE: Did not throw exception and should throw node hierarchy error.");
+        return;
+    } catch (e) {
+        if (e.code != 3) {
+            debug("FAILURE: Threw an exception with a code other than 3; should throw node hierarchy error.");
+            return;
+        }
+    }
+
+    debug('SUCCESS!')
+}
+
+</script>
+</head>
+<body onload="runTest();">
+This tests that a document only supports one document element.
+If the test is successful, 'SUCCESS' will be displayed below, otherwise 'FAILURE' and a reason will be displayed.
+<pre id="console"></pre>
+</body>
+</html>
index 1da30d149069d14b5420e404c680b4228acca2e4..420729edfd0de0378dd0731b2474d31a55c256e1 100644 (file)
@@ -1,3 +1,17 @@
+2006-05-16  Rob Buis  <buis@kde.org>
+
+        Reviewed by Darin.
+
+        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=5624
+        document.createElementNS() should not allow to insert a second <html> element
+
+        Do extra checks for document nodes to detect multiple document elements
+        and document types.
+
+        * dom/Document.cpp:
+        (WebCore::Document::childTypeAllowed):
+        * dom/Document.h:
+
 2006-05-17  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Darin.
index d774f4fde8299224bd33ff896734ae7c8587ff04..725a450c15b63efbfb430afcc66b9444c5534bdf 100644 (file)
@@ -1649,40 +1649,32 @@ MouseEventWithHitTestResults Document::prepareMouseEvent(bool readonly, bool act
 }
 
 // DOM Section 1.1.1
-bool Document::childAllowed(Node *newChild)
-{
-    // Documents may contain a maximum of one Element child
-    if (newChild->isElementNode()) {
-        Node *c;
-        for (c = firstChild(); c; c = c->nextSibling()) {
-            if (c->isElementNode())
-                return false;
-        }
-    }
-
-    // Documents may contain a maximum of one DocumentType child
-    if (newChild->nodeType() == DOCUMENT_TYPE_NODE) {
-        Node *c;
-        for (c = firstChild(); c; c = c->nextSibling()) {
-            if (c->nodeType() == DOCUMENT_TYPE_NODE)
-                return false;
-        }
-    }
-
-    return childTypeAllowed(newChild->nodeType());
-}
-
 bool Document::childTypeAllowed(NodeType type)
 {
     switch (type) {
-        case ELEMENT_NODE:
-        case PROCESSING_INSTRUCTION_NODE:
+        case ATTRIBUTE_NODE:
+        case CDATA_SECTION_NODE:
+        case DOCUMENT_FRAGMENT_NODE:
+        case DOCUMENT_NODE:
+        case ENTITY_NODE:
+        case ENTITY_REFERENCE_NODE:
+        case NOTATION_NODE:
+        case TEXT_NODE:
+        case XPATH_NAMESPACE_NODE:
+            return false;
         case COMMENT_NODE:
+        case PROCESSING_INSTRUCTION_NODE:
+            return true;
         case DOCUMENT_TYPE_NODE:
+        case ELEMENT_NODE:
+            // Documents may contain no more than one of each of these.
+            // (One Element and one DocumentType.)
+            for (Node* c = firstChild(); c; c = c->nextSibling())
+                if (c->nodeType() == type)
+                    return false;
             return true;
-        default:
-            return false;
     }
+    return false;
 }
 
 PassRefPtr<Node> Document::cloneNode(bool /*deep*/)
index 6b5e32be4a9dcc0d4cdfc0829fec5ff8f16f73e7..59c331aa9221b233850b9d2d2c27a52491f65f30 100644 (file)
@@ -367,7 +367,6 @@ public:
     
     MouseEventWithHitTestResults prepareMouseEvent(bool readonly, bool active, bool mouseMove, const IntPoint& point, const PlatformMouseEvent&);
 
-    virtual bool childAllowed(Node*);
     virtual bool childTypeAllowed(NodeType);
     virtual PassRefPtr<Node> cloneNode(bool deep);