Commit 9ed2ebae authored by Yi Su's avatar Yi Su Committed by Commit Bot

Remove unused parameter |opt_split| in __gCrWeb.findInPage.highlightWord.

The parameter |opt_split| in __gCrWeb.findInPage.highlightWord is always
false. Since we don't support AND search in FindInPage, this parameter
should be removed. This is a preparation work for fixing the bug.

Bug: 228585
Change-Id: I4c0bd3381c7dc0f5012fa4c161814e52a5a1ec97
Reviewed-on: https://chromium-review.googlesource.com/c/1341834Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609273}
parent 52facbd9
...@@ -23,9 +23,10 @@ ...@@ -23,9 +23,10 @@
namespace { namespace {
// JavaScript invocation to search for 'foo' (for 1000 milliseconds). // JavaScript invocation format string, with one NSString placeholder for the
NSString* kJavaScriptToSearchForFoo = // search target and timeout set to 1000ms.
@"__gCrWeb.findInPage.highlightWord('foo', false, 1000)"; NSString* kJavaScriptSearchCallFormat =
@"__gCrWeb.findInPage.highlightWord('%@', 1000)";
// Other JavaScript functions invoked by the tests. // Other JavaScript functions invoked by the tests.
NSString* kJavaScriptIncrementIndex = @"__gCrWeb.findInPage.incrementIndex()"; NSString* kJavaScriptIncrementIndex = @"__gCrWeb.findInPage.incrementIndex()";
...@@ -97,7 +98,8 @@ class FindInPageJsTest : public ChromeWebTest { ...@@ -97,7 +98,8 @@ class FindInPageJsTest : public ChromeWebTest {
// Search for 'foo'. Performing the search sets the index to point to the // Search for 'foo'. Performing the search sets the index to point to the
// first visible occurrence of 'foo'. // first visible occurrence of 'foo'.
ExecuteJavaScript(kJavaScriptToSearchForFoo); ExecuteJavaScript(
[NSString stringWithFormat:kJavaScriptSearchCallFormat, @"foo"]);
AssertJavaScriptValue(kJavaScriptIndex, 1); AssertJavaScriptValue(kJavaScriptIndex, 1);
AssertJavaScriptValue(kJavaScriptSpansLength, kNumberOfFoosInHtml); AssertJavaScriptValue(kJavaScriptSpansLength, kNumberOfFoosInHtml);
} }
...@@ -194,7 +196,8 @@ TEST_F(FindInPageJsTest, NoneVisible) { ...@@ -194,7 +196,8 @@ TEST_F(FindInPageJsTest, NoneVisible) {
// Search for 'foo'. Performing the search sets the index to point to 0 since // Search for 'foo'. Performing the search sets the index to point to 0 since
// there are no visible occurrences of 'foo'. // there are no visible occurrences of 'foo'.
ExecuteJavaScript(kJavaScriptToSearchForFoo); ExecuteJavaScript(
[NSString stringWithFormat:kJavaScriptSearchCallFormat, @"foo"]);
AssertJavaScriptValue(kJavaScriptIndex, 0); AssertJavaScriptValue(kJavaScriptIndex, 0);
AssertJavaScriptValue(kJavaScriptSpansLength, 6); AssertJavaScriptValue(kJavaScriptSpansLength, 6);
...@@ -218,9 +221,8 @@ TEST_F(FindInPageJsTest, SearchForNonAscii) { ...@@ -218,9 +221,8 @@ TEST_F(FindInPageJsTest, SearchForNonAscii) {
// Search for the non-Ascii value. Performing the search sets the index to // Search for the non-Ascii value. Performing the search sets the index to
// point to the first visible occurrence of the non-Ascii. // point to the first visible occurrence of the non-Ascii.
NSString* result = ExecuteJavaScript([NSString NSString* result = ExecuteJavaScript(
stringWithFormat:@"__gCrWeb.findInPage.highlightWord('%@', false, 1000)", [NSString stringWithFormat:kJavaScriptSearchCallFormat, kNonAscii]);
kNonAscii]);
ASSERT_TRUE(result); ASSERT_TRUE(result);
AssertJavaScriptValue(kJavaScriptIndex, 0); AssertJavaScriptValue(kJavaScriptIndex, 0);
AssertJavaScriptValue(kJavaScriptSpansLength, 1); AssertJavaScriptValue(kJavaScriptSpansLength, 1);
...@@ -236,8 +238,8 @@ TEST_F(FindInPageJsTest, SearchForWhitespace) { ...@@ -236,8 +238,8 @@ TEST_F(FindInPageJsTest, SearchForWhitespace) {
// Search for space. Performing the search sets the index to // Search for space. Performing the search sets the index to
// point to the first visible occurrence of the whitespace. // point to the first visible occurrence of the whitespace.
NSString* result = NSString* result = ExecuteJavaScript(
ExecuteJavaScript(@"__gCrWeb.findInPage.highlightWord(' ', false, 1000)"); [NSString stringWithFormat:kJavaScriptSearchCallFormat, @" "]);
ASSERT_TRUE(result); ASSERT_TRUE(result);
AssertJavaScriptValue(kJavaScriptIndex, 0); AssertJavaScriptValue(kJavaScriptIndex, 0);
AssertJavaScriptValue(kJavaScriptSpansLength, 8); AssertJavaScriptValue(kJavaScriptSpansLength, 8);
......
...@@ -30,7 +30,7 @@ NSString* const kFindInPageInit = @"window.__gCrWeb.findInPage && " ...@@ -30,7 +30,7 @@ NSString* const kFindInPageInit = @"window.__gCrWeb.findInPage && "
// to spend any time at runtime to format this constant into another constant. // to spend any time at runtime to format this constant into another constant.
NSString* const kFindInPageVerbatim = NSString* const kFindInPageVerbatim =
@"window.__gCrWeb.findInPage && " @"window.__gCrWeb.findInPage && "
"window.__gCrWeb.findInPage.highlightWord(%@, false, 100.0);"; "window.__gCrWeb.findInPage.highlightWord(%@, 100.0);";
// The timeout of 100ms is hardcoded into this string so we don't have // The timeout of 100ms is hardcoded into this string so we don't have
// to spend any time at runtime to format this constant into another constant. // to spend any time at runtime to format this constant into another constant.
......
...@@ -107,27 +107,10 @@ function getCurrentSpan_() { ...@@ -107,27 +107,10 @@ function getCurrentSpan_() {
/** /**
* Creates the regex needed to find the text. * Creates the regex needed to find the text.
* @param {string} findText Phrase to look for. * @param {string} findText Phrase to look for.
* @param {boolean} opt_split True to split up the phrase.
* @return {RegExp} regex needed to find the text. * @return {RegExp} regex needed to find the text.
*/ */
function getRegex_(findText, opt_split) { function getRegex_(findText) {
let regexString = ''; let regexString = '(' + escapeRegex_(findText) + ')';
if (opt_split) {
let words = [];
let split = findText.split(' ');
for (let i = 0; i < split.length; i++) {
words.push(escapeRegex_(split[i]));
}
let joinedWords = words.join('|');
regexString = '(' +
// Match at least one word.
'\\b(?:' + joinedWords + ')' +
// Include zero or more additional words separated by whitespace.
'(?:\\s*\\b(?:' + joinedWords + '))*' +
')';
} else {
regexString = '(' + escapeRegex_(findText) + ')';
}
return new RegExp(regexString, 'ig'); return new RegExp(regexString, 'ig');
}; };
...@@ -153,14 +136,11 @@ __gCrWeb.findInPage.overTime = function() { ...@@ -153,14 +136,11 @@ __gCrWeb.findInPage.overTime = function() {
/** /**
* Looks for a phrase in the DOM. * Looks for a phrase in the DOM.
* @param {string} findText Phrase to look for like "ben franklin". * @param {string} findText Phrase to look for like "ben franklin".
* @param {boolean} opt_split True to split up the words and look for any
* of them. False to require the full phrase to be there.
* Undefined will try the full phrase, and if nothing is found do the split.
* @param {number} timeout Maximum time to run. * @param {number} timeout Maximum time to run.
* @return {string} How many results there are in the page in the form of * @return {string} How many results there are in the page in the form of
[highlightedWordsCount, [index, pageLocationX, pageLocationY]]. [highlightedWordsCount, [index, pageLocationX, pageLocationY]].
*/ */
__gCrWeb.findInPage.highlightWord = function(findText, opt_split, timeout) { __gCrWeb.findInPage.highlightWord = function(findText, timeout) {
if (__gCrWeb.findInPage.spans && __gCrWeb.findInPage.spans.length) { if (__gCrWeb.findInPage.spans && __gCrWeb.findInPage.spans.length) {
// Clean up a previous run. // Clean up a previous run.
clearHighlight_(); clearHighlight_();
...@@ -193,7 +173,7 @@ __gCrWeb.findInPage.highlightWord = function(findText, opt_split, timeout) { ...@@ -193,7 +173,7 @@ __gCrWeb.findInPage.highlightWord = function(findText, opt_split, timeout) {
__gCrWeb.findInPage.replacementsIndex = 0; __gCrWeb.findInPage.replacementsIndex = 0;
__gCrWeb.findInPage.replacementNewNodesIndex = 0; __gCrWeb.findInPage.replacementNewNodesIndex = 0;
__gCrWeb.findInPage.regex = getRegex_(findText, opt_split); __gCrWeb.findInPage.regex = getRegex_(findText);
searchInProgress_ = true; searchInProgress_ = true;
...@@ -209,7 +189,6 @@ __gCrWeb.findInPage.highlightWord = function(findText, opt_split, timeout) { ...@@ -209,7 +189,6 @@ __gCrWeb.findInPage.highlightWord = function(findText, opt_split, timeout) {
whether the text was found and int idicates text position. whether the text was found and int idicates text position.
*/ */
__gCrWeb.findInPage.pumpSearch = function(timeout) { __gCrWeb.findInPage.pumpSearch = function(timeout) {
let opt_split = false;
// TODO(justincohen): It would be better if this DCHECKed. // TODO(justincohen): It would be better if this DCHECKed.
if (searchInProgress_ == false) if (searchInProgress_ == false)
return NO_RESULTS; return NO_RESULTS;
...@@ -335,25 +314,11 @@ __gCrWeb.findInPage.pumpSearch = function(timeout) { ...@@ -335,25 +314,11 @@ __gCrWeb.findInPage.pumpSearch = function(timeout) {
searchInProgress_ = false; searchInProgress_ = false;
// Try again flow. let pos = __gCrWeb.findInPage.goNext();
// If opt_split is true, we are done since we won't do any better. if (pos) {
// If opt_split is false, they were explicit about wanting the full thing return '[' + __gCrWeb.findInPage.visibleFound + ',' + pos + ']';
// so do not try with a split.
// If opt_split is undefined and we did not find an answer, go ahead and try
// splitting the terms.
if (__gCrWeb.findInPage.spans.length == 0 && opt_split === undefined) {
// Try to be more aggressive:
return __gCrWeb.findInPage.highlightWord(findText, true);
} else { } else {
let pos = __gCrWeb.findInPage.goNext(); return NO_RESULTS;
if (pos) {
return '[' + __gCrWeb.findInPage.visibleFound + ',' + pos + ']';
} else if (opt_split === undefined) {
// Nothing visible, go ahead and be more aggressive.
return __gCrWeb.findInPage.highlightWord(findText, true);
} else {
return NO_RESULTS;
}
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment