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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 387 |
388 EXPECT_EQ(3, textFinder().totalMatchCount()); | 388 EXPECT_EQ(3, textFinder().totalMatchCount()); |
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 TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOM) |
| 398 { |
| 399 document().body()->setInnerHTML("<b>XXXXFindMeYYYY</b><i></i>", ASSERT_NO_EX
CEPTION); |
| 400 |
| 401 int identifier = 0; |
| 402 WebString searchText(String("FindMe")); |
| 403 WebFindOptions findOptions; // Default. |
| 404 bool wrapWithinFrame = true; |
| 405 WebRect* selectionRect = nullptr; |
| 406 bool activeNow; |
| 407 |
| 408 textFinder().resetMatchCount(); |
| 409 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); |
| 410 while (textFinder().scopingInProgress()) |
| 411 runPendingTasks(); |
| 412 |
| 413 findOptions.findNext = true; |
| 414 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect, &activeNow)); |
| 415 EXPECT_TRUE(activeNow); |
| 416 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect, &activeNow)); |
| 417 EXPECT_TRUE(activeNow); |
| 418 |
| 419 // Add new text to DOM and try FindNext. |
| 420 Element* iElement = toElement(document().body()->lastChild()); |
| 421 ASSERT_TRUE(iElement); |
| 422 iElement->setInnerHTML("ZZFindMe", ASSERT_NO_EXCEPTION); |
| 423 |
| 424 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect, &activeNow)); |
| 425 Range* activeMatch = textFinder().activeMatch(); |
| 426 ASSERT_TRUE(activeMatch); |
| 427 EXPECT_FALSE(activeNow); |
| 428 EXPECT_EQ(2, activeMatch->startOffset()); |
| 429 EXPECT_EQ(8, activeMatch->endOffset()); |
| 430 |
| 431 // Restart full search and check that added text is found. |
| 432 findOptions.findNext = false; |
| 433 textFinder().resetMatchCount(); |
| 434 textFinder().cancelPendingScopingEffort(); |
| 435 textFinder().scopeStringMatches(identifier, searchText, findOptions, true); |
| 436 while (textFinder().scopingInProgress()) |
| 437 runPendingTasks(); |
| 438 EXPECT_EQ(2, textFinder().totalMatchCount()); |
| 439 |
| 440 WebVector<WebFloatRect> matchRects; |
| 441 textFinder().findMatchRects(matchRects); |
| 442 ASSERT_EQ(2u, matchRects.size()); |
| 443 Node* textInBElement = document().body()->firstChild()->firstChild(); |
| 444 Node* textInIElement = document().body()->lastChild()->firstChild(); |
| 445 EXPECT_EQ(findInPageRect(textInBElement, 4, textInBElement, 10), matchRects[
0]); |
| 446 EXPECT_EQ(findInPageRect(textInIElement, 2, textInIElement, 8), matchRects[1
]); |
| 447 } |
| 448 |
397 class TextFinderFakeTimerTest : public TextFinderTest { | 449 class TextFinderFakeTimerTest : public TextFinderTest { |
398 protected: | 450 protected: |
399 // A simple platform that mocks out the clock. | 451 // A simple platform that mocks out the clock. |
400 class TimeProxyPlatform : public TestingPlatformSupport { | 452 class TimeProxyPlatform : public TestingPlatformSupport { |
401 public: | 453 public: |
402 TimeProxyPlatform() | 454 TimeProxyPlatform() |
403 : m_timeCounter(m_oldPlatform->currentTimeSeconds()) | 455 : m_timeCounter(m_oldPlatform->currentTimeSeconds()) |
404 { | 456 { |
405 } | 457 } |
406 | 458 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // There will be only one iteration before timeout, because increment | 507 // There will be only one iteration before timeout, because increment |
456 // of the TimeProxyPlatform timer is greater than timeout threshold. | 508 // of the TimeProxyPlatform timer is greater than timeout threshold. |
457 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); | 509 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); |
458 while (textFinder().scopingInProgress()) | 510 while (textFinder().scopingInProgress()) |
459 runPendingTasks(); | 511 runPendingTasks(); |
460 | 512 |
461 EXPECT_EQ(4, textFinder().totalMatchCount()); | 513 EXPECT_EQ(4, textFinder().totalMatchCount()); |
462 } | 514 } |
463 | 515 |
464 } // namespace blink | 516 } // namespace blink |
OLD | NEW |