Index: chrome/browser/autocomplete/keyword_provider_unittest.cc |
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc |
index 617811b45045c4769e7a404538dd6fa0e9e10793..d6e53651a4ae95b88f85a06a749c082bb82bcd73 100644 |
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc |
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc |
@@ -17,10 +17,16 @@ |
class KeywordProviderTest : public testing::Test { |
protected: |
template<class ResultType> |
- struct test_data { |
+ struct MatchType { |
+ const ResultType member; |
+ bool allowed_to_be_default_match; |
+ }; |
+ |
+ template<class ResultType> |
+ struct TestData { |
const string16 input; |
const size_t num_results; |
- const ResultType output[3]; |
+ const MatchType<ResultType> output[3]; |
}; |
KeywordProviderTest() : kw_provider_(NULL) { } |
@@ -30,7 +36,7 @@ class KeywordProviderTest : public testing::Test { |
virtual void TearDown(); |
template<class ResultType> |
- void RunTest(test_data<ResultType>* keyword_cases, |
+ void RunTest(TestData<ResultType>* keyword_cases, |
int num_cases, |
ResultType AutocompleteMatch::* member); |
@@ -64,7 +70,7 @@ void KeywordProviderTest::TearDown() { |
template<class ResultType> |
void KeywordProviderTest::RunTest( |
- test_data<ResultType>* keyword_cases, |
+ TestData<ResultType>* keyword_cases, |
int num_cases, |
ResultType AutocompleteMatch::* member) { |
ACMatches matches; |
@@ -75,60 +81,87 @@ void KeywordProviderTest::RunTest( |
kw_provider_->Start(input, false); |
EXPECT_TRUE(kw_provider_->done()); |
matches = kw_provider_->matches(); |
- EXPECT_EQ(keyword_cases[i].num_results, matches.size()) << |
- ASCIIToUTF16("Input was: ") + keyword_cases[i].input; |
+ const string16 description = |
Peter Kasting
2013/08/06 22:56:16
Nit: Maybe instead of manually adding "<< descript
Mark P
2013/08/07 00:44:31
Done.
|
+ ASCIIToUTF16("Input was: ") + keyword_cases[i].input; |
+ EXPECT_EQ(keyword_cases[i].num_results, matches.size()) << description; |
if (matches.size() == keyword_cases[i].num_results) { |
- for (size_t j = 0; j < keyword_cases[i].num_results; ++j) { |
- EXPECT_EQ(keyword_cases[i].output[j], matches[j].*member); |
+ for (size_t j = 0; j < matches.size(); ++j) { |
+ EXPECT_EQ(keyword_cases[i].output[j].member, matches[j].*member) << |
+ description; |
+ EXPECT_EQ(keyword_cases[i].output[j].allowed_to_be_default_match, |
+ matches[j].allowed_to_be_default_match) << description; |
} |
} |
} |
} |
TEST_F(KeywordProviderTest, Edit) { |
- test_data<string16> edit_cases[] = { |
+ const MatchType<string16> kEmptyMatch = { string16(), false }; |
+ TestData<string16> edit_cases[] = { |
// Searching for a nonexistent prefix should give nothing. |
- {ASCIIToUTF16("Not Found"), 0, {}}, |
- {ASCIIToUTF16("aaaaaNot Found"), 0, {}}, |
+ { ASCIIToUTF16("Not Found"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("aaaaaNot Found"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
// Check that tokenization only collapses whitespace between first tokens, |
// no-query-input cases have a space appended, and action is not escaped. |
- {ASCIIToUTF16("z"), 1, {ASCIIToUTF16("z ")}}, |
- {ASCIIToUTF16("z \t"), 1, {ASCIIToUTF16("z ")}}, |
+ { ASCIIToUTF16("z"), 1, |
+ { { ASCIIToUTF16("z "), true }, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("z \t"), 1, |
+ { { ASCIIToUTF16("z "), true }, kEmptyMatch, kEmptyMatch } }, |
// Check that exact, substituting keywords with a verbatim search term |
// don't generate a result. (These are handled by SearchProvider.) |
- {ASCIIToUTF16("z foo"), 0, {}}, |
- {ASCIIToUTF16("z a b c++"), 0, {}}, |
+ { ASCIIToUTF16("z foo"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("z a b c++"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
// Matches should be limited to three, and sorted in quality order, not |
// alphabetical. |
- {ASCIIToUTF16("aaa"), 2, {ASCIIToUTF16("aaaa "), |
- ASCIIToUTF16("aaaaa ")}}, |
- {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("aa 1 2 3"), |
- ASCIIToUTF16("ab 1 2 3"), |
- ASCIIToUTF16("aaaa 1 2 3")}}, |
- {ASCIIToUTF16("www.a"), 3, {ASCIIToUTF16("aa "), |
- ASCIIToUTF16("ab "), |
- ASCIIToUTF16("aaaa ")}}, |
+ { ASCIIToUTF16("aaa"), 2, |
+ { { ASCIIToUTF16("aaaa "), false }, |
+ { ASCIIToUTF16("aaaaa "), false }, |
+ kEmptyMatch } }, |
+ { ASCIIToUTF16("a 1 2 3"), 3, |
+ { { ASCIIToUTF16("aa 1 2 3"), false }, |
+ { ASCIIToUTF16("ab 1 2 3"), false }, |
+ { ASCIIToUTF16("aaaa 1 2 3"), false } } }, |
+ { ASCIIToUTF16("www.a"), 3, |
+ { { ASCIIToUTF16("aa "), false }, |
+ { ASCIIToUTF16("ab "), false }, |
+ { ASCIIToUTF16("aaaa "), false } } }, |
// Exact matches should prevent returning inexact matches. Also, the |
// verbatim query for this keyword match should not be returned. (It's |
// returned by SearchProvider.) |
- {ASCIIToUTF16("aaaa foo"), 0, {}}, |
- {ASCIIToUTF16("www.aaaa foo"), 0, {}}, |
+ { ASCIIToUTF16("aaaa foo"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("www.aaaa foo"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
// Clean up keyword input properly. "http" and "https" are the only |
// allowed schemes. |
- {ASCIIToUTF16("www"), 1, {ASCIIToUTF16("www ")}}, |
- {ASCIIToUTF16("www."), 0, {}}, |
- {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("www w"), |
- ASCIIToUTF16("weasel w")}}, |
- {ASCIIToUTF16("http://www"), 1, {ASCIIToUTF16("www ")}}, |
- {ASCIIToUTF16("http://www."), 0, {}}, |
- {ASCIIToUTF16("ftp: blah"), 0, {}}, |
- {ASCIIToUTF16("mailto:z"), 0, {}}, |
- {ASCIIToUTF16("ftp://z"), 0, {}}, |
- {ASCIIToUTF16("https://z"), 1, {ASCIIToUTF16("z ")}}, |
+ { ASCIIToUTF16("www"), 1, |
+ { { ASCIIToUTF16("www "), true }, kEmptyMatch, kEmptyMatch }}, |
+ { ASCIIToUTF16("www."), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("www.w w"), 2, |
+ { { ASCIIToUTF16("www w"), false }, |
+ { ASCIIToUTF16("weasel w"), false }, |
+ kEmptyMatch } }, |
+ { ASCIIToUTF16("http://www"), 1, |
+ { { ASCIIToUTF16("www "), true }, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("http://www."), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("ftp: blah"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("mailto:z"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("ftp://z"), 0, |
+ { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
+ { ASCIIToUTF16("https://z"), 1, |
+ { { ASCIIToUTF16("z "), true }, kEmptyMatch, kEmptyMatch } }, |
}; |
RunTest<string16>(edit_cases, arraysize(edit_cases), |
@@ -136,24 +169,26 @@ TEST_F(KeywordProviderTest, Edit) { |
} |
TEST_F(KeywordProviderTest, URL) { |
- test_data<GURL> url_cases[] = { |
+ TestData<GURL> url_cases[] = { |
// No query input -> empty destination URL. |
- {ASCIIToUTF16("z"), 1, {GURL()}}, |
- {ASCIIToUTF16("z \t"), 1, {GURL()}}, |
+ {ASCIIToUTF16("z"), 1, {{GURL(), true}}}, |
+ {ASCIIToUTF16("z \t"), 1, {{GURL(), true}}}, |
// Check that tokenization only collapses whitespace between first tokens |
// and query input, but not rest of URL, is escaped. |
- {ASCIIToUTF16("w bar +baz"), 2, {GURL(" +%2B?=bar+%2Bbazfoo "), |
- GURL("bar+%2Bbaz=z")}}, |
+ {ASCIIToUTF16("w bar +baz"), 2, {{GURL(" +%2B?=bar+%2Bbazfoo "), false}, |
+ {GURL("bar+%2Bbaz=z"), false}}}, |
// Substitution should work with various locations of the "%s". |
- {ASCIIToUTF16("aaa 1a2b"), 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"), |
- GURL("1a2b")}}, |
- {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?foo=1+2+3"), |
- GURL("bogus URL 1+2+3"), |
- GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}}, |
- {ASCIIToUTF16("www.w w"), 2, {GURL(" +%2B?=wfoo "), |
- GURL("weaselwweasel")}}, |
+ {ASCIIToUTF16("aaa 1a2b"), 2, |
+ {{GURL("http://aaaa/?aaaa=1&b=1a2b&c"), false}, |
+ {GURL("1a2b"), false}}}, |
+ {ASCIIToUTF16("a 1 2 3"), 3, |
+ {{GURL("aa.com?foo=1+2+3"), false}, |
+ {GURL("bogus URL 1+2+3"), false}, |
+ {GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false}}}, |
+ {ASCIIToUTF16("www.w w"), 2, {{GURL(" +%2B?=wfoo "), false}, |
+ {GURL("weaselwweasel"), false}}}, |
}; |
RunTest<GURL>(url_cases, arraysize(url_cases), |
@@ -161,12 +196,12 @@ TEST_F(KeywordProviderTest, URL) { |
} |
TEST_F(KeywordProviderTest, Contents) { |
- test_data<string16> contents_cases[] = { |
+ TestData<string16> contents_cases[] = { |
// No query input -> substitute "<enter query>" into contents. |
{ASCIIToUTF16("z"), 1, |
- {ASCIIToUTF16("Search z for <enter query>")}}, |
+ {{ASCIIToUTF16("Search z for <enter query>"), true}}}, |
{ASCIIToUTF16("z \t"), 1, |
- {ASCIIToUTF16("Search z for <enter query>")}}, |
+ {{ASCIIToUTF16("Search z for <enter query>"), true}}}, |
// Exact keyword matches with remaining text should return nothing. |
{ASCIIToUTF16("www.www www"), 0, {}}, |
@@ -179,17 +214,17 @@ TEST_F(KeywordProviderTest, Contents) { |
// Substitution should work with various locations of the "%s". |
{ASCIIToUTF16("aaa"), 2, |
- {ASCIIToUTF16("Search aaaa for <enter query>"), |
- ASCIIToUTF16("Search aaaaa for <enter query>")}}, |
+ {{ASCIIToUTF16("Search aaaa for <enter query>"), false}, |
+ {ASCIIToUTF16("Search aaaaa for <enter query>"), false}}}, |
{ASCIIToUTF16("www.w w"), 2, |
- {ASCIIToUTF16("Search www for w"), |
- ASCIIToUTF16("Search weasel for w")}}, |
+ {{ASCIIToUTF16("Search www for w"), false}, |
+ {ASCIIToUTF16("Search weasel for w"), false}}}, |
// Also, check that tokenization only collapses whitespace between first |
// tokens and contents are not escaped or unescaped. |
{ASCIIToUTF16("a 1 2+ 3"), 3, |
- {ASCIIToUTF16("Search aa for 1 2+ 3"), |
- ASCIIToUTF16("Search ab for 1 2+ 3"), |
- ASCIIToUTF16("Search aaaa for 1 2+ 3")}}, |
+ {{ASCIIToUTF16("Search aa for 1 2+ 3"), false}, |
+ {ASCIIToUTF16("Search ab for 1 2+ 3"), false}, |
+ {ASCIIToUTF16("Search aaaa for 1 2+ 3"), false}}}, |
}; |
RunTest<string16>(contents_cases, arraysize(contents_cases), |
@@ -286,10 +321,11 @@ TEST_F(KeywordProviderTest, ExtraQueryParams) { |
CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
switches::kExtraSearchQueryParams, "a=b"); |
- test_data<GURL> url_cases[] = { |
- {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?a=b&foo=1+2+3"), |
- GURL("bogus URL 1+2+3"), |
- GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}}, |
+ TestData<GURL> url_cases[] = { |
+ {ASCIIToUTF16("a 1 2 3"), 3, |
+ {{GURL("aa.com?a=b&foo=1+2+3"), false}, |
+ {GURL("bogus URL 1+2+3"), false}, |
+ {GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false}}}, |
}; |
RunTest<GURL>(url_cases, arraysize(url_cases), |