OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "web/TextFinder.h" | 6 #include "web/TextFinder.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/NodeList.h" | 10 #include "core/dom/NodeList.h" |
11 #include "core/dom/Range.h" | 11 #include "core/dom/Range.h" |
12 #include "core/dom/shadow/ShadowRoot.h" | 12 #include "core/dom/shadow/ShadowRoot.h" |
| 13 #include "core/frame/FrameHost.h" |
13 #include "core/html/HTMLElement.h" | 14 #include "core/html/HTMLElement.h" |
| 15 #include "core/layout/TextAutosizer.h" |
| 16 #include "core/page/Page.h" |
14 #include "platform/testing/UnitTestHelpers.h" | 17 #include "platform/testing/UnitTestHelpers.h" |
15 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
16 #include "public/web/WebDocument.h" | 19 #include "public/web/WebDocument.h" |
17 #include "web/FindInPageCoordinates.h" | 20 #include "web/FindInPageCoordinates.h" |
18 #include "web/WebLocalFrameImpl.h" | 21 #include "web/WebLocalFrameImpl.h" |
19 #include "web/tests/FrameTestHelpers.h" | 22 #include "web/tests/FrameTestHelpers.h" |
20 #include "wtf/OwnPtr.h" | 23 #include "wtf/OwnPtr.h" |
21 #include <gtest/gtest.h> | 24 #include <gtest/gtest.h> |
22 | 25 |
23 using blink::testing::runPendingTasks; | 26 using blink::testing::runPendingTasks; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // Wrap to the first match (last occurence in the document). | 130 // Wrap to the first match (last occurence in the document). |
128 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); | 131 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); |
129 activeMatch = textFinder().activeMatch(); | 132 activeMatch = textFinder().activeMatch(); |
130 ASSERT_TRUE(activeMatch); | 133 ASSERT_TRUE(activeMatch); |
131 EXPECT_EQ(textNode, activeMatch->startContainer()); | 134 EXPECT_EQ(textNode, activeMatch->startContainer()); |
132 EXPECT_EQ(14, activeMatch->startOffset()); | 135 EXPECT_EQ(14, activeMatch->startOffset()); |
133 EXPECT_EQ(textNode, activeMatch->endContainer()); | 136 EXPECT_EQ(textNode, activeMatch->endContainer()); |
134 EXPECT_EQ(20, activeMatch->endOffset()); | 137 EXPECT_EQ(20, activeMatch->endOffset()); |
135 } | 138 } |
136 | 139 |
| 140 TEST_F(TextFinderTest, FindTextAutosizing) |
| 141 { |
| 142 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT
ION); |
| 143 |
| 144 int identifier = 0; |
| 145 WebString searchText(String("FindMe")); |
| 146 WebFindOptions findOptions; // Default. |
| 147 bool wrapWithinFrame = true; |
| 148 WebRect* selectionRect = nullptr; |
| 149 |
| 150 // Set viewport scale to 20 in order to simulate zoom-in |
| 151 PinchViewport& pinchViewport = document().page()->frameHost().pinchViewport(
); |
| 152 pinchViewport.setScale(20); |
| 153 |
| 154 // Enforce autosizing |
| 155 document().settings()->setTextAutosizingEnabled(true); |
| 156 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(20, 20)); |
| 157 document().textAutosizer()->updatePageInfo(); |
| 158 |
| 159 // In case of autosizing, scale _should_ change |
| 160 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); |
| 161 ASSERT_TRUE(textFinder().activeMatch()); |
| 162 ASSERT_EQ(1, pinchViewport.scale()); // in this case to 1 |
| 163 |
| 164 // Disable autosizing and reset scale to 20 |
| 165 pinchViewport.setScale(20); |
| 166 document().settings()->setTextAutosizingEnabled(false); |
| 167 document().textAutosizer()->updatePageInfo(); |
| 168 |
| 169 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); |
| 170 ASSERT_TRUE(textFinder().activeMatch()); |
| 171 ASSERT_EQ(20, pinchViewport.scale()); |
| 172 } |
| 173 |
137 TEST_F(TextFinderTest, FindTextNotFound) | 174 TEST_F(TextFinderTest, FindTextNotFound) |
138 { | 175 { |
139 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT
ION); | 176 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT
ION); |
140 | 177 |
141 int identifier = 0; | 178 int identifier = 0; |
142 WebString searchText(String("Boo")); | 179 WebString searchText(String("Boo")); |
143 WebFindOptions findOptions; // Default. | 180 WebFindOptions findOptions; // Default. |
144 bool wrapWithinFrame = true; | 181 bool wrapWithinFrame = true; |
145 WebRect* selectionRect = nullptr; | 182 WebRect* selectionRect = nullptr; |
146 | 183 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 // There will be only one iteration before timeout, because increment | 502 // There will be only one iteration before timeout, because increment |
466 // of the TimeProxyPlatform timer is greater than timeout threshold. | 503 // of the TimeProxyPlatform timer is greater than timeout threshold. |
467 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); | 504 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); |
468 while (textFinder().scopingInProgress()) | 505 while (textFinder().scopingInProgress()) |
469 runPendingTasks(); | 506 runPendingTasks(); |
470 | 507 |
471 EXPECT_EQ(4, textFinder().totalMatchCount()); | 508 EXPECT_EQ(4, textFinder().totalMatchCount()); |
472 } | 509 } |
473 | 510 |
474 } // namespace blink | 511 } // namespace blink |
OLD | NEW |