| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 updatedCharacterDataRecords() const { | 152 updatedCharacterDataRecords() const { |
| 144 return m_updatedCharacterDataRecords; | 153 return m_updatedCharacterDataRecords; |
| 145 } | 154 } |
| 146 | 155 |
| 147 DECLARE_TRACE(); | 156 DECLARE_TRACE(); |
| 148 | 157 |
| 149 private: | 158 private: |
| 150 // Implement |SynchronousMutationObserver| member functions. | 159 // Implement |SynchronousMutationObserver| member functions. |
| 151 void contextDestroyed(Document*) final; | 160 void contextDestroyed(Document*) final; |
| 152 void didChangeChildren(const ContainerNode&) final; | 161 void didChangeChildren(const ContainerNode&) final; |
| 153 void didMergeTextNodes(Text&, unsigned) final; | 162 void didMergeTextNodes(const Text&, const NodeWithIndex&, unsigned) final; |
| 154 void didMoveTreeToNewDocument(const Node& root) final; | 163 void didMoveTreeToNewDocument(const Node& root) final; |
| 155 void didSplitTextNode(const Text&) final; | 164 void didSplitTextNode(const Text&) final; |
| 156 void didUpdateCharacterData(CharacterData*, | 165 void didUpdateCharacterData(CharacterData*, |
| 157 unsigned offset, | 166 unsigned offset, |
| 158 unsigned oldLength, | 167 unsigned oldLength, |
| 159 unsigned newLength) final; | 168 unsigned newLength) final; |
| 160 void nodeChildrenWillBeRemoved(ContainerNode&) final; | 169 void nodeChildrenWillBeRemoved(ContainerNode&) final; |
| 161 void nodeWillBeRemoved(Node&) final; | 170 void nodeWillBeRemoved(Node&) final; |
| 162 | 171 |
| 163 int m_contextDestroyedCalledCounter = 0; | 172 int m_contextDestroyedCalledCounter = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 179 | 188 |
| 180 void TestSynchronousMutationObserver::contextDestroyed(Document*) { | 189 void TestSynchronousMutationObserver::contextDestroyed(Document*) { |
| 181 ++m_contextDestroyedCalledCounter; | 190 ++m_contextDestroyedCalledCounter; |
| 182 } | 191 } |
| 183 | 192 |
| 184 void TestSynchronousMutationObserver::didChangeChildren( | 193 void TestSynchronousMutationObserver::didChangeChildren( |
| 185 const ContainerNode& container) { | 194 const ContainerNode& container) { |
| 186 m_childrenChangedNodes.push_back(&container); | 195 m_childrenChangedNodes.push_back(&container); |
| 187 } | 196 } |
| 188 | 197 |
| 189 void TestSynchronousMutationObserver::didMergeTextNodes(Text& node, | 198 void TestSynchronousMutationObserver::didMergeTextNodes( |
| 190 unsigned offset) { | 199 const Text& node, |
| 191 m_mergeTextNodesRecords.push_back(new MergeTextNodesRecord(&node, offset)); | 200 const NodeWithIndex& nodeWithIndex, |
| 201 unsigned offset) { |
| 202 m_mergeTextNodesRecords.push_back( |
| 203 new MergeTextNodesRecord(&node, nodeWithIndex, offset)); |
| 192 } | 204 } |
| 193 | 205 |
| 194 void TestSynchronousMutationObserver::didMoveTreeToNewDocument( | 206 void TestSynchronousMutationObserver::didMoveTreeToNewDocument( |
| 195 const Node& root) { | 207 const Node& root) { |
| 196 m_moveTreeToNewDocumentNodes.push_back(&root); | 208 m_moveTreeToNewDocumentNodes.push_back(&root); |
| 197 } | 209 } |
| 198 | 210 |
| 199 void TestSynchronousMutationObserver::didSplitTextNode(const Text& node) { | 211 void TestSynchronousMutationObserver::didSplitTextNode(const Text& node) { |
| 200 m_splitTextNodes.push_back(&node); | 212 m_splitTextNodes.push_back(&node); |
| 201 } | 213 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 Text* mergeSampleA = document().createTextNode("a123456789"); | 526 Text* mergeSampleA = document().createTextNode("a123456789"); |
| 515 document().body()->appendChild(mergeSampleA); | 527 document().body()->appendChild(mergeSampleA); |
| 516 | 528 |
| 517 Text* mergeSampleB = document().createTextNode("b123456789"); | 529 Text* mergeSampleB = document().createTextNode("b123456789"); |
| 518 document().body()->appendChild(mergeSampleB); | 530 document().body()->appendChild(mergeSampleB); |
| 519 | 531 |
| 520 EXPECT_EQ(0u, observer.mergeTextNodesRecords().size()); | 532 EXPECT_EQ(0u, observer.mergeTextNodesRecords().size()); |
| 521 document().body()->normalize(); | 533 document().body()->normalize(); |
| 522 | 534 |
| 523 ASSERT_EQ(1u, observer.mergeTextNodesRecords().size()); | 535 ASSERT_EQ(1u, observer.mergeTextNodesRecords().size()); |
| 524 EXPECT_EQ(mergeSampleB, observer.mergeTextNodesRecords()[0]->m_node); | 536 EXPECT_EQ(mergeSampleA, observer.mergeTextNodesRecords()[0]->m_node); |
| 537 EXPECT_EQ(mergeSampleB, |
| 538 observer.mergeTextNodesRecords()[0]->m_nodeToBeRemoved); |
| 525 EXPECT_EQ(10u, observer.mergeTextNodesRecords()[0]->m_offset); | 539 EXPECT_EQ(10u, observer.mergeTextNodesRecords()[0]->m_offset); |
| 526 } | 540 } |
| 527 | 541 |
| 528 TEST_F(DocumentTest, SynchronousMutationNotifierMoveTreeToNewDocument) { | 542 TEST_F(DocumentTest, SynchronousMutationNotifierMoveTreeToNewDocument) { |
| 529 auto& observer = *new TestSynchronousMutationObserver(document()); | 543 auto& observer = *new TestSynchronousMutationObserver(document()); |
| 530 | 544 |
| 531 Node* moveSample = document().createElement("div"); | 545 Node* moveSample = document().createElement("div"); |
| 532 moveSample->appendChild(document().createTextNode("a123")); | 546 moveSample->appendChild(document().createTextNode("a123")); |
| 533 moveSample->appendChild(document().createTextNode("b456")); | 547 moveSample->appendChild(document().createTextNode("b456")); |
| 534 document().body()->appendChild(moveSample); | 548 document().body()->appendChild(moveSample); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 { | 644 { |
| 631 setHtmlInnerHTML( | 645 setHtmlInnerHTML( |
| 632 "<body>" | 646 "<body>" |
| 633 "<meta name=\"theme-color\" content=\"#00ff00\">"); | 647 "<meta name=\"theme-color\" content=\"#00ff00\">"); |
| 634 EXPECT_EQ(Color(0, 255, 0), document().themeColor()) | 648 EXPECT_EQ(Color(0, 255, 0), document().themeColor()) |
| 635 << "Theme color should be bright green."; | 649 << "Theme color should be bright green."; |
| 636 } | 650 } |
| 637 } | 651 } |
| 638 | 652 |
| 639 } // namespace blink | 653 } // namespace blink |
| OLD | NEW |