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 "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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 WebVector<WebFloatRect> matchRects; | 389 WebVector<WebFloatRect> matchRects; |
390 textFinder().findMatchRects(matchRects); | 390 textFinder().findMatchRects(matchRects); |
391 ASSERT_EQ(3u, matchRects.size()); | 391 ASSERT_EQ(3u, matchRects.size()); |
392 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]); | 392 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]); |
393 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]); | 393 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]); |
394 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]); | 394 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]); |
395 } | 395 } |
396 | 396 |
397 class TextFinderFakeTimerTest : public TextFinderTest { | 397 class TextFinderFakeTimerTest : public TextFinderTest { |
398 protected: | 398 protected: |
399 // A simple platform that mocks out the clock. | 399 void SetUp() override |
400 class TimeProxyPlatform : public TestingPlatformSupport { | 400 { |
401 public: | 401 s_timeElapsed = 0.0; |
402 TimeProxyPlatform() | 402 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); |
403 : m_timeCounter(m_oldPlatform->currentTimeSeconds()) | 403 } |
404 { | |
405 } | |
406 | 404 |
407 private: | 405 void TearDown() override |
408 Platform& ensureFallback() | 406 { |
409 { | 407 setTimeFunctionsForTesting(m_originalTimeFunction); |
410 ASSERT(m_oldPlatform); | 408 } |
411 return *m_oldPlatform; | |
412 } | |
413 | 409 |
414 // From blink::Platform: | 410 private: |
415 double currentTimeSeconds() override | 411 static double returnMockTime() |
416 { | 412 { |
417 return ++m_timeCounter; | 413 s_timeElapsed += 1.0; |
418 } | 414 return s_timeElapsed; |
| 415 } |
419 | 416 |
420 // These two methods allow timers to work correctly. | 417 TimeFunction m_originalTimeFunction; |
421 double monotonicallyIncreasingTimeSeconds() override | 418 static double s_timeElapsed; |
422 { | 419 }; |
423 return ensureFallback().monotonicallyIncreasingTimeSeconds(); | |
424 } | |
425 | 420 |
426 WebUnitTestSupport* unitTestSupport() override { return ensureFallback()
.unitTestSupport(); } | 421 double TextFinderFakeTimerTest::s_timeElapsed; |
427 WebString defaultLocale() override { return ensureFallback().defaultLoca
le(); } | |
428 WebCompositorSupport* compositorSupport() override { return ensureFallba
ck().compositorSupport(); } | |
429 | |
430 double m_timeCounter; | |
431 }; | |
432 | |
433 TimeProxyPlatform m_proxyTimePlatform; | |
434 }; | |
435 | 422 |
436 TEST_F(TextFinderFakeTimerTest, ScopeWithTimeouts) | 423 TEST_F(TextFinderFakeTimerTest, ScopeWithTimeouts) |
437 { | 424 { |
438 // Make a long string. | 425 // Make a long string. |
439 String text(Vector<UChar>(100)); | 426 String text(Vector<UChar>(100)); |
440 text.fill('a'); | 427 text.fill('a'); |
441 String searchPattern("abc"); | 428 String searchPattern("abc"); |
442 // Make 4 substrings "abc" in text. | 429 // Make 4 substrings "abc" in text. |
443 text.insert(searchPattern, 1); | 430 text.insert(searchPattern, 1); |
444 text.insert(searchPattern, 10); | 431 text.insert(searchPattern, 10); |
(...skipping 10 matching lines...) Expand all Loading... |
455 // There will be only one iteration before timeout, because increment | 442 // There will be only one iteration before timeout, because increment |
456 // of the TimeProxyPlatform timer is greater than timeout threshold. | 443 // of the TimeProxyPlatform timer is greater than timeout threshold. |
457 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); | 444 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); |
458 while (textFinder().scopingInProgress()) | 445 while (textFinder().scopingInProgress()) |
459 runPendingTasks(); | 446 runPendingTasks(); |
460 | 447 |
461 EXPECT_EQ(4, textFinder().totalMatchCount()); | 448 EXPECT_EQ(4, textFinder().totalMatchCount()); |
462 } | 449 } |
463 | 450 |
464 } // namespace blink | 451 } // namespace blink |
OLD | NEW |