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 void SetUp() override | 451 void SetUp() override |
400 { | 452 { |
401 s_timeElapsed = 0.0; | 453 s_timeElapsed = 0.0; |
402 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); | 454 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); |
403 } | 455 } |
404 | 456 |
405 void TearDown() override | 457 void TearDown() override |
406 { | 458 { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // There will be only one iteration before timeout, because increment | 494 // There will be only one iteration before timeout, because increment |
443 // of the TimeProxyPlatform timer is greater than timeout threshold. | 495 // of the TimeProxyPlatform timer is greater than timeout threshold. |
444 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); | 496 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true
); |
445 while (textFinder().scopingInProgress()) | 497 while (textFinder().scopingInProgress()) |
446 runPendingTasks(); | 498 runPendingTasks(); |
447 | 499 |
448 EXPECT_EQ(4, textFinder().totalMatchCount()); | 500 EXPECT_EQ(4, textFinder().totalMatchCount()); |
449 } | 501 } |
450 | 502 |
451 } // namespace blink | 503 } // namespace blink |
OLD | NEW |