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

Unified 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, 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/markers/TextMatchMarkerListTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerListTest.cpp b/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerListTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bb5a6c07ee4a6d5683973eec4c89bedcf3b482c9
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerListTest.cpp
@@ -0,0 +1,96 @@
+// Copyright 2017 The Chromium Authors. All rights reserved. Use of
+// this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/editing/markers/TextMatchMarkerList.h"
+
+#include "core/editing/EditingTestBase.h"
+#include "core/html/HTMLElement.h"
+#include "platform/heap/Handle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class TextMatchMarkerListTest : public EditingTestBase {
+ protected:
+ TextMatchMarkerListTest() : m_markerList(new TextMatchMarkerList()) {}
+
+ DocumentMarker* createMarker(unsigned startOffset,
+ unsigned endOffset,
+ bool activeMatch = false) {
+ return new TextMatchMarker(startOffset, endOffset, activeMatch);
+ }
+
+ void setBodyInnerHTML(const char* bodyContent) {
+ document().body()->setInnerHTML(String::fromUTF8(bodyContent));
+ }
+
+ Persistent<TextMatchMarkerList> m_markerList;
+};
+
+TEST_F(TextMatchMarkerListTest, PushBackSorted) {
+ m_markerList->add(createMarker(0, 5));
+ m_markerList->add(createMarker(5, 10));
+
+ EXPECT_EQ(2u, m_markerList->size());
+
+ EXPECT_EQ(0u, m_markerList->at(0)->startOffset());
+ EXPECT_EQ(5u, m_markerList->at(0)->endOffset());
+
+ EXPECT_EQ(5u, m_markerList->at(1)->startOffset());
+ EXPECT_EQ(10u, m_markerList->at(1)->endOffset());
+}
+
+TEST_F(TextMatchMarkerListTest, SetTextMatchMarkersActive) {
+ m_markerList->add(createMarker(0, 5));
+ m_markerList->add(createMarker(5, 10));
+ m_markerList->add(createMarker(10, 15));
+
+ m_markerList->setTextMatchMarkersActive(5, 10, true);
+
+ EXPECT_EQ(3u, m_markerList->size());
+ EXPECT_FALSE(m_markerList->at(0)->activeMatch());
+ EXPECT_TRUE(m_markerList->at(1)->activeMatch());
+ EXPECT_FALSE(m_markerList->at(2)->activeMatch());
+}
+
+TEST_F(TextMatchMarkerListTest, SetTextMatchMarkersInactive) {
+ m_markerList->add(createMarker(0, 5, true));
+ m_markerList->add(createMarker(5, 10, true));
+ m_markerList->add(createMarker(10, 15, true));
+
+ m_markerList->setTextMatchMarkersActive(5, 10, false);
+
+ EXPECT_EQ(3u, m_markerList->size());
+ EXPECT_TRUE(m_markerList->at(0)->activeMatch());
+ EXPECT_FALSE(m_markerList->at(1)->activeMatch());
+ EXPECT_TRUE(m_markerList->at(2)->activeMatch());
+}
+
+TEST_F(TextMatchMarkerListTest, UpdateRenderedRects) {
+ setBodyInnerHTML("<div style='margin: 100px'>foo</div>");
+ Element* div = toElement(document().body()->firstChild());
+ Node* divText = div->firstChild();
+ document().updateStyleAndLayout();
+
+ m_markerList->add(createMarker(0, 3));
+ Vector<IntRect> renderedRects;
+ m_markerList->appendRenderedRectsToInputList(*divText, &renderedRects);
+ EXPECT_EQ(1u, renderedRects.size());
+ EXPECT_NE(0, renderedRects[0].x());
+ EXPECT_NE(0, renderedRects[0].y());
+
+ m_markerList->invalidateRects();
+
+ div->setAttribute(HTMLNames::styleAttr, "margin: 200px");
+ document().updateStyleAndLayout();
+
+ Vector<IntRect> newRenderedRects;
+ m_markerList->appendRenderedRectsToInputList(*divText, &newRenderedRects);
+ EXPECT_EQ(1u, newRenderedRects.size());
+ EXPECT_NE(0, newRenderedRects[0].x());
+ EXPECT_NE(0, newRenderedRects[0].y());
+ EXPECT_NE(renderedRects[0], newRenderedRects[0]);
+}
+
+} // namespace
« 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