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

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

Issue 962053003: tests: Use runPendingTasks instead of WebThread::enterRunLoop()/exitRunLoop() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 9 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 | Annotate | Revision Log
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 "config.h" 5 #include "config.h"
6 6
7 #include "web/TextFinder.h" 7 #include "web/TextFinder.h"
8 8
9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
11 #include "core/dom/NodeList.h" 11 #include "core/dom/NodeList.h"
12 #include "core/dom/Range.h" 12 #include "core/dom/Range.h"
13 #include "core/dom/shadow/ShadowRoot.h" 13 #include "core/dom/shadow/ShadowRoot.h"
14 #include "core/html/HTMLElement.h" 14 #include "core/html/HTMLElement.h"
15 #include "core/testing/UnitTestHelpers.h"
15 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
16 #include "public/web/WebDocument.h" 17 #include "public/web/WebDocument.h"
17 #include "web/FindInPageCoordinates.h" 18 #include "web/FindInPageCoordinates.h"
18 #include "web/WebLocalFrameImpl.h" 19 #include "web/WebLocalFrameImpl.h"
19 #include "web/tests/FrameTestHelpers.h" 20 #include "web/tests/FrameTestHelpers.h"
20 #include "wtf/OwnPtr.h" 21 #include "wtf/OwnPtr.h"
21 #include <gtest/gtest.h> 22 #include <gtest/gtest.h>
22 23
23 using namespace blink; 24 using namespace blink;
25 using blink::testing::runPendingTasks;
24 26
25 namespace { 27 namespace {
26 28
27 class TextFinderTest : public ::testing::Test { 29 class TextFinderTest : public ::testing::Test {
28 protected: 30 protected:
29 virtual void SetUp() override; 31 virtual void SetUp() override;
30 32
31 Document& document() const; 33 Document& document() const;
32 TextFinder& textFinder() const; 34 TextFinder& textFinder() const;
33 35
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 245 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
244 Node* textNode = document().body()->firstChild(); 246 Node* textNode = document().body()->firstChild();
245 247
246 int identifier = 0; 248 int identifier = 0;
247 WebString searchText(String("FindMe")); 249 WebString searchText(String("FindMe"));
248 WebFindOptions findOptions; // Default. 250 WebFindOptions findOptions; // Default.
249 251
250 textFinder().resetMatchCount(); 252 textFinder().resetMatchCount();
251 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 253 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
252 while (textFinder().scopingInProgress()) 254 while (textFinder().scopingInProgress())
253 FrameTestHelpers::runPendingTasks(); 255 runPendingTasks();
254 256
255 EXPECT_EQ(2, textFinder().totalMatchCount()); 257 EXPECT_EQ(2, textFinder().totalMatchCount());
256 WebVector<WebFloatRect> matchRects; 258 WebVector<WebFloatRect> matchRects;
257 textFinder().findMatchRects(matchRects); 259 textFinder().findMatchRects(matchRects);
258 ASSERT_EQ(2u, matchRects.size()); 260 ASSERT_EQ(2u, matchRects.size());
259 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 10), matchRects[0]); 261 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 10), matchRects[0]);
260 EXPECT_EQ(findInPageRect(textNode, 14, textNode, 20), matchRects[1]); 262 EXPECT_EQ(findInPageRect(textNode, 14, textNode, 20), matchRects[1]);
261 } 263 }
262 264
263 TEST_F(TextFinderTest, ScopeTextMatchesWithShadowDOM) 265 TEST_F(TextFinderTest, ScopeTextMatchesWithShadowDOM)
264 { 266 {
265 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ; 267 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ;
266 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = document().body()->createShadowR oot(ASSERT_NO_EXCEPTION); 268 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = document().body()->createShadowR oot(ASSERT_NO_EXCEPTION);
267 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION); 269 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION);
268 Node* textInBElement = document().body()->firstChild()->firstChild(); 270 Node* textInBElement = document().body()->firstChild()->firstChild();
269 Node* textInIElement = document().body()->lastChild()->firstChild(); 271 Node* textInIElement = document().body()->lastChild()->firstChild();
270 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild(); 272 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild();
271 273
272 int identifier = 0; 274 int identifier = 0;
273 WebString searchText(String("fOO")); 275 WebString searchText(String("fOO"));
274 WebFindOptions findOptions; // Default. 276 WebFindOptions findOptions; // Default.
275 277
276 textFinder().resetMatchCount(); 278 textFinder().resetMatchCount();
277 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 279 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
278 while (textFinder().scopingInProgress()) 280 while (textFinder().scopingInProgress())
279 FrameTestHelpers::runPendingTasks(); 281 runPendingTasks();
280 282
281 // TextIterator currently returns the matches in the document order, instead of the visual order. It visits 283 // TextIterator currently returns the matches in the document order, instead of the visual order. It visits
282 // the shadow roots first, so in this case the matches will be returned in t he order of <u> -> <b> -> <i>. 284 // the shadow roots first, so in this case the matches will be returned in t he order of <u> -> <b> -> <i>.
283 EXPECT_EQ(3, textFinder().totalMatchCount()); 285 EXPECT_EQ(3, textFinder().totalMatchCount());
284 WebVector<WebFloatRect> matchRects; 286 WebVector<WebFloatRect> matchRects;
285 textFinder().findMatchRects(matchRects); 287 textFinder().findMatchRects(matchRects);
286 ASSERT_EQ(3u, matchRects.size()); 288 ASSERT_EQ(3u, matchRects.size());
287 EXPECT_EQ(findInPageRect(textInUElement, 0, textInUElement, 3), matchRects[0 ]); 289 EXPECT_EQ(findInPageRect(textInUElement, 0, textInUElement, 3), matchRects[0 ]);
288 EXPECT_EQ(findInPageRect(textInBElement, 0, textInBElement, 3), matchRects[1 ]); 290 EXPECT_EQ(findInPageRect(textInBElement, 0, textInBElement, 3), matchRects[1 ]);
289 EXPECT_EQ(findInPageRect(textInIElement, 0, textInIElement, 3), matchRects[2 ]); 291 EXPECT_EQ(findInPageRect(textInIElement, 0, textInIElement, 3), matchRects[2 ]);
290 } 292 }
291 293
292 TEST_F(TextFinderTest, ScopeRepeatPatternTextMatches) 294 TEST_F(TextFinderTest, ScopeRepeatPatternTextMatches)
293 { 295 {
294 document().body()->setInnerHTML("ab ab ab ab ab", ASSERT_NO_EXCEPTION); 296 document().body()->setInnerHTML("ab ab ab ab ab", ASSERT_NO_EXCEPTION);
295 Node* textNode = document().body()->firstChild(); 297 Node* textNode = document().body()->firstChild();
296 298
297 int identifier = 0; 299 int identifier = 0;
298 WebString searchText(String("ab ab")); 300 WebString searchText(String("ab ab"));
299 WebFindOptions findOptions; // Default. 301 WebFindOptions findOptions; // Default.
300 302
301 textFinder().resetMatchCount(); 303 textFinder().resetMatchCount();
302 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 304 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
303 while (textFinder().scopingInProgress()) 305 while (textFinder().scopingInProgress())
304 FrameTestHelpers::runPendingTasks(); 306 runPendingTasks();
305 307
306 EXPECT_EQ(2, textFinder().totalMatchCount()); 308 EXPECT_EQ(2, textFinder().totalMatchCount());
307 WebVector<WebFloatRect> matchRects; 309 WebVector<WebFloatRect> matchRects;
308 textFinder().findMatchRects(matchRects); 310 textFinder().findMatchRects(matchRects);
309 ASSERT_EQ(2u, matchRects.size()); 311 ASSERT_EQ(2u, matchRects.size());
310 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 5), matchRects[0]); 312 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 5), matchRects[0]);
311 EXPECT_EQ(findInPageRect(textNode, 6, textNode, 11), matchRects[1]); 313 EXPECT_EQ(findInPageRect(textNode, 6, textNode, 11), matchRects[1]);
312 } 314 }
313 315
314 TEST_F(TextFinderTest, OverlappingMatches) 316 TEST_F(TextFinderTest, OverlappingMatches)
315 { 317 {
316 document().body()->setInnerHTML("aababaa", ASSERT_NO_EXCEPTION); 318 document().body()->setInnerHTML("aababaa", ASSERT_NO_EXCEPTION);
317 Node* textNode = document().body()->firstChild(); 319 Node* textNode = document().body()->firstChild();
318 320
319 int identifier = 0; 321 int identifier = 0;
320 WebString searchText(String("aba")); 322 WebString searchText(String("aba"));
321 WebFindOptions findOptions; // Default. 323 WebFindOptions findOptions; // Default.
322 324
323 textFinder().resetMatchCount(); 325 textFinder().resetMatchCount();
324 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 326 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
325 while (textFinder().scopingInProgress()) 327 while (textFinder().scopingInProgress())
326 FrameTestHelpers::runPendingTasks(); 328 runPendingTasks();
327 329
328 // We shouldn't find overlapped matches. 330 // We shouldn't find overlapped matches.
329 EXPECT_EQ(1, textFinder().totalMatchCount()); 331 EXPECT_EQ(1, textFinder().totalMatchCount());
330 WebVector<WebFloatRect> matchRects; 332 WebVector<WebFloatRect> matchRects;
331 textFinder().findMatchRects(matchRects); 333 textFinder().findMatchRects(matchRects);
332 ASSERT_EQ(1u, matchRects.size()); 334 ASSERT_EQ(1u, matchRects.size());
333 EXPECT_EQ(findInPageRect(textNode, 1, textNode, 4), matchRects[0]); 335 EXPECT_EQ(findInPageRect(textNode, 1, textNode, 4), matchRects[0]);
334 } 336 }
335 337
336 TEST_F(TextFinderTest, SequentialMatches) 338 TEST_F(TextFinderTest, SequentialMatches)
337 { 339 {
338 document().body()->setInnerHTML("ababab", ASSERT_NO_EXCEPTION); 340 document().body()->setInnerHTML("ababab", ASSERT_NO_EXCEPTION);
339 Node* textNode = document().body()->firstChild(); 341 Node* textNode = document().body()->firstChild();
340 342
341 int identifier = 0; 343 int identifier = 0;
342 WebString searchText(String("ab")); 344 WebString searchText(String("ab"));
343 WebFindOptions findOptions; // Default. 345 WebFindOptions findOptions; // Default.
344 346
345 textFinder().resetMatchCount(); 347 textFinder().resetMatchCount();
346 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); 348 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
347 while (textFinder().scopingInProgress()) 349 while (textFinder().scopingInProgress())
348 FrameTestHelpers::runPendingTasks(); 350 runPendingTasks();
349 351
350 EXPECT_EQ(3, textFinder().totalMatchCount()); 352 EXPECT_EQ(3, textFinder().totalMatchCount());
351 WebVector<WebFloatRect> matchRects; 353 WebVector<WebFloatRect> matchRects;
352 textFinder().findMatchRects(matchRects); 354 textFinder().findMatchRects(matchRects);
353 ASSERT_EQ(3u, matchRects.size()); 355 ASSERT_EQ(3u, matchRects.size());
354 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]); 356 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]);
355 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]); 357 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]);
356 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]); 358 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]);
357 } 359 }
358 360
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 465
464 int identifier = 0; 466 int identifier = 0;
465 WebFindOptions findOptions; // Default. 467 WebFindOptions findOptions; // Default.
466 468
467 textFinder().resetMatchCount(); 469 textFinder().resetMatchCount();
468 470
469 // There will be only one iteration before timeout, because increment 471 // There will be only one iteration before timeout, because increment
470 // of the TimeProxyPlatform timer is greater than timeout threshold. 472 // of the TimeProxyPlatform timer is greater than timeout threshold.
471 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true ); 473 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true );
472 while (textFinder().scopingInProgress()) 474 while (textFinder().scopingInProgress())
473 FrameTestHelpers::runPendingTasks(); 475 runPendingTasks();
474 476
475 EXPECT_EQ(4, textFinder().totalMatchCount()); 477 EXPECT_EQ(4, textFinder().totalMatchCount());
476 } 478 }
477 479
478 } // namespace 480 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698