| 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
|
|
|