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

Unified Diff: third_party/WebKit/Source/web/tests/TextFinderTest.cpp

Issue 1605863002: Restart search in page when new text is found. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added default value for local var Created 4 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/tests/TextFinderTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/TextFinderTest.cpp b/third_party/WebKit/Source/web/tests/TextFinderTest.cpp
index e3e716d68154a17c953a6a5ddf46ceba47c8ca96..653ce703a2867f5885c578235e71203d790051a3 100644
--- a/third_party/WebKit/Source/web/tests/TextFinderTest.cpp
+++ b/third_party/WebKit/Source/web/tests/TextFinderTest.cpp
@@ -394,6 +394,58 @@ TEST_F(TextFinderTest, SequentialMatches)
EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]);
}
+TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOM)
+{
+ document().body()->setInnerHTML("<b>XXXXFindMeYYYY</b><i></i>", ASSERT_NO_EXCEPTION);
+
+ int identifier = 0;
+ WebString searchText(String("FindMe"));
+ WebFindOptions findOptions; // Default.
+ bool wrapWithinFrame = true;
+ WebRect* selectionRect = nullptr;
+ bool activeNow;
+
+ textFinder().resetMatchCount();
+ textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
+ while (textFinder().scopingInProgress())
+ runPendingTasks();
+
+ findOptions.findNext = true;
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, &activeNow));
+ EXPECT_TRUE(activeNow);
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, &activeNow));
+ EXPECT_TRUE(activeNow);
+
+ // Add new text to DOM and try FindNext.
+ Element* iElement = toElement(document().body()->lastChild());
+ ASSERT_TRUE(iElement);
+ iElement->setInnerHTML("ZZFindMe", ASSERT_NO_EXCEPTION);
+
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, &activeNow));
+ Range* activeMatch = textFinder().activeMatch();
+ ASSERT_TRUE(activeMatch);
+ EXPECT_FALSE(activeNow);
+ EXPECT_EQ(2, activeMatch->startOffset());
+ EXPECT_EQ(8, activeMatch->endOffset());
+
+ // Restart full search and check that added text is found.
+ findOptions.findNext = false;
+ textFinder().resetMatchCount();
+ textFinder().cancelPendingScopingEffort();
+ textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
+ while (textFinder().scopingInProgress())
+ runPendingTasks();
+ EXPECT_EQ(2, textFinder().totalMatchCount());
+
+ WebVector<WebFloatRect> matchRects;
+ textFinder().findMatchRects(matchRects);
+ ASSERT_EQ(2u, matchRects.size());
+ Node* textInBElement = document().body()->firstChild()->firstChild();
+ Node* textInIElement = document().body()->lastChild()->firstChild();
+ EXPECT_EQ(findInPageRect(textInBElement, 4, textInBElement, 10), matchRects[0]);
+ EXPECT_EQ(findInPageRect(textInIElement, 2, textInIElement, 8), matchRects[1]);
+}
+
class TextFinderFakeTimerTest : public TextFinderTest {
protected:
void SetUp() override
« no previous file with comments | « third_party/WebKit/Source/web/WebLocalFrameImpl.cpp ('k') | third_party/WebKit/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698