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" |
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 "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
16 #include "public/web/WebDocument.h" | 16 #include "public/web/WebDocument.h" |
17 #include "web/FindInPageCoordinates.h" | 17 #include "web/FindInPageCoordinates.h" |
18 #include "web/WebLocalFrameImpl.h" | 18 #include "web/WebLocalFrameImpl.h" |
19 #include "web/tests/FrameTestHelpers.h" | 19 #include "web/tests/FrameTestHelpers.h" |
20 #include "wtf/OwnPtr.h" | 20 #include "wtf/OwnPtr.h" |
21 #include <gtest/gtest.h> | 21 #include <gtest/gtest.h> |
22 | 22 |
23 using namespace blink; | 23 using namespace blink; |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 class TextFinderTest : public ::testing::Test { | 27 class TextFinderTest : public ::testing::Test { |
28 protected: | 28 protected: |
29 virtual void SetUp() OVERRIDE; | 29 virtual void SetUp() override; |
30 | 30 |
31 Document& document() const; | 31 Document& document() const; |
32 TextFinder& textFinder() const; | 32 TextFinder& textFinder() const; |
33 | 33 |
34 static WebFloatRect findInPageRect(Node* startContainer, int startOffset, No
de* endContainer, int endOffset); | 34 static WebFloatRect findInPageRect(Node* startContainer, int startOffset, No
de* endContainer, int endOffset); |
35 | 35 |
36 private: | 36 private: |
37 FrameTestHelpers::WebViewHelper m_webViewHelper; | 37 FrameTestHelpers::WebViewHelper m_webViewHelper; |
38 RefPtrWillBePersistent<Document> m_document; | 38 RefPtrWillBePersistent<Document> m_document; |
39 TextFinder* m_textFinder; | 39 TextFinder* m_textFinder; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 WebVector<WebFloatRect> matchRects; | 351 WebVector<WebFloatRect> matchRects; |
352 textFinder().findMatchRects(matchRects); | 352 textFinder().findMatchRects(matchRects); |
353 ASSERT_EQ(3u, matchRects.size()); | 353 ASSERT_EQ(3u, matchRects.size()); |
354 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]); | 354 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]); |
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 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() |
(...skipping 16 matching lines...) Expand all Loading... |
389 } | 389 } |
390 | 390 |
391 private: | 391 private: |
392 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 } |
403 | 403 |
404 // These blink::Platform methods must be overriden to make a usable obje
ct. | 404 // These blink::Platform methods must be overriden to make a usable obje
ct. |
405 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) OVERRIDE | 405 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) override |
406 { | 406 { |
407 ensureFallback().cryptographicallyRandomValues(buffer, length); | 407 ensureFallback().cryptographicallyRandomValues(buffer, length); |
408 } | 408 } |
409 | 409 |
410 virtual const unsigned char* getTraceCategoryEnabledFlag(const char* cat
egoryName) OVERRIDE | 410 virtual const unsigned char* getTraceCategoryEnabledFlag(const char* cat
egoryName) override |
411 { | 411 { |
412 return ensureFallback().getTraceCategoryEnabledFlag(categoryName); | 412 return ensureFallback().getTraceCategoryEnabledFlag(categoryName); |
413 } | 413 } |
414 | 414 |
415 // These two methods allow timers to work correctly. | 415 // These two methods allow timers to work correctly. |
416 virtual double monotonicallyIncreasingTime() OVERRIDE | 416 virtual double monotonicallyIncreasingTime() override |
417 { | 417 { |
418 return ensureFallback().monotonicallyIncreasingTime(); | 418 return ensureFallback().monotonicallyIncreasingTime(); |
419 } | 419 } |
420 | 420 |
421 virtual void setSharedTimerFireInterval(double interval) OVERRIDE | 421 virtual void setSharedTimerFireInterval(double interval) override |
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 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 { |
(...skipping 29 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 |