Chromium Code Reviews| Index: Source/web/tests/TextFinderTest.cpp |
| diff --git a/Source/web/tests/TextFinderTest.cpp b/Source/web/tests/TextFinderTest.cpp |
| index dd863774c9d67024269ad69b756d0a4766649755..c82cc0fbef4b7e8dca4c8dfcdb9032ab08873cde 100644 |
| --- a/Source/web/tests/TextFinderTest.cpp |
| +++ b/Source/web/tests/TextFinderTest.cpp |
| @@ -10,7 +10,10 @@ |
| #include "core/dom/NodeList.h" |
| #include "core/dom/Range.h" |
| #include "core/dom/shadow/ShadowRoot.h" |
| +#include "core/frame/FrameHost.h" |
| #include "core/html/HTMLElement.h" |
| +#include "core/layout/TextAutosizer.h" |
| +#include "core/page/Page.h" |
| #include "platform/testing/UnitTestHelpers.h" |
| #include "public/platform/Platform.h" |
| #include "public/web/WebDocument.h" |
| @@ -30,6 +33,7 @@ protected: |
| Document& document() const; |
| TextFinder& textFinder() const; |
| + LocalFrame& frame() const; |
| static WebFloatRect findInPageRect(Node* startContainer, int startOffset, Node* endContainer, int endOffset); |
| @@ -59,6 +63,11 @@ TextFinder& TextFinderTest::textFinder() const |
| return *m_textFinder; |
| } |
| +LocalFrame& TextFinderTest::frame() const |
| +{ |
| + return *m_webViewHelper.webViewImpl()->mainFrameImpl()->frame(); |
| +} |
| + |
| WebFloatRect TextFinderTest::findInPageRect(Node* startContainer, int startOffset, Node* endContainer, int endOffset) |
| { |
| RefPtrWillBeRawPtr<Range> range = Range::create(startContainer->document(), startContainer, startOffset, endContainer, endOffset); |
| @@ -134,6 +143,40 @@ TEST_F(TextFinderTest, FindTextSimple) |
| EXPECT_EQ(20, activeMatch->endOffset()); |
| } |
| +TEST_F(TextFinderTest, FindTextAutosizing) |
| +{ |
| + document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPTION); |
| + |
| + int identifier = 0; |
| + WebString searchText(String("FindMe")); |
| + WebFindOptions findOptions; // Default. |
| + bool wrapWithinFrame = true; |
| + WebRect* selectionRect = nullptr; |
| + |
| + // Set viewport scale to 20 in order to simulate zoom-in |
| + PinchViewport& pinchViewport = frame().page()->frameHost().pinchViewport(); |
|
philipj_slow
2015/07/16 07:44:17
Would document().page() do the same thing? If so y
|
| + pinchViewport.setScale(20); |
| + |
| + // Enforce autosizing |
| + document().settings()->setTextAutosizingEnabled(true); |
| + document().settings()->setTextAutosizingWindowSizeOverride(IntSize(20, 20)); |
| + document().textAutosizer()->updatePageInfo(); |
| + |
| + // In case of autosizing, scale _should_ change |
| + ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect)); |
| + ASSERT_TRUE(textFinder().activeMatch()); |
| + ASSERT_EQ(1, pinchViewport.scale()); // in this case to 1 |
| + |
| + // Disable autosizing and reset scale to 20 |
| + pinchViewport.setScale(20); |
| + document().settings()->setTextAutosizingEnabled(false); |
| + document().textAutosizer()->updatePageInfo(); |
| + |
| + ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect)); |
| + ASSERT_TRUE(textFinder().activeMatch()); |
| + ASSERT_EQ(20, pinchViewport.scale()); |
| +} |
| + |
| TEST_F(TextFinderTest, FindTextNotFound) |
| { |
| document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPTION); |