Improve Node pre-insertion validation when the parent is a Document
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Sep 2015 05:08:39 +0000 (05:08 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Sep 2015 05:08:39 +0000 (05:08 +0000)
commitb227c4885347e3d057423bdbd5c0456f90f8643e
tree368517c5a9a638b25fa8e49a3e5ce19f65a2eeca
parent4f663c6ebb7b78159f76df2bcbcb3952c0bd8f52
Improve Node pre-insertion validation when the parent is a Document
https://bugs.webkit.org/show_bug.cgi?id=149109
<rdar://problem/22560436>

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline several W3C tests now that more checks are passing.

* web-platform-tests/dom/nodes/Node-insertBefore-expected.txt:
* web-platform-tests/dom/nodes/Node-replaceChild-expected.txt:
* web-platform-tests/dom/nodes/append-on-Document-expected.txt:
* web-platform-tests/dom/nodes/prepend-on-Document-expected.txt:

Source/WebCore:

Improve Node pre-insertion validation when the parent is a Document to
match the specification:
https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
https://dom.spec.whatwg.org/#concept-node-replace

This affects the following API: Node.insertBefore(), Node.appendChild(),
Node.replaceChild().

WebKit current fails to do the following checks whenever the parent is a
Document from pre-insertion validation:
1. If the inserted Node is a DocumentFragment, we should make sure it
  contains only one Element.
-> This is because a Document can have only one child that is an
   Element [1].
2.a. If an Element is inserted, we should make sure it is not inserted
     before a DocumentType.
2.b. If a DocumentType is inserted, we should make sure it is not
     inserted after an Element.
-> This is because the DocType must come before the optional Element
   child [1].

Firefox and Chrome already match the specification here. This patch
aligns WebKit's behavior with those browsers and the specification.

[1] https://dom.spec.whatwg.org/#node-trees

No new tests, already covered by existing W3C tests.

* dom/ContainerNode.cpp:
(WebCore::checkAcceptChild):
(WebCore::checkAddChild):
(WebCore::checkReplaceChild):
(WebCore::ContainerNode::insertBefore):
(WebCore::ContainerNode::appendChild):
(WebCore::containsConsideringHostElements): Deleted.
(WebCore::checkAcceptChildGuaranteedNodeTypes): Deleted.
* dom/Document.cpp:
(WebCore::Document::canAcceptChild):
(WebCore::Document::cloneNodeInternal): Deleted.
* dom/Document.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189682 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-insertBefore-expected.txt
LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-replaceChild-expected.txt
LayoutTests/imported/w3c/web-platform-tests/dom/nodes/append-on-Document-expected.txt
LayoutTests/imported/w3c/web-platform-tests/dom/nodes/prepend-on-Document-expected.txt
LayoutTests/userscripts/mixed-case-stylesheet.html
Source/WebCore/ChangeLog
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h