Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: third_party/WebKit/Source/web/tests/TextFinderTest.cpp

Issue 1865813002: Remove RawPtr from Source/web/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "web/TextFinder.h" 5 #include "web/TextFinder.h"
6 6
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/NodeList.h" 9 #include "core/dom/NodeList.h"
10 #include "core/dom/Range.h" 10 #include "core/dom/Range.h"
(...skipping 17 matching lines...) Expand all
28 namespace blink { 28 namespace blink {
29 29
30 class TextFinderTest : public ::testing::Test { 30 class TextFinderTest : public ::testing::Test {
31 protected: 31 protected:
32 TextFinderTest() 32 TextFinderTest()
33 { 33 {
34 m_webViewHelper.initialize(); 34 m_webViewHelper.initialize();
35 WebLocalFrameImpl& frameImpl = *m_webViewHelper.webViewImpl()->mainFrame Impl(); 35 WebLocalFrameImpl& frameImpl = *m_webViewHelper.webViewImpl()->mainFrame Impl();
36 frameImpl.viewImpl()->resize(WebSize(640, 480)); 36 frameImpl.viewImpl()->resize(WebSize(640, 480));
37 frameImpl.viewImpl()->updateAllLifecyclePhases(); 37 frameImpl.viewImpl()->updateAllLifecyclePhases();
38 m_document = RawPtr<Document>(frameImpl.document()); 38 m_document = static_cast<Document*>(frameImpl.document());
39 m_textFinder = &frameImpl.ensureTextFinder(); 39 m_textFinder = &frameImpl.ensureTextFinder();
40 } 40 }
41 41
42 Document& document() const; 42 Document& document() const;
43 TextFinder& textFinder() const; 43 TextFinder& textFinder() const;
44 44
45 static WebFloatRect findInPageRect(Node* startContainer, int startOffset, No de* endContainer, int endOffset); 45 static WebFloatRect findInPageRect(Node* startContainer, int startOffset, No de* endContainer, int endOffset);
46 46
47 private: 47 private:
48 FrameTestHelpers::WebViewHelper m_webViewHelper; 48 FrameTestHelpers::WebViewHelper m_webViewHelper;
49 Persistent<Document> m_document; 49 Persistent<Document> m_document;
50 Persistent<TextFinder> m_textFinder; 50 Persistent<TextFinder> m_textFinder;
51 }; 51 };
52 52
53 Document& TextFinderTest::document() const 53 Document& TextFinderTest::document() const
54 { 54 {
55 return *m_document; 55 return *m_document;
56 } 56 }
57 57
58 TextFinder& TextFinderTest::textFinder() const 58 TextFinder& TextFinderTest::textFinder() const
59 { 59 {
60 return *m_textFinder; 60 return *m_textFinder;
61 } 61 }
62 62
63 WebFloatRect TextFinderTest::findInPageRect(Node* startContainer, int startOffse t, Node* endContainer, int endOffset) 63 WebFloatRect TextFinderTest::findInPageRect(Node* startContainer, int startOffse t, Node* endContainer, int endOffset)
64 { 64 {
65 RawPtr<Range> range = Range::create(startContainer->document(), startContain er, startOffset, endContainer, endOffset); 65 Range* range = Range::create(startContainer->document(), startContainer, sta rtOffset, endContainer, endOffset);
66 return WebFloatRect(findInPageRectFromRange(range.get())); 66 return WebFloatRect(findInPageRectFromRange(range));
67 } 67 }
68 68
69 TEST_F(TextFinderTest, FindTextSimple) 69 TEST_F(TextFinderTest, FindTextSimple)
70 { 70 {
71 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 71 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
72 Node* textNode = document().body()->firstChild(); 72 Node* textNode = document().body()->firstChild();
73 73
74 int identifier = 0; 74 int identifier = 0;
75 WebString searchText(String("FindMe")); 75 WebString searchText(String("FindMe"));
76 WebFindOptions findOptions; // Default. 76 WebFindOptions findOptions; // Default.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 bool wrapWithinFrame = true; 179 bool wrapWithinFrame = true;
180 WebRect* selectionRect = nullptr; 180 WebRect* selectionRect = nullptr;
181 181
182 EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWith inFrame, selectionRect)); 182 EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWith inFrame, selectionRect));
183 EXPECT_FALSE(textFinder().activeMatch()); 183 EXPECT_FALSE(textFinder().activeMatch());
184 } 184 }
185 185
186 TEST_F(TextFinderTest, FindTextInShadowDOM) 186 TEST_F(TextFinderTest, FindTextInShadowDOM)
187 { 187 {
188 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ; 188 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ;
189 RawPtr<ShadowRoot> shadowRoot = document().body()->createShadowRootInternal( ShadowRootType::V0, ASSERT_NO_EXCEPTION); 189 ShadowRoot* shadowRoot = document().body()->createShadowRootInternal(ShadowR ootType::V0, ASSERT_NO_EXCEPTION);
190 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION); 190 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION);
191 Node* textInBElement = document().body()->firstChild()->firstChild(); 191 Node* textInBElement = document().body()->firstChild()->firstChild();
192 Node* textInIElement = document().body()->lastChild()->firstChild(); 192 Node* textInIElement = document().body()->lastChild()->firstChild();
193 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild(); 193 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild();
194 194
195 int identifier = 0; 195 int identifier = 0;
196 WebString searchText(String("foo")); 196 WebString searchText(String("foo"));
197 WebFindOptions findOptions; // Default. 197 WebFindOptions findOptions; // Default.
198 bool wrapWithinFrame = true; 198 bool wrapWithinFrame = true;
199 WebRect* selectionRect = nullptr; 199 WebRect* selectionRect = nullptr;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 WebVector<WebFloatRect> matchRects; 293 WebVector<WebFloatRect> matchRects;
294 textFinder().findMatchRects(matchRects); 294 textFinder().findMatchRects(matchRects);
295 ASSERT_EQ(2u, matchRects.size()); 295 ASSERT_EQ(2u, matchRects.size());
296 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 10), matchRects[0]); 296 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 10), matchRects[0]);
297 EXPECT_EQ(findInPageRect(textNode, 14, textNode, 20), matchRects[1]); 297 EXPECT_EQ(findInPageRect(textNode, 14, textNode, 20), matchRects[1]);
298 } 298 }
299 299
300 TEST_F(TextFinderTest, ScopeTextMatchesWithShadowDOM) 300 TEST_F(TextFinderTest, ScopeTextMatchesWithShadowDOM)
301 { 301 {
302 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ; 302 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ;
303 RawPtr<ShadowRoot> shadowRoot = document().body()->createShadowRootInternal( ShadowRootType::V0, ASSERT_NO_EXCEPTION); 303 ShadowRoot* shadowRoot = document().body()->createShadowRootInternal(ShadowR ootType::V0, ASSERT_NO_EXCEPTION);
304 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION); 304 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION);
305 Node* textInBElement = document().body()->firstChild()->firstChild(); 305 Node* textInBElement = document().body()->firstChild()->firstChild();
306 Node* textInIElement = document().body()->lastChild()->firstChild(); 306 Node* textInIElement = document().body()->lastChild()->firstChild();
307 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild(); 307 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild();
308 308
309 int identifier = 0; 309 int identifier = 0;
310 WebString searchText(String("fOO")); 310 WebString searchText(String("fOO"));
311 WebFindOptions findOptions; // Default. 311 WebFindOptions findOptions; // Default.
312 312
313 textFinder().resetMatchCount(); 313 textFinder().resetMatchCount();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // There will be only one iteration before timeout, because increment 494 // There will be only one iteration before timeout, because increment
495 // of the TimeProxyPlatform timer is greater than timeout threshold. 495 // of the TimeProxyPlatform timer is greater than timeout threshold.
496 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true ); 496 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true );
497 while (textFinder().scopingInProgress()) 497 while (textFinder().scopingInProgress())
498 runPendingTasks(); 498 runPendingTasks();
499 499
500 EXPECT_EQ(4, textFinder().totalMatchCount()); 500 EXPECT_EQ(4, textFinder().totalMatchCount());
501 } 501 }
502 502
503 } // namespace blink 503 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/tests/LinkSelectionTest.cpp ('k') | third_party/WebKit/Source/web/tests/TopControlsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698