OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, 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/editing/markers/DocumentMarkerController.h" | 31 #include "core/editing/markers/DocumentMarkerController.h" |
32 | 32 |
| 33 #include <memory> |
33 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
34 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
35 #include "core/dom/Range.h" | 36 #include "core/dom/Range.h" |
36 #include "core/dom/Text.h" | 37 #include "core/dom/Text.h" |
37 #include "core/editing/EphemeralRange.h" | 38 #include "core/editing/EphemeralRange.h" |
38 #include "core/editing/markers/RenderedDocumentMarker.h" | |
39 #include "core/html/HTMLElement.h" | 39 #include "core/html/HTMLElement.h" |
40 #include "core/testing/DummyPageHolder.h" | 40 #include "core/testing/DummyPageHolder.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
42 #include "wtf/PassRefPtr.h" | 42 #include "wtf/PassRefPtr.h" |
43 #include "wtf/RefPtr.h" | 43 #include "wtf/RefPtr.h" |
44 #include <memory> | |
45 | 44 |
46 namespace blink { | 45 namespace blink { |
47 | 46 |
48 class DocumentMarkerControllerTest : public ::testing::Test { | 47 class DocumentMarkerControllerTest : public ::testing::Test { |
49 protected: | 48 protected: |
50 DocumentMarkerControllerTest() | 49 DocumentMarkerControllerTest() |
51 : m_dummyPageHolder(DummyPageHolder::create(IntSize(800, 600))) {} | 50 : m_dummyPageHolder(DummyPageHolder::create(IntSize(800, 600))) {} |
52 | 51 |
53 Document& document() const { return m_dummyPageHolder->document(); } | 52 Document& document() const { return m_dummyPageHolder->document(); } |
54 DocumentMarkerController& markerController() const { | 53 DocumentMarkerController& markerController() const { |
(...skipping 11 matching lines...) Expand all Loading... |
66 | 65 |
67 Text* DocumentMarkerControllerTest::createTextNode(const char* textContents) { | 66 Text* DocumentMarkerControllerTest::createTextNode(const char* textContents) { |
68 return document().createTextNode(String::fromUTF8(textContents)); | 67 return document().createTextNode(String::fromUTF8(textContents)); |
69 } | 68 } |
70 | 69 |
71 void DocumentMarkerControllerTest::markNodeContents(Node* node) { | 70 void DocumentMarkerControllerTest::markNodeContents(Node* node) { |
72 // Force layoutObjects to be created; TextIterator, which is used in | 71 // Force layoutObjects to be created; TextIterator, which is used in |
73 // DocumentMarkerControllerTest::addMarker(), needs them. | 72 // DocumentMarkerControllerTest::addMarker(), needs them. |
74 document().updateStyleAndLayout(); | 73 document().updateStyleAndLayout(); |
75 auto range = EphemeralRange::rangeOfContents(*node); | 74 auto range = EphemeralRange::rangeOfContents(*node); |
76 markerController().addMarker(range.startPosition(), range.endPosition(), | 75 markerController().addTextMatchMarker(range, false); |
77 DocumentMarker::Spelling); | |
78 } | |
79 | |
80 void DocumentMarkerControllerTest::markNodeContentsWithComposition(Node* node) { | |
81 // Force layoutObjects to be created; TextIterator, which is used in | |
82 // DocumentMarkerControllerTest::addMarker(), needs them. | |
83 document().updateStyleAndLayout(); | |
84 auto range = EphemeralRange::rangeOfContents(*node); | |
85 markerController().addCompositionMarker(range.startPosition(), | |
86 range.endPosition(), Color::black, | |
87 false, Color::black); | |
88 } | 76 } |
89 | 77 |
90 void DocumentMarkerControllerTest::setBodyInnerHTML(const char* bodyContent) { | 78 void DocumentMarkerControllerTest::setBodyInnerHTML(const char* bodyContent) { |
91 document().body()->setInnerHTML(String::fromUTF8(bodyContent)); | 79 document().body()->setInnerHTML(String::fromUTF8(bodyContent)); |
92 } | 80 } |
93 | 81 |
94 TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument) { | 82 TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument) { |
95 setBodyInnerHTML("<b><i>foo</i></b>"); | 83 setBodyInnerHTML("<b><i>foo</i></b>"); |
96 Element* parent = toElement(document().body()->firstChild()->firstChild()); | 84 Element* parent = toElement(document().body()->firstChild()->firstChild()); |
97 markNodeContents(parent); | 85 markNodeContents(parent); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // No more reference to marked node. | 181 // No more reference to marked node. |
194 ThreadState::current()->collectAllGarbage(); | 182 ThreadState::current()->collectAllGarbage(); |
195 EXPECT_EQ(0u, markerController().markers().size()); | 183 EXPECT_EQ(0u, markerController().markers().size()); |
196 } | 184 } |
197 | 185 |
198 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects) { | 186 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects) { |
199 setBodyInnerHTML("<div style='margin: 100px'>foo</div>"); | 187 setBodyInnerHTML("<div style='margin: 100px'>foo</div>"); |
200 Element* div = toElement(document().body()->firstChild()); | 188 Element* div = toElement(document().body()->firstChild()); |
201 markNodeContents(div); | 189 markNodeContents(div); |
202 Vector<IntRect> renderedRects = | 190 Vector<IntRect> renderedRects = |
203 markerController().renderedRectsForMarkers(DocumentMarker::Spelling); | 191 markerController().renderedRectsForMarkers(DocumentMarker::TextMatch); |
204 EXPECT_EQ(1u, renderedRects.size()); | 192 EXPECT_EQ(1u, renderedRects.size()); |
205 | 193 |
206 div->setAttribute(HTMLNames::styleAttr, "margin: 200px"); | 194 div->setAttribute(HTMLNames::styleAttr, "margin: 200px"); |
207 document().updateStyleAndLayout(); | 195 document().updateStyleAndLayout(); |
208 Vector<IntRect> newRenderedRects = | 196 Vector<IntRect> newRenderedRects = |
209 markerController().renderedRectsForMarkers(DocumentMarker::Spelling); | 197 markerController().renderedRectsForMarkers(DocumentMarker::TextMatch); |
210 EXPECT_EQ(1u, newRenderedRects.size()); | 198 EXPECT_EQ(1u, newRenderedRects.size()); |
211 EXPECT_NE(renderedRects[0], newRenderedRects[0]); | 199 EXPECT_NE(renderedRects[0], newRenderedRects[0]); |
212 } | 200 } |
213 | |
214 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRectsForComposition) { | |
215 setBodyInnerHTML("<div style='margin: 100px'>foo</div>"); | |
216 Element* div = toElement(document().body()->firstChild()); | |
217 markNodeContentsWithComposition(div); | |
218 Vector<IntRect> renderedRects = | |
219 markerController().renderedRectsForMarkers(DocumentMarker::Composition); | |
220 EXPECT_EQ(1u, renderedRects.size()); | |
221 | |
222 div->setAttribute(HTMLNames::styleAttr, "margin: 200px"); | |
223 document().updateStyleAndLayout(); | |
224 Vector<IntRect> newRenderedRects = | |
225 markerController().renderedRectsForMarkers(DocumentMarker::Composition); | |
226 EXPECT_EQ(1u, newRenderedRects.size()); | |
227 EXPECT_NE(renderedRects[0], newRenderedRects[0]); | |
228 } | |
229 | 201 |
230 TEST_F(DocumentMarkerControllerTest, CompositionMarkersNotMerged) { | 202 TEST_F(DocumentMarkerControllerTest, CompositionMarkersNotMerged) { |
231 setBodyInnerHTML("<div style='margin: 100px'>foo</div>"); | 203 setBodyInnerHTML("<div style='margin: 100px'>foo</div>"); |
232 Node* text = document().body()->firstChild()->firstChild(); | 204 Node* text = document().body()->firstChild()->firstChild(); |
233 document().updateStyleAndLayout(); | 205 document().updateStyleAndLayout(); |
234 markerController().addCompositionMarker(Position(text, 0), Position(text, 1), | 206 markerController().addCompositionMarker(Position(text, 0), Position(text, 1), |
235 Color::black, false, Color::black); | 207 Color::black, false, Color::black); |
236 markerController().addCompositionMarker(Position(text, 1), Position(text, 3), | 208 markerController().addCompositionMarker(Position(text, 1), Position(text, 3), |
237 Color::black, true, Color::black); | 209 Color::black, true, Color::black); |
238 | 210 |
(...skipping 11 matching lines...) Expand all Loading... |
250 // Try to make active a marker that doesn't exist. | 222 // Try to make active a marker that doesn't exist. |
251 EXPECT_FALSE(markerController().setMarkersActive(range, true)); | 223 EXPECT_FALSE(markerController().setMarkersActive(range, true)); |
252 | 224 |
253 // Add a marker and try it once more. | 225 // Add a marker and try it once more. |
254 markerController().addTextMatchMarker(range, false); | 226 markerController().addTextMatchMarker(range, false); |
255 EXPECT_EQ(1u, markerController().markers().size()); | 227 EXPECT_EQ(1u, markerController().markers().size()); |
256 EXPECT_TRUE(markerController().setMarkersActive(range, true)); | 228 EXPECT_TRUE(markerController().setMarkersActive(range, true)); |
257 } | 229 } |
258 | 230 |
259 } // namespace blink | 231 } // namespace blink |
OLD | NEW |