Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/web/tests/TextFinderTest.cpp

Issue 2537773008: Fix search restart after zero entries. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/web/TextFinder.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 textFinder().findMatchRects(matchRects); 501 textFinder().findMatchRects(matchRects);
502 ASSERT_EQ(2u, matchRects.size()); 502 ASSERT_EQ(2u, matchRects.size());
503 Node* textInBElement = document().body()->firstChild()->firstChild(); 503 Node* textInBElement = document().body()->firstChild()->firstChild();
504 Node* textInIElement = document().body()->lastChild()->firstChild(); 504 Node* textInIElement = document().body()->lastChild()->firstChild();
505 EXPECT_EQ(findInPageRect(textInBElement, 4, textInBElement, 10), 505 EXPECT_EQ(findInPageRect(textInBElement, 4, textInBElement, 10),
506 matchRects[0]); 506 matchRects[0]);
507 EXPECT_EQ(findInPageRect(textInIElement, 2, textInIElement, 8), 507 EXPECT_EQ(findInPageRect(textInIElement, 2, textInIElement, 8),
508 matchRects[1]); 508 matchRects[1]);
509 } 509 }
510 510
511 TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOMAfterNoMatches) {
512 document().body()->setInnerHTML("<b>XXXXYYYY</b><i></i>");
513 document().updateStyleAndLayout();
514
515 int identifier = 0;
516 WebString searchText(String("FindMe"));
517 WebFindOptions findOptions; // Default.
518 bool wrapWithinFrame = true;
519 bool activeNow = false;
520
521 textFinder().resetMatchCount();
522 textFinder().startScopingStringMatches(identifier, searchText, findOptions);
523 while (textFinder().scopingInProgress())
524 runPendingTasks();
525
526 findOptions.findNext = true;
527 ASSERT_FALSE(textFinder().find(identifier, searchText, findOptions,
528 wrapWithinFrame, &activeNow));
529 EXPECT_FALSE(activeNow);
530
531 // Add new text to DOM and try FindNext.
532 Element* iElement = toElement(document().body()->lastChild());
533 ASSERT_TRUE(iElement);
534 iElement->setInnerHTML("ZZFindMe");
535 document().updateStyleAndLayout();
536
537 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions,
538 wrapWithinFrame, &activeNow));
539 Range* activeMatch = textFinder().activeMatch();
540 ASSERT_TRUE(activeMatch);
541 EXPECT_FALSE(activeNow);
542 EXPECT_EQ(2, activeMatch->startOffset());
543 EXPECT_EQ(8, activeMatch->endOffset());
544
545 // Restart full search and check that added text is found.
546 findOptions.findNext = false;
547 textFinder().resetMatchCount();
548 textFinder().cancelPendingScopingEffort();
549 textFinder().startScopingStringMatches(identifier, searchText, findOptions);
550 while (textFinder().scopingInProgress())
551 runPendingTasks();
552 EXPECT_EQ(1, textFinder().totalMatchCount());
553
554 WebVector<WebFloatRect> matchRects;
555 textFinder().findMatchRects(matchRects);
556 ASSERT_EQ(1u, matchRects.size());
557 Node* textInIElement = document().body()->lastChild()->firstChild();
558 EXPECT_EQ(findInPageRect(textInIElement, 2, textInIElement, 8),
559 matchRects[0]);
560 }
561
511 class TextFinderFakeTimerTest : public TextFinderTest { 562 class TextFinderFakeTimerTest : public TextFinderTest {
512 protected: 563 protected:
513 void SetUp() override { 564 void SetUp() override {
514 s_timeElapsed = 0.0; 565 s_timeElapsed = 0.0;
515 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); 566 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime);
516 } 567 }
517 568
518 void TearDown() override { 569 void TearDown() override {
519 setTimeFunctionsForTesting(m_originalTimeFunction); 570 setTimeFunctionsForTesting(m_originalTimeFunction);
520 } 571 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 // of the TimeProxyPlatform timer is greater than timeout threshold. 605 // of the TimeProxyPlatform timer is greater than timeout threshold.
555 textFinder().startScopingStringMatches(identifier, searchPattern, 606 textFinder().startScopingStringMatches(identifier, searchPattern,
556 findOptions); 607 findOptions);
557 while (textFinder().scopingInProgress()) 608 while (textFinder().scopingInProgress())
558 runPendingTasks(); 609 runPendingTasks();
559 610
560 EXPECT_EQ(4, textFinder().totalMatchCount()); 611 EXPECT_EQ(4, textFinder().totalMatchCount());
561 } 612 }
562 613
563 } // namespace blink 614 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/TextFinder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698