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

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 "explicit" 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/TextMatchMarkerList.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/editing/EditingTestBase.h"
8 #include "core/html/HTMLElement.h"
9 #include "platform/heap/Handle.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace blink {
13
14 class TextMatchMarkerListTest : public EditingTestBase {
15 protected:
16 TextMatchMarkerListTest() : m_markerList(new TextMatchMarkerList()) {}
17
18 DocumentMarker* createMarker(unsigned startOffset,
19 unsigned endOffset,
20 bool activeMatch = false) {
21 return new TextMatchMarker(startOffset, endOffset, activeMatch);
22 }
23
24 void setBodyInnerHTML(const char* bodyContent) {
25 document().body()->setInnerHTML(String::fromUTF8(bodyContent));
26 }
27
28 Persistent<TextMatchMarkerList> m_markerList;
29 };
30
31 TEST_F(TextMatchMarkerListTest, PushBackSorted) {
32 m_markerList->add(createMarker(0, 5));
33 m_markerList->add(createMarker(5, 10));
34
35 EXPECT_EQ(2u, m_markerList->size());
36
37 EXPECT_EQ(0u, m_markerList->at(0)->startOffset());
38 EXPECT_EQ(5u, m_markerList->at(0)->endOffset());
39
40 EXPECT_EQ(5u, m_markerList->at(1)->startOffset());
41 EXPECT_EQ(10u, m_markerList->at(1)->endOffset());
42 }
43
44 TEST_F(TextMatchMarkerListTest, SetTextMatchMarkersActive) {
45 m_markerList->add(createMarker(0, 5));
46 m_markerList->add(createMarker(5, 10));
47 m_markerList->add(createMarker(10, 15));
48
49 m_markerList->setTextMatchMarkersActive(5, 10, true);
50
51 EXPECT_EQ(3u, m_markerList->size());
52 EXPECT_FALSE(m_markerList->at(0)->activeMatch());
53 EXPECT_TRUE(m_markerList->at(1)->activeMatch());
54 EXPECT_FALSE(m_markerList->at(2)->activeMatch());
55 }
56
57 TEST_F(TextMatchMarkerListTest, SetTextMatchMarkersInactive) {
58 m_markerList->add(createMarker(0, 5, true));
59 m_markerList->add(createMarker(5, 10, true));
60 m_markerList->add(createMarker(10, 15, true));
61
62 m_markerList->setTextMatchMarkersActive(5, 10, false);
63
64 EXPECT_EQ(3u, m_markerList->size());
65 EXPECT_TRUE(m_markerList->at(0)->activeMatch());
66 EXPECT_FALSE(m_markerList->at(1)->activeMatch());
67 EXPECT_TRUE(m_markerList->at(2)->activeMatch());
68 }
69
70 TEST_F(TextMatchMarkerListTest, UpdateRenderedRects) {
71 setBodyInnerHTML("<div style='margin: 100px'>foo</div>");
72 Element* div = toElement(document().body()->firstChild());
73 Node* divText = div->firstChild();
74 document().updateStyleAndLayout();
75
76 m_markerList->add(createMarker(0, 3));
77 Vector<IntRect> renderedRects;
78 m_markerList->appendRenderedRectsToInputList(*divText, &renderedRects);
79 EXPECT_EQ(1u, renderedRects.size());
80 EXPECT_NE(0, renderedRects[0].x());
81 EXPECT_NE(0, renderedRects[0].y());
82
83 m_markerList->invalidateRects();
84
85 div->setAttribute(HTMLNames::styleAttr, "margin: 200px");
86 document().updateStyleAndLayout();
87
88 Vector<IntRect> newRenderedRects;
89 m_markerList->appendRenderedRectsToInputList(*divText, &newRenderedRects);
90 EXPECT_EQ(1u, newRenderedRects.size());
91 EXPECT_NE(0, newRenderedRects[0].x());
92 EXPECT_NE(0, newRenderedRects[0].y());
93 EXPECT_NE(renderedRects[0], newRenderedRects[0]);
94 }
95
96 } // namespace
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/TextMatchMarkerList.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698