| Index: chrome/browser/autocomplete/search_provider_unittest.cc
|
| diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
|
| index d92fa2b890359bbe2ac1d607b1e2234db990a902..044ab754df528173798a04a8f1ad3a7b07cbc2ee 100644
|
| --- a/chrome/browser/autocomplete/search_provider_unittest.cc
|
| +++ b/chrome/browser/autocomplete/search_provider_unittest.cc
|
| @@ -437,14 +437,18 @@ void SearchProviderTest::ForcedQueryTestHelper(
|
| const std::string& json,
|
| const std::string expected_matches[3],
|
| const std::string& error_description) {
|
| - QueryForInput(ASCIIToUTF16(input), false, false);
|
| - net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
|
| - SearchProvider::kDefaultProviderURLFetcherID);
|
| - ASSERT_TRUE(fetcher);
|
| - fetcher->set_response_code(200);
|
| - fetcher->SetResponseString(json);
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| - RunTillProviderDone();
|
| + // Send the query twice in order to bypass checks about whether a single
|
| + // new reply can change the inline autocompletion.
|
| + for (size_t i = 0; i < 2; i++) {
|
| + QueryForInput(ASCIIToUTF16(input), false, false);
|
| + net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
|
| + SearchProvider::kDefaultProviderURLFetcherID);
|
| + ASSERT_TRUE(fetcher);
|
| + fetcher->set_response_code(200);
|
| + fetcher->SetResponseString(json);
|
| + fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| + RunTillProviderDone();
|
| + }
|
|
|
| const ACMatches& matches = provider_->matches();
|
| ASSERT_LE(matches.size(), 3u);
|
| @@ -1126,7 +1130,7 @@ TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) {
|
| AutocompleteMatch nav_match;
|
| EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match));
|
| EXPECT_TRUE(nav_match.keyword.empty());
|
| - EXPECT_TRUE(nav_match.allowed_to_be_default_match);
|
| + EXPECT_FALSE(nav_match.allowed_to_be_default_match);
|
| EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match));
|
| }
|
|
|
| @@ -1159,9 +1163,9 @@ TEST_F(SearchProviderTest, SuggestRelevance) {
|
| EXPECT_GT(match_a1.relevance, match_a2.relevance);
|
| EXPECT_GT(match_a2.relevance, match_a3.relevance);
|
| EXPECT_TRUE(verbatim.allowed_to_be_default_match);
|
| - EXPECT_TRUE(match_a1.allowed_to_be_default_match);
|
| - EXPECT_TRUE(match_a2.allowed_to_be_default_match);
|
| - EXPECT_TRUE(match_a3.allowed_to_be_default_match);
|
| + EXPECT_FALSE(match_a1.allowed_to_be_default_match);
|
| + EXPECT_FALSE(match_a2.allowed_to_be_default_match);
|
| + EXPECT_FALSE(match_a3.allowed_to_be_default_match);
|
| }
|
|
|
| // Verifies that the default provider abandons suggested relevance scores
|
| @@ -1194,22 +1198,26 @@ TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) {
|
| };
|
|
|
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
|
| - QueryForInput(ASCIIToUTF16("k a"), false, true);
|
| - net::TestURLFetcher* default_fetcher =
|
| - test_factory_.GetFetcherByID(
|
| - SearchProvider::kDefaultProviderURLFetcherID);
|
| - ASSERT_TRUE(default_fetcher);
|
| - default_fetcher->set_response_code(200);
|
| - default_fetcher->SetResponseString(cases[i].default_provider_json);
|
| - default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
|
| - net::TestURLFetcher* keyword_fetcher =
|
| - test_factory_.GetFetcherByID(
|
| - SearchProvider::kKeywordProviderURLFetcherID);
|
| - ASSERT_TRUE(keyword_fetcher);
|
| - keyword_fetcher->set_response_code(200);
|
| - keyword_fetcher->SetResponseString(cases[i].keyword_provider_json);
|
| - keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
|
| - RunTillProviderDone();
|
| + // Send the query twice in order to bypass checks about whether a single
|
| + // new reply can change the inline autocompletion.
|
| + for (size_t j = 0; j < 2; j++) {
|
| + QueryForInput(ASCIIToUTF16("k a"), false, true);
|
| + net::TestURLFetcher* default_fetcher =
|
| + test_factory_.GetFetcherByID(
|
| + SearchProvider::kDefaultProviderURLFetcherID);
|
| + ASSERT_TRUE(default_fetcher);
|
| + default_fetcher->set_response_code(200);
|
| + default_fetcher->SetResponseString(cases[i].default_provider_json);
|
| + default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
|
| + net::TestURLFetcher* keyword_fetcher =
|
| + test_factory_.GetFetcherByID(
|
| + SearchProvider::kKeywordProviderURLFetcherID);
|
| + ASSERT_TRUE(keyword_fetcher);
|
| + keyword_fetcher->set_response_code(200);
|
| + keyword_fetcher->SetResponseString(cases[i].keyword_provider_json);
|
| + keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
|
| + RunTillProviderDone();
|
| + }
|
|
|
| const std::string description = "for input with default_provider_json=" +
|
| cases[i].default_provider_json + " and keyword_provider_json=" +
|
| @@ -1267,7 +1275,7 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
|
| // Negative values will have no effect; the calculated value will be used.
|
| { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
|
| "\"google:suggestrelevance\":[9998]}]",
|
| - { { "a", true}, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
|
| + { { "a", true}, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
|
| kEmptyMatch },
|
| std::string() },
|
| { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
|
| @@ -1289,8 +1297,8 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
|
| "{\"google:suggesttype\":[\"NAVIGATION\"],"
|
| "\"google:verbatimrelevance\":9999,"
|
| "\"google:suggestrelevance\":[9998]}]",
|
| - { { "a", true }, { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
|
| - kEmptyMatch },
|
| + { { "a", true }, { "a.com", false }, kEmptyMatch, kEmptyMatch,
|
| + kEmptyMatch, kEmptyMatch },
|
| std::string() },
|
| { "[\"a\",[\"http://a.com\"],[],[],"
|
| "{\"google:suggesttype\":[\"NAVIGATION\"],"
|
| @@ -1317,8 +1325,8 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
|
| // Ensure that both types of relevance scores reorder matches together.
|
| { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
|
| "\"google:verbatimrelevance\":9998}]",
|
| - { { "a1", true }, { "a", true }, { "a2", true }, kEmptyMatch, kEmptyMatch,
|
| - kEmptyMatch },
|
| + { { "a1", true }, { "a", true }, { "a2", false }, kEmptyMatch,
|
| + kEmptyMatch, kEmptyMatch },
|
| "1" },
|
|
|
| // Allow non-inlineable matches to be the highest-scoring match but,
|
| @@ -1363,13 +1371,13 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
|
| "1" },
|
| { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2],"
|
| "\"google:verbatimrelevance\":0}]",
|
| - { { "a2", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
|
| + { { "a2", true }, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
|
| kEmptyMatch },
|
| "2" },
|
| { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3],"
|
| "\"google:verbatimrelevance\":2}]",
|
| - { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch,
|
| - kEmptyMatch },
|
| + { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch,
|
| + kEmptyMatch, kEmptyMatch },
|
| "2" },
|
| { "[\"a\",[\"http://a.com\"],[],[],"
|
| "{\"google:suggesttype\":[\"NAVIGATION\"],"
|
| @@ -1382,7 +1390,7 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
|
| "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
|
| "\"google:suggestrelevance\":[1, 2],"
|
| "\"google:verbatimrelevance\":0}]",
|
| - { { "a2.com", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch,
|
| + { { "a2.com", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch,
|
| kEmptyMatch, kEmptyMatch },
|
| "2.com" },
|
|
|
| @@ -1406,37 +1414,37 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
|
|
|
| // Ensure that incorrectly sized suggestion relevance lists are ignored.
|
| { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
|
| - { { "a", true }, { "a1", true }, { "a2", true }, kEmptyMatch, kEmptyMatch,
|
| - kEmptyMatch },
|
| + { { "a", true }, { "a1", false }, { "a2", false }, kEmptyMatch,
|
| + kEmptyMatch, kEmptyMatch },
|
| std::string() },
|
| { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
|
| - { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
|
| + { { "a", true }, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
|
| kEmptyMatch },
|
| std::string() },
|
| { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
|
| "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
|
| "\"google:suggestrelevance\":[1]}]",
|
| - { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch,
|
| + { { "a", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch,
|
| kEmptyMatch, kEmptyMatch },
|
| std::string() },
|
| { "[\"a\",[\"http://a1.com\"],[],[],"
|
| "{\"google:suggesttype\":[\"NAVIGATION\"],"
|
| "\"google:suggestrelevance\":[9999, 1]}]",
|
| - { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch,
|
| + { { "a", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch,
|
| kEmptyMatch, kEmptyMatch },
|
| std::string() },
|
|
|
| // Ensure that all 'verbatim' results are merged with their maximum score.
|
| { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
|
| "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
|
| - { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch,
|
| - kEmptyMatch },
|
| + { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch,
|
| + kEmptyMatch, kEmptyMatch },
|
| "2" },
|
| { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
|
| "{\"google:suggestrelevance\":[9998, 9997, 9999],"
|
| "\"google:verbatimrelevance\":0}]",
|
| - { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch,
|
| - kEmptyMatch },
|
| + { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch,
|
| + kEmptyMatch, kEmptyMatch },
|
| "2" },
|
|
|
| // Ensure that verbatim is always generated without other suggestions.
|
| @@ -1452,15 +1460,19 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
|
| };
|
|
|
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
|
| - QueryForInput(ASCIIToUTF16("a"), false, false);
|
| - net::TestURLFetcher* fetcher =
|
| - test_factory_.GetFetcherByID(
|
| - SearchProvider::kDefaultProviderURLFetcherID);
|
| - ASSERT_TRUE(fetcher);
|
| - fetcher->set_response_code(200);
|
| - fetcher->SetResponseString(cases[i].json);
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| - RunTillProviderDone();
|
| + // Send the query twice in order to bypass checks about whether a single
|
| + // new reply can change the inline autocompletion.
|
| + for (size_t j = 0; j < 2; j++) {
|
| + QueryForInput(ASCIIToUTF16("a"), false, false);
|
| + net::TestURLFetcher* fetcher =
|
| + test_factory_.GetFetcherByID(
|
| + SearchProvider::kDefaultProviderURLFetcherID);
|
| + ASSERT_TRUE(fetcher);
|
| + fetcher->set_response_code(200);
|
| + fetcher->SetResponseString(cases[i].json);
|
| + fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| + RunTillProviderDone();
|
| + }
|
|
|
| const std::string description = "for input with json=" + cases[i].json;
|
| const ACMatches& matches = provider_->matches();
|
| @@ -1550,7 +1562,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
|
| "\"google:suggestrelevance\":[9998]}]",
|
| { { "a", true, true },
|
| - { "a1", true, true },
|
| + { "a1", true, false },
|
| { "k a", false, false },
|
| kEmptyMatch, kEmptyMatch, kEmptyMatch },
|
| std::string() },
|
| @@ -1589,7 +1601,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| "\"google:verbatimrelevance\":9998}]",
|
| { { "a1", true, true },
|
| { "a", true, true },
|
| - { "a2", true, true },
|
| + { "a2", true, false },
|
| { "k a", false, false },
|
| kEmptyMatch, kEmptyMatch },
|
| "1" },
|
| @@ -1654,7 +1666,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| {
|
| { "k a", false, false },
|
| { "a2", true, true },
|
| - { "a1", true, true },
|
| + { "a1", true, false },
|
| kEmptyMatch, kEmptyMatch, kEmptyMatch },
|
| "2" },
|
| { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3],"
|
| @@ -1662,7 +1674,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| { { "k a", false, false },
|
| { "a2", true, true },
|
| { "a", true, true },
|
| - { "a1", true, true },
|
| + { "a1", true, false },
|
| kEmptyMatch, kEmptyMatch },
|
| "2" },
|
|
|
| @@ -1697,14 +1709,14 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| // mode) score more highly than the default verbatim.
|
| { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
|
| { { "a", true, true },
|
| - { "a1", true, true },
|
| - { "a2", true, true },
|
| + { "a1", true, false },
|
| + { "a2", true, false },
|
| { "k a", false, false },
|
| kEmptyMatch, kEmptyMatch },
|
| std::string() },
|
| { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
|
| { { "a", true, true },
|
| - { "a1", true, true },
|
| + { "a1", true, false },
|
| { "k a", false, false },
|
| kEmptyMatch, kEmptyMatch, kEmptyMatch },
|
| std::string() },
|
| @@ -1732,7 +1744,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
|
| { { "a2", true, true },
|
| { "a", true, true },
|
| - { "a1", true, true },
|
| + { "a1", true, false },
|
| { "k a", false, false },
|
| kEmptyMatch, kEmptyMatch },
|
| "2" },
|
| @@ -1741,7 +1753,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| "\"google:verbatimrelevance\":0}]",
|
| { { "a2", true, true },
|
| { "a", true, true },
|
| - { "a1", true, true },
|
| + { "a1", true, false },
|
| { "k a", false, false },
|
| kEmptyMatch, kEmptyMatch },
|
| "2" },
|
| @@ -1800,7 +1812,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| { { "a2.com", false, false },
|
| { "a1.com", false, false },
|
| { "a", true, true },
|
| - { "a3", true, true },
|
| + { "a3", true, false },
|
| { "k a", false, false },
|
| kEmptyMatch },
|
| std::string() },
|
| @@ -1811,7 +1823,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| { { "a1.com", false, false },
|
| { "a2.com", false, false },
|
| { "a", true, true },
|
| - { "a3", true, true },
|
| + { "a3", true, false },
|
| { "k a", false, false },
|
| kEmptyMatch },
|
| std::string() },
|
| @@ -1908,27 +1920,31 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| };
|
|
|
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
|
| - QueryForInput(ASCIIToUTF16("k a"), false, true);
|
| + // Send the query twice in order to bypass checks about whether a single
|
| + // new reply can change the inline autocompletion.
|
| + for (size_t j = 0; j < 2; j++) {
|
| + QueryForInput(ASCIIToUTF16("k a"), false, true);
|
|
|
| - // Set up a default fetcher with no results.
|
| - net::TestURLFetcher* default_fetcher =
|
| - test_factory_.GetFetcherByID(
|
| - SearchProvider::kDefaultProviderURLFetcherID);
|
| - ASSERT_TRUE(default_fetcher);
|
| - default_fetcher->set_response_code(200);
|
| - default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
|
| - default_fetcher = NULL;
|
| + // Set up a default fetcher with no results.
|
| + net::TestURLFetcher* default_fetcher =
|
| + test_factory_.GetFetcherByID(
|
| + SearchProvider::kDefaultProviderURLFetcherID);
|
| + ASSERT_TRUE(default_fetcher);
|
| + default_fetcher->set_response_code(200);
|
| + default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
|
| + default_fetcher = NULL;
|
|
|
| - // Set up a keyword fetcher with provided results.
|
| - net::TestURLFetcher* keyword_fetcher =
|
| - test_factory_.GetFetcherByID(
|
| - SearchProvider::kKeywordProviderURLFetcherID);
|
| - ASSERT_TRUE(keyword_fetcher);
|
| - keyword_fetcher->set_response_code(200);
|
| - keyword_fetcher->SetResponseString(cases[i].json);
|
| - keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
|
| - keyword_fetcher = NULL;
|
| - RunTillProviderDone();
|
| + // Set up a keyword fetcher with provided results.
|
| + net::TestURLFetcher* keyword_fetcher =
|
| + test_factory_.GetFetcherByID(
|
| + SearchProvider::kKeywordProviderURLFetcherID);
|
| + ASSERT_TRUE(keyword_fetcher);
|
| + keyword_fetcher->set_response_code(200);
|
| + keyword_fetcher->SetResponseString(cases[i].json);
|
| + keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
|
| + keyword_fetcher = NULL;
|
| + RunTillProviderDone();
|
| + }
|
|
|
| const std::string description = "for input with json=" + cases[i].json;
|
| const ACMatches& matches = provider_->matches();
|
| @@ -1958,6 +1974,127 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
|
| }
|
| }
|
|
|
| +TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) {
|
| + struct Match {
|
| + std::string contents;
|
| + bool allowed_to_be_default_match;
|
| + };
|
| + const Match kEmptyMatch = { kNotApplicable, false };
|
| + // This test sends two separate queries, each receiving different JSON
|
| + // replies, and checks that receiving the second reply doesn't cause
|
| + // an unexpected inline autcompletion.
|
| + struct {
|
| + const std::string first_json;
|
| + const std::string second_json;
|
| + const Match matches[4];
|
| + } cases[] = {
|
| + // A simple test that verifies we inline autocomplete if the new top
|
| + // suggestion is the same as the old inline autocompleted suggestion.
|
| + { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggestrelevance\":[1302, 1301]}]",
|
| + "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggestrelevance\":[1302, 1301]}]",
|
| + { { "ab1", true }, { "ab2", false }, { "ab", true }, kEmptyMatch } },
|
| + // Ditto, just for a navigation suggestion.
|
| + { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
|
| + "\"google:suggestrelevance\":[1302, 1301]}]",
|
| + "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
|
| + "\"google:suggestrelevance\":[1302, 1301]}]",
|
| + { { "ab1.com", true }, { "ab2.com", false }, { "ab", true },
|
| + kEmptyMatch } },
|
| +
|
| + // Without an original inline autcompletion, a new inline autcompletion
|
| + // should be rejected.
|
| + { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggestrelevance\":[900, 800]}]",
|
| + "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
|
| + "{\"google:suggestrelevance\":[1302, 1301],"
|
| + "\"google:verbatimrelevance\":1300}]",
|
| + { { "ab1", false }, { "ab2", false }, { "ab", true }, kEmptyMatch } },
|
| + { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggestrelevance\":[900, 800]}]",
|
| + "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggestrelevance\":[1301, 1302]}]",
|
| + { { "ab2", false }, { "ab1", false }, { "ab", true }, kEmptyMatch } },
|
| + // Now, the same verifications but with the new inline autocompletion as a
|
| + // navsuggestion. The new autocompletion should still be rejected.
|
| + { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
|
| + "\"google:suggestrelevance\":[900, 800]}]",
|
| + "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
|
| + "\"google:suggestrelevance\":[1302, 1301]}]",
|
| + { { "ab1.com", false }, { "ab2.com", false }, { "ab", true },
|
| + kEmptyMatch } },
|
| + { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
|
| + "\"google:suggestrelevance\":[900, 800]}]",
|
| + "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
|
| + "{\"google:verbatimrelevance\":1300,"
|
| + "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
|
| + "\"google:suggestrelevance\":[1301, 1302]}]",
|
| + { { "ab2.com", false }, { "ab1.com", false }, { "ab", true },
|
| + kEmptyMatch } },
|
| + };
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
|
| + // First, send the query "a" and receive the provided JSON reply,
|
| + // |first_json|.
|
| + QueryForInput(ASCIIToUTF16("a"), false, false);
|
| + net::TestURLFetcher* first_fetcher =
|
| + test_factory_.GetFetcherByID(
|
| + SearchProvider::kDefaultProviderURLFetcherID);
|
| + ASSERT_TRUE(first_fetcher);
|
| + first_fetcher->set_response_code(200);
|
| + first_fetcher->SetResponseString(cases[i].first_json);
|
| + first_fetcher->delegate()->OnURLFetchComplete(first_fetcher);
|
| + RunTillProviderDone();
|
| +
|
| + // Then, send the query "ab" and get the provided JSON reply,
|
| + // |second_json|.
|
| + QueryForInput(ASCIIToUTF16("ab"), false, false);
|
| + net::TestURLFetcher* second_fetcher =
|
| + test_factory_.GetFetcherByID(
|
| + SearchProvider::kDefaultProviderURLFetcherID);
|
| + ASSERT_TRUE(second_fetcher);
|
| + second_fetcher->set_response_code(200);
|
| + second_fetcher->SetResponseString(cases[i].second_json);
|
| + second_fetcher->delegate()->OnURLFetchComplete(second_fetcher);
|
| + RunTillProviderDone();
|
| +
|
| + // Finally, check that we have the expected results.
|
| + const std::string description = "for input with first_json=" +
|
| + cases[i].first_json + " and second_json=" + cases[i].second_json;
|
| + const ACMatches& matches = provider_->matches();
|
| + ASSERT_FALSE(matches.empty());
|
| + ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
|
| + size_t j = 0;
|
| + // Ensure that the returned matches equal the expectations.
|
| + for (; j < matches.size(); ++j) {
|
| + EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
|
| + matches[j].contents) << description;
|
| + EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
|
| + matches[j].allowed_to_be_default_match) << description;
|
| + }
|
| + // Ensure that no expected matches are missing.
|
| + for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
|
| + EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) <<
|
| + "Case # " << j << " " << description;
|
| + }
|
| +}
|
| +
|
| TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
|
| // We hardcode the string "term1" below, so ensure that the search term that
|
| // got added to history already is that string.
|
| @@ -2090,27 +2227,29 @@ TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) {
|
| kEmptyMatch, kEmptyMatch } },
|
|
|
| // Ensure topmost inlineable SUGGEST matches are NOT allowed for URL
|
| - // input. SearchProvider disregards search and verbatim suggested
|
| - // relevances.
|
| + // input.
|
| { "a.com", "[\"a.com\",[\"a.com info\"],[],[],"
|
| "{\"google:suggestrelevance\":[9999]}]",
|
| - { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| - { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true },
|
| + { { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
|
| + { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| kEmptyMatch, kEmptyMatch } },
|
| { "a.com", "[\"a.com\",[\"a.com info\"],[],[],"
|
| "{\"google:suggestrelevance\":[9999]}]",
|
| - { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| - { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true },
|
| + { { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
|
| + { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| kEmptyMatch, kEmptyMatch } },
|
|
|
| // Ensure the fallback mechanism allows inlinable NAVIGATION matches.
|
| { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[],"
|
| "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
|
| "\"google:suggestrelevance\":[9999, 9998]}]",
|
| - { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true },
|
| - { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| - { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true },
|
| + { { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
|
| + { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true },
|
| + { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| kEmptyMatch } },
|
| + // In this case, when we abandon relevance scores, we restore the
|
| + // |allowed_to_be_default_match| of the "a.com info" query. This doesn't
|
| + // violate any constraints because we know it's not going to be used.
|
| { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[],"
|
| "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
|
| "\"google:suggestrelevance\":[9998, 9997],"
|
| @@ -2126,43 +2265,52 @@ TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) {
|
| { "a.com", "[\"a.com\",[\"info\"],[],[],"
|
| "{\"google:suggestrelevance\":[9999]}]",
|
| { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false },
|
| - { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| + { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| kEmptyMatch, kEmptyMatch } },
|
| { "a.com", "[\"a.com\",[\"info\"],[],[],"
|
| "{\"google:suggestrelevance\":[9999]}]",
|
| { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false },
|
| - { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| + { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
|
| kEmptyMatch, kEmptyMatch } },
|
| };
|
|
|
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
|
| - QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
|
| - net::TestURLFetcher* fetcher =
|
| - test_factory_.GetFetcherByID(
|
| - SearchProvider::kDefaultProviderURLFetcherID);
|
| - ASSERT_TRUE(fetcher);
|
| - fetcher->set_response_code(200);
|
| - fetcher->SetResponseString(cases[i].json);
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| - RunTillProviderDone();
|
| + // Send the query twice in order to bypass checks about whether a single
|
| + // new reply can change the inline autocompletion.
|
| + for (size_t j = 0; j < 2; j++) {
|
| + QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
|
| + net::TestURLFetcher* fetcher =
|
| + test_factory_.GetFetcherByID(
|
| + SearchProvider::kDefaultProviderURLFetcherID);
|
| + ASSERT_TRUE(fetcher);
|
| + fetcher->set_response_code(200);
|
| + fetcher->SetResponseString(cases[i].json);
|
| + fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| + RunTillProviderDone();
|
| + }
|
|
|
| + const std::string description = "input=" + cases[i].input + " json=" +
|
| + cases[i].json;
|
| size_t j = 0;
|
| const ACMatches& matches = provider_->matches();
|
| - ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output));
|
| + ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output)) <<
|
| + description;
|
| // Ensure that the returned matches equal the expectations.
|
| for (; j < matches.size(); ++j) {
|
| EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents),
|
| - matches[j].contents);
|
| - EXPECT_EQ(cases[i].output[j].match_type, matches[j].type);
|
| + matches[j].contents) << description;
|
| + EXPECT_EQ(cases[i].output[j].match_type, matches[j].type) << description;
|
| EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match,
|
| - matches[j].allowed_to_be_default_match);
|
| + matches[j].allowed_to_be_default_match) << description;
|
| }
|
| // Ensure that no expected matches are missing.
|
| for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) {
|
| - EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents);
|
| + EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents) <<
|
| + description;
|
| EXPECT_EQ(AutocompleteMatchType::NUM_TYPES,
|
| - cases[i].output[j].match_type);
|
| - EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match);
|
| + cases[i].output[j].match_type) << description;
|
| + EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match) <<
|
| + description;
|
| }
|
| }
|
| }
|
|
|