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; |
24 | 27 |
25 namespace blink { | 28 namespace blink { |
26 | 29 |
27 class TextFinderTest : public ::testing::Test { | 30 class TextFinderTest : public ::testing::Test { |
28 protected: | 31 protected: |
29 void SetUp() override; | 32 void SetUp() override; |
30 | 33 |
31 Document& document() const; | 34 Document& document() const; |
32 TextFinder& textFinder() const; | 35 TextFinder& textFinder() const; |
36 LocalFrame& frame() const; | |
33 | 37 |
34 static WebFloatRect findInPageRect(Node* startContainer, int startOffset, No de* endContainer, int endOffset); | 38 static WebFloatRect findInPageRect(Node* startContainer, int startOffset, No de* endContainer, int endOffset); |
35 | 39 |
36 private: | 40 private: |
37 FrameTestHelpers::WebViewHelper m_webViewHelper; | 41 FrameTestHelpers::WebViewHelper m_webViewHelper; |
38 RefPtrWillBePersistent<Document> m_document; | 42 RefPtrWillBePersistent<Document> m_document; |
39 TextFinder* m_textFinder; | 43 TextFinder* m_textFinder; |
40 }; | 44 }; |
41 | 45 |
42 void TextFinderTest::SetUp() | 46 void TextFinderTest::SetUp() |
43 { | 47 { |
44 m_webViewHelper.initialize(); | 48 m_webViewHelper.initialize(); |
45 WebLocalFrameImpl& frameImpl = *m_webViewHelper.webViewImpl()->mainFrameImpl (); | 49 WebLocalFrameImpl& frameImpl = *m_webViewHelper.webViewImpl()->mainFrameImpl (); |
46 frameImpl.viewImpl()->resize(WebSize(640, 480)); | 50 frameImpl.viewImpl()->resize(WebSize(640, 480)); |
47 frameImpl.viewImpl()->layout(); | 51 frameImpl.viewImpl()->layout(); |
48 m_document = PassRefPtrWillBeRawPtr<Document>(frameImpl.document()); | 52 m_document = PassRefPtrWillBeRawPtr<Document>(frameImpl.document()); |
49 m_textFinder = &frameImpl.ensureTextFinder(); | 53 m_textFinder = &frameImpl.ensureTextFinder(); |
50 } | 54 } |
51 | 55 |
52 Document& TextFinderTest::document() const | 56 Document& TextFinderTest::document() const |
53 { | 57 { |
54 return *m_document; | 58 return *m_document; |
55 } | 59 } |
56 | 60 |
57 TextFinder& TextFinderTest::textFinder() const | 61 TextFinder& TextFinderTest::textFinder() const |
58 { | 62 { |
59 return *m_textFinder; | 63 return *m_textFinder; |
60 } | 64 } |
61 | 65 |
66 LocalFrame& TextFinderTest::frame() const | |
67 { | |
68 return *m_webViewHelper.webViewImpl()->mainFrameImpl()->frame(); | |
69 } | |
70 | |
62 WebFloatRect TextFinderTest::findInPageRect(Node* startContainer, int startOffse t, Node* endContainer, int endOffset) | 71 WebFloatRect TextFinderTest::findInPageRect(Node* startContainer, int startOffse t, Node* endContainer, int endOffset) |
63 { | 72 { |
64 RefPtrWillBeRawPtr<Range> range = Range::create(startContainer->document(), startContainer, startOffset, endContainer, endOffset); | 73 RefPtrWillBeRawPtr<Range> range = Range::create(startContainer->document(), startContainer, startOffset, endContainer, endOffset); |
65 return WebFloatRect(findInPageRectFromRange(range.get())); | 74 return WebFloatRect(findInPageRectFromRange(range.get())); |
66 } | 75 } |
67 | 76 |
68 TEST_F(TextFinderTest, FindTextSimple) | 77 TEST_F(TextFinderTest, FindTextSimple) |
69 { | 78 { |
70 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); | 79 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); |
71 Node* textNode = document().body()->firstChild(); | 80 Node* textNode = document().body()->firstChild(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 // Wrap to the first match (last occurence in the document). | 136 // Wrap to the first match (last occurence in the document). |
128 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); | 137 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); |
129 activeMatch = textFinder().activeMatch(); | 138 activeMatch = textFinder().activeMatch(); |
130 ASSERT_TRUE(activeMatch); | 139 ASSERT_TRUE(activeMatch); |
131 EXPECT_EQ(textNode, activeMatch->startContainer()); | 140 EXPECT_EQ(textNode, activeMatch->startContainer()); |
132 EXPECT_EQ(14, activeMatch->startOffset()); | 141 EXPECT_EQ(14, activeMatch->startOffset()); |
133 EXPECT_EQ(textNode, activeMatch->endContainer()); | 142 EXPECT_EQ(textNode, activeMatch->endContainer()); |
134 EXPECT_EQ(20, activeMatch->endOffset()); | 143 EXPECT_EQ(20, activeMatch->endOffset()); |
135 } | 144 } |
136 | 145 |
146 TEST_F(TextFinderTest, FindTextAutosizing) | |
147 { | |
148 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); | |
149 | |
150 int identifier = 0; | |
151 WebString searchText(String("FindMe")); | |
152 WebFindOptions findOptions; // Default. | |
153 bool wrapWithinFrame = true; | |
154 WebRect* selectionRect = nullptr; | |
155 | |
156 // Set viewport scale to 20 in order to simulate zoom-in | |
157 PinchViewport& pinchViewport = frame().page()->frameHost().pinchViewport(); | |
philipj_slow
2015/07/16 07:44:17
Would document().page() do the same thing? If so y
| |
158 pinchViewport.setScale(20); | |
159 | |
160 // Enforce autosizing | |
161 document().settings()->setTextAutosizingEnabled(true); | |
162 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(20, 20)); | |
163 document().textAutosizer()->updatePageInfo(); | |
164 | |
165 // In case of autosizing, scale _should_ change | |
166 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); | |
167 ASSERT_TRUE(textFinder().activeMatch()); | |
168 ASSERT_EQ(1, pinchViewport.scale()); // in this case to 1 | |
169 | |
170 // Disable autosizing and reset scale to 20 | |
171 pinchViewport.setScale(20); | |
172 document().settings()->setTextAutosizingEnabled(false); | |
173 document().textAutosizer()->updatePageInfo(); | |
174 | |
175 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); | |
176 ASSERT_TRUE(textFinder().activeMatch()); | |
177 ASSERT_EQ(20, pinchViewport.scale()); | |
178 } | |
179 | |
137 TEST_F(TextFinderTest, FindTextNotFound) | 180 TEST_F(TextFinderTest, FindTextNotFound) |
138 { | 181 { |
139 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); | 182 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); |
140 | 183 |
141 int identifier = 0; | 184 int identifier = 0; |
142 WebString searchText(String("Boo")); | 185 WebString searchText(String("Boo")); |
143 WebFindOptions findOptions; // Default. | 186 WebFindOptions findOptions; // Default. |
144 bool wrapWithinFrame = true; | 187 bool wrapWithinFrame = true; |
145 WebRect* selectionRect = nullptr; | 188 WebRect* selectionRect = nullptr; |
146 | 189 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 // There will be only one iteration before timeout, because increment | 508 // There will be only one iteration before timeout, because increment |
466 // of the TimeProxyPlatform timer is greater than timeout threshold. | 509 // of the TimeProxyPlatform timer is greater than timeout threshold. |
467 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true ); | 510 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true ); |
468 while (textFinder().scopingInProgress()) | 511 while (textFinder().scopingInProgress()) |
469 runPendingTasks(); | 512 runPendingTasks(); |
470 | 513 |
471 EXPECT_EQ(4, textFinder().totalMatchCount()); | 514 EXPECT_EQ(4, textFinder().totalMatchCount()); |
472 } | 515 } |
473 | 516 |
474 } // namespace blink | 517 } // namespace blink |
OLD | NEW |