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

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

Issue 2784753002: Add TextMatchMarkerList in preparation for DocumentMarkerController refactor (Closed)
Patch Set: Remove unnecessary TextMatchMarker constructor Created 3 years, 8 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved. Use of
2 // this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/editing/markers/TextMatchMarkerList.h"
6
7 #include "core/dom/Document.h"
8 #include "core/html/HTMLElement.h"
9 #include "core/testing/DummyPageHolder.h"
10 #include "platform/heap/Handle.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace blink {
14
15 class TextMatchMarkerListTest : public ::testing::Test {
Xiaocheng 2017/03/29 23:20:57 You may inherit from EditingTestBase (in editing/E
16 protected:
17 TextMatchMarkerListTest()
18 : m_markerList(new TextMatchMarkerList()),
19 m_dummyPageHolder(DummyPageHolder::create(IntSize(800, 600))) {}
20
21 Document& document() const { return m_dummyPageHolder->document(); }
22
23 DocumentMarker* createMarker(unsigned startOffset,
24 unsigned endOffset,
25 bool activeMatch = false) {
26 return new TextMatchMarker(startOffset, endOffset, activeMatch);
27 }
28
29 void setBodyInnerHTML(const char* bodyContent) {
30 document().body()->setInnerHTML(String::fromUTF8(bodyContent));
31 }
32
33 Persistent<TextMatchMarkerList> m_markerList;
34
35 private:
36 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
37 };
38
39 TEST_F(TextMatchMarkerListTest, PushBackSorted) {
40 m_markerList->add(createMarker(0, 5));
41 m_markerList->add(createMarker(5, 10));
42
43 EXPECT_EQ(2u, m_markerList->size());
44
45 EXPECT_EQ(0u, m_markerList->at(0)->startOffset());
46 EXPECT_EQ(5u, m_markerList->at(0)->endOffset());
47
48 EXPECT_EQ(5u, m_markerList->at(1)->startOffset());
49 EXPECT_EQ(10u, m_markerList->at(1)->endOffset());
50 }
51
52 TEST_F(TextMatchMarkerListTest, SetTextMatchMarkersActive) {
53 m_markerList->add(createMarker(0, 5));
54 m_markerList->add(createMarker(5, 10));
55 m_markerList->add(createMarker(10, 15));
56
57 m_markerList->setTextMatchMarkersActive(5, 10, true);
58
59 EXPECT_EQ(3u, m_markerList->size());
60 EXPECT_FALSE(m_markerList->at(0)->activeMatch());
61 EXPECT_TRUE(m_markerList->at(1)->activeMatch());
62 EXPECT_FALSE(m_markerList->at(2)->activeMatch());
63 }
64
65 TEST_F(TextMatchMarkerListTest, SetTextMatchMarkersInactive) {
66 m_markerList->add(createMarker(0, 5, true));
67 m_markerList->add(createMarker(5, 10, true));
68 m_markerList->add(createMarker(10, 15, true));
69
70 m_markerList->setTextMatchMarkersActive(5, 10, false);
71
72 EXPECT_EQ(3u, m_markerList->size());
73 EXPECT_TRUE(m_markerList->at(0)->activeMatch());
74 EXPECT_FALSE(m_markerList->at(1)->activeMatch());
75 EXPECT_TRUE(m_markerList->at(2)->activeMatch());
76 }
77
78 TEST_F(TextMatchMarkerListTest, UpdateRenderedRects) {
79 setBodyInnerHTML("<div style='margin: 100px'>foo</div>");
80 Element* div = toElement(document().body()->firstChild());
81 Node* divText = div->firstChild();
82 document().updateStyleAndLayout();
83
84 m_markerList->add(createMarker(0, 3));
85 Vector<IntRect> renderedRects;
86 m_markerList->appendRenderedRectsToInputList(*divText, &renderedRects);
87 EXPECT_EQ(1u, renderedRects.size());
88
Xiaocheng 2017/03/29 23:20:57 Do we want to inspect the actual value of the rect
rlanday 2017/03/29 23:54:55 I don't know if it's 100% predictable, the rendere
89 m_markerList->invalidateRects();
90
91 div->setAttribute(HTMLNames::styleAttr, "margin: 200px");
92 document().updateStyleAndLayout();
93
94 Vector<IntRect> newRenderedRects;
95 m_markerList->appendRenderedRectsToInputList(*divText, &newRenderedRects);
96 EXPECT_EQ(1u, newRenderedRects.size());
97 EXPECT_NE(renderedRects[0], newRenderedRects[0]);
98 }
99
100 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698