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

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

Issue 10274023: Omnibox SearchProvider Experiment Client Implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make BestURLPrefix perform case-insensitive comparison. Created 8 years, 6 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 | « chrome/browser/autocomplete/search_provider.cc ('k') | chrome/browser/autocomplete/url_prefix.h » ('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 c9dacc628535bea2e885cf316699d2b7647622c2..210c923583e5737bf107e13e4467d3a6a395f370 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -716,13 +716,130 @@ TEST_F(SearchProviderTest, SuggestRelevance) {
EXPECT_GT(match_a2.relevance, match_a3.relevance);
}
+// Verifies that suggest experiment results are added properly.
+TEST_F(SearchProviderTest, SuggestRelevanceExperiment) {
+ const std::string kNotApplicable("Not Applicable");
+ struct {
+ const std::string input;
+ const std::string json;
+ const std::string matches[4];
+ } cases[] = {
+ // Ensure that suggestrelevance scores reorder matches.
+ { "a", "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
+ { "a", "c", "b", kNotApplicable } },
+ { "a", "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
+ "\"google:suggestrelevance\":[1, 2]}]",
+ { "a", "c.com", kNotApplicable, kNotApplicable } },
+
+ // Ensure that verbatimrelevance scores reorder or suppress what-you-typed.
+ // Negative values will have no effect; the calculated value will be used.
+ { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]",
+ { "a1", "a", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
+ { "a1", kNotApplicable, kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1}]",
+ { "a", "a1", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"http://a.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\"],"
+ "\"google:verbatimrelevance\":1}]",
+ { "a.com", "a", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"http://a.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\"],"
+ "\"google:verbatimrelevance\":0}]",
+ { "a.com", kNotApplicable, kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"http://a.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\"],"
+ "\"google:verbatimrelevance\":-1}]",
+ { "a", "a.com", kNotApplicable, kNotApplicable } },
+
+ // Ensure that both types of relevance scores reorder matches together.
+ { "a", "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[3, 1],"
+ "\"google:verbatimrelevance\":2}]",
+ { "a1", "a", "a2", kNotApplicable } },
+
+ // Ensure that only inlinable matches may be ranked as the highest result.
+ // If the server suggests relevance scores that violate this constraint,
+ // then all other matches are ranked lower than the what-you-typed result.
+ { "a", "[\"a\",[\"b\"],[],[],{\"google:verbatimrelevance\":0}]",
+ { "a", "b", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
+ { "a", "b", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
+ "\"google:verbatimrelevance\":0}]",
+ { "a", "b", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"http://b.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\"],"
+ "\"google:verbatimrelevance\":0}]",
+ { "a", "b.com", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"http://b.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\"],"
+ "\"google:suggestrelevance\":[9999]}]",
+ { "a", "b.com", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"http://b.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\"],"
+ "\"google:suggestrelevance\":[9999],"
+ "\"google:verbatimrelevance\":0}]",
+ { "a", "b.com", kNotApplicable, kNotApplicable } },
+
+ // Ensure that all suggestions are considered, regardless of order.
+ { "a", "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
+ "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
+ { "a", "h", "g", "f" } },
+ { "a", "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
+ "\"http://e.com\", \"http://f.com\", \"http://g.com\","
+ "\"http://h.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
+ "\"NAVIGATION\", \"NAVIGATION\","
+ "\"NAVIGATION\", \"NAVIGATION\","
+ "\"NAVIGATION\"],"
+ "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
+ { "a", "h.com", kNotApplicable, kNotApplicable } },
+
+ // Ensure that incorrectly sized suggestion relevance lists are ignored.
+ { "a", "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
+ { "a", "a1", "a2", kNotApplicable } },
+ { "a", "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
+ { "a", "a1", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
+ "\"google:suggestrelevance\":[1]}]",
+ { "a", "a1.com", kNotApplicable, kNotApplicable } },
+ { "a", "[\"a\",[\"http://a1.com\"],[],[],"
+ "{\"google:suggesttype\":[\"NAVIGATION\"],"
+ "\"google:suggestrelevance\":[9999, 1]}]",
+ { "a", "a1.com", kNotApplicable, kNotApplicable } },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
+ QueryForInput(ASCIIToUTF16(cases[i].input), false);
+ TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
+ SearchProvider::kDefaultProviderURLFetcherID);
+ fetcher->set_response_code(200);
+ fetcher->SetResponseString(cases[i].json);
+ fetcher->delegate()->OnURLFetchComplete(fetcher);
+ RunTillProviderDone();
+
+ const ACMatches& matches = provider_->matches();
+ EXPECT_NE(string16::npos, matches[0].inline_autocomplete_offset);
+
+ size_t j = 0;
+ // Ensure that the supplied matches equal the expectations.
+ for (; j < matches.size(); ++j)
+ EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents);
+ // Ensure that no expected matches are missing.
+ for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
+ EXPECT_EQ(kNotApplicable, cases[i].matches[j]);
+ }
+}
+
// Verifies inline autocompletion of navigational results.
TEST_F(SearchProviderTest, NavigationInline) {
struct {
const std::string input;
const std::string url;
// Test the expected fill_into_edit, which may drop "http://".
- // Some cases will not trim "http://" because "www." is not a valid prefix.
+ // Some cases do not trim "http://" to match from the start of the scheme.
const std::string fill_into_edit;
size_t inline_offset;
} cases[] = {
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | chrome/browser/autocomplete/url_prefix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698