innerHTML should always add a mutation record for removing all children
https://bugs.webkit.org/show_bug.cgi?id=148782
<rdar://problem/22571962>

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Rebaseline a test now that all test test cases are passing.

* web-platform-tests/dom/nodes/MutationObserver-inner-outer-expected.txt:

Source/WebCore:

Fixed the bug by disabling WebKit's optimization to avoid the node replacement when the behavior
is observable to scripts by either:
 - Author scripts has a reference to the node
 - MutationObserver can be observing this subtree
 - Mutation events can be observing this subtree

Note that no caller of this function exposes fragment to author scripts so it couldn't be referenced.
It also means that we don't need to check DOMNodeInsertedIntoDocument since it doesn't bubble up
(it's only relevant if the text node in fragment has its event listener but that's impossible).

Test: fast/dom/innerHTML-single-text-node.html

* dom/ChildListMutationScope.h:
(WebCore::ChildListMutationScope::canObserve): Added.

* editing/markup.cpp:
(WebCore::hasMutationEventListeners): Added.
(WebCore::replaceChildrenWithFragment):

LayoutTests:

Add a more comprehensive test for replacing a single text node with innerHTML's setter to ensure
WebKit's optimization to avoid replacing the node should not be observable by scripts in any way.

* fast/dom/innerHTML-single-text-node-expected.txt: Added.
* fast/dom/innerHTML-single-text-node.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@195263 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/ChildListMutationScope.h b/Source/WebCore/dom/ChildListMutationScope.h
index 5a671da..7022f35 100644
--- a/Source/WebCore/dom/ChildListMutationScope.h
+++ b/Source/WebCore/dom/ChildListMutationScope.h
@@ -82,6 +82,8 @@
             m_accumulator = ChildListMutationAccumulator::getOrCreate(target);
     }
 
+    bool canObserve() const { return m_accumulator; }
+
     void childAdded(Node& child)
     {
         if (m_accumulator && m_accumulator->hasObservers())