Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarkerControllerTest.cpp

Issue 2723663002: Refactor DocumentMarkerController (Closed)
Patch Set: Use correct base commit Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 12 matching lines...) Expand all
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().addMarker(range.startPosition(), range.endPosition(),
77 DocumentMarker::Spelling); 76 DocumentMarker::TextMatch);
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 } 77 }
89 78
90 void DocumentMarkerControllerTest::setBodyInnerHTML(const char* bodyContent) { 79 void DocumentMarkerControllerTest::setBodyInnerHTML(const char* bodyContent) {
91 document().body()->setInnerHTML(String::fromUTF8(bodyContent)); 80 document().body()->setInnerHTML(String::fromUTF8(bodyContent));
92 } 81 }
93 82
94 TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument) { 83 TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument) {
95 setBodyInnerHTML("<b><i>foo</i></b>"); 84 setBodyInnerHTML("<b><i>foo</i></b>");
96 Element* parent = toElement(document().body()->firstChild()->firstChild()); 85 Element* parent = toElement(document().body()->firstChild()->firstChild());
97 markNodeContents(parent); 86 markNodeContents(parent);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // No more reference to marked node. 182 // No more reference to marked node.
194 ThreadState::current()->collectAllGarbage(); 183 ThreadState::current()->collectAllGarbage();
195 EXPECT_EQ(0u, markerController().markers().size()); 184 EXPECT_EQ(0u, markerController().markers().size());
196 } 185 }
197 186
198 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects) { 187 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects) {
199 setBodyInnerHTML("<div style='margin: 100px'>foo</div>"); 188 setBodyInnerHTML("<div style='margin: 100px'>foo</div>");
200 Element* div = toElement(document().body()->firstChild()); 189 Element* div = toElement(document().body()->firstChild());
201 markNodeContents(div); 190 markNodeContents(div);
202 Vector<IntRect> renderedRects = 191 Vector<IntRect> renderedRects =
203 markerController().renderedRectsForMarkers(DocumentMarker::Spelling); 192 markerController().renderedRectsForMarkers(DocumentMarker::TextMatch);
204 EXPECT_EQ(1u, renderedRects.size()); 193 EXPECT_EQ(1u, renderedRects.size());
205 194
206 div->setAttribute(HTMLNames::styleAttr, "margin: 200px"); 195 div->setAttribute(HTMLNames::styleAttr, "margin: 200px");
207 document().updateStyleAndLayout(); 196 document().updateStyleAndLayout();
208 Vector<IntRect> newRenderedRects = 197 Vector<IntRect> newRenderedRects =
209 markerController().renderedRectsForMarkers(DocumentMarker::Spelling); 198 markerController().renderedRectsForMarkers(DocumentMarker::TextMatch);
210 EXPECT_EQ(1u, newRenderedRects.size()); 199 EXPECT_EQ(1u, newRenderedRects.size());
211 EXPECT_NE(renderedRects[0], newRenderedRects[0]); 200 EXPECT_NE(renderedRects[0], newRenderedRects[0]);
212 } 201 }
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 202
230 TEST_F(DocumentMarkerControllerTest, CompositionMarkersNotMerged) { 203 TEST_F(DocumentMarkerControllerTest, CompositionMarkersNotMerged) {
231 setBodyInnerHTML("<div style='margin: 100px'>foo</div>"); 204 setBodyInnerHTML("<div style='margin: 100px'>foo</div>");
232 Node* text = document().body()->firstChild()->firstChild(); 205 Node* text = document().body()->firstChild()->firstChild();
233 document().updateStyleAndLayout(); 206 document().updateStyleAndLayout();
234 markerController().addCompositionMarker(Position(text, 0), Position(text, 1), 207 markerController().addCompositionMarker(Position(text, 0), Position(text, 1),
235 Color::black, false, Color::black); 208 Color::black, false, Color::black);
236 markerController().addCompositionMarker(Position(text, 1), Position(text, 3), 209 markerController().addCompositionMarker(Position(text, 1), Position(text, 3),
237 Color::black, true, Color::black); 210 Color::black, true, Color::black);
238 211
(...skipping 11 matching lines...) Expand all
250 // Try to make active a marker that doesn't exist. 223 // Try to make active a marker that doesn't exist.
251 EXPECT_FALSE(markerController().setMarkersActive(range, true)); 224 EXPECT_FALSE(markerController().setMarkersActive(range, true));
252 225
253 // Add a marker and try it once more. 226 // Add a marker and try it once more.
254 markerController().addTextMatchMarker(range, false); 227 markerController().addTextMatchMarker(range, false);
255 EXPECT_EQ(1u, markerController().markers().size()); 228 EXPECT_EQ(1u, markerController().markers().size());
256 EXPECT_TRUE(markerController().setMarkersActive(range, true)); 229 EXPECT_TRUE(markerController().setMarkersActive(range, true));
257 } 230 }
258 231
259 } // namespace blink 232 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698