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

Side by Side Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 481693004: Omnibox: Prevent Asynchronous Suggestions from Changing Default Match (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix interactive test Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 const bool allowed_to_be_default_match; 132 const bool allowed_to_be_default_match;
133 const base::string16 fill_into_edit; 133 const base::string16 fill_into_edit;
134 }; 134 };
135 135
136 struct TestData { 136 struct TestData {
137 const base::string16 input; 137 const base::string16 input;
138 const size_t num_results; 138 const size_t num_results;
139 const ResultInfo output[3]; 139 const ResultInfo output[3];
140 }; 140 };
141 141
142 struct ExpectedMatch {
143 std::string contents;
144 bool allowed_to_be_default_match;
145 };
146
142 SearchProviderTest() 147 SearchProviderTest()
143 : default_t_url_(NULL), 148 : default_t_url_(NULL),
144 term1_(ASCIIToUTF16("term1")), 149 term1_(ASCIIToUTF16("term1")),
145 keyword_t_url_(NULL), 150 keyword_t_url_(NULL),
146 keyword_term_(ASCIIToUTF16("keyword")), 151 keyword_term_(ASCIIToUTF16("keyword")),
147 run_loop_(NULL) { 152 run_loop_(NULL) {
148 ResetFieldTrialList(); 153 ResetFieldTrialList();
149 } 154 }
150 155
151 // See description above class for what this registers. 156 // See description above class for what this registers.
152 virtual void SetUp() OVERRIDE; 157 virtual void SetUp() OVERRIDE;
153 virtual void TearDown() OVERRIDE; 158 virtual void TearDown() OVERRIDE;
154 159
155 void RunTest(TestData* cases, int num_cases, bool prefer_keyword); 160 void RunTest(TestData* cases, int num_cases, bool prefer_keyword);
156 161
157 protected: 162 protected:
158 // Needed for AutocompleteFieldTrial::ActivateStaticTrials(); 163 // Needed for AutocompleteFieldTrial::ActivateStaticTrials();
159 scoped_ptr<base::FieldTrialList> field_trial_list_; 164 scoped_ptr<base::FieldTrialList> field_trial_list_;
160 165
161 // Default value used for testing. 166 // Default values used for testing.
162 static const std::string kNotApplicable; 167 static const std::string kNotApplicable;
168 static const ExpectedMatch kEmptyExpectedMatch;
msw 2014/08/27 18:44:39 nit: use |kEmptyMatch| for less line wrapping with
Mark P 2014/08/27 23:08:19 Can't do that without changing the name of countle
msw 2014/08/28 19:21:40 Acknowledged.
163 169
164 // Adds a search for |term|, using the engine |t_url| to the history, and 170 // Adds a search for |term|, using the engine |t_url| to the history, and
165 // returns the URL for that search. 171 // returns the URL for that search.
166 GURL AddSearchToHistory(TemplateURL* t_url, base::string16 term, int visit_cou nt); 172 GURL AddSearchToHistory(TemplateURL* t_url, base::string16 term, int visit_cou nt);
167 173
168 // Looks for a match in |provider_| with |contents| equal to |contents|. 174 // Looks for a match in |provider_| with |contents| equal to |contents|.
169 // Sets |match| to it if found. Returns whether |match| was set. 175 // Sets |match| to it if found. Returns whether |match| was set.
170 bool FindMatchWithContents(const base::string16& contents, 176 bool FindMatchWithContents(const base::string16& contents,
171 AutocompleteMatch* match); 177 AutocompleteMatch* match);
172 178
(...skipping 27 matching lines...) Expand all
200 // Runs SearchProvider on |input|, for which the suggest server replies 206 // Runs SearchProvider on |input|, for which the suggest server replies
201 // with |json|, and expects that the resulting matches' contents equals 207 // with |json|, and expects that the resulting matches' contents equals
202 // that in |matches|. An empty entry in |matches| means no match should 208 // that in |matches|. An empty entry in |matches| means no match should
203 // be returned in that position. Reports any errors with a message that 209 // be returned in that position. Reports any errors with a message that
204 // includes |error_description|. 210 // includes |error_description|.
205 void ForcedQueryTestHelper(const std::string& input, 211 void ForcedQueryTestHelper(const std::string& input,
206 const std::string& json, 212 const std::string& json,
207 const std::string matches[3], 213 const std::string matches[3],
208 const std::string& error_description); 214 const std::string& error_description);
209 215
216 // Verifies that |matches| and |expected_matches| agree on the first
217 // |num_expected_matches|, displaying an error message that includes
218 // |description| for any disagreement.
219 void CheckMatches(const std::string& description,
220 const size_t num_expected_matches,
221 const ExpectedMatch expected_matches[],
222 const ACMatches& matches);
223
210 void ResetFieldTrialList(); 224 void ResetFieldTrialList();
211 225
212 // Create a field trial, with ZeroSuggest activation based on |enabled|. 226 // Create a field trial, with ZeroSuggest activation based on |enabled|.
213 base::FieldTrial* CreateZeroSuggestFieldTrial(bool enabled); 227 base::FieldTrial* CreateZeroSuggestFieldTrial(bool enabled);
214 228
215 void ClearAllResults(); 229 void ClearAllResults();
216 230
217 // See description above class for details of these fields. 231 // See description above class for details of these fields.
218 TemplateURL* default_t_url_; 232 TemplateURL* default_t_url_;
219 const base::string16 term1_; 233 const base::string16 term1_;
(...skipping 14 matching lines...) Expand all
234 scoped_refptr<SearchProviderForTest> provider_; 248 scoped_refptr<SearchProviderForTest> provider_;
235 249
236 // If non-NULL, OnProviderUpdate quits the current |run_loop_|. 250 // If non-NULL, OnProviderUpdate quits the current |run_loop_|.
237 base::RunLoop* run_loop_; 251 base::RunLoop* run_loop_;
238 252
239 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); 253 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
240 }; 254 };
241 255
242 // static 256 // static
243 const std::string SearchProviderTest::kNotApplicable = "Not Applicable"; 257 const std::string SearchProviderTest::kNotApplicable = "Not Applicable";
258 const SearchProviderTest::ExpectedMatch
259 SearchProviderTest::kEmptyExpectedMatch = { kNotApplicable, false };
244 260
245 void SearchProviderTest::SetUp() { 261 void SearchProviderTest::SetUp() {
246 // Make sure that fetchers are automatically ungregistered upon destruction. 262 // Make sure that fetchers are automatically ungregistered upon destruction.
247 test_factory_.set_remove_fetcher_on_delete(true); 263 test_factory_.set_remove_fetcher_on_delete(true);
248 264
249 // We need both the history service and template url model loaded. 265 // We need both the history service and template url model loaded.
250 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); 266 ASSERT_TRUE(profile_.CreateHistoryService(true, false));
251 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 267 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
252 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); 268 &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
253 269
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // Tell the SearchProvider the default suggest query is done. 450 // Tell the SearchProvider the default suggest query is done.
435 default_fetcher->set_response_code(200); 451 default_fetcher->set_response_code(200);
436 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 452 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
437 } 453 }
438 454
439 void SearchProviderTest::ForcedQueryTestHelper( 455 void SearchProviderTest::ForcedQueryTestHelper(
440 const std::string& input, 456 const std::string& input,
441 const std::string& json, 457 const std::string& json,
442 const std::string expected_matches[3], 458 const std::string expected_matches[3],
443 const std::string& error_description) { 459 const std::string& error_description) {
444 QueryForInput(ASCIIToUTF16(input), false, false); 460 // Send the query twice in order to have a synchronous pass after the first
445 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 461 // reply is received. This is necessary because SearchProvider doesn't allow
446 SearchProvider::kDefaultProviderURLFetcherID); 462 // an asynchronous reply to change the default match.
447 ASSERT_TRUE(fetcher); 463 for (size_t i = 0; i < 2; i++) {
msw 2014/08/27 18:44:38 nit: ++i
Mark P 2014/08/27 23:08:19 Done throughout.
448 fetcher->set_response_code(200); 464 QueryForInput(ASCIIToUTF16(input), false, false);
449 fetcher->SetResponseString(json); 465 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
450 fetcher->delegate()->OnURLFetchComplete(fetcher); 466 SearchProvider::kDefaultProviderURLFetcherID);
451 RunTillProviderDone(); 467 ASSERT_TRUE(fetcher);
468 fetcher->set_response_code(200);
469 fetcher->SetResponseString(json);
470 fetcher->delegate()->OnURLFetchComplete(fetcher);
471 RunTillProviderDone();
472 }
452 473
453 const ACMatches& matches = provider_->matches(); 474 const ACMatches& matches = provider_->matches();
454 ASSERT_LE(matches.size(), 3u); 475 ASSERT_LE(matches.size(), 3u);
455 size_t i = 0; 476 size_t i = 0;
456 // Ensure that the returned matches equal the expectations. 477 // Ensure that the returned matches equal the expectations.
457 for (; i < matches.size(); ++i) { 478 for (; i < matches.size(); ++i) {
458 EXPECT_EQ(ASCIIToUTF16(expected_matches[i]), matches[i].contents) << 479 EXPECT_EQ(ASCIIToUTF16(expected_matches[i]), matches[i].contents) <<
459 error_description; 480 error_description;
460 } 481 }
461 // Ensure that no expected matches are missing. 482 // Ensure that no expected matches are missing.
462 for (; i < 3u; ++i) { 483 for (; i < 3u; ++i) {
463 EXPECT_EQ(std::string(), expected_matches[i]) << 484 EXPECT_EQ(std::string(), expected_matches[i]) <<
464 "Case #" << i << ": " << error_description; 485 "Case #" << i << ": " << error_description;
465 } 486 }
466 } 487 }
467 488
489 void SearchProviderTest::CheckMatches(const std::string& description,
490 const size_t num_expected_matches,
491 const ExpectedMatch expected_matches[],
492 const ACMatches& matches) {
493 ASSERT_FALSE(matches.empty());
494 ASSERT_LE(matches.size(), num_expected_matches);
495 size_t j = 0;
msw 2014/08/27 18:44:38 nit: use |i|
Mark P 2014/08/27 23:08:20 Done. (refactoring error)
496 // Ensure that the returned matches equal the expectations.
497 for (; j < matches.size(); ++j) {
498 EXPECT_EQ(ASCIIToUTF16(expected_matches[j].contents),
499 matches[j].contents) << description << " Case # " << j;
500 EXPECT_EQ(expected_matches[j].allowed_to_be_default_match,
501 matches[j].allowed_to_be_default_match) << description
502 << " Case # " << j;
503 }
504 // Ensure that no expected matches are missing.
505 for (; j < num_expected_matches; ++j) {
506 EXPECT_EQ(kNotApplicable, expected_matches[j].contents) <<
507 "Case # " << j << " " << description;
508 }
509 }
510
468 void SearchProviderTest::ResetFieldTrialList() { 511 void SearchProviderTest::ResetFieldTrialList() {
469 // Destroy the existing FieldTrialList before creating a new one to avoid 512 // Destroy the existing FieldTrialList before creating a new one to avoid
470 // a DCHECK. 513 // a DCHECK.
471 field_trial_list_.reset(); 514 field_trial_list_.reset();
472 field_trial_list_.reset(new base::FieldTrialList( 515 field_trial_list_.reset(new base::FieldTrialList(
473 new metrics::SHA1EntropyProvider("foo"))); 516 new metrics::SHA1EntropyProvider("foo")));
474 variations::testing::ClearAllVariationParams(); 517 variations::testing::ClearAllVariationParams();
475 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial( 518 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial(
476 "AutocompleteDynamicTrial_0", "DefaultGroup"); 519 "AutocompleteDynamicTrial_0", "DefaultGroup");
477 trial->group(); 520 trial->group();
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 fetcher->delegate()->OnURLFetchComplete(fetcher); 1166 fetcher->delegate()->OnURLFetchComplete(fetcher);
1124 fetcher = NULL; 1167 fetcher = NULL;
1125 1168
1126 // Run till the history results complete. 1169 // Run till the history results complete.
1127 RunTillProviderDone(); 1170 RunTillProviderDone();
1128 1171
1129 // Make sure the only match is 'a.com' and it doesn't have a template_url. 1172 // Make sure the only match is 'a.com' and it doesn't have a template_url.
1130 AutocompleteMatch nav_match; 1173 AutocompleteMatch nav_match;
1131 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); 1174 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match));
1132 EXPECT_TRUE(nav_match.keyword.empty()); 1175 EXPECT_TRUE(nav_match.keyword.empty());
1133 EXPECT_TRUE(nav_match.allowed_to_be_default_match); 1176 EXPECT_FALSE(nav_match.allowed_to_be_default_match);
1134 EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match)); 1177 EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match));
1135 } 1178 }
1136 1179
1137 // Verifies that the most relevant suggest results are added properly. 1180 // Verifies that the most relevant suggest results are added properly.
1138 TEST_F(SearchProviderTest, SuggestRelevance) { 1181 TEST_F(SearchProviderTest, SuggestRelevance) {
1139 QueryForInput(ASCIIToUTF16("a"), false, false); 1182 QueryForInput(ASCIIToUTF16("a"), false, false);
1140 1183
1141 // Make sure the default provider's suggest service was queried. 1184 // Make sure the default provider's suggest service was queried.
1142 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 1185 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
1143 SearchProvider::kDefaultProviderURLFetcherID); 1186 SearchProvider::kDefaultProviderURLFetcherID);
(...skipping 12 matching lines...) Expand all
1156 AutocompleteMatch verbatim, match_a1, match_a2, match_a3, match_a4; 1199 AutocompleteMatch verbatim, match_a1, match_a2, match_a3, match_a4;
1157 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim)); 1200 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim));
1158 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1)); 1201 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1));
1159 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2)); 1202 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2));
1160 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3)); 1203 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3));
1161 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4)); 1204 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4));
1162 EXPECT_GT(verbatim.relevance, match_a1.relevance); 1205 EXPECT_GT(verbatim.relevance, match_a1.relevance);
1163 EXPECT_GT(match_a1.relevance, match_a2.relevance); 1206 EXPECT_GT(match_a1.relevance, match_a2.relevance);
1164 EXPECT_GT(match_a2.relevance, match_a3.relevance); 1207 EXPECT_GT(match_a2.relevance, match_a3.relevance);
1165 EXPECT_TRUE(verbatim.allowed_to_be_default_match); 1208 EXPECT_TRUE(verbatim.allowed_to_be_default_match);
1166 EXPECT_TRUE(match_a1.allowed_to_be_default_match); 1209 EXPECT_FALSE(match_a1.allowed_to_be_default_match);
1167 EXPECT_TRUE(match_a2.allowed_to_be_default_match); 1210 EXPECT_FALSE(match_a2.allowed_to_be_default_match);
1168 EXPECT_TRUE(match_a3.allowed_to_be_default_match); 1211 EXPECT_FALSE(match_a3.allowed_to_be_default_match);
1169 } 1212 }
1170 1213
1171 // Verifies that the default provider abandons suggested relevance scores 1214 // Verifies that the default provider abandons suggested relevance scores
1172 // when in keyword mode. This should happen regardless of whether the 1215 // when in keyword mode. This should happen regardless of whether the
1173 // keyword provider returns suggested relevance scores. 1216 // keyword provider returns suggested relevance scores.
1174 TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) { 1217 TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) {
1175 struct { 1218 struct {
1176 const std::string default_provider_json; 1219 const std::string default_provider_json;
1177 const std::string keyword_provider_json; 1220 const std::string keyword_provider_json;
1178 const std::string matches[5]; 1221 const std::string matches[5];
(...skipping 12 matching lines...) Expand all
1191 "{\"google:verbatimrelevance\":9700," 1234 "{\"google:verbatimrelevance\":9700,"
1192 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 1235 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
1193 "\"google:suggestrelevance\":[9900, 9800]}]", 1236 "\"google:suggestrelevance\":[9900, 9800]}]",
1194 "[\"a\",[\"akeyword-query\"],[],[],{\"google:suggesttype\":[\"QUERY\"]," 1237 "[\"a\",[\"akeyword-query\"],[],[],{\"google:suggesttype\":[\"QUERY\"],"
1195 "\"google:verbatimrelevance\":9500," 1238 "\"google:verbatimrelevance\":9500,"
1196 "\"google:suggestrelevance\":[9600]}]", 1239 "\"google:suggestrelevance\":[9600]}]",
1197 { "akeyword-query", "a", "k a", "adefault.com", "k adefault-query" } } 1240 { "akeyword-query", "a", "k a", "adefault.com", "k adefault-query" } }
1198 }; 1241 };
1199 1242
1200 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1243 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1201 QueryForInput(ASCIIToUTF16("k a"), false, true); 1244 // Send the query twice in order to have a synchronous pass after the first
1202 net::TestURLFetcher* default_fetcher = 1245 // reply is received. This is necessary because SearchProvider doesn't
1203 test_factory_.GetFetcherByID( 1246 // allow an asynchronous reply to change the default match.
1204 SearchProvider::kDefaultProviderURLFetcherID); 1247 for (size_t j = 0; j < 2; j++) {
msw 2014/08/27 18:44:38 nit: ++j
Mark P 2014/08/27 23:08:20 Done.
1205 ASSERT_TRUE(default_fetcher); 1248 QueryForInput(ASCIIToUTF16("k a"), false, true);
1206 default_fetcher->set_response_code(200); 1249 net::TestURLFetcher* default_fetcher =
1207 default_fetcher->SetResponseString(cases[i].default_provider_json); 1250 test_factory_.GetFetcherByID(
1208 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 1251 SearchProvider::kDefaultProviderURLFetcherID);
1209 net::TestURLFetcher* keyword_fetcher = 1252 ASSERT_TRUE(default_fetcher);
1210 test_factory_.GetFetcherByID( 1253 default_fetcher->set_response_code(200);
1211 SearchProvider::kKeywordProviderURLFetcherID); 1254 default_fetcher->SetResponseString(cases[i].default_provider_json);
1212 ASSERT_TRUE(keyword_fetcher); 1255 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
1213 keyword_fetcher->set_response_code(200); 1256 net::TestURLFetcher* keyword_fetcher =
1214 keyword_fetcher->SetResponseString(cases[i].keyword_provider_json); 1257 test_factory_.GetFetcherByID(
1215 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); 1258 SearchProvider::kKeywordProviderURLFetcherID);
1216 RunTillProviderDone(); 1259 ASSERT_TRUE(keyword_fetcher);
1260 keyword_fetcher->set_response_code(200);
1261 keyword_fetcher->SetResponseString(cases[i].keyword_provider_json);
1262 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
1263 RunTillProviderDone();
1264 }
1217 1265
1218 const std::string description = "for input with default_provider_json=" + 1266 const std::string description = "for input with default_provider_json=" +
1219 cases[i].default_provider_json + " and keyword_provider_json=" + 1267 cases[i].default_provider_json + " and keyword_provider_json=" +
1220 cases[i].keyword_provider_json; 1268 cases[i].keyword_provider_json;
1221 const ACMatches& matches = provider_->matches(); 1269 const ACMatches& matches = provider_->matches();
1222 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 1270 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
1223 size_t j = 0; 1271 size_t j = 0;
1224 // Ensure that the returned matches equal the expectations. 1272 // Ensure that the returned matches equal the expectations.
msw 2014/08/27 18:44:39 Too bad this doesn't check |allowed_to_be_default_
Mark P 2014/08/27 23:08:19 It would be nice if the helper functions in the un
msw 2014/08/28 19:21:39 Acknowledged.
1225 for (; j < matches.size(); ++j) { 1273 for (; j < matches.size(); ++j) {
1226 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents) << 1274 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents) <<
1227 description; 1275 description;
1228 } 1276 }
1229 // Ensure that no expected matches are missing. 1277 // Ensure that no expected matches are missing.
1230 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 1278 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1231 EXPECT_EQ(std::string(), cases[i].matches[j]) << description; 1279 EXPECT_EQ(std::string(), cases[i].matches[j]) << description;
1232 } 1280 }
1233 } 1281 }
1234 1282
(...skipping 29 matching lines...) Expand all
1264 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," 1312 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
1265 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", 1313 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]",
1266 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch, 1314 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch,
1267 kEmptyMatch, kEmptyMatch }, 1315 kEmptyMatch, kEmptyMatch },
1268 std::string() }, 1316 std::string() },
1269 1317
1270 // Ensure that verbatimrelevance scores reorder or suppress verbatim. 1318 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
1271 // Negative values will have no effect; the calculated value will be used. 1319 // Negative values will have no effect; the calculated value will be used.
1272 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," 1320 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
1273 "\"google:suggestrelevance\":[9998]}]", 1321 "\"google:suggestrelevance\":[9998]}]",
1274 { { "a", true}, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1322 { { "a", true}, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1275 kEmptyMatch }, 1323 kEmptyMatch },
1276 std::string() }, 1324 std::string() },
1277 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," 1325 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
1278 "\"google:suggestrelevance\":[9999]}]", 1326 "\"google:suggestrelevance\":[9999]}]",
1279 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1327 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1280 kEmptyMatch }, 1328 kEmptyMatch },
1281 "1" }, 1329 "1" },
1282 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," 1330 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0,"
1283 "\"google:suggestrelevance\":[9999]}]", 1331 "\"google:suggestrelevance\":[9999]}]",
1284 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1332 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1285 kEmptyMatch }, 1333 kEmptyMatch },
1286 "1" }, 1334 "1" },
1287 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," 1335 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1,"
1288 "\"google:suggestrelevance\":[9999]}]", 1336 "\"google:suggestrelevance\":[9999]}]",
1289 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1337 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1290 kEmptyMatch }, 1338 kEmptyMatch },
1291 "1" }, 1339 "1" },
1292 { "[\"a\",[\"http://a.com\"],[],[]," 1340 { "[\"a\",[\"http://a.com\"],[],[],"
1293 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1341 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1294 "\"google:verbatimrelevance\":9999," 1342 "\"google:verbatimrelevance\":9999,"
1295 "\"google:suggestrelevance\":[9998]}]", 1343 "\"google:suggestrelevance\":[9998]}]",
1296 { { "a", true }, { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1344 { { "a", true }, { "a.com", false }, kEmptyMatch, kEmptyMatch,
1297 kEmptyMatch }, 1345 kEmptyMatch, kEmptyMatch },
1298 std::string() }, 1346 std::string() },
1299 { "[\"a\",[\"http://a.com\"],[],[]," 1347 { "[\"a\",[\"http://a.com\"],[],[],"
1300 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1348 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1301 "\"google:verbatimrelevance\":9998," 1349 "\"google:verbatimrelevance\":9998,"
1302 "\"google:suggestrelevance\":[9999]}]", 1350 "\"google:suggestrelevance\":[9999]}]",
1303 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1351 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1304 kEmptyMatch }, 1352 kEmptyMatch },
1305 ".com" }, 1353 ".com" },
1306 { "[\"a\",[\"http://a.com\"],[],[]," 1354 { "[\"a\",[\"http://a.com\"],[],[],"
1307 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1355 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1308 "\"google:verbatimrelevance\":0," 1356 "\"google:verbatimrelevance\":0,"
1309 "\"google:suggestrelevance\":[9999]}]", 1357 "\"google:suggestrelevance\":[9999]}]",
1310 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1358 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1311 kEmptyMatch }, 1359 kEmptyMatch },
1312 ".com" }, 1360 ".com" },
1313 { "[\"a\",[\"http://a.com\"],[],[]," 1361 { "[\"a\",[\"http://a.com\"],[],[],"
1314 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1362 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1315 "\"google:verbatimrelevance\":-1," 1363 "\"google:verbatimrelevance\":-1,"
1316 "\"google:suggestrelevance\":[9999]}]", 1364 "\"google:suggestrelevance\":[9999]}]",
1317 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1365 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1318 kEmptyMatch }, 1366 kEmptyMatch },
1319 ".com" }, 1367 ".com" },
1320 1368
1321 // Ensure that both types of relevance scores reorder matches together. 1369 // Ensure that both types of relevance scores reorder matches together.
1322 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," 1370 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
1323 "\"google:verbatimrelevance\":9998}]", 1371 "\"google:verbatimrelevance\":9998}]",
1324 { { "a1", true }, { "a", true }, { "a2", true }, kEmptyMatch, kEmptyMatch, 1372 { { "a1", true }, { "a", true }, { "a2", false }, kEmptyMatch,
1325 kEmptyMatch }, 1373 kEmptyMatch, kEmptyMatch },
1326 "1" }, 1374 "1" },
1327 1375
1328 // Allow non-inlineable matches to be the highest-scoring match but, 1376 // Check that an inlineable result appears first regardless of its score.
1329 // if the result set lacks a single inlineable result, abandon suggested 1377 // Also, if the result set lacks a single inlineable result, abandon the
1330 // relevance scores entirely. 1378 // request to suppress verbatim (verbatim_relevance=0), which will then
1379 // cause verbatim to appear (first).
1331 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", 1380 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
1332 { { "b", false }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1381 { { "a", true }, { "b", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1333 kEmptyMatch }, 1382 kEmptyMatch },
1334 std::string() }, 1383 std::string() },
1335 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," 1384 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
1336 "\"google:verbatimrelevance\":0}]", 1385 "\"google:verbatimrelevance\":0}]",
1337 { { "a", true }, { "b", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1386 { { "a", true }, { "b", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1338 kEmptyMatch }, 1387 kEmptyMatch },
1339 std::string() }, 1388 std::string() },
1340 { "[\"a\",[\"http://b.com\"],[],[]," 1389 { "[\"a\",[\"http://b.com\"],[],[],"
1341 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1390 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1342 "\"google:suggestrelevance\":[9999]}]", 1391 "\"google:suggestrelevance\":[9999]}]",
1343 { { "b.com", false }, { "a", true }, kEmptyMatch, kEmptyMatch, 1392 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch,
1344 kEmptyMatch, kEmptyMatch }, 1393 kEmptyMatch, kEmptyMatch },
1345 std::string() }, 1394 std::string() },
1346 { "[\"a\",[\"http://b.com\"],[],[]," 1395 { "[\"a\",[\"http://b.com\"],[],[],"
1347 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1396 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1348 "\"google:suggestrelevance\":[9999]," 1397 "\"google:suggestrelevance\":[9999],"
1349 "\"google:verbatimrelevance\":0}]", 1398 "\"google:verbatimrelevance\":0}]",
1350 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch, 1399 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch,
1351 kEmptyMatch, kEmptyMatch }, 1400 kEmptyMatch, kEmptyMatch },
1352 std::string() }, 1401 std::string() },
1353 1402
1354 // Allow low-scoring matches. 1403 // Allow low-scoring matches.
1355 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", 1404 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
1356 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1405 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1357 kEmptyMatch }, 1406 kEmptyMatch },
1358 "1" }, 1407 "1" },
1359 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", 1408 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":10}]",
1360 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1409 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1361 kEmptyMatch }, 1410 kEmptyMatch },
1362 "1" }, 1411 "1" },
1363 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," 1412 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[10],"
1364 "\"google:verbatimrelevance\":0}]", 1413 "\"google:verbatimrelevance\":0}]",
1365 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1414 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1366 kEmptyMatch }, 1415 kEmptyMatch },
1367 "1" }, 1416 "1" },
1368 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," 1417 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10, 20],"
1369 "\"google:verbatimrelevance\":0}]", 1418 "\"google:verbatimrelevance\":0}]",
1370 { { "a2", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1419 { { "a2", true }, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1371 kEmptyMatch }, 1420 kEmptyMatch },
1372 "2" }, 1421 "2" },
1373 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," 1422 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10, 30],"
1374 "\"google:verbatimrelevance\":2}]", 1423 "\"google:verbatimrelevance\":20}]",
1375 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, 1424 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch,
1376 kEmptyMatch }, 1425 kEmptyMatch, kEmptyMatch },
1377 "2" }, 1426 "2" },
1378 { "[\"a\",[\"http://a.com\"],[],[]," 1427 { "[\"a\",[\"http://a.com\"],[],[],"
1379 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1428 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1380 "\"google:suggestrelevance\":[1]," 1429 "\"google:suggestrelevance\":[10],"
1381 "\"google:verbatimrelevance\":0}]", 1430 "\"google:verbatimrelevance\":0}]",
1382 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1431 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1383 kEmptyMatch }, 1432 kEmptyMatch },
1384 ".com" }, 1433 ".com" },
1385 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1434 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1386 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1435 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1387 "\"google:suggestrelevance\":[1, 2]," 1436 "\"google:suggestrelevance\":[10, 20],"
1388 "\"google:verbatimrelevance\":0}]", 1437 "\"google:verbatimrelevance\":0}]",
1389 { { "a2.com", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, 1438 { { "a2.com", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch,
1390 kEmptyMatch, kEmptyMatch }, 1439 kEmptyMatch, kEmptyMatch },
1391 "2.com" }, 1440 "2.com" },
1392 1441
1393 // Ensure that all suggestions are considered, regardless of order. 1442 // Ensure that all suggestions are considered, regardless of order.
1394 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," 1443 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
1395 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1444 "{\"google:suggestrelevance\":[10, 20, 30, 40, 50, 60, 70]}]",
1396 { { "a", true }, { "h", false }, { "g", false }, { "f", false }, 1445 { { "a", true }, { "h", false }, { "g", false }, { "f", false },
1397 { "e", false }, { "d", false } }, 1446 { "e", false }, { "d", false } },
1398 std::string() }, 1447 std::string() },
1399 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," 1448 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
1400 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," 1449 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
1401 "\"http://h.com\"],[],[]," 1450 "\"http://h.com\"],[],[],"
1402 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," 1451 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
1403 "\"NAVIGATION\", \"NAVIGATION\"," 1452 "\"NAVIGATION\", \"NAVIGATION\","
1404 "\"NAVIGATION\", \"NAVIGATION\"," 1453 "\"NAVIGATION\", \"NAVIGATION\","
1405 "\"NAVIGATION\"]," 1454 "\"NAVIGATION\"],"
1406 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1455 "\"google:suggestrelevance\":[10, 20, 30, 40, 50, 60, 70]}]",
1407 { { "a", true }, { "h.com", false }, { "g.com", false }, 1456 { { "a", true }, { "h.com", false }, { "g.com", false },
1408 { "f.com", false }, { "e.com", false }, { "d.com", false } }, 1457 { "f.com", false }, { "e.com", false }, { "d.com", false } },
1409 std::string() }, 1458 std::string() },
1410 1459
1411 // Ensure that incorrectly sized suggestion relevance lists are ignored. 1460 // Ensure that incorrectly sized suggestion relevance lists are ignored.
1412 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", 1461 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10]}]",
1413 { { "a", true }, { "a1", true }, { "a2", true }, kEmptyMatch, kEmptyMatch, 1462 { { "a", true }, { "a1", false }, { "a2", false }, kEmptyMatch,
1414 kEmptyMatch }, 1463 kEmptyMatch, kEmptyMatch },
1415 std::string() }, 1464 std::string() },
1416 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", 1465 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 10]}]",
1417 { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1466 { { "a", true }, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1418 kEmptyMatch }, 1467 kEmptyMatch },
1419 std::string() }, 1468 std::string() },
1420 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1469 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1421 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1470 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1422 "\"google:suggestrelevance\":[1]}]", 1471 "\"google:suggestrelevance\":[10]}]",
1423 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, 1472 { { "a", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch,
1424 kEmptyMatch, kEmptyMatch }, 1473 kEmptyMatch, kEmptyMatch },
1425 std::string() }, 1474 std::string() },
1426 { "[\"a\",[\"http://a1.com\"],[],[]," 1475 { "[\"a\",[\"http://a1.com\"],[],[],"
1427 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1476 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1428 "\"google:suggestrelevance\":[9999, 1]}]", 1477 "\"google:suggestrelevance\":[9999, 10]}]",
1429 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, 1478 { { "a", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch,
1430 kEmptyMatch, kEmptyMatch }, 1479 kEmptyMatch, kEmptyMatch },
1431 std::string() }, 1480 std::string() },
1432 1481
1433 // Ensure that all 'verbatim' results are merged with their maximum score. 1482 // Ensure that all 'verbatim' results are merged with their maximum score.
1434 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1483 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1435 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1484 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1436 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, 1485 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch,
1437 kEmptyMatch }, 1486 kEmptyMatch, kEmptyMatch },
1438 "2" }, 1487 "2" },
1439 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1488 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1440 "{\"google:suggestrelevance\":[9998, 9997, 9999]," 1489 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
1441 "\"google:verbatimrelevance\":0}]", 1490 "\"google:verbatimrelevance\":0}]",
1442 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, 1491 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch,
1443 kEmptyMatch }, 1492 kEmptyMatch, kEmptyMatch },
1444 "2" }, 1493 "2" },
1445 1494
1446 // Ensure that verbatim is always generated without other suggestions. 1495 // Ensure that verbatim is always generated without other suggestions.
1447 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). 1496 // TODO(msw): Ensure verbatimrelevance is respected (except suppression).
1448 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", 1497 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
1449 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1498 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1450 kEmptyMatch }, 1499 kEmptyMatch },
1451 std::string() }, 1500 std::string() },
1452 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", 1501 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
1453 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1502 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch,
1454 kEmptyMatch }, 1503 kEmptyMatch },
1455 std::string() }, 1504 std::string() },
1456 }; 1505 };
1457 1506
1458 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1507 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1459 QueryForInput(ASCIIToUTF16("a"), false, false); 1508 // Send the query twice in order to have a synchronous pass after the first
1460 net::TestURLFetcher* fetcher = 1509 // reply is received. This is necessary because SearchProvider doesn't
1461 test_factory_.GetFetcherByID( 1510 // allow an asynchronous reply to change the default match.
1462 SearchProvider::kDefaultProviderURLFetcherID); 1511 for (size_t j = 0; j < 2; j++) {
msw 2014/08/27 18:44:38 nit: ++j
Mark P 2014/08/27 23:08:20 Done.
1463 ASSERT_TRUE(fetcher); 1512 QueryForInput(ASCIIToUTF16("a"), false, false);
1464 fetcher->set_response_code(200); 1513 net::TestURLFetcher* fetcher =
1465 fetcher->SetResponseString(cases[i].json); 1514 test_factory_.GetFetcherByID(
1466 fetcher->delegate()->OnURLFetchComplete(fetcher); 1515 SearchProvider::kDefaultProviderURLFetcherID);
1467 RunTillProviderDone(); 1516 ASSERT_TRUE(fetcher);
1517 fetcher->set_response_code(200);
1518 fetcher->SetResponseString(cases[i].json);
1519 fetcher->delegate()->OnURLFetchComplete(fetcher);
1520 RunTillProviderDone();
1521 }
1468 1522
1469 const std::string description = "for input with json=" + cases[i].json; 1523 const std::string description = "for input with json=" + cases[i].json;
1470 const ACMatches& matches = provider_->matches(); 1524 const ACMatches& matches = provider_->matches();
1471 ASSERT_FALSE(matches.empty()); 1525 ASSERT_FALSE(matches.empty());
1472 // Find the first match that's allowed to be the default match and check 1526 // Find the first match that's allowed to be the default match and check
1473 // its inline_autocompletion. 1527 // its inline_autocompletion.
1474 ACMatches::const_iterator it = FindDefaultMatch(matches); 1528 ACMatches::const_iterator it = FindDefaultMatch(matches);
1475 ASSERT_NE(matches.end(), it); 1529 ASSERT_NE(matches.end(), it);
1476 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 1530 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
1477 it->inline_autocompletion) << description; 1531 it->inline_autocompletion) << description;
1478 1532
1479 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 1533 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
1480 size_t j = 0; 1534 size_t j = 0;
1481 // Ensure that the returned matches equal the expectations. 1535 // Ensure that the returned matches equal the expectations.
msw 2014/08/27 18:44:38 Can this use CheckMatches?
Mark P 2014/08/27 23:08:20 Yes. Good catch. Done.
1482 for (; j < matches.size(); ++j) { 1536 for (; j < matches.size(); ++j) {
1483 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), 1537 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
1484 matches[j].contents) << description; 1538 matches[j].contents) << description;
1485 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, 1539 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
1486 matches[j].allowed_to_be_default_match) << description; 1540 matches[j].allowed_to_be_default_match) << description;
1487 } 1541 }
1488 // Ensure that no expected matches are missing. 1542 // Ensure that no expected matches are missing.
1489 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 1543 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1490 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << 1544 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) <<
1491 "Case # " << i << " " << description; 1545 "Case # " << i << " " << description;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 { "b.com", false, false }, 1601 { "b.com", false, false },
1548 { "k a", false, false }, 1602 { "k a", false, false },
1549 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1603 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1550 std::string() }, 1604 std::string() },
1551 1605
1552 // Ensure that verbatimrelevance scores reorder or suppress verbatim. 1606 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
1553 // Negative values will have no effect; the calculated value will be used. 1607 // Negative values will have no effect; the calculated value will be used.
1554 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," 1608 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
1555 "\"google:suggestrelevance\":[9998]}]", 1609 "\"google:suggestrelevance\":[9998]}]",
1556 { { "a", true, true }, 1610 { { "a", true, true },
1557 { "a1", true, true }, 1611 { "a1", true, false },
1558 { "k a", false, false }, 1612 { "k a", false, false },
1559 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1613 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1560 std::string() }, 1614 std::string() },
1561 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," 1615 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
1562 "\"google:suggestrelevance\":[9999]}]", 1616 "\"google:suggestrelevance\":[9999]}]",
1563 { { "a1", true, true }, 1617 { { "a1", true, true },
1564 { "a", true, true }, 1618 { "a", true, true },
1565 { "k a", false, false }, 1619 { "k a", false, false },
1566 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1620 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1567 "1" }, 1621 "1" },
(...skipping 18 matching lines...) Expand all
1586 { "a.com", false, false }, 1640 { "a.com", false, false },
1587 { "k a", false, false }, 1641 { "k a", false, false },
1588 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1642 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1589 std::string() }, 1643 std::string() },
1590 1644
1591 // Ensure that both types of relevance scores reorder matches together. 1645 // Ensure that both types of relevance scores reorder matches together.
1592 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," 1646 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
1593 "\"google:verbatimrelevance\":9998}]", 1647 "\"google:verbatimrelevance\":9998}]",
1594 { { "a1", true, true }, 1648 { { "a1", true, true },
1595 { "a", true, true }, 1649 { "a", true, true },
1596 { "a2", true, true }, 1650 { "a2", true, false },
1597 { "k a", false, false }, 1651 { "k a", false, false },
1598 kEmptyMatch, kEmptyMatch }, 1652 kEmptyMatch, kEmptyMatch },
1599 "1" }, 1653 "1" },
1600 1654
1601 // Check that non-inlinable matches may be ranked as the highest result 1655 // Check that an inlinable match appears first regardless of its score.
msw 2014/08/27 18:44:38 nit: "inlineable" seems more comment, fix up all t
Mark P 2014/08/27 23:08:20 Fixed all (two).
1602 // if there is at least one inlineable match.
1603 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", 1656 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
1604 { { "b", true, false }, 1657 { { "a", true, true },
1605 { "a", true, true }, 1658 { "b", true, false },
1606 { "k a", false, false }, 1659 { "k a", false, false },
1607 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1660 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1608 std::string() }, 1661 std::string() },
1609 { "[\"a\",[\"http://b.com\"],[],[]," 1662 { "[\"a\",[\"http://b.com\"],[],[],"
1610 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1663 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1611 "\"google:suggestrelevance\":[9999]}]", 1664 "\"google:suggestrelevance\":[9999]}]",
1612 { { "b.com", false, false }, 1665 { { "a", true, true },
1613 { "a", true, true }, 1666 { "b.com", false, false },
1614 { "k a", false, false }, 1667 { "k a", false, false },
1615 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1668 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1616 std::string() }, 1669 std::string() },
1617 // On the other hand, if there is no inlineable match, restore 1670 // If there is no inlineable match, restore the keyword verbatim score.
1618 // the keyword verbatim score. 1671 // The keyword verbatim match will then appear first.
1619 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," 1672 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
1620 "\"google:verbatimrelevance\":0}]", 1673 "\"google:verbatimrelevance\":0}]",
1621 { { "b", true, false }, 1674 { { "a", true, true },
1622 { "a", true, true }, 1675 { "b", true, false },
1623 { "k a", false, false }, 1676 { "k a", false, false },
1624 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1677 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1625 std::string() }, 1678 std::string() },
1626 { "[\"a\",[\"http://b.com\"],[],[]," 1679 { "[\"a\",[\"http://b.com\"],[],[],"
1627 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1680 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1628 "\"google:suggestrelevance\":[9999]," 1681 "\"google:suggestrelevance\":[9999],"
1629 "\"google:verbatimrelevance\":0}]", 1682 "\"google:verbatimrelevance\":0}]",
1630 { { "b.com", false, false }, 1683 { { "a", true, true },
1631 { "a", true, true }, 1684 { "b.com", false, false },
1632 { "k a", false, false }, 1685 { "k a", false, false },
1633 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1686 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1634 std::string() }, 1687 std::string() },
1635 1688
1636 // The top result does not have to score as highly as calculated 1689 // The top result does not have to score as highly as calculated
1637 // verbatim. i.e., there are no minimum score restrictions in 1690 // verbatim. i.e., there are no minimum score restrictions in
1638 // this provider. 1691 // this provider.
1639 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", 1692 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
1640 { { "a1", true, true }, 1693 { { "a1", true, true },
1641 { "k a", false, false }, 1694 { "k a", false, false },
1642 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1695 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1643 "1" }, 1696 "1" },
1644 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", 1697 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":10}]",
1645 { { "a1", true, true }, 1698 { { "a1", true, true },
1646 { "k a", false, false }, 1699 { "k a", false, false },
1647 { "a", true, true }, 1700 { "a", true, true },
1648 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1701 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1649 "1" }, 1702 "1" },
1650 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," 1703 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[10],"
1651 "\"google:verbatimrelevance\":0}]", 1704 "\"google:verbatimrelevance\":0}]",
1652 { { "k a", false, false }, 1705 { { "a1", true, true },
1653 { "a1", true, true }, 1706 { "k a", false, false },
1654 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1707 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1655 "1" }, 1708 "1" },
1656 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," 1709 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10, 20],"
1657 "\"google:verbatimrelevance\":0}]", 1710 "\"google:verbatimrelevance\":0}]",
1658 { 1711 { { "a2", true, true },
1659 { "k a", false, false }, 1712 { "k a", false, false },
1660 { "a2", true, true }, 1713 { "a1", true, false },
1661 { "a1", true, true },
1662 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1714 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1663 "2" }, 1715 "2" },
1664 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," 1716 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10, 30],"
1665 "\"google:verbatimrelevance\":2}]", 1717 "\"google:verbatimrelevance\":20}]",
1666 { { "k a", false, false }, 1718 { { "a2", true, true },
1667 { "a2", true, true }, 1719 { "k a", false, false },
1668 { "a", true, true }, 1720 { "a", true, true },
1669 { "a1", true, true }, 1721 { "a1", true, false },
1670 kEmptyMatch, kEmptyMatch }, 1722 kEmptyMatch, kEmptyMatch },
1671 "2" }, 1723 "2" },
1672 1724
1673 // Ensure that all suggestions are considered, regardless of order. 1725 // Ensure that all suggestions are considered, regardless of order.
1674 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," 1726 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
1675 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1727 "{\"google:suggestrelevance\":[10, 20, 30, 40, 50, 60, 70]}]",
1676 { { "a", true, true }, 1728 { { "a", true, true },
1677 { "k a", false, false }, 1729 { "k a", false, false },
1678 { "h", true, false }, 1730 { "h", true, false },
1679 { "g", true, false }, 1731 { "g", true, false },
1680 { "f", true, false }, 1732 { "f", true, false },
1681 { "e", true, false } }, 1733 { "e", true, false } },
1682 std::string() }, 1734 std::string() },
1683 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," 1735 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
1684 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," 1736 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
1685 "\"http://h.com\"],[],[]," 1737 "\"http://h.com\"],[],[],"
1686 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," 1738 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
1687 "\"NAVIGATION\", \"NAVIGATION\"," 1739 "\"NAVIGATION\", \"NAVIGATION\","
1688 "\"NAVIGATION\", \"NAVIGATION\"," 1740 "\"NAVIGATION\", \"NAVIGATION\","
1689 "\"NAVIGATION\"]," 1741 "\"NAVIGATION\"],"
1690 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1742 "\"google:suggestrelevance\":[10, 20, 30, 40, 50, 60, 70]}]",
1691 { { "a", true, true }, 1743 { { "a", true, true },
1692 { "k a", false, false }, 1744 { "k a", false, false },
1693 { "h.com", false, false }, 1745 { "h.com", false, false },
1694 { "g.com", false, false }, 1746 { "g.com", false, false },
1695 { "f.com", false, false }, 1747 { "f.com", false, false },
1696 { "e.com", false, false } }, 1748 { "e.com", false, false } },
1697 std::string() }, 1749 std::string() },
1698 1750
1699 // Ensure that incorrectly sized suggestion relevance lists are ignored. 1751 // Ensure that incorrectly sized suggestion relevance lists are ignored.
1700 // Note that keyword suggestions by default (not in suggested relevance 1752 // Note that keyword suggestions by default (not in suggested relevance
1701 // mode) score more highly than the default verbatim. 1753 // mode) score more highly than the default verbatim.
1702 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", 1754 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
1703 { { "a", true, true }, 1755 { { "a", true, true },
1704 { "a1", true, true }, 1756 { "a1", true, false },
1705 { "a2", true, true }, 1757 { "a2", true, false },
1706 { "k a", false, false }, 1758 { "k a", false, false },
1707 kEmptyMatch, kEmptyMatch }, 1759 kEmptyMatch, kEmptyMatch },
1708 std::string() }, 1760 std::string() },
1709 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", 1761 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
1710 { { "a", true, true }, 1762 { { "a", true, true },
1711 { "a1", true, true }, 1763 { "a1", true, false },
1712 { "k a", false, false }, 1764 { "k a", false, false },
1713 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1765 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1714 std::string() }, 1766 std::string() },
1715 // In this case, ignoring the suggested relevance scores means we keep 1767 // In this case, ignoring the suggested relevance scores means we keep
1716 // only one navsuggest result. 1768 // only one navsuggest result.
1717 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1769 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1718 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1770 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1719 "\"google:suggestrelevance\":[1]}]", 1771 "\"google:suggestrelevance\":[1]}]",
1720 { { "a", true, true }, 1772 { { "a", true, true },
1721 { "a1.com", false, false }, 1773 { "a1.com", false, false },
1722 { "k a", false, false }, 1774 { "k a", false, false },
1723 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1775 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1724 std::string() }, 1776 std::string() },
1725 { "[\"a\",[\"http://a1.com\"],[],[]," 1777 { "[\"a\",[\"http://a1.com\"],[],[],"
1726 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1778 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1727 "\"google:suggestrelevance\":[9999, 1]}]", 1779 "\"google:suggestrelevance\":[9999, 1]}]",
1728 { { "a", true, true }, 1780 { { "a", true, true },
1729 { "a1.com", false, false }, 1781 { "a1.com", false, false },
1730 { "k a", false, false }, 1782 { "k a", false, false },
1731 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1783 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1732 std::string() }, 1784 std::string() },
1733 1785
1734 // Ensure that all 'verbatim' results are merged with their maximum score. 1786 // Ensure that all 'verbatim' results are merged with their maximum score.
1735 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1787 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1736 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1788 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1737 { { "a2", true, true }, 1789 { { "a2", true, true },
1738 { "a", true, true }, 1790 { "a", true, true },
1739 { "a1", true, true }, 1791 { "a1", true, false },
1740 { "k a", false, false }, 1792 { "k a", false, false },
1741 kEmptyMatch, kEmptyMatch }, 1793 kEmptyMatch, kEmptyMatch },
1742 "2" }, 1794 "2" },
1743 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1795 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1744 "{\"google:suggestrelevance\":[9998, 9997, 9999]," 1796 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
1745 "\"google:verbatimrelevance\":0}]", 1797 "\"google:verbatimrelevance\":0}]",
1746 { { "a2", true, true }, 1798 { { "a2", true, true },
1747 { "a", true, true }, 1799 { "a", true, true },
1748 { "a1", true, true }, 1800 { "a1", true, false },
1749 { "k a", false, false }, 1801 { "k a", false, false },
1750 kEmptyMatch, kEmptyMatch }, 1802 kEmptyMatch, kEmptyMatch },
1751 "2" }, 1803 "2" },
1752 1804
1753 // Ensure that verbatim is always generated without other suggestions. 1805 // Ensure that verbatim is always generated without other suggestions.
1754 // TODO(mpearson): Ensure the value of verbatimrelevance is respected 1806 // TODO(mpearson): Ensure the value of verbatimrelevance is respected
1755 // (except when suggested relevances are ignored). 1807 // (except when suggested relevances are ignored).
1756 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", 1808 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
1757 { { "k a", false, false }, 1809 { { "a", true, true },
1758 { "a", true, true }, 1810 { "k a", false, false },
1759 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1811 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1760 std::string() }, 1812 std::string() },
1761 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", 1813 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
1762 { { "a", true, true }, 1814 { { "a", true, true },
1763 { "k a", false, false }, 1815 { "k a", false, false },
1764 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1816 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1765 std::string() }, 1817 std::string() },
1766 1818
1767 // In reorder mode, navsuggestions will not need to be demoted (because 1819 // In reorder mode, navsuggestions will not need to be demoted (because
1768 // they are marked as not allowed to be default match and will be 1820 // they are marked as not allowed to be default match and will be
1769 // reordered as necessary). 1821 // reordered as necessary).
1770 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1822 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1771 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1823 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1772 "\"google:verbatimrelevance\":9990," 1824 "\"google:verbatimrelevance\":9990,"
1773 "\"google:suggestrelevance\":[9998, 9999]}]", 1825 "\"google:suggestrelevance\":[9998, 9999]}]",
1774 { { "a2.com", false, false }, 1826 { { "a", true, true },
1827 { "a2.com", false, false },
1775 { "a1.com", false, false }, 1828 { "a1.com", false, false },
1776 { "a", true, true },
1777 { "k a", false, false }, 1829 { "k a", false, false },
1778 kEmptyMatch, kEmptyMatch }, 1830 kEmptyMatch, kEmptyMatch },
1779 std::string() }, 1831 std::string() },
1780 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1832 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1781 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1833 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1782 "\"google:verbatimrelevance\":9990," 1834 "\"google:verbatimrelevance\":9990,"
1783 "\"google:suggestrelevance\":[9999, 9998]}]", 1835 "\"google:suggestrelevance\":[9999, 9998]}]",
1784 { { "a1.com", false, false }, 1836 { { "a", true, true },
1837 { "a1.com", false, false },
1785 { "a2.com", false, false }, 1838 { "a2.com", false, false },
1786 { "a", true, true },
1787 { "k a", false, false }, 1839 { "k a", false, false },
1788 kEmptyMatch, kEmptyMatch }, 1840 kEmptyMatch, kEmptyMatch },
1789 std::string() }, 1841 std::string() },
1790 { "[\"a\",[\"https://a/\"],[],[]," 1842 { "[\"a\",[\"https://a/\"],[],[],"
1791 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1843 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1792 "\"google:suggestrelevance\":[9999]}]", 1844 "\"google:suggestrelevance\":[9999]}]",
1793 { { "https://a", false, false }, 1845 { { "a", true, true },
1794 { "a", true, true }, 1846 { "https://a", false, false },
1795 { "k a", false, false }, 1847 { "k a", false, false },
1796 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1848 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1797 std::string() }, 1849 std::string() },
1798 // Check when navsuggest scores more than verbatim and there is query 1850 // Check when navsuggest scores more than verbatim and there is query
1799 // suggestion but it scores lower. 1851 // suggestion but it scores lower.
1800 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1852 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1801 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1853 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1802 "\"google:verbatimrelevance\":9990," 1854 "\"google:verbatimrelevance\":9990,"
1803 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", 1855 "\"google:suggestrelevance\":[9998, 9999, 1300]}]",
1804 { { "a2.com", false, false }, 1856 { { "a", true, true },
1857 { "a2.com", false, false },
1805 { "a1.com", false, false }, 1858 { "a1.com", false, false },
1806 { "a", true, true }, 1859 { "a3", true, false },
1807 { "a3", true, true },
1808 { "k a", false, false }, 1860 { "k a", false, false },
1809 kEmptyMatch }, 1861 kEmptyMatch },
1810 std::string() }, 1862 std::string() },
1811 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1863 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1812 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1864 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1813 "\"google:verbatimrelevance\":9990," 1865 "\"google:verbatimrelevance\":9990,"
1814 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", 1866 "\"google:suggestrelevance\":[9999, 9998, 1300]}]",
1815 { { "a1.com", false, false }, 1867 { { "a", true, true },
1868 { "a1.com", false, false },
1816 { "a2.com", false, false }, 1869 { "a2.com", false, false },
1817 { "a", true, true }, 1870 { "a3", true, false },
1818 { "a3", true, true },
1819 { "k a", false, false }, 1871 { "k a", false, false },
1820 kEmptyMatch }, 1872 kEmptyMatch },
1821 std::string() }, 1873 std::string() },
1822 // Check when navsuggest scores more than a query suggestion. There is 1874 // Check when navsuggest scores more than a query suggestion. There is
1823 // a verbatim but it scores lower. 1875 // a verbatim but it scores lower.
1824 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1876 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1825 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1877 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1826 "\"google:verbatimrelevance\":9990," 1878 "\"google:verbatimrelevance\":9990,"
1827 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 1879 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
1828 { { "a2.com", false, false }, 1880 { { "a3", true, true },
1881 { "a2.com", false, false },
1829 { "a1.com", false, false }, 1882 { "a1.com", false, false },
1830 { "a3", true, true },
1831 { "a", true, true }, 1883 { "a", true, true },
1832 { "k a", false, false }, 1884 { "k a", false, false },
1833 kEmptyMatch }, 1885 kEmptyMatch },
1834 "3" }, 1886 "3" },
1835 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1887 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1836 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1888 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1837 "\"google:verbatimrelevance\":9990," 1889 "\"google:verbatimrelevance\":9990,"
1838 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 1890 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
1839 { { "a1.com", false, false }, 1891 { { "a3", true, true },
1892 { "a1.com", false, false },
1840 { "a2.com", false, false }, 1893 { "a2.com", false, false },
1841 { "a3", true, true },
1842 { "a", true, true }, 1894 { "a", true, true },
1843 { "k a", false, false }, 1895 { "k a", false, false },
1844 kEmptyMatch }, 1896 kEmptyMatch },
1845 "3" }, 1897 "3" },
1846 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1898 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1847 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1899 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1848 "\"google:verbatimrelevance\":0," 1900 "\"google:verbatimrelevance\":0,"
1849 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 1901 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
1850 { { "a2.com", false, false }, 1902 { { "a3", true, true },
1903 { "a2.com", false, false },
1851 { "a1.com", false, false }, 1904 { "a1.com", false, false },
1852 { "a3", true, true },
1853 { "k a", false, false }, 1905 { "k a", false, false },
1854 kEmptyMatch, kEmptyMatch }, 1906 kEmptyMatch, kEmptyMatch },
1855 "3" }, 1907 "3" },
1856 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1908 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1857 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1909 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1858 "\"google:verbatimrelevance\":0," 1910 "\"google:verbatimrelevance\":0,"
1859 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 1911 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
1860 { { "a1.com", false, false }, 1912 { { "a3", true, true },
1913 { "a1.com", false, false },
1861 { "a2.com", false, false }, 1914 { "a2.com", false, false },
1862 { "a3", true, true },
1863 { "k a", false, false }, 1915 { "k a", false, false },
1864 kEmptyMatch, kEmptyMatch }, 1916 kEmptyMatch, kEmptyMatch },
1865 "3" }, 1917 "3" },
1866 // Check when there is neither verbatim nor a query suggestion that, 1918 // Check when there is neither verbatim nor a query suggestion that,
1867 // because we can't demote navsuggestions below a query suggestion, 1919 // because we can't demote navsuggestions below a query suggestion,
1868 // we restore the keyword verbatim score. 1920 // we restore the keyword verbatim score.
1869 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1921 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1870 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1922 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1871 "\"google:verbatimrelevance\":0," 1923 "\"google:verbatimrelevance\":0,"
1872 "\"google:suggestrelevance\":[9998, 9999]}]", 1924 "\"google:suggestrelevance\":[9998, 9999]}]",
1873 { { "a2.com", false, false }, 1925 { { "a", true, true },
1926 { "a2.com", false, false },
1874 { "a1.com", false, false }, 1927 { "a1.com", false, false },
1875 { "a", true, true },
1876 { "k a", false, false }, 1928 { "k a", false, false },
1877 kEmptyMatch, kEmptyMatch }, 1929 kEmptyMatch, kEmptyMatch },
1878 std::string() }, 1930 std::string() },
1879 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1931 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1880 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1932 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1881 "\"google:verbatimrelevance\":0," 1933 "\"google:verbatimrelevance\":0,"
1882 "\"google:suggestrelevance\":[9999, 9998]}]", 1934 "\"google:suggestrelevance\":[9999, 9998]}]",
1883 { { "a1.com", false, false }, 1935 { { "a", true, true },
1936 { "a1.com", false, false },
1884 { "a2.com", false, false }, 1937 { "a2.com", false, false },
1885 { "a", true, true },
1886 { "k a", false, false }, 1938 { "k a", false, false },
1887 kEmptyMatch, kEmptyMatch }, 1939 kEmptyMatch, kEmptyMatch },
1888 std::string() }, 1940 std::string() },
1889 // More checks that everything works when it's not necessary to demote. 1941 // More checks that everything works when it's not necessary to demote.
1890 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1942 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1891 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1943 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1892 "\"google:verbatimrelevance\":9990," 1944 "\"google:verbatimrelevance\":9990,"
1893 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", 1945 "\"google:suggestrelevance\":[9997, 9998, 9999]}]",
1894 { { "a3", true, true }, 1946 { { "a3", true, true },
1895 { "a2.com", false, false }, 1947 { "a2.com", false, false },
1896 { "a1.com", false, false }, 1948 { "a1.com", false, false },
1897 { "a", true, true }, 1949 { "a", true, true },
1898 { "k a", false, false }, 1950 { "k a", false, false },
1899 kEmptyMatch }, 1951 kEmptyMatch },
1900 "3" }, 1952 "3" },
1901 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1953 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1902 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1954 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1903 "\"google:verbatimrelevance\":9990," 1955 "\"google:verbatimrelevance\":9990,"
1904 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1956 "\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1905 { { "a3", true, true }, 1957 { { "a3", true, true },
1906 { "a1.com", false, false }, 1958 { "a1.com", false, false },
1907 { "a2.com", false, false }, 1959 { "a2.com", false, false },
1908 { "a", true, true }, 1960 { "a", true, true },
1909 { "k a", false, false }, 1961 { "k a", false, false },
1910 kEmptyMatch }, 1962 kEmptyMatch },
1911 "3" }, 1963 "3" },
1912 }; 1964 };
1913 1965
1914 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1966 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1915 QueryForInput(ASCIIToUTF16("k a"), false, true); 1967 // Send the query twice in order to have a synchronous pass after the first
1968 // reply is received. This is necessary because SearchProvider doesn't
1969 // allow an asynchronous reply to change the default match.
1970 for (size_t j = 0; j < 2; j++) {
msw 2014/08/27 18:44:38 nit: ++j
Mark P 2014/08/27 23:08:19 Done.
1971 QueryForInput(ASCIIToUTF16("k a"), false, true);
1916 1972
1917 // Set up a default fetcher with no results. 1973 // Set up a default fetcher with no results.
1918 net::TestURLFetcher* default_fetcher = 1974 net::TestURLFetcher* default_fetcher =
1919 test_factory_.GetFetcherByID( 1975 test_factory_.GetFetcherByID(
1920 SearchProvider::kDefaultProviderURLFetcherID); 1976 SearchProvider::kDefaultProviderURLFetcherID);
1921 ASSERT_TRUE(default_fetcher); 1977 ASSERT_TRUE(default_fetcher);
1922 default_fetcher->set_response_code(200); 1978 default_fetcher->set_response_code(200);
1923 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 1979 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
1924 default_fetcher = NULL; 1980 default_fetcher = NULL;
1925 1981
1926 // Set up a keyword fetcher with provided results. 1982 // Set up a keyword fetcher with provided results.
1927 net::TestURLFetcher* keyword_fetcher = 1983 net::TestURLFetcher* keyword_fetcher =
1928 test_factory_.GetFetcherByID( 1984 test_factory_.GetFetcherByID(
1929 SearchProvider::kKeywordProviderURLFetcherID); 1985 SearchProvider::kKeywordProviderURLFetcherID);
1930 ASSERT_TRUE(keyword_fetcher); 1986 ASSERT_TRUE(keyword_fetcher);
1931 keyword_fetcher->set_response_code(200); 1987 keyword_fetcher->set_response_code(200);
1932 keyword_fetcher->SetResponseString(cases[i].json); 1988 keyword_fetcher->SetResponseString(cases[i].json);
1933 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); 1989 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
1934 keyword_fetcher = NULL; 1990 keyword_fetcher = NULL;
1935 RunTillProviderDone(); 1991 RunTillProviderDone();
1992 }
1936 1993
1937 const std::string description = "for input with json=" + cases[i].json; 1994 const std::string description = "for input with json=" + cases[i].json;
1938 const ACMatches& matches = provider_->matches(); 1995 const ACMatches& matches = provider_->matches();
1939 ASSERT_FALSE(matches.empty()); 1996 ASSERT_FALSE(matches.empty());
1940 // Find the first match that's allowed to be the default match and check 1997 // Find the first match that's allowed to be the default match and check
1941 // its inline_autocompletion. 1998 // its inline_autocompletion.
1942 ACMatches::const_iterator it = FindDefaultMatch(matches); 1999 ACMatches::const_iterator it = FindDefaultMatch(matches);
1943 ASSERT_NE(matches.end(), it); 2000 ASSERT_NE(matches.end(), it);
1944 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 2001 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
1945 it->inline_autocompletion) << description; 2002 it->inline_autocompletion) << description;
1946 2003
1947 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 2004 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
1948 size_t j = 0; 2005 size_t j = 0;
1949 // Ensure that the returned matches equal the expectations. 2006 // Ensure that the returned matches equal the expectations.
msw 2014/08/27 18:44:38 Ditto, too bad this also checks |from_keyword|.
Mark P 2014/08/27 23:08:19 I suppose I could add from_keyword to CheckMatches
msw 2014/08/28 19:21:40 Acknowledged.
1950 for (; j < matches.size(); ++j) { 2007 for (; j < matches.size(); ++j) {
1951 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), 2008 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
1952 matches[j].contents) << description; 2009 matches[j].contents) << description;
1953 EXPECT_EQ(cases[i].matches[j].from_keyword, 2010 EXPECT_EQ(cases[i].matches[j].from_keyword,
1954 matches[j].keyword == ASCIIToUTF16("k")) << description; 2011 matches[j].keyword == ASCIIToUTF16("k")) << description;
1955 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, 2012 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
1956 matches[j].allowed_to_be_default_match) << description; 2013 matches[j].allowed_to_be_default_match) << description;
1957 } 2014 }
1958 // Ensure that no expected matches are missing. 2015 // Ensure that no expected matches are missing.
1959 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 2016 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1960 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << 2017 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) <<
1961 "Case # " << i << " " << description; 2018 "Case # " << i << " " << description;
1962 } 2019 }
1963 } 2020 }
1964 2021
2022 TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) {
2023 // This test sends two separate queries, each receiving different JSON
2024 // replies, and checks that at each stage of processing (receiving first
2025 // asynchronous reply, handling new keystroke synchronously / sending the
2026 // second request, and receiving the second asynchronous reply) we have the
2027 // expected matches. In particular, receiving the second reply shouldn't
2028 // cause an unexpected inline autcompletion.
2029 struct {
2030 const std::string first_json;
2031 const ExpectedMatch first_async_matches[4];
2032 const ExpectedMatch sync_matches[4];
2033 const std::string second_json;
2034 const ExpectedMatch second_async_matches[4];
2035 } cases[] = {
2036 // A simple test that verifies we don't inline autocomplete after the
2037 // first asynchronous reply, but we do at the next keystroke if the
2038 // reply's results were good enough. Furthermore, we should continue
2039 // inline autocompleting after the second asynchronous reply if the new
2040 // top suggestion is the same as the old inline autocompleted suggestion.
2041 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2042 "{\"google:verbatimrelevance\":1300,"
msw 2014/08/27 18:44:39 nit: most tests avoid numbers near this threshold,
Mark P 2014/08/27 23:08:19 Done.
2043 "\"google:suggestrelevance\":[1302, 1301]}]",
2044 { { "a", true }, { "ab1", false }, { "ab2", false },
2045 kEmptyExpectedMatch },
2046 { { "ab1", true }, { "ab2", true }, { "ab", true },
2047 kEmptyExpectedMatch },
2048 "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
2049 "{\"google:verbatimrelevance\":1300,"
2050 "\"google:suggestrelevance\":[1302, 1301]}]",
2051 { { "ab1", true }, { "ab2", false }, { "ab", true },
2052 kEmptyExpectedMatch } },
2053 // Ditto, just for a navigation suggestion.
2054 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
2055 "{\"google:verbatimrelevance\":1300,"
2056 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2057 "\"google:suggestrelevance\":[1302, 1301]}]",
2058 { { "a", true }, { "ab1.com", false }, { "ab2.com", false },
2059 kEmptyExpectedMatch },
2060 { { "ab1.com", true }, { "ab2.com", true }, { "ab", true },
2061 kEmptyExpectedMatch },
2062 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
2063 "{\"google:verbatimrelevance\":1300,"
2064 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2065 "\"google:suggestrelevance\":[1302, 1301]}]",
2066 { { "ab1.com", true }, { "ab2.com", false }, { "ab", true },
2067 kEmptyExpectedMatch } },
2068 // A more realistic test of the same situation.
2069 { "[\"a\",[\"abcdef\", \"abcdef.com\", \"abc\"],[],[],"
2070 "{\"google:verbatimrelevance\":900,"
2071 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\", \"QUERY\"],"
2072 "\"google:suggestrelevance\":[1250, 1200, 1000]}]",
2073 { { "a", true }, { "abcdef", false }, { "abcdef.com", false },
2074 { "abc", false } },
2075 { { "abcdef", true }, { "abcdef.com", true }, { "abc", true },
2076 { "ab", true } },
2077 "[\"ab\",[\"abcdef\", \"abcdef.com\", \"abc\"],[],[],"
2078 "{\"google:verbatimrelevance\":900,"
2079 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\", \"QUERY\"],"
2080 "\"google:suggestrelevance\":[1250, 1200, 1000]}]",
2081 { { "abcdef", true }, { "abcdef.com", false }, { "abc", false },
2082 { "ab", true } } },
2083
2084 // Without an original inline autcompletion, a new inline autcompletion
2085 // should be rejected.
2086 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2087 "{\"google:verbatimrelevance\":1300,"
2088 "\"google:suggestrelevance\":[900, 800]}]",
2089 { { "a", true }, { "ab1", false }, { "ab2", false },
2090 kEmptyExpectedMatch },
2091 { { "ab", true }, { "ab1", true }, { "ab2", true },
2092 kEmptyExpectedMatch },
2093 "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
2094 "{\"google:verbatimrelevance\":1300,"
2095 "\"google:suggestrelevance\":[1302, 1301]}]",
2096 { { "ab", true }, { "ab1", false }, { "ab2", false },
2097 kEmptyExpectedMatch } },
2098 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2099 "{\"google:verbatimrelevance\":1300,"
2100 "\"google:suggestrelevance\":[900, 800]}]",
2101 { { "a", true }, { "ab1", false }, { "ab2", false },
2102 kEmptyExpectedMatch },
2103 { { "ab", true }, { "ab1", true }, { "ab2", true },
2104 kEmptyExpectedMatch },
2105 "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
2106 "{\"google:verbatimrelevance\":1300,"
2107 "\"google:suggestrelevance\":[1301, 1302]}]",
msw 2014/08/27 18:44:38 This case only differs from above in this scoring
Mark P 2014/08/27 23:08:20 No, I didn't intend to do something more complex.
msw 2014/08/28 19:21:39 Acknowledged.
2108 { { "ab", true }, { "ab2", false }, { "ab1", false },
2109 kEmptyExpectedMatch } },
2110 // Now, the same verifications but with the new inline autocompletion as a
2111 // navsuggestion. The new autocompletion should still be rejected.
2112 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
2113 "{\"google:verbatimrelevance\":1300,"
2114 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2115 "\"google:suggestrelevance\":[900, 800]}]",
2116 { { "a", true }, { "ab1.com", false }, { "ab2.com", false },
2117 kEmptyExpectedMatch },
2118 { { "ab", true }, { "ab1.com", true }, { "ab2.com", true },
2119 kEmptyExpectedMatch },
2120 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
2121 "{\"google:verbatimrelevance\":1300,"
2122 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2123 "\"google:suggestrelevance\":[1302, 1301]}]",
2124 { { "ab", true }, { "ab1.com", false }, { "ab2.com", false },
2125 kEmptyExpectedMatch } },
2126 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
msw 2014/08/27 18:44:39 Ditto, similar case.
Mark P 2014/08/27 23:08:19 Acknowledged.
2127 "{\"google:verbatimrelevance\":1300,"
2128 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2129 "\"google:suggestrelevance\":[900, 800]}]",
2130 { { "a", true }, { "ab1.com", false }, { "ab2.com", false },
2131 kEmptyExpectedMatch },
2132 { { "ab", true }, { "ab1.com", true }, { "ab2.com", true },
2133 kEmptyExpectedMatch },
2134 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
2135 "{\"google:verbatimrelevance\":1300,"
2136 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2137 "\"google:suggestrelevance\":[1301, 1302]}]",
2138 { { "ab", true }, { "ab2.com", false }, { "ab1.com", false },
2139 kEmptyExpectedMatch } },
2140
2141 // It's okay to abandon an inline autocompletion asynchronously.
msw 2014/08/27 18:44:39 Wait, but why?* If I were about to hit enter for t
Mark P 2014/08/27 23:08:20 From discussion with the suggest folks, this shoul
msw 2014/08/28 19:21:40 Acknowledged.
2142 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2143 "{\"google:verbatimrelevance\":1300,"
2144 "\"google:suggestrelevance\":[1302, 1301]}]",
2145 { { "a", true }, { "ab1", false }, { "ab2", false },
2146 kEmptyExpectedMatch },
2147 { { "ab1", true }, { "ab2", true }, { "ab", true },
2148 kEmptyExpectedMatch },
2149 "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
2150 "{\"google:verbatimrelevance\":1300,"
2151 "\"google:suggestrelevance\":[900, 800]}]",
2152 { { "ab", true }, { "ab1", true }, { "ab2", false },
2153 kEmptyExpectedMatch } },
2154
2155 // Note: it's possible that the suggest server returns a suggestion with
2156 // an inline autocompletion (that as usual we delay in allowing it to
2157 // be displayed as an inline autocompletion until the next keystroke),
2158 // then, in reply to the next keystroke, the server returns a different
2159 // suggestion as an inline autocompletion. This is not likely to happen.
2160 // Regardless, if it does, one could imagine three different behaviors:
2161 // - keep the original inline autocompletion until the next keystroke
2162 // (i.e., don't abandon an inline autocompletion asynchronously)
2163 // - abandon all inline autocompletions
msw 2014/08/27 18:44:38 nit: if you want to expound upon these behaviors (
Mark P 2014/08/27 23:08:20 Done. I found expanding it useful for me, and lik
msw 2014/08/28 19:21:39 Acknowledged.
2164 // - ignore the new inline autocompletion, yet possibly keep the original
2165 // if it scores well in the most recent reply
2166 // All of these behaviors are reasonable. The main thing we want to
2167 // ensure is that the second asynchronous reply shouldn't cause _a new_
2168 // inline autocompletion to be displayed. We test that here.
2169 // (BTW, it happens that the code does the third of those bullets.)
2170 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2171 "{\"google:verbatimrelevance\":1300,"
2172 "\"google:suggestrelevance\":[1302, 1301]}]",
2173 { { "a", true }, { "ab1", false }, { "ab2", false },
2174 kEmptyExpectedMatch },
2175 { { "ab1", true }, { "ab2", true }, { "ab", true },
2176 kEmptyExpectedMatch },
2177 "[\"ab\",[\"ab1\", \"ab3\"],[],[],"
2178 "{\"google:verbatimrelevance\":1300,"
2179 "\"google:suggestrelevance\":[1302, 1400]}]",
2180 { { "ab1", true }, { "ab3", false }, { "ab", true },
2181 kEmptyExpectedMatch } },
2182 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2183 "{\"google:verbatimrelevance\":1300,"
2184 "\"google:suggestrelevance\":[1302, 1301]}]",
2185 { { "a", true }, { "ab1", false }, { "ab2", false },
2186 kEmptyExpectedMatch },
2187 { { "ab1", true }, { "ab2", true }, { "ab", true },
2188 kEmptyExpectedMatch },
2189 "[\"ab\",[\"ab1\", \"ab3\"],[],[],"
2190 "{\"google:verbatimrelevance\":1300,"
2191 "\"google:suggestrelevance\":[900, 1400]}]",
2192 { { "ab", true }, { "ab3", false }, { "ab1", true },
2193 kEmptyExpectedMatch } },
2194 };
2195
2196 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
msw 2014/08/27 18:44:38 nit: ++i
Mark P 2014/08/27 23:08:20 Done.
2197 // First, send the query "a" and receive the provided JSON reply,
msw 2014/08/27 18:44:39 nit: remove "provided" for a one-liner.
Mark P 2014/08/27 23:08:19 Done.
2198 // |first_json|.
2199 ClearAllResults();
2200 QueryForInput(ASCIIToUTF16("a"), false, false);
msw 2014/08/27 18:44:38 This [clear, query, set response, get provider, ru
Mark P 2014/08/27 23:08:20 Done. The helper function can get (and does) now
msw 2014/08/28 19:21:40 Thank you for this nice cleanup!
2201 net::TestURLFetcher* first_fetcher =
2202 test_factory_.GetFetcherByID(
2203 SearchProvider::kDefaultProviderURLFetcherID);
2204 ASSERT_TRUE(first_fetcher);
2205 first_fetcher->set_response_code(200);
2206 first_fetcher->SetResponseString(cases[i].first_json);
2207 first_fetcher->delegate()->OnURLFetchComplete(first_fetcher);
2208 RunTillProviderDone();
2209
2210 // Verify that the matches after the asynchronous results are as expected.
2211 std::string description = "first asynchronous reply for input with "
msw 2014/08/27 18:44:39 nit: s/reply/response/ to match other comments? th
Mark P 2014/08/27 23:08:20 Consistency is a virtue. Fixed all.
2212 "first_json=" + cases[i].first_json;
2213 CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].first_async_matches),
2214 cases[i].first_async_matches, provider_->matches());
2215
2216 // Then, send the query "ab" and check the synchronous matches.
2217 description = "synchronous response after first keystroke after input "
msw 2014/08/27 18:44:38 nit: "the first keystroke"
Mark P 2014/08/27 23:08:19 Done.
2218 "with first_json=" + cases[i].first_json;
2219 QueryForInput(ASCIIToUTF16("ab"), false, false);
2220 CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].sync_matches),
2221 cases[i].sync_matches, provider_->matches());
2222
2223 // Finally, get the provided JSON reply, |second_json|, and verify the
2224 // matches after the second asynchronous reply are as expected.
2225 description = "second asynchronous response after input with first_json=" +
2226 cases[i].first_json + " and second_json=" + cases[i].second_json;
2227 net::TestURLFetcher* second_fetcher =
2228 test_factory_.GetFetcherByID(
2229 SearchProvider::kDefaultProviderURLFetcherID);
2230 ASSERT_TRUE(second_fetcher);
2231 second_fetcher->set_response_code(200);
2232 second_fetcher->SetResponseString(cases[i].second_json);
2233 second_fetcher->delegate()->OnURLFetchComplete(second_fetcher);
2234 RunTillProviderDone();
2235 CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].second_async_matches),
2236 cases[i].second_async_matches, provider_->matches());
2237 }
2238 }
2239
1965 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { 2240 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
1966 // We hardcode the string "term1" below, so ensure that the search term that 2241 // We hardcode the string "term1" below, so ensure that the search term that
1967 // got added to history already is that string. 2242 // got added to history already is that string.
1968 ASSERT_EQ(ASCIIToUTF16("term1"), term1_); 2243 ASSERT_EQ(ASCIIToUTF16("term1"), term1_);
1969 base::string16 term = term1_.substr(0, term1_.length() - 1); 2244 base::string16 term = term1_.substr(0, term1_.length() - 1);
1970 2245
1971 AddSearchToHistory(default_t_url_, term + ASCIIToUTF16("2"), 2); 2246 AddSearchToHistory(default_t_url_, term + ASCIIToUTF16("2"), 2);
1972 profile_.BlockUntilHistoryProcessesPendingRequests(); 2247 profile_.BlockUntilHistoryProcessesPendingRequests();
1973 2248
1974 struct { 2249 struct {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 fetcher->delegate()->OnURLFetchComplete(fetcher); 2308 fetcher->delegate()->OnURLFetchComplete(fetcher);
2034 RunTillProviderDone(); 2309 RunTillProviderDone();
2035 2310
2036 const std::string description = "for input with json=" + cases[i].json; 2311 const std::string description = "for input with json=" + cases[i].json;
2037 const ACMatches& matches = provider_->matches(); 2312 const ACMatches& matches = provider_->matches();
2038 2313
2039 // Ensure no extra matches are present. 2314 // Ensure no extra matches are present.
2040 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 2315 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
2041 2316
2042 size_t j = 0; 2317 size_t j = 0;
2043 // Ensure that the returned matches equal the expectations. 2318 // Ensure that the returned matches equal the expectations.
msw 2014/08/27 18:44:38 Ditto, too bad this doesn't check |allowed_to_be_d
Mark P 2014/08/27 23:08:19 Acknowledged.
2044 for (; j < matches.size(); ++j) 2319 for (; j < matches.size(); ++j)
2045 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), 2320 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]),
2046 matches[j].contents) << description; 2321 matches[j].contents) << description;
2047 // Ensure that no expected matches are missing. 2322 // Ensure that no expected matches are missing.
2048 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 2323 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
2049 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) << 2324 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) <<
2050 "Case # " << i << " " << description; 2325 "Case # " << i << " " << description;
2051 } 2326 }
2052 } 2327 }
2053 2328
2054 // Verifies suggest relevance behavior for URL input. 2329 // Verifies suggest relevance behavior for URL input.
2055 TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) { 2330 TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) {
2056 struct DefaultFetcherUrlInputMatch { 2331 struct DefaultFetcherUrlInputMatch {
2057 const std::string match_contents; 2332 const std::string match_contents;
2058 AutocompleteMatch::Type match_type; 2333 AutocompleteMatch::Type match_type;
2059 bool allowed_to_be_default_match; 2334 bool allowed_to_be_default_match;
2060 }; 2335 };
2061 const DefaultFetcherUrlInputMatch kEmptyMatch = 2336 const DefaultFetcherUrlInputMatch kEmptyMatch =
2062 { kNotApplicable, AutocompleteMatchType::NUM_TYPES, false }; 2337 { kNotApplicable, AutocompleteMatchType::NUM_TYPES, false };
2063 struct { 2338 struct {
2064 const std::string input; 2339 const std::string input;
2065 const std::string json; 2340 const std::string json;
2066 const DefaultFetcherUrlInputMatch output[4]; 2341 const DefaultFetcherUrlInputMatch output[4];
2067 } cases[] = { 2342 } cases[] = {
2068 // Ensure NAVIGATION matches are allowed to be listed first for URL 2343 // Ensure NAVIGATION matches are allowed to be listed first for URL input.
2069 // input regardless of whether the match is inlineable. Note that 2344 // Non-inlineable matches should not be allowed to be the default match.
2070 // non-inlineable matches should not be allowed to be the default match. 2345 // Note that the top-scoring inlineable match is moved to the top
2346 // regardless of its score.
2071 { "a.com", "[\"a.com\",[\"http://b.com/\"],[],[]," 2347 { "a.com", "[\"a.com\",[\"http://b.com/\"],[],[],"
2072 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2348 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2073 "\"google:suggestrelevance\":[9999]}]", 2349 "\"google:suggestrelevance\":[9999]}]",
2074 { { "b.com", AutocompleteMatchType::NAVSUGGEST, false }, 2350 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2075 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2351 { "b.com", AutocompleteMatchType::NAVSUGGEST, false },
2076 kEmptyMatch, kEmptyMatch } }, 2352 kEmptyMatch, kEmptyMatch } },
2077 { "a.com", "[\"a.com\",[\"https://b.com\"],[],[]," 2353 { "a.com", "[\"a.com\",[\"https://b.com\"],[],[],"
2078 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2354 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2079 "\"google:suggestrelevance\":[9999]}]", 2355 "\"google:suggestrelevance\":[9999]}]",
2080 { { "https://b.com", AutocompleteMatchType::NAVSUGGEST, false }, 2356 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2081 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2357 { "https://b.com", AutocompleteMatchType::NAVSUGGEST, false },
2082 kEmptyMatch, kEmptyMatch } }, 2358 kEmptyMatch, kEmptyMatch } },
2083 { "a.com", "[\"a.com\",[\"http://a.com/a\"],[],[]," 2359 { "a.com", "[\"a.com\",[\"http://a.com/a\"],[],[],"
2084 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2360 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2085 "\"google:suggestrelevance\":[9999]}]", 2361 "\"google:suggestrelevance\":[9999]}]",
2086 { { "a.com/a", AutocompleteMatchType::NAVSUGGEST, true }, 2362 { { "a.com/a", AutocompleteMatchType::NAVSUGGEST, true },
2087 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2363 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2088 kEmptyMatch, kEmptyMatch } }, 2364 kEmptyMatch, kEmptyMatch } },
2089 { "a.com", "[\"a.com\",[\"https://a.com\"],[],[]," 2365 { "a.com", "[\"a.com\",[\"https://a.com\"],[],[],"
2090 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2366 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2091 "\"google:suggestrelevance\":[9999]}]", 2367 "\"google:suggestrelevance\":[9999]}]",
2092 { { "https://a.com", AutocompleteMatchType::NAVSUGGEST, true }, 2368 { { "https://a.com", AutocompleteMatchType::NAVSUGGEST, true },
2093 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2369 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2094 kEmptyMatch, kEmptyMatch } }, 2370 kEmptyMatch, kEmptyMatch } },
2095 2371
2096 // Ensure topmost inlineable SUGGEST matches are NOT allowed for URL 2372 // Ensure topmost inlineable SUGGEST matches are NOT allowed for URL
2097 // input. SearchProvider disregards search and verbatim suggested 2373 // input. SearchProvider disregards search and verbatim suggested
2098 // relevances. 2374 // relevances.
2099 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," 2375 { "a.com", "[\"a.com\",[\"a.com info\"],[],[],"
2100 "{\"google:suggestrelevance\":[9999]}]", 2376 "{\"google:suggestrelevance\":[9999]}]",
2101 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2377 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2102 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, 2378 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2103 kEmptyMatch, kEmptyMatch } }, 2379 kEmptyMatch, kEmptyMatch } },
2104 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," 2380 { "a.com", "[\"a.com\",[\"a.com info\"],[],[],"
2105 "{\"google:suggestrelevance\":[9999]}]", 2381 "{\"google:suggestrelevance\":[9999]}]",
2106 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2382 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2107 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, 2383 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2108 kEmptyMatch, kEmptyMatch } }, 2384 kEmptyMatch, kEmptyMatch } },
2109 2385
2110 // Ensure the fallback mechanism allows inlinable NAVIGATION matches. 2386 // Ensure the fallback mechanism allows inlinable NAVIGATION matches.
2111 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[]," 2387 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[],"
2112 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 2388 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
2113 "\"google:suggestrelevance\":[9999, 9998]}]", 2389 "\"google:suggestrelevance\":[9999, 9998]}]",
2114 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, 2390 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true },
2115 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2391 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2116 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, 2392 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2117 kEmptyMatch } }, 2393 kEmptyMatch } },
2118 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[]," 2394 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[],"
2119 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 2395 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
2120 "\"google:suggestrelevance\":[9998, 9997]," 2396 "\"google:suggestrelevance\":[9998, 9997],"
2121 "\"google:verbatimrelevance\":9999}]", 2397 "\"google:verbatimrelevance\":9999}]",
2122 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, 2398 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true },
2123 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2399 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2124 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, 2400 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2125 kEmptyMatch } }, 2401 kEmptyMatch } },
2126 2402
2127 // Ensure topmost non-inlineable SUGGEST matches are allowed for URL 2403 // Ensure non-inlineable SUGGEST matches are allowed for URL input
2128 // input assuming the top inlineable match is not a query (i.e., is a 2404 // assuming the best inlineable match is not a query (i.e., is a
2129 // NAVSUGGEST). 2405 // NAVSUGGEST). The best inlineable match will be at the top of the
2406 // list regardless of its score.
2130 { "a.com", "[\"a.com\",[\"info\"],[],[]," 2407 { "a.com", "[\"a.com\",[\"info\"],[],[],"
2131 "{\"google:suggestrelevance\":[9999]}]", 2408 "{\"google:suggestrelevance\":[9999]}]",
2132 { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false }, 2409 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2133 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2410 { "info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2134 kEmptyMatch, kEmptyMatch } }, 2411 kEmptyMatch, kEmptyMatch } },
2135 { "a.com", "[\"a.com\",[\"info\"],[],[]," 2412 { "a.com", "[\"a.com\",[\"info\"],[],[],"
2136 "{\"google:suggestrelevance\":[9999]}]", 2413 "{\"google:suggestrelevance\":[9999]}]",
2137 { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false }, 2414 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2138 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2415 { "info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2139 kEmptyMatch, kEmptyMatch } }, 2416 kEmptyMatch, kEmptyMatch } },
2140 }; 2417 };
2141 2418
2142 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2419 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
2143 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); 2420 // Send the query twice in order to have a synchronous pass after the first
2144 net::TestURLFetcher* fetcher = 2421 // reply is received. This is necessary because SearchProvider doesn't
2145 test_factory_.GetFetcherByID( 2422 // allow an asynchronous reply to change the default match.
2146 SearchProvider::kDefaultProviderURLFetcherID); 2423 for (size_t j = 0; j < 2; j++) {
msw 2014/08/27 18:44:39 nit: ++j
Mark P 2014/08/27 23:08:19 Done.
2147 ASSERT_TRUE(fetcher); 2424 QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
2148 fetcher->set_response_code(200); 2425 net::TestURLFetcher* fetcher =
2149 fetcher->SetResponseString(cases[i].json); 2426 test_factory_.GetFetcherByID(
2150 fetcher->delegate()->OnURLFetchComplete(fetcher); 2427 SearchProvider::kDefaultProviderURLFetcherID);
2151 RunTillProviderDone(); 2428 ASSERT_TRUE(fetcher);
2429 fetcher->set_response_code(200);
2430 fetcher->SetResponseString(cases[i].json);
2431 fetcher->delegate()->OnURLFetchComplete(fetcher);
2432 RunTillProviderDone();
2433 }
2152 2434
2435 const std::string description = "input=" + cases[i].input + " json=" +
2436 cases[i].json;
2153 size_t j = 0; 2437 size_t j = 0;
2154 const ACMatches& matches = provider_->matches(); 2438 const ACMatches& matches = provider_->matches();
2155 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output)); 2439 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output)) <<
2440 description;
msw 2014/08/27 18:44:39 nit: SCOPED_TRACE may be your friend here and in s
Mark P 2014/08/27 23:08:20 Good idea. Fixed all << whatever in this file to
msw 2014/08/28 19:21:40 Acknowledged.
2156 // Ensure that the returned matches equal the expectations. 2441 // Ensure that the returned matches equal the expectations.
msw 2014/08/27 18:44:38 Ditto, too bad this also checks |match_type|.
Mark P 2014/08/27 23:08:19 Acknowledged.
2157 for (; j < matches.size(); ++j) { 2442 for (; j < matches.size(); ++j) {
2158 EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents), 2443 EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents),
2159 matches[j].contents); 2444 matches[j].contents) << description;
2160 EXPECT_EQ(cases[i].output[j].match_type, matches[j].type); 2445 EXPECT_EQ(cases[i].output[j].match_type, matches[j].type) << description;
2161 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match, 2446 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match,
2162 matches[j].allowed_to_be_default_match); 2447 matches[j].allowed_to_be_default_match) << description;
2163 } 2448 }
2164 // Ensure that no expected matches are missing. 2449 // Ensure that no expected matches are missing.
2165 for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) { 2450 for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) {
2166 EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents); 2451 EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents) <<
2452 description;
2167 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES, 2453 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES,
2168 cases[i].output[j].match_type); 2454 cases[i].output[j].match_type) << description;
2169 EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match); 2455 EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match) <<
2456 description;
2170 } 2457 }
2171 } 2458 }
2172 } 2459 }
2173 2460
2174 // A basic test that verifies the field trial triggered parsing logic. 2461 // A basic test that verifies the field trial triggered parsing logic.
2175 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) { 2462 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) {
2176 QueryForInput(ASCIIToUTF16("foo"), false, false); 2463 QueryForInput(ASCIIToUTF16("foo"), false, false);
2177 2464
2178 // Make sure the default providers suggest service was queried. 2465 // Make sure the default providers suggest service was queried.
2179 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 2466 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 "?www.abc.com", "c.com", true, false }, 2659 "?www.abc.com", "c.com", true, false },
2373 { "?ab", "http://www.abc.com", 2660 { "?ab", "http://www.abc.com",
2374 "?www.abc.com", "c.com", true, false }, 2661 "?www.abc.com", "c.com", true, false },
2375 { "?abc.com", "http://www.abc.com", 2662 { "?abc.com", "http://www.abc.com",
2376 "?www.abc.com", "", true, true }, 2663 "?www.abc.com", "", true, true },
2377 }; 2664 };
2378 2665
2379 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2666 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
2380 // First test regular mode. 2667 // First test regular mode.
2381 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); 2668 QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
2382 AutocompleteMatch match( 2669 SearchSuggestionParser::NavigationResult result(
2383 provider_->NavigationToMatch(SearchSuggestionParser::NavigationResult( 2670 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
2384 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), 2671 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
2385 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), 2672 false, 0, false, ASCIIToUTF16(cases[i].input), std::string());
2386 false, 0, false, ASCIIToUTF16(cases[i].input), std::string()))); 2673 result.set_received_after_last_keystroke(false);
2674 AutocompleteMatch match(provider_->NavigationToMatch(result));
2387 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 2675 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
2388 match.inline_autocompletion); 2676 match.inline_autocompletion);
2389 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); 2677 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit);
2390 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, 2678 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode,
2391 match.allowed_to_be_default_match); 2679 match.allowed_to_be_default_match);
2392 2680
2393 // Then test prevent-inline-autocomplete mode. 2681 // Then test prevent-inline-autocomplete mode.
2394 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); 2682 QueryForInput(ASCIIToUTF16(cases[i].input), true, false);
2683 SearchSuggestionParser::NavigationResult result_prevent_inline(
2684 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
2685 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
2686 false, 0, false, ASCIIToUTF16(cases[i].input), std::string());
2687 result_prevent_inline.set_received_after_last_keystroke(false);
2395 AutocompleteMatch match_prevent_inline( 2688 AutocompleteMatch match_prevent_inline(
2396 provider_->NavigationToMatch(SearchSuggestionParser::NavigationResult( 2689 provider_->NavigationToMatch(result_prevent_inline));
2397 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
2398 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
2399 false, 0, false, ASCIIToUTF16(cases[i].input), std::string())));
2400 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 2690 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
2401 match_prevent_inline.inline_autocompletion); 2691 match_prevent_inline.inline_autocompletion);
2402 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), 2692 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit),
2403 match_prevent_inline.fill_into_edit); 2693 match_prevent_inline.fill_into_edit);
2404 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, 2694 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode,
2405 match_prevent_inline.allowed_to_be_default_match); 2695 match_prevent_inline.allowed_to_be_default_match);
2406 } 2696 }
2407 } 2697 }
2408 2698
2409 // Verifies that "http://" is not trimmed for input that is a leading substring. 2699 // Verifies that "http://" is not trimmed for input that is a leading substring.
2410 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { 2700 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) {
2411 const base::string16 input(ASCIIToUTF16("ht")); 2701 const base::string16 input(ASCIIToUTF16("ht"));
2412 const base::string16 url(ASCIIToUTF16("http://a.com")); 2702 const base::string16 url(ASCIIToUTF16("http://a.com"));
2413 const SearchSuggestionParser::NavigationResult result( 2703 SearchSuggestionParser::NavigationResult result(
2414 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), 2704 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url),
2415 AutocompleteMatchType::NAVSUGGEST, 2705 AutocompleteMatchType::NAVSUGGEST,
2416 base::string16(), std::string(), false, 0, false, input, std::string()); 2706 base::string16(), std::string(), false, 0, false, input, std::string());
2707 result.set_received_after_last_keystroke(false);
2417 2708
2418 // Check the offset and strings when inline autocompletion is allowed. 2709 // Check the offset and strings when inline autocompletion is allowed.
2419 QueryForInput(input, false, false); 2710 QueryForInput(input, false, false);
2420 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); 2711 AutocompleteMatch match_inline(provider_->NavigationToMatch(result));
2421 EXPECT_EQ(url, match_inline.fill_into_edit); 2712 EXPECT_EQ(url, match_inline.fill_into_edit);
2422 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); 2713 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion);
2423 EXPECT_TRUE(match_inline.allowed_to_be_default_match); 2714 EXPECT_TRUE(match_inline.allowed_to_be_default_match);
2424 EXPECT_EQ(url, match_inline.contents); 2715 EXPECT_EQ(url, match_inline.contents);
2425 2716
2426 // Check the same strings when inline autocompletion is prevented. 2717 // Check the same strings when inline autocompletion is prevented.
2427 QueryForInput(input, true, false); 2718 QueryForInput(input, true, false);
2428 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); 2719 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result));
2429 EXPECT_EQ(url, match_prevent.fill_into_edit); 2720 EXPECT_EQ(url, match_prevent.fill_into_edit);
2430 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); 2721 EXPECT_FALSE(match_prevent.allowed_to_be_default_match);
2431 EXPECT_EQ(url, match_prevent.contents); 2722 EXPECT_EQ(url, match_prevent.contents);
2432 } 2723 }
2433 2724
2434 // Verifies that input "w" marks a more significant domain label than "www.". 2725 // Verifies that input "w" marks a more significant domain label than "www.".
2435 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { 2726 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) {
2436 QueryForInput(ASCIIToUTF16("w"), false, false); 2727 QueryForInput(ASCIIToUTF16("w"), false, false);
2437 AutocompleteMatch match( 2728 SearchSuggestionParser::NavigationResult result(
2438 provider_->NavigationToMatch(SearchSuggestionParser::NavigationResult( 2729 ChromeAutocompleteSchemeClassifier(&profile_),
2439 ChromeAutocompleteSchemeClassifier(&profile_), 2730 GURL("http://www.wow.com"), AutocompleteMatchType::NAVSUGGEST,
2440 GURL("http://www.wow.com"), 2731 base::string16(), std::string(), false, 0, false, ASCIIToUTF16("w"),
2441 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), 2732 std::string());
2442 false, 0, false, ASCIIToUTF16("w"), std::string()))); 2733 result.set_received_after_last_keystroke(false);
2734 AutocompleteMatch match(provider_->NavigationToMatch(result));
2443 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); 2735 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion);
2444 EXPECT_TRUE(match.allowed_to_be_default_match); 2736 EXPECT_TRUE(match.allowed_to_be_default_match);
2445 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); 2737 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit);
2446 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); 2738 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents);
2447 2739
2448 // Ensure that the match for input "w" is marked on "wow" and not "www". 2740 // Ensure that the match for input "w" is marked on "wow" and not "www".
2449 ASSERT_EQ(3U, match.contents_class.size()); 2741 ASSERT_EQ(3U, match.contents_class.size());
2450 EXPECT_EQ(0U, match.contents_class[0].offset); 2742 EXPECT_EQ(0U, match.contents_class[0].offset);
2451 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 2743 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
2452 match.contents_class[0].style); 2744 match.contents_class[0].style);
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
3268 // Mismatching input will return empty prefetch data. 3560 // Mismatching input will return empty prefetch data.
3269 AutocompleteInput input2(base::ASCIIToUTF16("weather n"), 3561 AutocompleteInput input2(base::ASCIIToUTF16("weather n"),
3270 base::string16::npos, base::string16(), GURL(), 3562 base::string16::npos, base::string16(), GURL(),
3271 metrics::OmniboxEventProto::INVALID_SPEC, false, 3563 metrics::OmniboxEventProto::INVALID_SPEC, false,
3272 false, true, true, 3564 false, true, true,
3273 ChromeAutocompleteSchemeClassifier(&profile_)); 3565 ChromeAutocompleteSchemeClassifier(&profile_));
3274 provider_->DoAnswersQuery(input2); 3566 provider_->DoAnswersQuery(input2);
3275 EXPECT_TRUE(provider_->prefetch_data_.full_query_text.empty()); 3567 EXPECT_TRUE(provider_->prefetch_data_.full_query_text.empty());
3276 EXPECT_TRUE(provider_->prefetch_data_.query_type.empty()); 3568 EXPECT_TRUE(provider_->prefetch_data_.query_type.empty());
3277 } 3569 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698