| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 32 | 32 |
| 33 #include "core/dom/NodeWithIndex.h" |
| 33 #include "core/dom/SynchronousMutationObserver.h" | 34 #include "core/dom/SynchronousMutationObserver.h" |
| 34 #include "core/dom/Text.h" | 35 #include "core/dom/Text.h" |
| 35 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
| 36 #include "core/html/HTMLHeadElement.h" | 37 #include "core/html/HTMLHeadElement.h" |
| 37 #include "core/html/HTMLLinkElement.h" | 38 #include "core/html/HTMLLinkElement.h" |
| 38 #include "core/testing/DummyPageHolder.h" | 39 #include "core/testing/DummyPageHolder.h" |
| 39 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
| 40 #include "platform/weborigin/ReferrerPolicy.h" | 41 #include "platform/weborigin/ReferrerPolicy.h" |
| 41 #include "platform/weborigin/SchemeRegistry.h" | 42 #include "platform/weborigin/SchemeRegistry.h" |
| 42 #include "platform/weborigin/SecurityOrigin.h" | 43 #include "platform/weborigin/SecurityOrigin.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 72 | 73 |
| 73 namespace { | 74 namespace { |
| 74 | 75 |
| 75 class TestSynchronousMutationObserver | 76 class TestSynchronousMutationObserver |
| 76 : public GarbageCollectedFinalized<TestSynchronousMutationObserver>, | 77 : public GarbageCollectedFinalized<TestSynchronousMutationObserver>, |
| 77 public SynchronousMutationObserver { | 78 public SynchronousMutationObserver { |
| 78 USING_GARBAGE_COLLECTED_MIXIN(TestSynchronousMutationObserver); | 79 USING_GARBAGE_COLLECTED_MIXIN(TestSynchronousMutationObserver); |
| 79 | 80 |
| 80 public: | 81 public: |
| 81 struct MergeTextNodesRecord : GarbageCollected<MergeTextNodesRecord> { | 82 struct MergeTextNodesRecord : GarbageCollected<MergeTextNodesRecord> { |
| 82 Member<Text> m_node; | 83 Member<const Text> m_node; |
| 84 Member<Node> m_nodeToBeRemoved; |
| 83 unsigned m_offset = 0; | 85 unsigned m_offset = 0; |
| 84 | 86 |
| 85 MergeTextNodesRecord(Text* node, unsigned offset) | 87 MergeTextNodesRecord(const Text* node, |
| 86 : m_node(node), m_offset(offset) {} | 88 const NodeWithIndex& nodeWithIndex, |
| 89 unsigned offset) |
| 90 : m_node(node), |
| 91 m_nodeToBeRemoved(nodeWithIndex.node()), |
| 92 m_offset(offset) {} |
| 87 | 93 |
| 88 DEFINE_INLINE_TRACE() { visitor->trace(m_node); } | 94 DEFINE_INLINE_TRACE() { |
| 95 visitor->trace(m_node); |
| 96 visitor->trace(m_nodeToBeRemoved); |
| 97 } |
| 89 }; | 98 }; |
| 90 | 99 |
| 91 struct UpdateCharacterDataRecord | 100 struct UpdateCharacterDataRecord |
| 92 : GarbageCollected<UpdateCharacterDataRecord> { | 101 : GarbageCollected<UpdateCharacterDataRecord> { |
| 93 Member<CharacterData> m_node; | 102 Member<CharacterData> m_node; |
| 94 unsigned m_offset = 0; | 103 unsigned m_offset = 0; |
| 95 unsigned m_oldLength = 0; | 104 unsigned m_oldLength = 0; |
| 96 unsigned m_newLength = 0; | 105 unsigned m_newLength = 0; |
| 97 | 106 |
| 98 UpdateCharacterDataRecord(CharacterData* node, | 107 UpdateCharacterDataRecord(CharacterData* node, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 updatedCharacterDataRecords() const { | 148 updatedCharacterDataRecords() const { |
| 140 return m_updatedCharacterDataRecords; | 149 return m_updatedCharacterDataRecords; |
| 141 } | 150 } |
| 142 | 151 |
| 143 DECLARE_TRACE(); | 152 DECLARE_TRACE(); |
| 144 | 153 |
| 145 private: | 154 private: |
| 146 // Implement |SynchronousMutationObserver| member functions. | 155 // Implement |SynchronousMutationObserver| member functions. |
| 147 void contextDestroyed(Document*) final; | 156 void contextDestroyed(Document*) final; |
| 148 void didChangeChildren(const ContainerNode&) final; | 157 void didChangeChildren(const ContainerNode&) final; |
| 149 void didMergeTextNodes(Text&, unsigned) final; | 158 void didMergeTextNodes(const Text&, const NodeWithIndex&, unsigned) final; |
| 150 void didSplitTextNode(const Text&) final; | 159 void didSplitTextNode(const Text&) final; |
| 151 void didUpdateCharacterData(CharacterData*, | 160 void didUpdateCharacterData(CharacterData*, |
| 152 unsigned offset, | 161 unsigned offset, |
| 153 unsigned oldLength, | 162 unsigned oldLength, |
| 154 unsigned newLength) final; | 163 unsigned newLength) final; |
| 155 void nodeChildrenWillBeRemoved(ContainerNode&) final; | 164 void nodeChildrenWillBeRemoved(ContainerNode&) final; |
| 156 void nodeWillBeRemoved(Node&) final; | 165 void nodeWillBeRemoved(Node&) final; |
| 157 | 166 |
| 158 int m_contextDestroyedCalledCounter = 0; | 167 int m_contextDestroyedCalledCounter = 0; |
| 159 HeapVector<Member<const ContainerNode>> m_childrenChangedNodes; | 168 HeapVector<Member<const ContainerNode>> m_childrenChangedNodes; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 | 182 |
| 174 void TestSynchronousMutationObserver::contextDestroyed(Document*) { | 183 void TestSynchronousMutationObserver::contextDestroyed(Document*) { |
| 175 ++m_contextDestroyedCalledCounter; | 184 ++m_contextDestroyedCalledCounter; |
| 176 } | 185 } |
| 177 | 186 |
| 178 void TestSynchronousMutationObserver::didChangeChildren( | 187 void TestSynchronousMutationObserver::didChangeChildren( |
| 179 const ContainerNode& container) { | 188 const ContainerNode& container) { |
| 180 m_childrenChangedNodes.push_back(&container); | 189 m_childrenChangedNodes.push_back(&container); |
| 181 } | 190 } |
| 182 | 191 |
| 183 void TestSynchronousMutationObserver::didMergeTextNodes(Text& node, | 192 void TestSynchronousMutationObserver::didMergeTextNodes( |
| 184 unsigned offset) { | 193 const Text& node, |
| 185 m_mergeTextNodesRecords.push_back(new MergeTextNodesRecord(&node, offset)); | 194 const NodeWithIndex& nodeWithIndex, |
| 195 unsigned offset) { |
| 196 m_mergeTextNodesRecords.append( |
| 197 new MergeTextNodesRecord(&node, nodeWithIndex, offset)); |
| 186 } | 198 } |
| 187 | 199 |
| 188 void TestSynchronousMutationObserver::didSplitTextNode(const Text& node) { | 200 void TestSynchronousMutationObserver::didSplitTextNode(const Text& node) { |
| 189 m_splitTextNodes.push_back(&node); | 201 m_splitTextNodes.push_back(&node); |
| 190 } | 202 } |
| 191 | 203 |
| 192 void TestSynchronousMutationObserver::didUpdateCharacterData( | 204 void TestSynchronousMutationObserver::didUpdateCharacterData( |
| 193 CharacterData* characterData, | 205 CharacterData* characterData, |
| 194 unsigned offset, | 206 unsigned offset, |
| 195 unsigned oldLength, | 207 unsigned oldLength, |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 Text* mergeSampleA = document().createTextNode("a123456789"); | 514 Text* mergeSampleA = document().createTextNode("a123456789"); |
| 503 document().body()->appendChild(mergeSampleA); | 515 document().body()->appendChild(mergeSampleA); |
| 504 | 516 |
| 505 Text* mergeSampleB = document().createTextNode("b123456789"); | 517 Text* mergeSampleB = document().createTextNode("b123456789"); |
| 506 document().body()->appendChild(mergeSampleB); | 518 document().body()->appendChild(mergeSampleB); |
| 507 | 519 |
| 508 EXPECT_EQ(observer.mergeTextNodesRecords().size(), 0u); | 520 EXPECT_EQ(observer.mergeTextNodesRecords().size(), 0u); |
| 509 document().body()->normalize(); | 521 document().body()->normalize(); |
| 510 | 522 |
| 511 ASSERT_EQ(observer.mergeTextNodesRecords().size(), 1u); | 523 ASSERT_EQ(observer.mergeTextNodesRecords().size(), 1u); |
| 512 EXPECT_EQ(observer.mergeTextNodesRecords()[0]->m_node, mergeSampleB); | 524 EXPECT_EQ(mergeSampleA, observer.mergeTextNodesRecords()[0]->m_node); |
| 525 EXPECT_EQ(mergeSampleB, |
| 526 observer.mergeTextNodesRecords()[0]->m_nodeToBeRemoved); |
| 513 EXPECT_EQ(observer.mergeTextNodesRecords()[0]->m_offset, 10u); | 527 EXPECT_EQ(observer.mergeTextNodesRecords()[0]->m_offset, 10u); |
| 514 } | 528 } |
| 515 | 529 |
| 516 TEST_F(DocumentTest, SynchronousMutationNotifieRemoveChild) { | 530 TEST_F(DocumentTest, SynchronousMutationNotifieRemoveChild) { |
| 517 auto& observer = *new TestSynchronousMutationObserver(document()); | 531 auto& observer = *new TestSynchronousMutationObserver(document()); |
| 518 document().documentElement()->removeChild(document().body()); | 532 document().documentElement()->removeChild(document().body()); |
| 519 ASSERT_EQ(1u, observer.childrenChangedNodes().size()); | 533 ASSERT_EQ(1u, observer.childrenChangedNodes().size()); |
| 520 EXPECT_EQ(document().documentElement(), observer.childrenChangedNodes()[0]); | 534 EXPECT_EQ(document().documentElement(), observer.childrenChangedNodes()[0]); |
| 521 } | 535 } |
| 522 | 536 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 { | 617 { |
| 604 setHtmlInnerHTML( | 618 setHtmlInnerHTML( |
| 605 "<body>" | 619 "<body>" |
| 606 "<meta name=\"theme-color\" content=\"#00ff00\">"); | 620 "<meta name=\"theme-color\" content=\"#00ff00\">"); |
| 607 EXPECT_EQ(Color(0, 255, 0), document().themeColor()) | 621 EXPECT_EQ(Color(0, 255, 0), document().themeColor()) |
| 608 << "Theme color should be bright green."; | 622 << "Theme color should be bright green."; |
| 609 } | 623 } |
| 610 } | 624 } |
| 611 | 625 |
| 612 } // namespace blink | 626 } // namespace blink |
| OLD | NEW |