Chromium Code Reviews| 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..9bd6015b82725e5068083004340c568e6faf113c |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerListTest.cpp |
| @@ -0,0 +1,100 @@ |
| +// 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/dom/Document.h" |
| +#include "core/html/HTMLElement.h" |
| +#include "core/testing/DummyPageHolder.h" |
| +#include "platform/heap/Handle.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blink { |
| + |
| +class TextMatchMarkerListTest : public ::testing::Test { |
|
Xiaocheng
2017/03/29 23:20:57
You may inherit from EditingTestBase (in editing/E
|
| + protected: |
| + TextMatchMarkerListTest() |
| + : m_markerList(new TextMatchMarkerList()), |
| + m_dummyPageHolder(DummyPageHolder::create(IntSize(800, 600))) {} |
| + |
| + Document& document() const { return m_dummyPageHolder->document(); } |
| + |
| + 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; |
| + |
| + private: |
| + std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| +}; |
| + |
| +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()); |
| + |
|
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
|
| + 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(renderedRects[0], newRenderedRects[0]); |
| +} |
| + |
| +} // namespace |