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

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: small clean up Created 4 years, 11 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 dc79c9f70374412e547454a6092adb04a728f5a3..fa1630d541149582978246355631f83f544496db 100644
--- a/third_party/WebKit/Source/web/tests/TextFinderTest.cpp
+++ b/third_party/WebKit/Source/web/tests/TextFinderTest.cpp
@@ -76,8 +76,9 @@ TEST_F(TextFinderTest, FindTextSimple)
WebFindOptions findOptions; // Default.
bool wrapWithinFrame = true;
WebRect* selectionRect = nullptr;
+ bool* activeNow = nullptr;
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
Range* activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textNode, activeMatch->startContainer());
@@ -86,7 +87,7 @@ TEST_F(TextFinderTest, FindTextSimple)
EXPECT_EQ(10, activeMatch->endOffset());
findOptions.findNext = true;
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textNode, activeMatch->startContainer());
@@ -95,7 +96,7 @@ TEST_F(TextFinderTest, FindTextSimple)
EXPECT_EQ(20, activeMatch->endOffset());
// Should wrap to the first match.
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textNode, activeMatch->startContainer());
@@ -108,7 +109,7 @@ TEST_F(TextFinderTest, FindTextSimple)
findOptions = WebFindOptions();
findOptions.forward = false;
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textNode, activeMatch->startContainer());
@@ -117,7 +118,7 @@ TEST_F(TextFinderTest, FindTextSimple)
EXPECT_EQ(20, activeMatch->endOffset());
findOptions.findNext = true;
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textNode, activeMatch->startContainer());
@@ -126,7 +127,7 @@ TEST_F(TextFinderTest, FindTextSimple)
EXPECT_EQ(10, activeMatch->endOffset());
// Wrap to the first match (last occurence in the document).
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textNode, activeMatch->startContainer());
@@ -144,6 +145,7 @@ TEST_F(TextFinderTest, FindTextAutosizing)
WebFindOptions findOptions; // Default.
bool wrapWithinFrame = true;
WebRect* selectionRect = nullptr;
+ bool* activeNow = nullptr;
// Set viewport scale to 20 in order to simulate zoom-in
VisualViewport& visualViewport = document().page()->frameHost().visualViewport();
@@ -155,7 +157,7 @@ TEST_F(TextFinderTest, FindTextAutosizing)
document().textAutosizer()->updatePageInfo();
// In case of autosizing, scale _should_ change
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
ASSERT_TRUE(textFinder().activeMatch());
ASSERT_EQ(1, visualViewport.scale()); // in this case to 1
@@ -164,7 +166,7 @@ TEST_F(TextFinderTest, FindTextAutosizing)
document().settings()->setTextAutosizingEnabled(false);
document().textAutosizer()->updatePageInfo();
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
ASSERT_TRUE(textFinder().activeMatch());
ASSERT_EQ(20, visualViewport.scale());
}
@@ -178,8 +180,9 @@ TEST_F(TextFinderTest, FindTextNotFound)
WebFindOptions findOptions; // Default.
bool wrapWithinFrame = true;
WebRect* selectionRect = nullptr;
+ bool* activeNow = nullptr;
- EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
EXPECT_FALSE(textFinder().activeMatch());
}
@@ -197,11 +200,12 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
WebFindOptions findOptions; // Default.
bool wrapWithinFrame = true;
WebRect* selectionRect = nullptr;
+ bool* activeNow = nullptr;
// TextIterator currently returns the matches in the composed treeorder, so
// in this case the matches will be returned in the order of
// <i> -> <u> -> <b>.
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
Range* activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textInIElement, activeMatch->startContainer());
@@ -210,7 +214,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
EXPECT_EQ(3, activeMatch->endOffset());
findOptions.findNext = true;
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textInUElement, activeMatch->startContainer());
@@ -218,7 +222,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
EXPECT_EQ(textInUElement, activeMatch->endContainer());
EXPECT_EQ(3, activeMatch->endOffset());
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textInBElement, activeMatch->startContainer());
@@ -227,7 +231,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
EXPECT_EQ(3, activeMatch->endOffset());
// Should wrap to the first match.
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textInIElement, activeMatch->startContainer());
@@ -240,7 +244,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
findOptions = WebFindOptions();
findOptions.forward = false;
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textInBElement, activeMatch->startContainer());
@@ -249,7 +253,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
EXPECT_EQ(3, activeMatch->endOffset());
findOptions.findNext = true;
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textInUElement, activeMatch->startContainer());
@@ -257,7 +261,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
EXPECT_EQ(textInUElement, activeMatch->endContainer());
EXPECT_EQ(3, activeMatch->endOffset());
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textInIElement, activeMatch->startContainer());
@@ -266,7 +270,7 @@ TEST_F(TextFinderTest, FindTextInShadowDOM)
EXPECT_EQ(3, activeMatch->endOffset());
// And wrap.
- ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect));
+ ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithinFrame, selectionRect, activeNow));
activeMatch = textFinder().activeMatch();
ASSERT_TRUE(activeMatch);
EXPECT_EQ(textInBElement, activeMatch->startContainer());
@@ -394,6 +398,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:
// A simple platform that mocks out the clock.

Powered by Google App Engine
This is Rietveld 408576698