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

Unified Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 2755503002: Add a new entry to omnibox_event.proto to log specific type of contextual suggestions (Closed)
Patch Set: Small fixes and sync. Created 3 years, 9 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
« no previous file with comments | « no previous file | components/metrics/proto/omnibox_event.proto » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 275328f4c34bb1ecf762f3ed4977609ddaeb1cfc..2df75358e0613a64ae88f51cb9c36d5ac4a3ea26 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -2507,6 +2507,77 @@ TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) {
EXPECT_EQ(0, providers_info[0].field_trial_triggered_in_session_size());
}
}
+// A basic test that verifies the specific type identifier parsing logic.
+TEST_F(SearchProviderTest, SpecificTypeIdentifierParsing) {
+ struct Match {
+ std::string contents;
+ int subtype_identifier;
+ };
+
+ struct {
+ const std::string input_text;
+ const std::string provider_response_json;
+ // The order of the expected matches is not important.
+ const Match expected_matches[2];
+ } cases[] = {
+ // Check that the specific type is set to 0 when these values are not
+ // provide in the response.
+ {"a",
+ "[\"a\",[\"ab\",\"http://b.com\"],[],[], "
+ "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]}]",
+ {{"ab", 0}, {"b.com", 0}}},
+
+ // Check that the specific type works for zero-suggest suggestions.
+ {"c",
+ "[\"c\",[\"cd\",\"http://d.com\"],[],[], "
+ "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
+ "\"google:subtypeid\":[1, 3]}]",
+ {{"cd", 1}, {"d.com", 3}}},
+
+ // Check that the specific type is set to zero when the number of
+ // suggestions is smaller than the number of id's provided.
+ {"foo",
+ "[\"foo\",[\"foo bar\", \"foo baz\"],[],[], "
+ "{\"google:suggesttype\":[\"QUERY\", \"QUERY\"],"
+ "\"google:subtypeid\":[1, 2, 3]}]",
+ {{"foo bar", 0}, {"foo baz", 0}}},
+
+ // Check that the specific type is set to zero when the number of
+ // suggestions is larger than the number of id's provided.
+ {"bar",
+ "[\"bar\",[\"bar foo\", \"bar foz\"],[],[], "
+ "{\"google:suggesttype\":[\"QUERY\", \"QUERY\"],"
+ "\"google:subtypeid\":[1]}]",
+ {{"bar foo", 0}, {"bar foz", 0}}},
+
+ // Check that ids stick to their suggestions when these are reordered
+ // based on suggetion relevance values.
+ {"e",
+ "[\"e\",[\"ef\",\"http://e.com\"],[],[], "
+ "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
+ "\"google:suggestrelevance\":[9300, 9800],"
+ "\"google:subtypeid\":[2, 4]}]",
+ {{"ef", 2}, {"e.com", 4}}}};
+
+ for (size_t i = 0; i < arraysize(cases); ++i) {
+ QueryForInputAndWaitForFetcherResponses(
+ ASCIIToUTF16(cases[i].input_text), false,
+ cases[i].provider_response_json, std::string());
+
+ // Check for the match and field trial triggered bits.
+ const ACMatches& matches = provider_->matches();
+ ASSERT_FALSE(matches.empty());
+ for (size_t j = 0; j < arraysize(cases[i].expected_matches); ++j) {
+ if (cases[i].expected_matches[j].contents == kNotApplicable)
+ continue;
+ AutocompleteMatch match;
+ EXPECT_TRUE(FindMatchWithContents(
+ ASCIIToUTF16(cases[i].expected_matches[j].contents), &match));
+ EXPECT_EQ(cases[i].expected_matches[j].subtype_identifier,
+ match.subtype_identifier);
+ }
+ }
+}
// Verifies inline autocompletion of navigational results.
TEST_F(SearchProviderTest, NavigationInline) {
@@ -2667,7 +2738,7 @@ TEST_F(SearchProviderTest, NavigationInline) {
QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
SearchSuggestionParser::NavigationResult result(
ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
- AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
+ AutocompleteMatchType::NAVSUGGEST, 0, base::string16(), std::string(),
false, 0, false, ASCIIToUTF16(cases[i].input));
result.set_received_after_last_keystroke(false);
AutocompleteMatch match(provider_->NavigationToMatch(result));
@@ -2681,7 +2752,7 @@ TEST_F(SearchProviderTest, NavigationInline) {
QueryForInput(ASCIIToUTF16(cases[i].input), true, false);
SearchSuggestionParser::NavigationResult result_prevent_inline(
ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
- AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
+ AutocompleteMatchType::NAVSUGGEST, 0, base::string16(), std::string(),
false, 0, false, ASCIIToUTF16(cases[i].input));
result_prevent_inline.set_received_after_last_keystroke(false);
AutocompleteMatch match_prevent_inline(
@@ -2701,8 +2772,8 @@ TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) {
const base::string16 url(ASCIIToUTF16("http://a.com"));
SearchSuggestionParser::NavigationResult result(
ChromeAutocompleteSchemeClassifier(&profile_), GURL(url),
- AutocompleteMatchType::NAVSUGGEST,
- base::string16(), std::string(), false, 0, false, input);
+ AutocompleteMatchType::NAVSUGGEST, 0, base::string16(), std::string(),
+ false, 0, false, input);
result.set_received_after_last_keystroke(false);
// Check the offset and strings when inline autocompletion is allowed.
@@ -2725,9 +2796,9 @@ TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) {
TEST_F(SearchProviderTest, NavigationInlineDomainClassify) {
QueryForInput(ASCIIToUTF16("w"), false, false);
SearchSuggestionParser::NavigationResult result(
- ChromeAutocompleteSchemeClassifier(&profile_),
- GURL("http://www.wow.com"), AutocompleteMatchType::NAVSUGGEST,
- base::string16(), std::string(), false, 0, false, ASCIIToUTF16("w"));
+ ChromeAutocompleteSchemeClassifier(&profile_), GURL("http://www.wow.com"),
+ AutocompleteMatchType::NAVSUGGEST, 0, base::string16(), std::string(),
+ false, 0, false, ASCIIToUTF16("w"));
result.set_received_after_last_keystroke(false);
AutocompleteMatch match(provider_->NavigationToMatch(result));
EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion);
@@ -2857,71 +2928,70 @@ TEST_F(SearchProviderTest, PrefetchMetadataParsing) {
const std::string keyword_provider_response_json;
const Match matches[5];
} cases[] = {
- // Default provider response does not have prefetch details. Ensure that the
- // suggestions are not marked as prefetch query.
- { "a",
- false,
- "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
- std::string(),
- { { "a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false },
- { "c", false, AutocompleteMatchType::SEARCH_SUGGEST, false },
- { "b", false, AutocompleteMatchType::SEARCH_SUGGEST, false },
- kEmptyMatch,
- kEmptyMatch
+ // Default provider response does not have prefetch details. Ensure that
+ // the suggestions are not marked as prefetch query.
+ {
+ "a",
+ false,
+ "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
+ std::string(),
+ {{"a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false},
+ {"c", false, AutocompleteMatchType::SEARCH_SUGGEST, false},
+ {"b", false, AutocompleteMatchType::SEARCH_SUGGEST, false},
+ kEmptyMatch,
+ kEmptyMatch},
},
- },
- // Ensure that default provider suggest response prefetch details are
- // parsed and recorded in AutocompleteMatch.
- { "ab",
- false,
- "[\"ab\",[\"abc\", \"http://b.com\", \"http://c.com\"],[],[],"
+ // Ensure that default provider suggest response prefetch details are
+ // parsed and recorded in AutocompleteMatch.
+ {
+ "ab",
+ false,
+ "[\"ab\",[\"abc\", \"http://b.com\", \"http://c.com\"],[],[],"
"{\"google:clientdata\":{\"phi\": 0},"
"\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\", \"NAVIGATION\"],"
"\"google:suggestrelevance\":[999, 12, 1]}]",
- std::string(),
- { { "ab", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false },
- { "abc", true, AutocompleteMatchType::SEARCH_SUGGEST, false },
- { "b.com", false, AutocompleteMatchType::NAVSUGGEST, false },
- { "c.com", false, AutocompleteMatchType::NAVSUGGEST, false },
- kEmptyMatch
+ std::string(),
+ {{"ab", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false},
+ {"abc", true, AutocompleteMatchType::SEARCH_SUGGEST, false},
+ {"b.com", false, AutocompleteMatchType::NAVSUGGEST, false},
+ {"c.com", false, AutocompleteMatchType::NAVSUGGEST, false},
+ kEmptyMatch},
},
- },
- // Default provider suggest response has prefetch details.
- // SEARCH_WHAT_YOU_TYPE suggestion outranks SEARCH_SUGGEST suggestion for
- // the same query string. Ensure that the prefetch details from
- // SEARCH_SUGGEST match are set onto SEARCH_WHAT_YOU_TYPE match.
- { "ab",
- false,
- "[\"ab\",[\"ab\", \"http://ab.com\"],[],[],"
+ // Default provider suggest response has prefetch details.
+ // SEARCH_WHAT_YOU_TYPE suggestion outranks SEARCH_SUGGEST suggestion for
+ // the same query string. Ensure that the prefetch details from
+ // SEARCH_SUGGEST match are set onto SEARCH_WHAT_YOU_TYPE match.
+ {
+ "ab",
+ false,
+ "[\"ab\",[\"ab\", \"http://ab.com\"],[],[],"
"{\"google:clientdata\":{\"phi\": 0},"
"\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
"\"google:suggestrelevance\":[99, 98]}]",
- std::string(),
- { {"ab", true, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false },
- {"ab.com", false, AutocompleteMatchType::NAVSUGGEST, false },
- kEmptyMatch,
- kEmptyMatch,
- kEmptyMatch
+ std::string(),
+ {{"ab", true, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false},
+ {"ab.com", false, AutocompleteMatchType::NAVSUGGEST, false},
+ kEmptyMatch,
+ kEmptyMatch,
+ kEmptyMatch},
},
- },
- // Default provider response has prefetch details. We prefer keyword
- // provider results. Ensure that prefetch bit for a suggestion from the
- // default search provider does not get copied onto a higher-scoring match
- // for the same query string from the keyword provider.
- { "k a",
- true,
- "[\"k a\",[\"a\", \"ab\"],[],[], {\"google:clientdata\":{\"phi\": 0},"
+ // Default provider response has prefetch details. We prefer keyword
+ // provider results. Ensure that prefetch bit for a suggestion from the
+ // default search provider does not get copied onto a higher-scoring match
+ // for the same query string from the keyword provider.
+ {
+ "k a",
+ true,
+ "[\"k a\",[\"a\", \"ab\"],[],[], {\"google:clientdata\":{\"phi\": 0},"
"\"google:suggesttype\":[\"QUERY\", \"QUERY\"],"
"\"google:suggestrelevance\":[9, 12]}]",
- "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
- { { "a", false, AutocompleteMatchType::SEARCH_OTHER_ENGINE, true},
- { "k a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false },
- { "ab", false, AutocompleteMatchType::SEARCH_SUGGEST, false },
- { "c", false, AutocompleteMatchType::SEARCH_SUGGEST, true },
- { "b", false, AutocompleteMatchType::SEARCH_SUGGEST, true }
- },
- }
- };
+ "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
+ {{"a", false, AutocompleteMatchType::SEARCH_OTHER_ENGINE, true},
+ {"k a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false},
+ {"ab", false, AutocompleteMatchType::SEARCH_SUGGEST, false},
+ {"c", false, AutocompleteMatchType::SEARCH_SUGGEST, true},
+ {"b", false, AutocompleteMatchType::SEARCH_SUGGEST, true}},
+ }};
for (size_t i = 0; i < arraysize(cases); ++i) {
QueryForInputAndWaitForFetcherResponses(
@@ -3474,7 +3544,7 @@ TEST_F(SearchProviderTest, AnswersCache) {
// Inject a scored result, which will trigger answer retrieval.
base::string16 query = base::ASCIIToUTF16("weather los angeles");
SearchSuggestionParser::SuggestResult suggest_result(
- query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(),
+ query, AutocompleteMatchType::SEARCH_HISTORY, 0, query, base::string16(),
base::string16(), base::string16(), base::string16(), nullptr,
std::string(), std::string(), false, 1200, false, false, query);
QueryForInput(ASCIIToUTF16("weather l"), false, false);
« no previous file with comments | « no previous file | components/metrics/proto/omnibox_event.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698