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 | 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" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]); | 355 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]); |
356 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]); | 356 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]); |
357 } | 357 } |
358 | 358 |
359 class TextFinderFakeTimerTest : public TextFinderTest { | 359 class TextFinderFakeTimerTest : public TextFinderTest { |
360 protected: | 360 protected: |
361 virtual void SetUp() OVERRIDE; | 361 virtual void SetUp() OVERRIDE; |
362 virtual void TearDown() OVERRIDE; | 362 virtual void TearDown() OVERRIDE; |
363 | 363 |
364 // A simple platform that mocks out the clock. | 364 // A simple platform that mocks out the clock. |
365 class TimeProxyPlatform : public blink::Platform { | 365 class TimeProxyPlatform : public Platform { |
366 public: | 366 public: |
367 TimeProxyPlatform() | 367 TimeProxyPlatform() |
368 : m_timeCounter(0.) | 368 : m_timeCounter(0.) |
369 , m_fallbackPlatform(0) | 369 , m_fallbackPlatform(0) |
370 { } | 370 { } |
371 | 371 |
372 void install() | 372 void install() |
373 { | 373 { |
374 // Check that the proxy wasn't installed yet. | 374 // Check that the proxy wasn't installed yet. |
375 ASSERT_NE(blink::Platform::current(), this); | 375 ASSERT_NE(Platform::current(), this); |
376 m_fallbackPlatform = blink::Platform::current(); | 376 m_fallbackPlatform = Platform::current(); |
377 m_timeCounter = m_fallbackPlatform->currentTime(); | 377 m_timeCounter = m_fallbackPlatform->currentTime(); |
378 blink::Platform::initialize(this); | 378 Platform::initialize(this); |
379 ASSERT_EQ(blink::Platform::current(), this); | 379 ASSERT_EQ(Platform::current(), this); |
380 } | 380 } |
381 | 381 |
382 void remove() | 382 void remove() |
383 { | 383 { |
384 // Check that the proxy was installed. | 384 // Check that the proxy was installed. |
385 ASSERT_EQ(blink::Platform::current(), this); | 385 ASSERT_EQ(Platform::current(), this); |
386 blink::Platform::initialize(m_fallbackPlatform); | 386 Platform::initialize(m_fallbackPlatform); |
387 ASSERT_EQ(blink::Platform::current(), m_fallbackPlatform); | 387 ASSERT_EQ(Platform::current(), m_fallbackPlatform); |
388 m_fallbackPlatform = 0; | 388 m_fallbackPlatform = 0; |
389 } | 389 } |
390 | 390 |
391 private: | 391 private: |
392 blink::Platform& ensureFallback() | 392 Platform& ensureFallback() |
393 { | 393 { |
394 ASSERT(m_fallbackPlatform); | 394 ASSERT(m_fallbackPlatform); |
395 return *m_fallbackPlatform; | 395 return *m_fallbackPlatform; |
396 } | 396 } |
397 | 397 |
398 // From blink::Platform: | 398 // From blink::Platform: |
399 virtual double currentTime() OVERRIDE | 399 virtual double currentTime() OVERRIDE |
400 { | 400 { |
401 return ++m_timeCounter; | 401 return ++m_timeCounter; |
402 } | 402 } |
(...skipping 19 matching lines...) Expand all Loading... |
422 { | 422 { |
423 ensureFallback().setSharedTimerFireInterval(interval); | 423 ensureFallback().setSharedTimerFireInterval(interval); |
424 } | 424 } |
425 | 425 |
426 virtual WebThread* currentThread() OVERRIDE { return ensureFallback().cu
rrentThread(); } | 426 virtual WebThread* currentThread() OVERRIDE { return ensureFallback().cu
rrentThread(); } |
427 virtual WebUnitTestSupport* unitTestSupport() OVERRIDE { return ensureFa
llback().unitTestSupport(); } | 427 virtual WebUnitTestSupport* unitTestSupport() OVERRIDE { return ensureFa
llback().unitTestSupport(); } |
428 virtual WebString defaultLocale() OVERRIDE { return ensureFallback().def
aultLocale(); } | 428 virtual WebString defaultLocale() OVERRIDE { return ensureFallback().def
aultLocale(); } |
429 virtual WebCompositorSupport* compositorSupport() OVERRIDE { return ensu
reFallback().compositorSupport(); } | 429 virtual WebCompositorSupport* compositorSupport() OVERRIDE { return ensu
reFallback().compositorSupport(); } |
430 | 430 |
431 double m_timeCounter; | 431 double m_timeCounter; |
432 blink::Platform* m_fallbackPlatform; | 432 Platform* m_fallbackPlatform; |
433 }; | 433 }; |
434 | 434 |
435 TimeProxyPlatform m_proxyTimePlatform; | 435 TimeProxyPlatform m_proxyTimePlatform; |
436 }; | 436 }; |
437 | 437 |
438 void TextFinderFakeTimerTest::SetUp() | 438 void TextFinderFakeTimerTest::SetUp() |
439 { | 439 { |
440 TextFinderTest::SetUp(); | 440 TextFinderTest::SetUp(); |
441 m_proxyTimePlatform.install(); | 441 m_proxyTimePlatform.install(); |
442 } | 442 } |
(...skipping 26 matching lines...) Expand all Loading... |
469 // There will be only one iteration before timeout, because increment | 469 // There will be only one iteration before timeout, because increment |
470 // of the TimeProxyPlatform timer is greater than timeout threshold. | 470 // of the TimeProxyPlatform timer is greater than timeout threshold. |
471 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); | 471 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); |
472 while (textFinder().scopingInProgress()) | 472 while (textFinder().scopingInProgress()) |
473 FrameTestHelpers::runPendingTasks(); | 473 FrameTestHelpers::runPendingTasks(); |
474 | 474 |
475 EXPECT_EQ(4, textFinder().totalMatchCount()); | 475 EXPECT_EQ(4, textFinder().totalMatchCount()); |
476 } | 476 } |
477 | 477 |
478 } // namespace | 478 } // namespace |
OLD | NEW |