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

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

Issue 2548253005: FindInPage: fix wrong match ordinal after javascript update. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/web/TextFinder.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/web/tests/WebFrameTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
index 380943d4bd35d176f42aaf4746e2d270e45c48ab..26ddeb5b94f45cb4bb6532bd0aadfb0a9e2dbb13 100644
--- a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
+++ b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
@@ -5004,6 +5004,88 @@ TEST_P(ParameterizedWebFrameTest, FindInPageJavaScriptUpdatesDOM) {
EXPECT_FALSE(activeNow);
}
+struct FakeTimerSetter {
kotenkov 2016/12/07 11:22:34 There are a couple of places containing similar co
+ FakeTimerSetter() {
+ s_timeElapsed = 0.0;
+ m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime);
+ }
+
+ ~FakeTimerSetter() { setTimeFunctionsForTesting(m_originalTimeFunction); }
+ static double returnMockTime() {
+ s_timeElapsed += 1.0;
+ return s_timeElapsed;
+ }
+
+ private:
+ TimeFunction m_originalTimeFunction;
+ static double s_timeElapsed;
+};
+double FakeTimerSetter::s_timeElapsed = 0.;
+
+TEST_P(ParameterizedWebFrameTest, FindInPageJavaScriptUpdatesDOMProperOrdinal) {
+ FakeTimerSetter fakeTimer;
+
+ const WebString searchPattern = WebString::fromUTF8("abc");
+ // We have 2 occurrences of the pattern in our text.
+ const char* html =
+ "foo bar foo bar foo abc bar foo bar foo bar foo bar foo bar foo bar foo "
+ "bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo "
+ "bar foo bar foo abc bar <div id='new_text'></div>";
+
+ FindUpdateWebFrameClient client;
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ webViewHelper.initialize(true, &client);
+
+ WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
+ FrameTestHelpers::loadHTMLString(frame, html,
+ URLTestHelpers::toKURL(m_baseURL));
+ webViewHelper.resize(WebSize(640, 480));
+ webViewHelper.webView()->setFocus(true);
+ runPendingTasks();
+
+ const int findIdentifier = 12345;
+ WebFindOptions options;
+
+ // The first search that will start the scoping process.
+ frame->requestFind(findIdentifier, searchPattern, options);
+ EXPECT_FALSE(client.findResultsAreReady());
+ EXPECT_EQ(1, client.count());
+ EXPECT_TRUE(frame->ensureTextFinder().scopingInProgress());
+
+ // The scoping won't find all the entries on the first run due to the fake
+ // timer.
+ while (frame->ensureTextFinder().scopingInProgress())
+ runPendingTasks();
+
+ EXPECT_EQ(2, client.count());
+ EXPECT_EQ(1, client.activeIndex());
+
+ options.findNext = true;
+
+ // The second search will jump to the next match without any scoping.
+ frame->requestFind(findIdentifier, searchPattern, options);
+
+ EXPECT_EQ(2, client.count());
+ EXPECT_EQ(2, client.activeIndex());
+ EXPECT_FALSE(frame->ensureTextFinder().scopingInProgress());
+
+ // Insert new text, which contains occurence of |searchText|.
+ frame->executeScript(
+ WebScriptSource("var textDiv = document.getElementById('new_text');"
+ "textDiv.innerHTML = 'foo abc';"));
+
+ // The third search will find a new match and initiate a new scoping.
+ frame->requestFind(findIdentifier, searchPattern, options);
+
+ EXPECT_TRUE(frame->ensureTextFinder().scopingInProgress());
+
+ while (frame->ensureTextFinder().scopingInProgress())
+ runPendingTasks();
+
+ EXPECT_EQ(3, client.count());
+ EXPECT_EQ(3, client.activeIndex());
+}
+
static WebPoint topLeft(const WebRect& rect) {
return WebPoint(rect.x, rect.y);
}
« 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