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

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: mike's extensive changes to tests 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 const bool allowed_to_be_default_match; 135 const bool allowed_to_be_default_match;
136 const base::string16 fill_into_edit; 136 const base::string16 fill_into_edit;
137 }; 137 };
138 138
139 struct TestData { 139 struct TestData {
140 const base::string16 input; 140 const base::string16 input;
141 const size_t num_results; 141 const size_t num_results;
142 const ResultInfo output[3]; 142 const ResultInfo output[3];
143 }; 143 };
144 144
145 struct ExpectedMatch {
146 std::string contents;
147 bool allowed_to_be_default_match;
148 };
149
145 SearchProviderTest() 150 SearchProviderTest()
146 : default_t_url_(NULL), 151 : default_t_url_(NULL),
147 term1_(ASCIIToUTF16("term1")), 152 term1_(ASCIIToUTF16("term1")),
148 keyword_t_url_(NULL), 153 keyword_t_url_(NULL),
149 keyword_term_(ASCIIToUTF16("keyword")), 154 keyword_term_(ASCIIToUTF16("keyword")),
150 run_loop_(NULL) { 155 run_loop_(NULL) {
151 ResetFieldTrialList(); 156 ResetFieldTrialList();
152 } 157 }
153 158
154 // See description above class for what this registers. 159 // See description above class for what this registers.
155 virtual void SetUp() OVERRIDE; 160 virtual void SetUp() OVERRIDE;
156 virtual void TearDown() OVERRIDE; 161 virtual void TearDown() OVERRIDE;
157 162
158 void RunTest(TestData* cases, int num_cases, bool prefer_keyword); 163 void RunTest(TestData* cases, int num_cases, bool prefer_keyword);
159 164
160 protected: 165 protected:
161 // Needed for AutocompleteFieldTrial::ActivateStaticTrials(); 166 // Needed for AutocompleteFieldTrial::ActivateStaticTrials();
162 scoped_ptr<base::FieldTrialList> field_trial_list_; 167 scoped_ptr<base::FieldTrialList> field_trial_list_;
163 168
164 // Default value used for testing. 169 // Default values used for testing.
165 static const std::string kNotApplicable; 170 static const std::string kNotApplicable;
171 static const ExpectedMatch kEmptyExpectedMatch;
166 172
167 // Adds a search for |term|, using the engine |t_url| to the history, and 173 // Adds a search for |term|, using the engine |t_url| to the history, and
168 // returns the URL for that search. 174 // returns the URL for that search.
169 GURL AddSearchToHistory(TemplateURL* t_url, base::string16 term, int visit_cou nt); 175 GURL AddSearchToHistory(TemplateURL* t_url, base::string16 term, int visit_cou nt);
170 176
171 // Looks for a match in |provider_| with |contents| equal to |contents|. 177 // Looks for a match in |provider_| with |contents| equal to |contents|.
172 // Sets |match| to it if found. Returns whether |match| was set. 178 // Sets |match| to it if found. Returns whether |match| was set.
173 bool FindMatchWithContents(const base::string16& contents, 179 bool FindMatchWithContents(const base::string16& contents,
174 AutocompleteMatch* match); 180 AutocompleteMatch* match);
175 181
(...skipping 12 matching lines...) Expand all
188 // Invokes Start on provider_, then runs all pending tasks. 194 // Invokes Start on provider_, then runs all pending tasks.
189 void QueryForInput(const base::string16& text, 195 void QueryForInput(const base::string16& text,
190 bool prevent_inline_autocomplete, 196 bool prevent_inline_autocomplete,
191 bool prefer_keyword); 197 bool prefer_keyword);
192 198
193 // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is 199 // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is
194 // non-NULL, sets it to the "what you typed" entry for |text|. 200 // non-NULL, sets it to the "what you typed" entry for |text|.
195 void QueryForInputAndSetWYTMatch(const base::string16& text, 201 void QueryForInputAndSetWYTMatch(const base::string16& text,
196 AutocompleteMatch* wyt_match); 202 AutocompleteMatch* wyt_match);
197 203
204 // Calls QueryForInput(), sets the JSON responses for the default and keyword
205 // fetchers, and waits until the responses have been returned and the matches
206 // returned. Use empty responses for each fetcher that shouldn't be set up /
207 // configured.
208 void QueryForInputAndWaitForFetcherResponses(
209 const base::string16& text,
210 const bool prefer_keyword,
211 const std::string& default_fetcher_response,
212 const std::string& keyword_fetcher_response);
213
198 // Notifies the URLFetcher for the suggest query corresponding to the default 214 // Notifies the URLFetcher for the suggest query corresponding to the default
199 // search provider that it's done. 215 // search provider that it's done.
200 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE. 216 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE.
201 void FinishDefaultSuggestQuery(); 217 void FinishDefaultSuggestQuery();
202 218
203 // Runs SearchProvider on |input|, for which the suggest server replies 219 // Runs SearchProvider on |input|, for which the suggest server replies
204 // with |json|, and expects that the resulting matches' contents equals 220 // with |json|, and expects that the resulting matches' contents equals
205 // that in |matches|. An empty entry in |matches| means no match should 221 // that in |matches|. An empty entry in |matches| means no match should
206 // be returned in that position. Reports any errors with a message that 222 // be returned in that position. Reports any errors with a message that
207 // includes |error_description|. 223 // includes |error_description|.
208 void ForcedQueryTestHelper(const std::string& input, 224 void ForcedQueryTestHelper(const std::string& input,
209 const std::string& json, 225 const std::string& json,
210 const std::string matches[3], 226 const std::string matches[3],
211 const std::string& error_description); 227 const std::string& error_description);
212 228
229 // Verifies that |matches| and |expected_matches| agree on the first
230 // |num_expected_matches|, displaying an error message that includes
231 // |description| for any disagreement.
232 void CheckMatches(const std::string& description,
233 const size_t num_expected_matches,
234 const ExpectedMatch expected_matches[],
235 const ACMatches& matches);
236
213 void ResetFieldTrialList(); 237 void ResetFieldTrialList();
214 238
215 // Create a field trial, with ZeroSuggest activation based on |enabled|. 239 // Create a field trial, with ZeroSuggest activation based on |enabled|.
216 base::FieldTrial* CreateZeroSuggestFieldTrial(bool enabled); 240 base::FieldTrial* CreateZeroSuggestFieldTrial(bool enabled);
217 241
218 void ClearAllResults(); 242 void ClearAllResults();
219 243
220 // See description above class for details of these fields. 244 // See description above class for details of these fields.
221 TemplateURL* default_t_url_; 245 TemplateURL* default_t_url_;
222 const base::string16 term1_; 246 const base::string16 term1_;
(...skipping 14 matching lines...) Expand all
237 scoped_refptr<SearchProviderForTest> provider_; 261 scoped_refptr<SearchProviderForTest> provider_;
238 262
239 // If non-NULL, OnProviderUpdate quits the current |run_loop_|. 263 // If non-NULL, OnProviderUpdate quits the current |run_loop_|.
240 base::RunLoop* run_loop_; 264 base::RunLoop* run_loop_;
241 265
242 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); 266 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
243 }; 267 };
244 268
245 // static 269 // static
246 const std::string SearchProviderTest::kNotApplicable = "Not Applicable"; 270 const std::string SearchProviderTest::kNotApplicable = "Not Applicable";
271 const SearchProviderTest::ExpectedMatch
272 SearchProviderTest::kEmptyExpectedMatch = { kNotApplicable, false };
247 273
248 void SearchProviderTest::SetUp() { 274 void SearchProviderTest::SetUp() {
249 // Make sure that fetchers are automatically ungregistered upon destruction. 275 // Make sure that fetchers are automatically ungregistered upon destruction.
250 test_factory_.set_remove_fetcher_on_delete(true); 276 test_factory_.set_remove_fetcher_on_delete(true);
251 277
252 // We need both the history service and template url model loaded. 278 // We need both the history service and template url model loaded.
253 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); 279 ASSERT_TRUE(profile_.CreateHistoryService(true, false));
254 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 280 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
255 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); 281 &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
256 282
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 bool prefer_keyword) { 334 bool prefer_keyword) {
309 ACMatches matches; 335 ACMatches matches;
310 for (int i = 0; i < num_cases; ++i) { 336 for (int i = 0; i < num_cases; ++i) {
311 AutocompleteInput input(cases[i].input, base::string16::npos, 337 AutocompleteInput input(cases[i].input, base::string16::npos,
312 base::string16(), GURL(), 338 base::string16(), GURL(),
313 metrics::OmniboxEventProto::INVALID_SPEC, false, 339 metrics::OmniboxEventProto::INVALID_SPEC, false,
314 prefer_keyword, true, true, 340 prefer_keyword, true, true,
315 ChromeAutocompleteSchemeClassifier(&profile_)); 341 ChromeAutocompleteSchemeClassifier(&profile_));
316 provider_->Start(input, false); 342 provider_->Start(input, false);
317 matches = provider_->matches(); 343 matches = provider_->matches();
318 base::string16 diagnostic_details = 344 SCOPED_TRACE(
319 ASCIIToUTF16("Input was: ") + 345 ASCIIToUTF16("Input was: ") +
320 cases[i].input + 346 cases[i].input +
321 ASCIIToUTF16("; prefer_keyword was: ") + 347 ASCIIToUTF16("; prefer_keyword was: ") +
322 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")); 348 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")));
323 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details; 349 EXPECT_EQ(cases[i].num_results, matches.size());
324 if (matches.size() == cases[i].num_results) { 350 if (matches.size() == cases[i].num_results) {
325 for (size_t j = 0; j < cases[i].num_results; ++j) { 351 for (size_t j = 0; j < cases[i].num_results; ++j) {
326 EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) << 352 EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url);
327 diagnostic_details; 353 EXPECT_EQ(cases[i].output[j].result_type, matches[j].type);
328 EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) <<
329 diagnostic_details;
330 EXPECT_EQ(cases[i].output[j].fill_into_edit, 354 EXPECT_EQ(cases[i].output[j].fill_into_edit,
331 matches[j].fill_into_edit) << diagnostic_details; 355 matches[j].fill_into_edit);
332 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match, 356 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match,
333 matches[j].allowed_to_be_default_match) << diagnostic_details; 357 matches[j].allowed_to_be_default_match);
334 } 358 }
335 } 359 }
336 } 360 }
337 } 361 }
338 362
339 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { 363 void SearchProviderTest::OnProviderUpdate(bool updated_matches) {
340 if (run_loop_ && provider_->done()) { 364 if (run_loop_ && provider_->done()) {
341 run_loop_->Quit(); 365 run_loop_->Quit();
342 run_loop_ = NULL; 366 run_loop_ = NULL;
343 } 367 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 ASSERT_GE(provider_->matches().size(), 1u); 402 ASSERT_GE(provider_->matches().size(), 1u);
379 EXPECT_TRUE(FindMatchWithDestination( 403 EXPECT_TRUE(FindMatchWithDestination(
380 GURL(default_t_url_->url_ref().ReplaceSearchTerms( 404 GURL(default_t_url_->url_ref().ReplaceSearchTerms(
381 TemplateURLRef::SearchTermsArgs(base::CollapseWhitespace( 405 TemplateURLRef::SearchTermsArgs(base::CollapseWhitespace(
382 text, false)), 406 text, false)),
383 TemplateURLServiceFactory::GetForProfile( 407 TemplateURLServiceFactory::GetForProfile(
384 &profile_)->search_terms_data())), 408 &profile_)->search_terms_data())),
385 wyt_match)); 409 wyt_match));
386 } 410 }
387 411
412 void SearchProviderTest::QueryForInputAndWaitForFetcherResponses(
413 const base::string16& text,
414 const bool prefer_keyword,
415 const std::string& default_fetcher_response,
416 const std::string& keyword_fetcher_response) {
417 QueryForInput(text, false, prefer_keyword);
418 if (!default_fetcher_response.empty()) {
419 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
420 SearchProvider::kDefaultProviderURLFetcherID);
421 ASSERT_TRUE(fetcher);
422 fetcher->set_response_code(200);
423 fetcher->SetResponseString(default_fetcher_response);
424 fetcher->delegate()->OnURLFetchComplete(fetcher);
425 }
426 if (!keyword_fetcher_response.empty()) {
427 net::TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID(
428 SearchProvider::kKeywordProviderURLFetcherID);
429 ASSERT_TRUE(keyword_fetcher);
430 keyword_fetcher->set_response_code(200);
431 keyword_fetcher->SetResponseString(keyword_fetcher_response);
432 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
433 }
434 RunTillProviderDone();
435 }
436
388 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url, 437 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url,
389 base::string16 term, 438 base::string16 term,
390 int visit_count) { 439 int visit_count) {
391 HistoryService* history = 440 HistoryService* history =
392 HistoryServiceFactory::GetForProfile(&profile_, 441 HistoryServiceFactory::GetForProfile(&profile_,
393 Profile::EXPLICIT_ACCESS); 442 Profile::EXPLICIT_ACCESS);
394 GURL search(t_url->url_ref().ReplaceSearchTerms( 443 GURL search(t_url->url_ref().ReplaceSearchTerms(
395 TemplateURLRef::SearchTermsArgs(term), 444 TemplateURLRef::SearchTermsArgs(term),
396 TemplateURLServiceFactory::GetForProfile( 445 TemplateURLServiceFactory::GetForProfile(
397 &profile_)->search_terms_data())); 446 &profile_)->search_terms_data()));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 // Tell the SearchProvider the default suggest query is done. 486 // Tell the SearchProvider the default suggest query is done.
438 default_fetcher->set_response_code(200); 487 default_fetcher->set_response_code(200);
439 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 488 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
440 } 489 }
441 490
442 void SearchProviderTest::ForcedQueryTestHelper( 491 void SearchProviderTest::ForcedQueryTestHelper(
443 const std::string& input, 492 const std::string& input,
444 const std::string& json, 493 const std::string& json,
445 const std::string expected_matches[3], 494 const std::string expected_matches[3],
446 const std::string& error_description) { 495 const std::string& error_description) {
447 QueryForInput(ASCIIToUTF16(input), false, false); 496 // Send the query twice in order to have a synchronous pass after the first
448 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 497 // response is received. This is necessary because SearchProvider doesn't
449 SearchProvider::kDefaultProviderURLFetcherID); 498 // allow an asynchronous response to change the default match.
450 ASSERT_TRUE(fetcher); 499 for (size_t i = 0; i < 2; ++i) {
451 fetcher->set_response_code(200); 500 QueryForInputAndWaitForFetcherResponses(
452 fetcher->SetResponseString(json); 501 ASCIIToUTF16(input), false, json, "");
453 fetcher->delegate()->OnURLFetchComplete(fetcher); 502 }
454 RunTillProviderDone();
455 503
456 const ACMatches& matches = provider_->matches(); 504 const ACMatches& matches = provider_->matches();
457 ASSERT_LE(matches.size(), 3u); 505 ASSERT_LE(matches.size(), 3u);
458 size_t i = 0; 506 size_t i = 0;
459 // Ensure that the returned matches equal the expectations. 507 // Ensure that the returned matches equal the expectations.
460 for (; i < matches.size(); ++i) { 508 for (; i < matches.size(); ++i) {
461 EXPECT_EQ(ASCIIToUTF16(expected_matches[i]), matches[i].contents) << 509 EXPECT_EQ(ASCIIToUTF16(expected_matches[i]), matches[i].contents) <<
462 error_description; 510 error_description;
463 } 511 }
464 // Ensure that no expected matches are missing. 512 // Ensure that no expected matches are missing.
465 for (; i < 3u; ++i) { 513 for (; i < 3u; ++i) {
466 EXPECT_EQ(std::string(), expected_matches[i]) << 514 EXPECT_EQ(std::string(), expected_matches[i]) <<
467 "Case #" << i << ": " << error_description; 515 "Case #" << i << ": " << error_description;
468 } 516 }
469 } 517 }
470 518
519 void SearchProviderTest::CheckMatches(const std::string& description,
520 const size_t num_expected_matches,
521 const ExpectedMatch expected_matches[],
522 const ACMatches& matches) {
523 ASSERT_FALSE(matches.empty());
524 ASSERT_LE(matches.size(), num_expected_matches);
525 size_t i = 0;
526 SCOPED_TRACE(description);
527 // Ensure that the returned matches equal the expectations.
528 for (; i < matches.size(); ++i) {
529 SCOPED_TRACE(" Case # " + base::IntToString(i));
530 EXPECT_EQ(ASCIIToUTF16(expected_matches[i].contents),
531 matches[i].contents);
msw 2014/08/28 19:21:40 nit: fits on line above.
Mark P 2014/08/28 20:18:52 Done.
532 EXPECT_EQ(expected_matches[i].allowed_to_be_default_match,
533 matches[i].allowed_to_be_default_match);
534 }
535 // Ensure that no expected matches are missing.
536 for (; i < num_expected_matches; ++i) {
537 SCOPED_TRACE(" Case # " + base::IntToString(i));
538 EXPECT_EQ(kNotApplicable, expected_matches[i].contents);
539 }
540 }
541
471 void SearchProviderTest::ResetFieldTrialList() { 542 void SearchProviderTest::ResetFieldTrialList() {
472 // Destroy the existing FieldTrialList before creating a new one to avoid 543 // Destroy the existing FieldTrialList before creating a new one to avoid
473 // a DCHECK. 544 // a DCHECK.
474 field_trial_list_.reset(); 545 field_trial_list_.reset();
475 field_trial_list_.reset(new base::FieldTrialList( 546 field_trial_list_.reset(new base::FieldTrialList(
476 new metrics::SHA1EntropyProvider("foo"))); 547 new metrics::SHA1EntropyProvider("foo")));
477 variations::testing::ClearAllVariationParams(); 548 variations::testing::ClearAllVariationParams();
478 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial( 549 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial(
479 "AutocompleteDynamicTrial_0", "DefaultGroup"); 550 "AutocompleteDynamicTrial_0", "DefaultGroup");
480 trial->group(); 551 trial->group();
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 ASCIIToUTF16("k a")) } }, 1175 ASCIIToUTF16("k a")) } },
1105 }; 1176 };
1106 1177
1107 RunTest(cases, arraysize(cases), false); 1178 RunTest(cases, arraysize(cases), false);
1108 } 1179 }
1109 1180
1110 // Verifies Navsuggest results don't set a TemplateURL, which Instant relies on. 1181 // Verifies Navsuggest results don't set a TemplateURL, which Instant relies on.
1111 // Also verifies that just the *first* navigational result is listed as a match 1182 // Also verifies that just the *first* navigational result is listed as a match
1112 // if suggested relevance scores were not sent. 1183 // if suggested relevance scores were not sent.
1113 TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) { 1184 TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) {
1114 QueryForInput(ASCIIToUTF16("a.c"), false, false); 1185 QueryForInputAndWaitForFetcherResponses(
1115 1186 ASCIIToUTF16("a.c"), false,
1116 // Make sure the default providers suggest service was queried.
1117 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
1118 SearchProvider::kDefaultProviderURLFetcherID);
1119 ASSERT_TRUE(fetcher);
1120
1121 // Tell the SearchProvider the suggest query is done.
1122 fetcher->set_response_code(200);
1123 fetcher->SetResponseString(
1124 "[\"a.c\",[\"a.com\", \"a.com/b\"],[\"a\", \"b\"],[]," 1187 "[\"a.c\",[\"a.com\", \"a.com/b\"],[\"a\", \"b\"],[],"
1125 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]"); 1188 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]",
1126 fetcher->delegate()->OnURLFetchComplete(fetcher); 1189 "");
msw 2014/08/28 19:21:40 nit: use std::string() here and elsewhere instead
Mark P 2014/08/28 20:18:52 Switched almost all the uses in this file (except
1127 fetcher = NULL;
1128
1129 // Run till the history results complete.
1130 RunTillProviderDone();
1131 1190
1132 // Make sure the only match is 'a.com' and it doesn't have a template_url. 1191 // Make sure the only match is 'a.com' and it doesn't have a template_url.
1133 AutocompleteMatch nav_match; 1192 AutocompleteMatch nav_match;
1134 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); 1193 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match));
1135 EXPECT_TRUE(nav_match.keyword.empty()); 1194 EXPECT_TRUE(nav_match.keyword.empty());
1136 EXPECT_TRUE(nav_match.allowed_to_be_default_match); 1195 EXPECT_FALSE(nav_match.allowed_to_be_default_match);
1137 EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match)); 1196 EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match));
1138 } 1197 }
1139 1198
1140 // Verifies that the most relevant suggest results are added properly. 1199 // Verifies that the most relevant suggest results are added properly.
1141 TEST_F(SearchProviderTest, SuggestRelevance) { 1200 TEST_F(SearchProviderTest, SuggestRelevance) {
1142 QueryForInput(ASCIIToUTF16("a"), false, false); 1201 QueryForInputAndWaitForFetcherResponses(
1143 1202 ASCIIToUTF16("a"), false, "[\"a\",[\"a1\", \"a2\", \"a3\", \"a4\"]]", "");
1144 // Make sure the default provider's suggest service was queried.
1145 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
1146 SearchProvider::kDefaultProviderURLFetcherID);
1147 ASSERT_TRUE(fetcher);
1148
1149 // Tell the SearchProvider the suggest query is done.
1150 fetcher->set_response_code(200);
1151 fetcher->SetResponseString("[\"a\",[\"a1\", \"a2\", \"a3\", \"a4\"]]");
1152 fetcher->delegate()->OnURLFetchComplete(fetcher);
1153 fetcher = NULL;
1154
1155 // Run till the history results complete.
1156 RunTillProviderDone();
1157 1203
1158 // Check the expected verbatim and (first 3) suggestions' relative relevances. 1204 // Check the expected verbatim and (first 3) suggestions' relative relevances.
1159 AutocompleteMatch verbatim, match_a1, match_a2, match_a3, match_a4; 1205 AutocompleteMatch verbatim, match_a1, match_a2, match_a3, match_a4;
1160 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim)); 1206 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim));
1161 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1)); 1207 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1));
1162 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2)); 1208 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2));
1163 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3)); 1209 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3));
1164 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4)); 1210 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4));
1165 EXPECT_GT(verbatim.relevance, match_a1.relevance); 1211 EXPECT_GT(verbatim.relevance, match_a1.relevance);
1166 EXPECT_GT(match_a1.relevance, match_a2.relevance); 1212 EXPECT_GT(match_a1.relevance, match_a2.relevance);
1167 EXPECT_GT(match_a2.relevance, match_a3.relevance); 1213 EXPECT_GT(match_a2.relevance, match_a3.relevance);
1168 EXPECT_TRUE(verbatim.allowed_to_be_default_match); 1214 EXPECT_TRUE(verbatim.allowed_to_be_default_match);
1169 EXPECT_TRUE(match_a1.allowed_to_be_default_match); 1215 EXPECT_FALSE(match_a1.allowed_to_be_default_match);
1170 EXPECT_TRUE(match_a2.allowed_to_be_default_match); 1216 EXPECT_FALSE(match_a2.allowed_to_be_default_match);
1171 EXPECT_TRUE(match_a3.allowed_to_be_default_match); 1217 EXPECT_FALSE(match_a3.allowed_to_be_default_match);
1172 } 1218 }
1173 1219
1174 // Verifies that the default provider abandons suggested relevance scores 1220 // Verifies that the default provider abandons suggested relevance scores
1175 // when in keyword mode. This should happen regardless of whether the 1221 // when in keyword mode. This should happen regardless of whether the
1176 // keyword provider returns suggested relevance scores. 1222 // keyword provider returns suggested relevance scores.
1177 TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) { 1223 TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) {
1178 struct { 1224 struct {
1179 const std::string default_provider_json; 1225 const std::string default_provider_json;
1180 const std::string keyword_provider_json; 1226 const std::string keyword_provider_json;
1181 const std::string matches[5]; 1227 const std::string matches[5];
(...skipping 11 matching lines...) Expand all
1193 { "[\"k a\",[\"k adefault-query\", \"adefault.com\"],[],[]," 1239 { "[\"k a\",[\"k adefault-query\", \"adefault.com\"],[],[],"
1194 "{\"google:verbatimrelevance\":9700," 1240 "{\"google:verbatimrelevance\":9700,"
1195 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 1241 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
1196 "\"google:suggestrelevance\":[9900, 9800]}]", 1242 "\"google:suggestrelevance\":[9900, 9800]}]",
1197 "[\"a\",[\"akeyword-query\"],[],[],{\"google:suggesttype\":[\"QUERY\"]," 1243 "[\"a\",[\"akeyword-query\"],[],[],{\"google:suggesttype\":[\"QUERY\"],"
1198 "\"google:verbatimrelevance\":9500," 1244 "\"google:verbatimrelevance\":9500,"
1199 "\"google:suggestrelevance\":[9600]}]", 1245 "\"google:suggestrelevance\":[9600]}]",
1200 { "akeyword-query", "a", "k a", "adefault.com", "k adefault-query" } } 1246 { "akeyword-query", "a", "k a", "adefault.com", "k adefault-query" } }
1201 }; 1247 };
1202 1248
1203 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1249 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1204 QueryForInput(ASCIIToUTF16("k a"), false, true); 1250 // Send the query twice in order to have a synchronous pass after the first
1205 net::TestURLFetcher* default_fetcher = 1251 // response is received. This is necessary because SearchProvider doesn't
1206 test_factory_.GetFetcherByID( 1252 // allow an asynchronous response to change the default match.
1207 SearchProvider::kDefaultProviderURLFetcherID); 1253 for (size_t j = 0; j < 2; ++j) {
1208 ASSERT_TRUE(default_fetcher); 1254 QueryForInputAndWaitForFetcherResponses(
1209 default_fetcher->set_response_code(200); 1255 ASCIIToUTF16("k a"), true, cases[i].default_provider_json,
1210 default_fetcher->SetResponseString(cases[i].default_provider_json); 1256 cases[i].keyword_provider_json);
1211 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 1257 }
1212 net::TestURLFetcher* keyword_fetcher =
1213 test_factory_.GetFetcherByID(
1214 SearchProvider::kKeywordProviderURLFetcherID);
1215 ASSERT_TRUE(keyword_fetcher);
1216 keyword_fetcher->set_response_code(200);
1217 keyword_fetcher->SetResponseString(cases[i].keyword_provider_json);
1218 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
1219 RunTillProviderDone();
1220 1258
1221 const std::string description = "for input with default_provider_json=" + 1259 SCOPED_TRACE(
1260 "for input with default_provider_json=" +
1222 cases[i].default_provider_json + " and keyword_provider_json=" + 1261 cases[i].default_provider_json + " and keyword_provider_json=" +
1223 cases[i].keyword_provider_json; 1262 cases[i].keyword_provider_json);
1224 const ACMatches& matches = provider_->matches(); 1263 const ACMatches& matches = provider_->matches();
1225 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 1264 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
1226 size_t j = 0; 1265 size_t j = 0;
1227 // Ensure that the returned matches equal the expectations. 1266 // Ensure that the returned matches equal the expectations.
1228 for (; j < matches.size(); ++j) { 1267 for (; j < matches.size(); ++j) {
msw 2014/08/28 19:21:40 nit: remove curly braces.
Mark P 2014/08/28 20:18:52 Done.
1229 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents) << 1268 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents);
1230 description;
1231 } 1269 }
1232 // Ensure that no expected matches are missing. 1270 // Ensure that no expected matches are missing.
1233 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 1271 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1234 EXPECT_EQ(std::string(), cases[i].matches[j]) << description; 1272 EXPECT_EQ(std::string(), cases[i].matches[j]);
1235 } 1273 }
1236 } 1274 }
1237 1275
1238 // Verifies that suggest results with relevance scores are added 1276 // Verifies that suggest results with relevance scores are added
1239 // properly when using the default fetcher. When adding a new test 1277 // properly when using the default fetcher. When adding a new test
1240 // case to this test, please consider adding it to the tests in 1278 // case to this test, please consider adding it to the tests in
1241 // KeywordFetcherSuggestRelevance below. 1279 // KeywordFetcherSuggestRelevance below.
1242 TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) { 1280 TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
1243 struct DefaultFetcherMatch {
1244 std::string contents;
1245 bool allowed_to_be_default_match;
1246 };
1247 const DefaultFetcherMatch kEmptyMatch = { kNotApplicable, false };
1248 struct { 1281 struct {
1249 const std::string json; 1282 const std::string json;
1250 const DefaultFetcherMatch matches[6]; 1283 const ExpectedMatch matches[6];
1251 const std::string inline_autocompletion; 1284 const std::string inline_autocompletion;
1252 } cases[] = { 1285 } cases[] = {
1253 // Ensure that suggestrelevance scores reorder matches. 1286 // Ensure that suggestrelevance scores reorder matches.
1254 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", 1287 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
1255 { { "a", true }, { "c", false }, { "b", false }, kEmptyMatch, kEmptyMatch, 1288 { { "a", true }, { "c", false }, { "b", false }, kEmptyExpectedMatch,
1256 kEmptyMatch }, 1289 kEmptyExpectedMatch, kEmptyExpectedMatch },
1257 std::string() }, 1290 std::string() },
1258 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," 1291 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
1259 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1292 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1260 "\"google:suggestrelevance\":[1, 2]}]", 1293 "\"google:suggestrelevance\":[1, 2]}]",
1261 { { "a", true }, { "c.com", false }, { "b.com", false }, kEmptyMatch, 1294 { { "a", true }, { "c.com", false }, { "b.com", false },
1262 kEmptyMatch, kEmptyMatch }, 1295 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1263 std::string() }, 1296 std::string() },
1264 1297
1265 // Without suggested relevance scores, we should only allow one 1298 // Without suggested relevance scores, we should only allow one
1266 // navsuggest result to be be displayed. 1299 // navsuggest result to be be displayed.
1267 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," 1300 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
1268 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", 1301 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]",
1269 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch, 1302 { { "a", true }, { "b.com", false }, kEmptyExpectedMatch,
1270 kEmptyMatch, kEmptyMatch }, 1303 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1271 std::string() }, 1304 std::string() },
1272 1305
1273 // Ensure that verbatimrelevance scores reorder or suppress verbatim. 1306 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
1274 // Negative values will have no effect; the calculated value will be used. 1307 // Negative values will have no effect; the calculated value will be used.
1275 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," 1308 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
1276 "\"google:suggestrelevance\":[9998]}]", 1309 "\"google:suggestrelevance\":[9998]}]",
1277 { { "a", true}, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1310 { { "a", true}, { "a1", false }, kEmptyExpectedMatch,
1278 kEmptyMatch }, 1311 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1279 std::string() }, 1312 std::string() },
1280 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," 1313 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
1281 "\"google:suggestrelevance\":[9999]}]", 1314 "\"google:suggestrelevance\":[9999]}]",
1282 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1315 { { "a1", true }, { "a", true }, kEmptyExpectedMatch,
1283 kEmptyMatch }, 1316 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1284 "1" }, 1317 "1" },
1285 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," 1318 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0,"
1286 "\"google:suggestrelevance\":[9999]}]", 1319 "\"google:suggestrelevance\":[9999]}]",
1287 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1320 { { "a1", true }, kEmptyExpectedMatch, kEmptyExpectedMatch,
1288 kEmptyMatch }, 1321 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1289 "1" }, 1322 "1" },
1290 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," 1323 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1,"
1291 "\"google:suggestrelevance\":[9999]}]", 1324 "\"google:suggestrelevance\":[9999]}]",
1292 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1325 { { "a1", true }, { "a", true }, kEmptyExpectedMatch,
1293 kEmptyMatch }, 1326 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1294 "1" }, 1327 "1" },
1295 { "[\"a\",[\"http://a.com\"],[],[]," 1328 { "[\"a\",[\"http://a.com\"],[],[],"
1296 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1329 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1297 "\"google:verbatimrelevance\":9999," 1330 "\"google:verbatimrelevance\":9999,"
1298 "\"google:suggestrelevance\":[9998]}]", 1331 "\"google:suggestrelevance\":[9998]}]",
1299 { { "a", true }, { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1332 { { "a", true }, { "a.com", false }, kEmptyExpectedMatch,
1300 kEmptyMatch }, 1333 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1301 std::string() }, 1334 std::string() },
1302 { "[\"a\",[\"http://a.com\"],[],[]," 1335 { "[\"a\",[\"http://a.com\"],[],[],"
1303 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1336 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1304 "\"google:verbatimrelevance\":9998," 1337 "\"google:verbatimrelevance\":9998,"
1305 "\"google:suggestrelevance\":[9999]}]", 1338 "\"google:suggestrelevance\":[9999]}]",
1306 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1339 { { "a.com", true }, { "a", true }, kEmptyExpectedMatch,
1307 kEmptyMatch }, 1340 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1308 ".com" }, 1341 ".com" },
1309 { "[\"a\",[\"http://a.com\"],[],[]," 1342 { "[\"a\",[\"http://a.com\"],[],[],"
1310 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1343 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1311 "\"google:verbatimrelevance\":0," 1344 "\"google:verbatimrelevance\":0,"
1312 "\"google:suggestrelevance\":[9999]}]", 1345 "\"google:suggestrelevance\":[9999]}]",
1313 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1346 { { "a.com", true }, kEmptyExpectedMatch, kEmptyExpectedMatch,
1314 kEmptyMatch }, 1347 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1315 ".com" }, 1348 ".com" },
1316 { "[\"a\",[\"http://a.com\"],[],[]," 1349 { "[\"a\",[\"http://a.com\"],[],[],"
1317 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1350 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1318 "\"google:verbatimrelevance\":-1," 1351 "\"google:verbatimrelevance\":-1,"
1319 "\"google:suggestrelevance\":[9999]}]", 1352 "\"google:suggestrelevance\":[9999]}]",
1320 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1353 { { "a.com", true }, { "a", true }, kEmptyExpectedMatch,
1321 kEmptyMatch }, 1354 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1322 ".com" }, 1355 ".com" },
1323 1356
1324 // Ensure that both types of relevance scores reorder matches together. 1357 // Ensure that both types of relevance scores reorder matches together.
1325 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," 1358 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
1326 "\"google:verbatimrelevance\":9998}]", 1359 "\"google:verbatimrelevance\":9998}]",
1327 { { "a1", true }, { "a", true }, { "a2", true }, kEmptyMatch, kEmptyMatch, 1360 { { "a1", true }, { "a", true }, { "a2", false }, kEmptyExpectedMatch,
1328 kEmptyMatch }, 1361 kEmptyExpectedMatch, kEmptyExpectedMatch },
1329 "1" }, 1362 "1" },
1330 1363
1331 // Allow non-inlineable matches to be the highest-scoring match but, 1364 // Check that an inlineable result appears first regardless of its score.
1332 // if the result set lacks a single inlineable result, abandon suggested 1365 // Also, if the result set lacks a single inlineable result, abandon the
1333 // relevance scores entirely. 1366 // request to suppress verbatim (verbatim_relevance=0), which will then
1367 // cause verbatim to appear (first).
1334 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", 1368 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
1335 { { "b", false }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1369 { { "a", true }, { "b", false }, kEmptyExpectedMatch,
1336 kEmptyMatch }, 1370 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1337 std::string() }, 1371 std::string() },
1338 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," 1372 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
1339 "\"google:verbatimrelevance\":0}]", 1373 "\"google:verbatimrelevance\":0}]",
1340 { { "a", true }, { "b", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1374 { { "a", true }, { "b", false }, kEmptyExpectedMatch,
1341 kEmptyMatch }, 1375 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1342 std::string() }, 1376 std::string() },
1343 { "[\"a\",[\"http://b.com\"],[],[]," 1377 { "[\"a\",[\"http://b.com\"],[],[],"
1344 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1378 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1345 "\"google:suggestrelevance\":[9999]}]", 1379 "\"google:suggestrelevance\":[9999]}]",
1346 { { "b.com", false }, { "a", true }, kEmptyMatch, kEmptyMatch, 1380 { { "a", true }, { "b.com", false }, kEmptyExpectedMatch,
1347 kEmptyMatch, kEmptyMatch }, 1381 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1348 std::string() }, 1382 std::string() },
1349 { "[\"a\",[\"http://b.com\"],[],[]," 1383 { "[\"a\",[\"http://b.com\"],[],[],"
1350 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1384 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1351 "\"google:suggestrelevance\":[9999]," 1385 "\"google:suggestrelevance\":[9999],"
1352 "\"google:verbatimrelevance\":0}]", 1386 "\"google:verbatimrelevance\":0}]",
1353 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch, 1387 { { "a", true }, { "b.com", false }, kEmptyExpectedMatch,
1354 kEmptyMatch, kEmptyMatch }, 1388 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1355 std::string() }, 1389 std::string() },
1356 1390
1357 // Allow low-scoring matches. 1391 // Allow low-scoring matches.
1358 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", 1392 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
1359 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1393 { { "a1", true }, kEmptyExpectedMatch, kEmptyExpectedMatch,
1360 kEmptyMatch }, 1394 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1361 "1" }, 1395 "1" },
1362 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", 1396 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":10}]",
1363 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1397 { { "a1", true }, { "a", true }, kEmptyExpectedMatch,
1364 kEmptyMatch }, 1398 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1365 "1" }, 1399 "1" },
1366 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," 1400 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[10],"
1367 "\"google:verbatimrelevance\":0}]", 1401 "\"google:verbatimrelevance\":0}]",
1368 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1402 { { "a1", true }, kEmptyExpectedMatch, kEmptyExpectedMatch,
1369 kEmptyMatch }, 1403 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1370 "1" }, 1404 "1" },
1371 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," 1405 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10, 20],"
1372 "\"google:verbatimrelevance\":0}]", 1406 "\"google:verbatimrelevance\":0}]",
1373 { { "a2", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1407 { { "a2", true }, { "a1", false }, kEmptyExpectedMatch,
1374 kEmptyMatch }, 1408 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1375 "2" }, 1409 "2" },
1376 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," 1410 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10, 30],"
1377 "\"google:verbatimrelevance\":2}]", 1411 "\"google:verbatimrelevance\":20}]",
1378 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, 1412 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyExpectedMatch,
1379 kEmptyMatch }, 1413 kEmptyExpectedMatch, kEmptyExpectedMatch },
1380 "2" }, 1414 "2" },
1381 { "[\"a\",[\"http://a.com\"],[],[]," 1415 { "[\"a\",[\"http://a.com\"],[],[],"
1382 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1416 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1383 "\"google:suggestrelevance\":[1]," 1417 "\"google:suggestrelevance\":[10],"
1384 "\"google:verbatimrelevance\":0}]", 1418 "\"google:verbatimrelevance\":0}]",
1385 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1419 { { "a.com", true }, kEmptyExpectedMatch, kEmptyExpectedMatch,
1386 kEmptyMatch }, 1420 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1387 ".com" }, 1421 ".com" },
1388 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1422 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1389 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1423 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1390 "\"google:suggestrelevance\":[1, 2]," 1424 "\"google:suggestrelevance\":[10, 20],"
1391 "\"google:verbatimrelevance\":0}]", 1425 "\"google:verbatimrelevance\":0}]",
1392 { { "a2.com", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, 1426 { { "a2.com", true }, { "a1.com", false }, kEmptyExpectedMatch,
1393 kEmptyMatch, kEmptyMatch }, 1427 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1394 "2.com" }, 1428 "2.com" },
1395 1429
1396 // Ensure that all suggestions are considered, regardless of order. 1430 // Ensure that all suggestions are considered, regardless of order.
1397 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," 1431 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
1398 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1432 "{\"google:suggestrelevance\":[10, 20, 30, 40, 50, 60, 70]}]",
1399 { { "a", true }, { "h", false }, { "g", false }, { "f", false }, 1433 { { "a", true }, { "h", false }, { "g", false }, { "f", false },
1400 { "e", false }, { "d", false } }, 1434 { "e", false }, { "d", false } },
1401 std::string() }, 1435 std::string() },
1402 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," 1436 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
1403 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," 1437 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
1404 "\"http://h.com\"],[],[]," 1438 "\"http://h.com\"],[],[],"
1405 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," 1439 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
1406 "\"NAVIGATION\", \"NAVIGATION\"," 1440 "\"NAVIGATION\", \"NAVIGATION\","
1407 "\"NAVIGATION\", \"NAVIGATION\"," 1441 "\"NAVIGATION\", \"NAVIGATION\","
1408 "\"NAVIGATION\"]," 1442 "\"NAVIGATION\"],"
1409 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1443 "\"google:suggestrelevance\":[10, 20, 30, 40, 50, 60, 70]}]",
1410 { { "a", true }, { "h.com", false }, { "g.com", false }, 1444 { { "a", true }, { "h.com", false }, { "g.com", false },
1411 { "f.com", false }, { "e.com", false }, { "d.com", false } }, 1445 { "f.com", false }, { "e.com", false }, { "d.com", false } },
1412 std::string() }, 1446 std::string() },
1413 1447
1414 // Ensure that incorrectly sized suggestion relevance lists are ignored. 1448 // Ensure that incorrectly sized suggestion relevance lists are ignored.
1415 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", 1449 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10]}]",
1416 { { "a", true }, { "a1", true }, { "a2", true }, kEmptyMatch, kEmptyMatch, 1450 { { "a", true }, { "a1", false }, { "a2", false }, kEmptyExpectedMatch,
1417 kEmptyMatch }, 1451 kEmptyExpectedMatch, kEmptyExpectedMatch },
1418 std::string() }, 1452 std::string() },
1419 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", 1453 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 10]}]",
1420 { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1454 { { "a", true }, { "a1", false }, kEmptyExpectedMatch,
1421 kEmptyMatch }, 1455 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1422 std::string() }, 1456 std::string() },
1423 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1457 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1424 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1458 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1425 "\"google:suggestrelevance\":[1]}]", 1459 "\"google:suggestrelevance\":[10]}]",
1426 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, 1460 { { "a", true }, { "a1.com", false }, kEmptyExpectedMatch,
1427 kEmptyMatch, kEmptyMatch }, 1461 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1428 std::string() }, 1462 std::string() },
1429 { "[\"a\",[\"http://a1.com\"],[],[]," 1463 { "[\"a\",[\"http://a1.com\"],[],[],"
1430 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1464 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1431 "\"google:suggestrelevance\":[9999, 1]}]", 1465 "\"google:suggestrelevance\":[9999, 10]}]",
1432 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, 1466 { { "a", true }, { "a1.com", false }, kEmptyExpectedMatch,
1433 kEmptyMatch, kEmptyMatch }, 1467 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1434 std::string() }, 1468 std::string() },
1435 1469
1436 // Ensure that all 'verbatim' results are merged with their maximum score. 1470 // Ensure that all 'verbatim' results are merged with their maximum score.
1437 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1471 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1438 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1472 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1439 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, 1473 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyExpectedMatch,
1440 kEmptyMatch }, 1474 kEmptyExpectedMatch, kEmptyExpectedMatch },
1441 "2" }, 1475 "2" },
1442 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1476 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1443 "{\"google:suggestrelevance\":[9998, 9997, 9999]," 1477 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
1444 "\"google:verbatimrelevance\":0}]", 1478 "\"google:verbatimrelevance\":0}]",
1445 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, 1479 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyExpectedMatch,
1446 kEmptyMatch }, 1480 kEmptyExpectedMatch, kEmptyExpectedMatch },
1447 "2" }, 1481 "2" },
1448 1482
1449 // Ensure that verbatim is always generated without other suggestions. 1483 // Ensure that verbatim is always generated without other suggestions.
1450 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). 1484 // TODO(msw): Ensure verbatimrelevance is respected (except suppression).
1451 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", 1485 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
1452 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1486 { { "a", true }, kEmptyExpectedMatch, kEmptyExpectedMatch,
1453 kEmptyMatch }, 1487 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1454 std::string() }, 1488 std::string() },
1455 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", 1489 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
1456 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, 1490 { { "a", true }, kEmptyExpectedMatch, kEmptyExpectedMatch,
1457 kEmptyMatch }, 1491 kEmptyExpectedMatch, kEmptyExpectedMatch, kEmptyExpectedMatch },
1458 std::string() }, 1492 std::string() },
1459 }; 1493 };
1460 1494
1461 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1495 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1462 QueryForInput(ASCIIToUTF16("a"), false, false); 1496 // Send the query twice in order to have a synchronous pass after the first
1463 net::TestURLFetcher* fetcher = 1497 // response is received. This is necessary because SearchProvider doesn't
1464 test_factory_.GetFetcherByID( 1498 // allow an asynchronous response to change the default match.
1465 SearchProvider::kDefaultProviderURLFetcherID); 1499 for (size_t j = 0; j < 2; ++j) {
1466 ASSERT_TRUE(fetcher); 1500 QueryForInputAndWaitForFetcherResponses(
1467 fetcher->set_response_code(200); 1501 ASCIIToUTF16("a"), false, cases[i].json, "");
1468 fetcher->SetResponseString(cases[i].json); 1502 }
1469 fetcher->delegate()->OnURLFetchComplete(fetcher);
1470 RunTillProviderDone();
1471 1503
1472 const std::string description = "for input with json=" + cases[i].json; 1504 const std::string description = "for input with json=" + cases[i].json;
1473 const ACMatches& matches = provider_->matches(); 1505 CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].matches),
1474 ASSERT_FALSE(matches.empty()); 1506 cases[i].matches, provider_->matches());
1475 // Find the first match that's allowed to be the default match and check
1476 // its inline_autocompletion.
1477 ACMatches::const_iterator it = FindDefaultMatch(matches);
1478 ASSERT_NE(matches.end(), it);
1479 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
1480 it->inline_autocompletion) << description;
1481
1482 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
1483 size_t j = 0;
1484 // Ensure that the returned matches equal the expectations.
1485 for (; j < matches.size(); ++j) {
1486 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
1487 matches[j].contents) << description;
1488 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
1489 matches[j].allowed_to_be_default_match) << description;
1490 }
1491 // Ensure that no expected matches are missing.
1492 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1493 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) <<
1494 "Case # " << i << " " << description;
1495 } 1507 }
1496 } 1508 }
1497 1509
1498 // Verifies that suggest results with relevance scores are added 1510 // Verifies that suggest results with relevance scores are added
1499 // properly when using the keyword fetcher. This is similar to the 1511 // properly when using the keyword fetcher. This is similar to the
1500 // test DefaultFetcherSuggestRelevance above but this uses inputs that 1512 // test DefaultFetcherSuggestRelevance above but this uses inputs that
1501 // trigger keyword suggestions (i.e., "k a" rather than "a") and has 1513 // trigger keyword suggestions (i.e., "k a" rather than "a") and has
1502 // different expectations (because now the results are a mix of 1514 // different expectations (because now the results are a mix of
1503 // keyword suggestions and default provider suggestions). When a new 1515 // keyword suggestions and default provider suggestions). When a new
1504 // test is added to this TEST_F, please consider if it would be 1516 // test is added to this TEST_F, please consider if it would be
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 { "b.com", false, false }, 1562 { "b.com", false, false },
1551 { "k a", false, false }, 1563 { "k a", false, false },
1552 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1564 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1553 std::string() }, 1565 std::string() },
1554 1566
1555 // Ensure that verbatimrelevance scores reorder or suppress verbatim. 1567 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
1556 // Negative values will have no effect; the calculated value will be used. 1568 // Negative values will have no effect; the calculated value will be used.
1557 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," 1569 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
1558 "\"google:suggestrelevance\":[9998]}]", 1570 "\"google:suggestrelevance\":[9998]}]",
1559 { { "a", true, true }, 1571 { { "a", true, true },
1560 { "a1", true, true }, 1572 { "a1", true, false },
1561 { "k a", false, false }, 1573 { "k a", false, false },
1562 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1574 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1563 std::string() }, 1575 std::string() },
1564 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," 1576 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
1565 "\"google:suggestrelevance\":[9999]}]", 1577 "\"google:suggestrelevance\":[9999]}]",
1566 { { "a1", true, true }, 1578 { { "a1", true, true },
1567 { "a", true, true }, 1579 { "a", true, true },
1568 { "k a", false, false }, 1580 { "k a", false, false },
1569 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1581 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1570 "1" }, 1582 "1" },
(...skipping 18 matching lines...) Expand all
1589 { "a.com", false, false }, 1601 { "a.com", false, false },
1590 { "k a", false, false }, 1602 { "k a", false, false },
1591 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1603 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1592 std::string() }, 1604 std::string() },
1593 1605
1594 // Ensure that both types of relevance scores reorder matches together. 1606 // Ensure that both types of relevance scores reorder matches together.
1595 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," 1607 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
1596 "\"google:verbatimrelevance\":9998}]", 1608 "\"google:verbatimrelevance\":9998}]",
1597 { { "a1", true, true }, 1609 { { "a1", true, true },
1598 { "a", true, true }, 1610 { "a", true, true },
1599 { "a2", true, true }, 1611 { "a2", true, false },
1600 { "k a", false, false }, 1612 { "k a", false, false },
1601 kEmptyMatch, kEmptyMatch }, 1613 kEmptyMatch, kEmptyMatch },
1602 "1" }, 1614 "1" },
1603 1615
1604 // Check that non-inlinable matches may be ranked as the highest result 1616 // Check that an inlineable match appears first regardless of its score.
1605 // if there is at least one inlineable match.
1606 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", 1617 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
1607 { { "b", true, false }, 1618 { { "a", true, true },
1608 { "a", true, true }, 1619 { "b", true, false },
1609 { "k a", false, false }, 1620 { "k a", false, false },
1610 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1621 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1611 std::string() }, 1622 std::string() },
1612 { "[\"a\",[\"http://b.com\"],[],[]," 1623 { "[\"a\",[\"http://b.com\"],[],[],"
1613 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1624 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1614 "\"google:suggestrelevance\":[9999]}]", 1625 "\"google:suggestrelevance\":[9999]}]",
1615 { { "b.com", false, false }, 1626 { { "a", true, true },
1616 { "a", true, true }, 1627 { "b.com", false, false },
1617 { "k a", false, false }, 1628 { "k a", false, false },
1618 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1629 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1619 std::string() }, 1630 std::string() },
1620 // On the other hand, if there is no inlineable match, restore 1631 // If there is no inlineable match, restore the keyword verbatim score.
1621 // the keyword verbatim score. 1632 // The keyword verbatim match will then appear first.
1622 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," 1633 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
1623 "\"google:verbatimrelevance\":0}]", 1634 "\"google:verbatimrelevance\":0}]",
1624 { { "b", true, false }, 1635 { { "a", true, true },
1625 { "a", true, true }, 1636 { "b", true, false },
1626 { "k a", false, false }, 1637 { "k a", false, false },
1627 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1638 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1628 std::string() }, 1639 std::string() },
1629 { "[\"a\",[\"http://b.com\"],[],[]," 1640 { "[\"a\",[\"http://b.com\"],[],[],"
1630 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1641 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1631 "\"google:suggestrelevance\":[9999]," 1642 "\"google:suggestrelevance\":[9999],"
1632 "\"google:verbatimrelevance\":0}]", 1643 "\"google:verbatimrelevance\":0}]",
1633 { { "b.com", false, false }, 1644 { { "a", true, true },
1634 { "a", true, true }, 1645 { "b.com", false, false },
1635 { "k a", false, false }, 1646 { "k a", false, false },
1636 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1647 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1637 std::string() }, 1648 std::string() },
1638 1649
1639 // The top result does not have to score as highly as calculated 1650 // The top result does not have to score as highly as calculated
1640 // verbatim. i.e., there are no minimum score restrictions in 1651 // verbatim. i.e., there are no minimum score restrictions in
1641 // this provider. 1652 // this provider.
1642 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", 1653 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
1643 { { "a1", true, true }, 1654 { { "a1", true, true },
1644 { "k a", false, false }, 1655 { "k a", false, false },
1645 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1656 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1646 "1" }, 1657 "1" },
1647 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", 1658 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":10}]",
1648 { { "a1", true, true }, 1659 { { "a1", true, true },
1649 { "k a", false, false }, 1660 { "k a", false, false },
1650 { "a", true, true }, 1661 { "a", true, true },
1651 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1662 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1652 "1" }, 1663 "1" },
1653 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," 1664 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[10],"
1654 "\"google:verbatimrelevance\":0}]", 1665 "\"google:verbatimrelevance\":0}]",
1655 { { "k a", false, false }, 1666 { { "a1", true, true },
1656 { "a1", true, true }, 1667 { "k a", false, false },
1657 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1668 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1658 "1" }, 1669 "1" },
1659 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," 1670 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10, 20],"
1660 "\"google:verbatimrelevance\":0}]", 1671 "\"google:verbatimrelevance\":0}]",
1661 { 1672 { { "a2", true, true },
1662 { "k a", false, false }, 1673 { "k a", false, false },
1663 { "a2", true, true }, 1674 { "a1", true, false },
1664 { "a1", true, true },
1665 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1675 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1666 "2" }, 1676 "2" },
1667 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," 1677 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[10, 30],"
1668 "\"google:verbatimrelevance\":2}]", 1678 "\"google:verbatimrelevance\":20}]",
1669 { { "k a", false, false }, 1679 { { "a2", true, true },
1670 { "a2", true, true }, 1680 { "k a", false, false },
1671 { "a", true, true }, 1681 { "a", true, true },
1672 { "a1", true, true }, 1682 { "a1", true, false },
1673 kEmptyMatch, kEmptyMatch }, 1683 kEmptyMatch, kEmptyMatch },
1674 "2" }, 1684 "2" },
1675 1685
1676 // Ensure that all suggestions are considered, regardless of order. 1686 // Ensure that all suggestions are considered, regardless of order.
1677 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," 1687 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
1678 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1688 "{\"google:suggestrelevance\":[10, 20, 30, 40, 50, 60, 70]}]",
1679 { { "a", true, true }, 1689 { { "a", true, true },
1680 { "k a", false, false }, 1690 { "k a", false, false },
1681 { "h", true, false }, 1691 { "h", true, false },
1682 { "g", true, false }, 1692 { "g", true, false },
1683 { "f", true, false }, 1693 { "f", true, false },
1684 { "e", true, false } }, 1694 { "e", true, false } },
1685 std::string() }, 1695 std::string() },
1686 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," 1696 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
1687 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," 1697 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
1688 "\"http://h.com\"],[],[]," 1698 "\"http://h.com\"],[],[],"
1689 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," 1699 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
1690 "\"NAVIGATION\", \"NAVIGATION\"," 1700 "\"NAVIGATION\", \"NAVIGATION\","
1691 "\"NAVIGATION\", \"NAVIGATION\"," 1701 "\"NAVIGATION\", \"NAVIGATION\","
1692 "\"NAVIGATION\"]," 1702 "\"NAVIGATION\"],"
1693 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1703 "\"google:suggestrelevance\":[10, 20, 30, 40, 50, 60, 70]}]",
1694 { { "a", true, true }, 1704 { { "a", true, true },
1695 { "k a", false, false }, 1705 { "k a", false, false },
1696 { "h.com", false, false }, 1706 { "h.com", false, false },
1697 { "g.com", false, false }, 1707 { "g.com", false, false },
1698 { "f.com", false, false }, 1708 { "f.com", false, false },
1699 { "e.com", false, false } }, 1709 { "e.com", false, false } },
1700 std::string() }, 1710 std::string() },
1701 1711
1702 // Ensure that incorrectly sized suggestion relevance lists are ignored. 1712 // Ensure that incorrectly sized suggestion relevance lists are ignored.
1703 // Note that keyword suggestions by default (not in suggested relevance 1713 // Note that keyword suggestions by default (not in suggested relevance
1704 // mode) score more highly than the default verbatim. 1714 // mode) score more highly than the default verbatim.
1705 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", 1715 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
1706 { { "a", true, true }, 1716 { { "a", true, true },
1707 { "a1", true, true }, 1717 { "a1", true, false },
1708 { "a2", true, true }, 1718 { "a2", true, false },
1709 { "k a", false, false }, 1719 { "k a", false, false },
1710 kEmptyMatch, kEmptyMatch }, 1720 kEmptyMatch, kEmptyMatch },
1711 std::string() }, 1721 std::string() },
1712 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", 1722 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
1713 { { "a", true, true }, 1723 { { "a", true, true },
1714 { "a1", true, true }, 1724 { "a1", true, false },
1715 { "k a", false, false }, 1725 { "k a", false, false },
1716 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1726 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1717 std::string() }, 1727 std::string() },
1718 // In this case, ignoring the suggested relevance scores means we keep 1728 // In this case, ignoring the suggested relevance scores means we keep
1719 // only one navsuggest result. 1729 // only one navsuggest result.
1720 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1730 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1721 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1731 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1722 "\"google:suggestrelevance\":[1]}]", 1732 "\"google:suggestrelevance\":[1]}]",
1723 { { "a", true, true }, 1733 { { "a", true, true },
1724 { "a1.com", false, false }, 1734 { "a1.com", false, false },
1725 { "k a", false, false }, 1735 { "k a", false, false },
1726 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1736 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1727 std::string() }, 1737 std::string() },
1728 { "[\"a\",[\"http://a1.com\"],[],[]," 1738 { "[\"a\",[\"http://a1.com\"],[],[],"
1729 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1739 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1730 "\"google:suggestrelevance\":[9999, 1]}]", 1740 "\"google:suggestrelevance\":[9999, 1]}]",
1731 { { "a", true, true }, 1741 { { "a", true, true },
1732 { "a1.com", false, false }, 1742 { "a1.com", false, false },
1733 { "k a", false, false }, 1743 { "k a", false, false },
1734 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1744 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1735 std::string() }, 1745 std::string() },
1736 1746
1737 // Ensure that all 'verbatim' results are merged with their maximum score. 1747 // Ensure that all 'verbatim' results are merged with their maximum score.
1738 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1748 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1739 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1749 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1740 { { "a2", true, true }, 1750 { { "a2", true, true },
1741 { "a", true, true }, 1751 { "a", true, true },
1742 { "a1", true, true }, 1752 { "a1", true, false },
1743 { "k a", false, false }, 1753 { "k a", false, false },
1744 kEmptyMatch, kEmptyMatch }, 1754 kEmptyMatch, kEmptyMatch },
1745 "2" }, 1755 "2" },
1746 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1756 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1747 "{\"google:suggestrelevance\":[9998, 9997, 9999]," 1757 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
1748 "\"google:verbatimrelevance\":0}]", 1758 "\"google:verbatimrelevance\":0}]",
1749 { { "a2", true, true }, 1759 { { "a2", true, true },
1750 { "a", true, true }, 1760 { "a", true, true },
1751 { "a1", true, true }, 1761 { "a1", true, false },
1752 { "k a", false, false }, 1762 { "k a", false, false },
1753 kEmptyMatch, kEmptyMatch }, 1763 kEmptyMatch, kEmptyMatch },
1754 "2" }, 1764 "2" },
1755 1765
1756 // Ensure that verbatim is always generated without other suggestions. 1766 // Ensure that verbatim is always generated without other suggestions.
1757 // TODO(mpearson): Ensure the value of verbatimrelevance is respected 1767 // TODO(mpearson): Ensure the value of verbatimrelevance is respected
1758 // (except when suggested relevances are ignored). 1768 // (except when suggested relevances are ignored).
1759 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", 1769 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
1760 { { "k a", false, false }, 1770 { { "a", true, true },
1761 { "a", true, true }, 1771 { "k a", false, false },
1762 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1772 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1763 std::string() }, 1773 std::string() },
1764 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", 1774 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
1765 { { "a", true, true }, 1775 { { "a", true, true },
1766 { "k a", false, false }, 1776 { "k a", false, false },
1767 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1777 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1768 std::string() }, 1778 std::string() },
1769 1779
1770 // In reorder mode, navsuggestions will not need to be demoted (because 1780 // In reorder mode, navsuggestions will not need to be demoted (because
1771 // they are marked as not allowed to be default match and will be 1781 // they are marked as not allowed to be default match and will be
1772 // reordered as necessary). 1782 // reordered as necessary).
1773 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1783 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1774 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1784 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1775 "\"google:verbatimrelevance\":9990," 1785 "\"google:verbatimrelevance\":9990,"
1776 "\"google:suggestrelevance\":[9998, 9999]}]", 1786 "\"google:suggestrelevance\":[9998, 9999]}]",
1777 { { "a2.com", false, false }, 1787 { { "a", true, true },
1788 { "a2.com", false, false },
1778 { "a1.com", false, false }, 1789 { "a1.com", false, false },
1779 { "a", true, true },
1780 { "k a", false, false }, 1790 { "k a", false, false },
1781 kEmptyMatch, kEmptyMatch }, 1791 kEmptyMatch, kEmptyMatch },
1782 std::string() }, 1792 std::string() },
1783 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1793 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1784 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1794 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1785 "\"google:verbatimrelevance\":9990," 1795 "\"google:verbatimrelevance\":9990,"
1786 "\"google:suggestrelevance\":[9999, 9998]}]", 1796 "\"google:suggestrelevance\":[9999, 9998]}]",
1787 { { "a1.com", false, false }, 1797 { { "a", true, true },
1798 { "a1.com", false, false },
1788 { "a2.com", false, false }, 1799 { "a2.com", false, false },
1789 { "a", true, true },
1790 { "k a", false, false }, 1800 { "k a", false, false },
1791 kEmptyMatch, kEmptyMatch }, 1801 kEmptyMatch, kEmptyMatch },
1792 std::string() }, 1802 std::string() },
1793 { "[\"a\",[\"https://a/\"],[],[]," 1803 { "[\"a\",[\"https://a/\"],[],[],"
1794 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1804 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1795 "\"google:suggestrelevance\":[9999]}]", 1805 "\"google:suggestrelevance\":[9999]}]",
1796 { { "https://a", false, false }, 1806 { { "a", true, true },
1797 { "a", true, true }, 1807 { "https://a", false, false },
1798 { "k a", false, false }, 1808 { "k a", false, false },
1799 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1809 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1800 std::string() }, 1810 std::string() },
1801 // Check when navsuggest scores more than verbatim and there is query 1811 // Check when navsuggest scores more than verbatim and there is query
1802 // suggestion but it scores lower. 1812 // suggestion but it scores lower.
1803 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1813 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1804 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1814 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1805 "\"google:verbatimrelevance\":9990," 1815 "\"google:verbatimrelevance\":9990,"
1806 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", 1816 "\"google:suggestrelevance\":[9998, 9999, 1300]}]",
1807 { { "a2.com", false, false }, 1817 { { "a", true, true },
1818 { "a2.com", false, false },
1808 { "a1.com", false, false }, 1819 { "a1.com", false, false },
1809 { "a", true, true }, 1820 { "a3", true, false },
1810 { "a3", true, true },
1811 { "k a", false, false }, 1821 { "k a", false, false },
1812 kEmptyMatch }, 1822 kEmptyMatch },
1813 std::string() }, 1823 std::string() },
1814 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1824 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1815 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1825 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1816 "\"google:verbatimrelevance\":9990," 1826 "\"google:verbatimrelevance\":9990,"
1817 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", 1827 "\"google:suggestrelevance\":[9999, 9998, 1300]}]",
1818 { { "a1.com", false, false }, 1828 { { "a", true, true },
1829 { "a1.com", false, false },
1819 { "a2.com", false, false }, 1830 { "a2.com", false, false },
1820 { "a", true, true }, 1831 { "a3", true, false },
1821 { "a3", true, true },
1822 { "k a", false, false }, 1832 { "k a", false, false },
1823 kEmptyMatch }, 1833 kEmptyMatch },
1824 std::string() }, 1834 std::string() },
1825 // Check when navsuggest scores more than a query suggestion. There is 1835 // Check when navsuggest scores more than a query suggestion. There is
1826 // a verbatim but it scores lower. 1836 // a verbatim but it scores lower.
1827 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1837 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1828 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1838 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1829 "\"google:verbatimrelevance\":9990," 1839 "\"google:verbatimrelevance\":9990,"
1830 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 1840 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
1831 { { "a2.com", false, false }, 1841 { { "a3", true, true },
1842 { "a2.com", false, false },
1832 { "a1.com", false, false }, 1843 { "a1.com", false, false },
1833 { "a3", true, true },
1834 { "a", true, true }, 1844 { "a", true, true },
1835 { "k a", false, false }, 1845 { "k a", false, false },
1836 kEmptyMatch }, 1846 kEmptyMatch },
1837 "3" }, 1847 "3" },
1838 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1848 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1839 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1849 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1840 "\"google:verbatimrelevance\":9990," 1850 "\"google:verbatimrelevance\":9990,"
1841 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 1851 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
1842 { { "a1.com", false, false }, 1852 { { "a3", true, true },
1853 { "a1.com", false, false },
1843 { "a2.com", false, false }, 1854 { "a2.com", false, false },
1844 { "a3", true, true },
1845 { "a", true, true }, 1855 { "a", true, true },
1846 { "k a", false, false }, 1856 { "k a", false, false },
1847 kEmptyMatch }, 1857 kEmptyMatch },
1848 "3" }, 1858 "3" },
1849 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1859 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1850 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1860 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1851 "\"google:verbatimrelevance\":0," 1861 "\"google:verbatimrelevance\":0,"
1852 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 1862 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
1853 { { "a2.com", false, false }, 1863 { { "a3", true, true },
1864 { "a2.com", false, false },
1854 { "a1.com", false, false }, 1865 { "a1.com", false, false },
1855 { "a3", true, true },
1856 { "k a", false, false }, 1866 { "k a", false, false },
1857 kEmptyMatch, kEmptyMatch }, 1867 kEmptyMatch, kEmptyMatch },
1858 "3" }, 1868 "3" },
1859 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1869 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1860 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1870 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1861 "\"google:verbatimrelevance\":0," 1871 "\"google:verbatimrelevance\":0,"
1862 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 1872 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
1863 { { "a1.com", false, false }, 1873 { { "a3", true, true },
1874 { "a1.com", false, false },
1864 { "a2.com", false, false }, 1875 { "a2.com", false, false },
1865 { "a3", true, true },
1866 { "k a", false, false }, 1876 { "k a", false, false },
1867 kEmptyMatch, kEmptyMatch }, 1877 kEmptyMatch, kEmptyMatch },
1868 "3" }, 1878 "3" },
1869 // Check when there is neither verbatim nor a query suggestion that, 1879 // Check when there is neither verbatim nor a query suggestion that,
1870 // because we can't demote navsuggestions below a query suggestion, 1880 // because we can't demote navsuggestions below a query suggestion,
1871 // we restore the keyword verbatim score. 1881 // we restore the keyword verbatim score.
1872 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1882 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1873 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1883 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1874 "\"google:verbatimrelevance\":0," 1884 "\"google:verbatimrelevance\":0,"
1875 "\"google:suggestrelevance\":[9998, 9999]}]", 1885 "\"google:suggestrelevance\":[9998, 9999]}]",
1876 { { "a2.com", false, false }, 1886 { { "a", true, true },
1887 { "a2.com", false, false },
1877 { "a1.com", false, false }, 1888 { "a1.com", false, false },
1878 { "a", true, true },
1879 { "k a", false, false }, 1889 { "k a", false, false },
1880 kEmptyMatch, kEmptyMatch }, 1890 kEmptyMatch, kEmptyMatch },
1881 std::string() }, 1891 std::string() },
1882 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1892 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1883 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1893 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1884 "\"google:verbatimrelevance\":0," 1894 "\"google:verbatimrelevance\":0,"
1885 "\"google:suggestrelevance\":[9999, 9998]}]", 1895 "\"google:suggestrelevance\":[9999, 9998]}]",
1886 { { "a1.com", false, false }, 1896 { { "a", true, true },
1897 { "a1.com", false, false },
1887 { "a2.com", false, false }, 1898 { "a2.com", false, false },
1888 { "a", true, true },
1889 { "k a", false, false }, 1899 { "k a", false, false },
1890 kEmptyMatch, kEmptyMatch }, 1900 kEmptyMatch, kEmptyMatch },
1891 std::string() }, 1901 std::string() },
1892 // More checks that everything works when it's not necessary to demote. 1902 // More checks that everything works when it's not necessary to demote.
1893 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1903 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1894 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1904 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1895 "\"google:verbatimrelevance\":9990," 1905 "\"google:verbatimrelevance\":9990,"
1896 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", 1906 "\"google:suggestrelevance\":[9997, 9998, 9999]}]",
1897 { { "a3", true, true }, 1907 { { "a3", true, true },
1898 { "a2.com", false, false }, 1908 { "a2.com", false, false },
1899 { "a1.com", false, false }, 1909 { "a1.com", false, false },
1900 { "a", true, true }, 1910 { "a", true, true },
1901 { "k a", false, false }, 1911 { "k a", false, false },
1902 kEmptyMatch }, 1912 kEmptyMatch },
1903 "3" }, 1913 "3" },
1904 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1914 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1905 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1915 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1906 "\"google:verbatimrelevance\":9990," 1916 "\"google:verbatimrelevance\":9990,"
1907 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1917 "\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1908 { { "a3", true, true }, 1918 { { "a3", true, true },
1909 { "a1.com", false, false }, 1919 { "a1.com", false, false },
1910 { "a2.com", false, false }, 1920 { "a2.com", false, false },
1911 { "a", true, true }, 1921 { "a", true, true },
1912 { "k a", false, false }, 1922 { "k a", false, false },
1913 kEmptyMatch }, 1923 kEmptyMatch },
1914 "3" }, 1924 "3" },
1915 }; 1925 };
1916 1926
1917 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1927 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1918 QueryForInput(ASCIIToUTF16("k a"), false, true); 1928 // Send the query twice in order to have a synchronous pass after the first
1929 // response is received. This is necessary because SearchProvider doesn't
1930 // allow an asynchronous response to change the default match.
1931 for (size_t j = 0; j < 2; ++j) {
1932 QueryForInput(ASCIIToUTF16("k a"), false, true);
1919 1933
1920 // Set up a default fetcher with no results. 1934 // Set up a default fetcher with no results.
1921 net::TestURLFetcher* default_fetcher = 1935 net::TestURLFetcher* default_fetcher =
1922 test_factory_.GetFetcherByID( 1936 test_factory_.GetFetcherByID(
1923 SearchProvider::kDefaultProviderURLFetcherID); 1937 SearchProvider::kDefaultProviderURLFetcherID);
1924 ASSERT_TRUE(default_fetcher); 1938 ASSERT_TRUE(default_fetcher);
1925 default_fetcher->set_response_code(200); 1939 default_fetcher->set_response_code(200);
1926 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 1940 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
1927 default_fetcher = NULL; 1941 default_fetcher = NULL;
1928 1942
1929 // Set up a keyword fetcher with provided results. 1943 // Set up a keyword fetcher with provided results.
1930 net::TestURLFetcher* keyword_fetcher = 1944 net::TestURLFetcher* keyword_fetcher =
1931 test_factory_.GetFetcherByID( 1945 test_factory_.GetFetcherByID(
1932 SearchProvider::kKeywordProviderURLFetcherID); 1946 SearchProvider::kKeywordProviderURLFetcherID);
1933 ASSERT_TRUE(keyword_fetcher); 1947 ASSERT_TRUE(keyword_fetcher);
1934 keyword_fetcher->set_response_code(200); 1948 keyword_fetcher->set_response_code(200);
1935 keyword_fetcher->SetResponseString(cases[i].json); 1949 keyword_fetcher->SetResponseString(cases[i].json);
1936 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); 1950 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
1937 keyword_fetcher = NULL; 1951 keyword_fetcher = NULL;
1938 RunTillProviderDone(); 1952 RunTillProviderDone();
1953 }
1939 1954
1940 const std::string description = "for input with json=" + cases[i].json; 1955 SCOPED_TRACE("for input with json=" + cases[i].json);
1941 const ACMatches& matches = provider_->matches(); 1956 const ACMatches& matches = provider_->matches();
1942 ASSERT_FALSE(matches.empty()); 1957 ASSERT_FALSE(matches.empty());
1943 // Find the first match that's allowed to be the default match and check 1958 // Find the first match that's allowed to be the default match and check
1944 // its inline_autocompletion. 1959 // its inline_autocompletion.
1945 ACMatches::const_iterator it = FindDefaultMatch(matches); 1960 ACMatches::const_iterator it = FindDefaultMatch(matches);
1946 ASSERT_NE(matches.end(), it); 1961 ASSERT_NE(matches.end(), it);
1947 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 1962 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
1948 it->inline_autocompletion) << description; 1963 it->inline_autocompletion);
1949 1964
1950 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 1965 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
1951 size_t j = 0; 1966 size_t j = 0;
1952 // Ensure that the returned matches equal the expectations. 1967 // Ensure that the returned matches equal the expectations.
1953 for (; j < matches.size(); ++j) { 1968 for (; j < matches.size(); ++j) {
1954 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), 1969 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
1955 matches[j].contents) << description; 1970 matches[j].contents);
1956 EXPECT_EQ(cases[i].matches[j].from_keyword, 1971 EXPECT_EQ(cases[i].matches[j].from_keyword,
1957 matches[j].keyword == ASCIIToUTF16("k")) << description; 1972 matches[j].keyword == ASCIIToUTF16("k"));
1958 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, 1973 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
1959 matches[j].allowed_to_be_default_match) << description; 1974 matches[j].allowed_to_be_default_match);
1960 } 1975 }
1961 // Ensure that no expected matches are missing. 1976 // Ensure that no expected matches are missing.
1962 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 1977 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) {
1963 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << 1978 SCOPED_TRACE(" Case # " + base::IntToString(i));
1964 "Case # " << i << " " << description; 1979 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents);
1980 }
1965 } 1981 }
1966 } 1982 }
1967 1983
1984 TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) {
1985 // This test sends two separate queries, each receiving different JSON
1986 // replies, and checks that at each stage of processing (receiving first
1987 // asynchronous response, handling new keystroke synchronously / sending the
1988 // second request, and receiving the second asynchronous response) we have the
1989 // expected matches. In particular, receiving the second response shouldn't
1990 // cause an unexpected inline autcompletion.
1991 struct {
1992 const std::string first_json;
1993 const ExpectedMatch first_async_matches[4];
1994 const ExpectedMatch sync_matches[4];
1995 const std::string second_json;
1996 const ExpectedMatch second_async_matches[4];
1997 } cases[] = {
1998 // A simple test that verifies we don't inline autocomplete after the
1999 // first asynchronous response, but we do at the next keystroke if the
2000 // response's results were good enough. Furthermore, we should continue
2001 // inline autocompleting after the second asynchronous response if the new
2002 // top suggestion is the same as the old inline autocompleted suggestion.
2003 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2004 "{\"google:verbatimrelevance\":9000,"
2005 "\"google:suggestrelevance\":[9002, 9001]}]",
2006 { { "a", true }, { "ab1", false }, { "ab2", false },
2007 kEmptyExpectedMatch },
2008 { { "ab1", true }, { "ab2", true }, { "ab", true },
2009 kEmptyExpectedMatch },
2010 "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
2011 "{\"google:verbatimrelevance\":9000,"
2012 "\"google:suggestrelevance\":[9002, 9001]}]",
2013 { { "ab1", true }, { "ab2", false }, { "ab", true },
2014 kEmptyExpectedMatch } },
2015 // Ditto, just for a navigation suggestion.
2016 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
2017 "{\"google:verbatimrelevance\":9000,"
2018 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2019 "\"google:suggestrelevance\":[9002, 9001]}]",
2020 { { "a", true }, { "ab1.com", false }, { "ab2.com", false },
2021 kEmptyExpectedMatch },
2022 { { "ab1.com", true }, { "ab2.com", true }, { "ab", true },
2023 kEmptyExpectedMatch },
2024 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
2025 "{\"google:verbatimrelevance\":9000,"
2026 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2027 "\"google:suggestrelevance\":[9002, 9001]}]",
2028 { { "ab1.com", true }, { "ab2.com", false }, { "ab", true },
2029 kEmptyExpectedMatch } },
2030 // A more realistic test of the same situation.
2031 { "[\"a\",[\"abcdef\", \"abcdef.com\", \"abc\"],[],[],"
2032 "{\"google:verbatimrelevance\":900,"
2033 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\", \"QUERY\"],"
2034 "\"google:suggestrelevance\":[1250, 1200, 1000]}]",
2035 { { "a", true }, { "abcdef", false }, { "abcdef.com", false },
2036 { "abc", false } },
2037 { { "abcdef", true }, { "abcdef.com", true }, { "abc", true },
2038 { "ab", true } },
2039 "[\"ab\",[\"abcdef\", \"abcdef.com\", \"abc\"],[],[],"
2040 "{\"google:verbatimrelevance\":900,"
2041 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\", \"QUERY\"],"
2042 "\"google:suggestrelevance\":[1250, 1200, 1000]}]",
2043 { { "abcdef", true }, { "abcdef.com", false }, { "abc", false },
2044 { "ab", true } } },
2045
2046 // Without an original inline autcompletion, a new inline autcompletion
2047 // should be rejected.
2048 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2049 "{\"google:verbatimrelevance\":9000,"
2050 "\"google:suggestrelevance\":[8000, 7000]}]",
2051 { { "a", true }, { "ab1", false }, { "ab2", false },
2052 kEmptyExpectedMatch },
2053 { { "ab", true }, { "ab1", true }, { "ab2", true },
2054 kEmptyExpectedMatch },
2055 "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
2056 "{\"google:verbatimrelevance\":9000,"
2057 "\"google:suggestrelevance\":[9002, 9001]}]",
2058 { { "ab", true }, { "ab1", false }, { "ab2", false },
2059 kEmptyExpectedMatch } },
2060 // For the same test except with the queries scored in the opposite order
2061 // on the second JSON response, the queries should be ordered by the second
2062 // response's scores, not the first.
2063 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2064 "{\"google:verbatimrelevance\":9000,"
2065 "\"google:suggestrelevance\":[8000, 7000]}]",
2066 { { "a", true }, { "ab1", false }, { "ab2", false },
2067 kEmptyExpectedMatch },
2068 { { "ab", true }, { "ab1", true }, { "ab2", true },
2069 kEmptyExpectedMatch },
2070 "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
2071 "{\"google:verbatimrelevance\":9000,"
2072 "\"google:suggestrelevance\":[9001, 9002]}]",
2073 { { "ab", true }, { "ab2", false }, { "ab1", false },
2074 kEmptyExpectedMatch } },
2075 // Now, the same verifications but with the new inline autocompletion as a
2076 // navsuggestion. The new autocompletion should still be rejected.
2077 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
2078 "{\"google:verbatimrelevance\":9000,"
2079 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2080 "\"google:suggestrelevance\":[8000, 7000]}]",
2081 { { "a", true }, { "ab1.com", false }, { "ab2.com", false },
2082 kEmptyExpectedMatch },
2083 { { "ab", true }, { "ab1.com", true }, { "ab2.com", true },
2084 kEmptyExpectedMatch },
2085 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
2086 "{\"google:verbatimrelevance\":9000,"
2087 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2088 "\"google:suggestrelevance\":[9002, 9001]}]",
2089 { { "ab", true }, { "ab1.com", false }, { "ab2.com", false },
2090 kEmptyExpectedMatch } },
2091 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[],"
2092 "{\"google:verbatimrelevance\":9000,"
2093 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2094 "\"google:suggestrelevance\":[8000, 7000]}]",
2095 { { "a", true }, { "ab1.com", false }, { "ab2.com", false },
2096 kEmptyExpectedMatch },
2097 { { "ab", true }, { "ab1.com", true }, { "ab2.com", true },
2098 kEmptyExpectedMatch },
2099 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[],"
2100 "{\"google:verbatimrelevance\":9000,"
2101 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2102 "\"google:suggestrelevance\":[9001, 9002]}]",
2103 { { "ab", true }, { "ab2.com", false }, { "ab1.com", false },
2104 kEmptyExpectedMatch } },
2105
2106 // It's okay to abandon an inline autocompletion asynchronously.
2107 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2108 "{\"google:verbatimrelevance\":9000,"
2109 "\"google:suggestrelevance\":[9002, 9001]}]",
2110 { { "a", true }, { "ab1", false }, { "ab2", false },
2111 kEmptyExpectedMatch },
2112 { { "ab1", true }, { "ab2", true }, { "ab", true },
2113 kEmptyExpectedMatch },
2114 "[\"ab\",[\"ab1\", \"ab2\"],[],[],"
2115 "{\"google:verbatimrelevance\":9000,"
2116 "\"google:suggestrelevance\":[8000, 7000]}]",
2117 { { "ab", true }, { "ab1", true }, { "ab2", false },
2118 kEmptyExpectedMatch } },
2119
2120 // Note: it's possible that the suggest server returns a suggestion with
2121 // an inline autocompletion (that as usual we delay in allowing it to
2122 // be displayed as an inline autocompletion until the next keystroke),
2123 // then, in response to the next keystroke, the server returns a different
2124 // suggestion as an inline autocompletion. This is not likely to happen.
2125 // Regardless, if it does, one could imagine three different behaviors:
2126 // - keep the original inline autocompletion until the next keystroke
2127 // (i.e., don't abandon an inline autocompletion asynchronously), then
2128 // use the new suggestion
2129 // - abandon all inline autocompletions upon the server response, then use
2130 // the new suggestion on the next keystroke
2131 // - ignore the new inline autocompletion provided by the server, yet
2132 // possibly keep the original if it scores well in the most recent
2133 // response, then use the new suggestion on the next keystroke
2134 // All of these behaviors are reasonable. The main thing we want to
2135 // ensure is that the second asynchronous response shouldn't cause _a new_
msw 2014/08/28 19:21:40 nit: the emphasis on _a new_ seems odd, use asteri
Mark P 2014/08/28 20:18:52 Done.
2136 // inline autocompletion to be displayed. We test that here.
2137 // (BTW, it happens that the code does the third of those bullets.)
msw 2014/08/28 19:21:40 nit: this seems odd as a "BTW" afterthought; inste
Mark P 2014/08/28 20:18:52 Done.
2138 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2139 "{\"google:verbatimrelevance\":9000,"
2140 "\"google:suggestrelevance\":[9002, 9001]}]",
2141 { { "a", true }, { "ab1", false }, { "ab2", false },
2142 kEmptyExpectedMatch },
2143 { { "ab1", true }, { "ab2", true }, { "ab", true },
2144 kEmptyExpectedMatch },
2145 "[\"ab\",[\"ab1\", \"ab3\"],[],[],"
2146 "{\"google:verbatimrelevance\":9000,"
2147 "\"google:suggestrelevance\":[9002, 9900]}]",
2148 { { "ab1", true }, { "ab3", false }, { "ab", true },
2149 kEmptyExpectedMatch } },
2150 { "[\"a\",[\"ab1\", \"ab2\"],[],[],"
2151 "{\"google:verbatimrelevance\":9000,"
2152 "\"google:suggestrelevance\":[9002, 9001]}]",
2153 { { "a", true }, { "ab1", false }, { "ab2", false },
2154 kEmptyExpectedMatch },
2155 { { "ab1", true }, { "ab2", true }, { "ab", true },
2156 kEmptyExpectedMatch },
2157 "[\"ab\",[\"ab1\", \"ab3\"],[],[],"
2158 "{\"google:verbatimrelevance\":9000,"
2159 "\"google:suggestrelevance\":[8000, 9500]}]",
2160 { { "ab", true }, { "ab3", false }, { "ab1", true },
2161 kEmptyExpectedMatch } },
2162 };
2163
2164 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2165 // First, send the query "a" and receive the JSON response |first_json|.
2166 ClearAllResults();
2167 QueryForInputAndWaitForFetcherResponses(
2168 ASCIIToUTF16("a"), false, cases[i].first_json, "");
2169
2170 // Verify that the matches after the asynchronous results are as expected.
2171 std::string description = "first asynchronous response for input with "
2172 "first_json=" + cases[i].first_json;
2173 CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].first_async_matches),
2174 cases[i].first_async_matches, provider_->matches());
2175
2176 // Then, send the query "ab" and check the synchronous matches.
2177 description = "synchronous response after the first keystroke after input "
2178 "with first_json=" + cases[i].first_json;
2179 QueryForInput(ASCIIToUTF16("ab"), false, false);
2180 CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].sync_matches),
2181 cases[i].sync_matches, provider_->matches());
2182
2183 // Finally, get the provided JSON response, |second_json|, and verify the
2184 // matches after the second asynchronous response are as expected.
2185 description = "second asynchronous response after input with first_json=" +
2186 cases[i].first_json + " and second_json=" + cases[i].second_json;
2187 net::TestURLFetcher* second_fetcher =
2188 test_factory_.GetFetcherByID(
2189 SearchProvider::kDefaultProviderURLFetcherID);
2190 ASSERT_TRUE(second_fetcher);
2191 second_fetcher->set_response_code(200);
2192 second_fetcher->SetResponseString(cases[i].second_json);
2193 second_fetcher->delegate()->OnURLFetchComplete(second_fetcher);
2194 RunTillProviderDone();
2195 CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].second_async_matches),
2196 cases[i].second_async_matches, provider_->matches());
2197 }
2198 }
2199
1968 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { 2200 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
1969 // We hardcode the string "term1" below, so ensure that the search term that 2201 // We hardcode the string "term1" below, so ensure that the search term that
1970 // got added to history already is that string. 2202 // got added to history already is that string.
1971 ASSERT_EQ(ASCIIToUTF16("term1"), term1_); 2203 ASSERT_EQ(ASCIIToUTF16("term1"), term1_);
1972 base::string16 term = term1_.substr(0, term1_.length() - 1); 2204 base::string16 term = term1_.substr(0, term1_.length() - 1);
1973 2205
1974 AddSearchToHistory(default_t_url_, term + ASCIIToUTF16("2"), 2); 2206 AddSearchToHistory(default_t_url_, term + ASCIIToUTF16("2"), 2);
1975 profile_.BlockUntilHistoryProcessesPendingRequests(); 2207 profile_.BlockUntilHistoryProcessesPendingRequests();
1976 2208
1977 struct { 2209 struct {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 "\"google:suggestrelevance\":[1440, 1430, 1420, 1410, 1400, 1390]}]", 2250 "\"google:suggestrelevance\":[1440, 1430, 1420, 1410, 1400, 1390]}]",
2019 { "term", "a1", "a2", "a3", "a4", "a5" } }, 2251 { "term", "a1", "a2", "a3", "a4", "a5" } },
2020 { term, 2252 { term,
2021 "[\"term\",[\"a1\", \"a2\", \"a3\", \"a4\"],[],[]," 2253 "[\"term\",[\"a1\", \"a2\", \"a3\", \"a4\"],[],[],"
2022 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\", \"QUERY\", \"QUERY\"]," 2254 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\", \"QUERY\", \"QUERY\"],"
2023 "\"google:verbatimrelevance\":1450," 2255 "\"google:verbatimrelevance\":1450,"
2024 "\"google:suggestrelevance\":[1430, 1410, 1390, 1370]}]", 2256 "\"google:suggestrelevance\":[1430, 1410, 1390, 1370]}]",
2025 { "term", "a1", "a2", "term2", "a3", "a4" } } 2257 { "term", "a1", "a2", "term2", "a3", "a4" } }
2026 }; 2258 };
2027 2259
2028 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2260 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2029 QueryForInput(cases[i].input, false, false); 2261 QueryForInputAndWaitForFetcherResponses(
2030 net::TestURLFetcher* fetcher = 2262 cases[i].input, false, cases[i].json, "");
2031 test_factory_.GetFetcherByID(
2032 SearchProvider::kDefaultProviderURLFetcherID);
2033 ASSERT_TRUE(fetcher);
2034 fetcher->set_response_code(200);
2035 fetcher->SetResponseString(cases[i].json);
2036 fetcher->delegate()->OnURLFetchComplete(fetcher);
2037 RunTillProviderDone();
2038 2263
2039 const std::string description = "for input with json=" + cases[i].json; 2264 const std::string description = "for input with json=" + cases[i].json;
2040 const ACMatches& matches = provider_->matches(); 2265 const ACMatches& matches = provider_->matches();
2041 2266
2042 // Ensure no extra matches are present. 2267 // Ensure no extra matches are present.
2043 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 2268 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
2044 2269
2045 size_t j = 0; 2270 size_t j = 0;
2046 // Ensure that the returned matches equal the expectations. 2271 // Ensure that the returned matches equal the expectations.
2047 for (; j < matches.size(); ++j) 2272 for (; j < matches.size(); ++j)
(...skipping 13 matching lines...) Expand all
2061 AutocompleteMatch::Type match_type; 2286 AutocompleteMatch::Type match_type;
2062 bool allowed_to_be_default_match; 2287 bool allowed_to_be_default_match;
2063 }; 2288 };
2064 const DefaultFetcherUrlInputMatch kEmptyMatch = 2289 const DefaultFetcherUrlInputMatch kEmptyMatch =
2065 { kNotApplicable, AutocompleteMatchType::NUM_TYPES, false }; 2290 { kNotApplicable, AutocompleteMatchType::NUM_TYPES, false };
2066 struct { 2291 struct {
2067 const std::string input; 2292 const std::string input;
2068 const std::string json; 2293 const std::string json;
2069 const DefaultFetcherUrlInputMatch output[4]; 2294 const DefaultFetcherUrlInputMatch output[4];
2070 } cases[] = { 2295 } cases[] = {
2071 // Ensure NAVIGATION matches are allowed to be listed first for URL 2296 // Ensure NAVIGATION matches are allowed to be listed first for URL input.
2072 // input regardless of whether the match is inlineable. Note that 2297 // Non-inlineable matches should not be allowed to be the default match.
2073 // non-inlineable matches should not be allowed to be the default match. 2298 // Note that the top-scoring inlineable match is moved to the top
2299 // regardless of its score.
2074 { "a.com", "[\"a.com\",[\"http://b.com/\"],[],[]," 2300 { "a.com", "[\"a.com\",[\"http://b.com/\"],[],[],"
2075 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2301 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2076 "\"google:suggestrelevance\":[9999]}]", 2302 "\"google:suggestrelevance\":[9999]}]",
2077 { { "b.com", AutocompleteMatchType::NAVSUGGEST, false }, 2303 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2078 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2304 { "b.com", AutocompleteMatchType::NAVSUGGEST, false },
2079 kEmptyMatch, kEmptyMatch } }, 2305 kEmptyMatch, kEmptyMatch } },
2080 { "a.com", "[\"a.com\",[\"https://b.com\"],[],[]," 2306 { "a.com", "[\"a.com\",[\"https://b.com\"],[],[],"
2081 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2307 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2082 "\"google:suggestrelevance\":[9999]}]", 2308 "\"google:suggestrelevance\":[9999]}]",
2083 { { "https://b.com", AutocompleteMatchType::NAVSUGGEST, false }, 2309 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2084 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2310 { "https://b.com", AutocompleteMatchType::NAVSUGGEST, false },
2085 kEmptyMatch, kEmptyMatch } }, 2311 kEmptyMatch, kEmptyMatch } },
2086 { "a.com", "[\"a.com\",[\"http://a.com/a\"],[],[]," 2312 { "a.com", "[\"a.com\",[\"http://a.com/a\"],[],[],"
2087 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2313 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2088 "\"google:suggestrelevance\":[9999]}]", 2314 "\"google:suggestrelevance\":[9999]}]",
2089 { { "a.com/a", AutocompleteMatchType::NAVSUGGEST, true }, 2315 { { "a.com/a", AutocompleteMatchType::NAVSUGGEST, true },
2090 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2316 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2091 kEmptyMatch, kEmptyMatch } }, 2317 kEmptyMatch, kEmptyMatch } },
2092 { "a.com", "[\"a.com\",[\"https://a.com\"],[],[]," 2318 { "a.com", "[\"a.com\",[\"https://a.com\"],[],[],"
2093 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2319 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2094 "\"google:suggestrelevance\":[9999]}]", 2320 "\"google:suggestrelevance\":[9999]}]",
2095 { { "https://a.com", AutocompleteMatchType::NAVSUGGEST, true }, 2321 { { "https://a.com", AutocompleteMatchType::NAVSUGGEST, true },
2096 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2322 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2097 kEmptyMatch, kEmptyMatch } }, 2323 kEmptyMatch, kEmptyMatch } },
2098 2324
2099 // Ensure topmost inlineable SUGGEST matches are NOT allowed for URL 2325 // Ensure topmost inlineable SUGGEST matches are NOT allowed for URL
2100 // input. SearchProvider disregards search and verbatim suggested 2326 // input. SearchProvider disregards search and verbatim suggested
2101 // relevances. 2327 // relevances.
2102 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," 2328 { "a.com", "[\"a.com\",[\"a.com info\"],[],[],"
2103 "{\"google:suggestrelevance\":[9999]}]", 2329 "{\"google:suggestrelevance\":[9999]}]",
2104 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2330 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2105 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, 2331 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2106 kEmptyMatch, kEmptyMatch } }, 2332 kEmptyMatch, kEmptyMatch } },
2107 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," 2333 { "a.com", "[\"a.com\",[\"a.com info\"],[],[],"
2108 "{\"google:suggestrelevance\":[9999]}]", 2334 "{\"google:suggestrelevance\":[9999]}]",
2109 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2335 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2110 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, 2336 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2111 kEmptyMatch, kEmptyMatch } }, 2337 kEmptyMatch, kEmptyMatch } },
2112 2338
2113 // Ensure the fallback mechanism allows inlinable NAVIGATION matches. 2339 // Ensure the fallback mechanism allows inlineable NAVIGATION matches.
2114 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[]," 2340 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[],"
2115 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 2341 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
2116 "\"google:suggestrelevance\":[9999, 9998]}]", 2342 "\"google:suggestrelevance\":[9999, 9998]}]",
2117 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, 2343 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true },
2118 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2344 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2119 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, 2345 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2120 kEmptyMatch } }, 2346 kEmptyMatch } },
2121 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[]," 2347 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[],"
2122 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 2348 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
2123 "\"google:suggestrelevance\":[9998, 9997]," 2349 "\"google:suggestrelevance\":[9998, 9997],"
2124 "\"google:verbatimrelevance\":9999}]", 2350 "\"google:verbatimrelevance\":9999}]",
2125 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, 2351 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true },
2126 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2352 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2127 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, 2353 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2128 kEmptyMatch } }, 2354 kEmptyMatch } },
2129 2355
2130 // Ensure topmost non-inlineable SUGGEST matches are allowed for URL 2356 // Ensure non-inlineable SUGGEST matches are allowed for URL input
2131 // input assuming the top inlineable match is not a query (i.e., is a 2357 // assuming the best inlineable match is not a query (i.e., is a
2132 // NAVSUGGEST). 2358 // NAVSUGGEST). The best inlineable match will be at the top of the
2359 // list regardless of its score.
2133 { "a.com", "[\"a.com\",[\"info\"],[],[]," 2360 { "a.com", "[\"a.com\",[\"info\"],[],[],"
2134 "{\"google:suggestrelevance\":[9999]}]", 2361 "{\"google:suggestrelevance\":[9999]}]",
2135 { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false }, 2362 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2136 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2363 { "info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2137 kEmptyMatch, kEmptyMatch } }, 2364 kEmptyMatch, kEmptyMatch } },
2138 { "a.com", "[\"a.com\",[\"info\"],[],[]," 2365 { "a.com", "[\"a.com\",[\"info\"],[],[],"
2139 "{\"google:suggestrelevance\":[9999]}]", 2366 "{\"google:suggestrelevance\":[9999]}]",
2140 { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false }, 2367 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
2141 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, 2368 { "info", AutocompleteMatchType::SEARCH_SUGGEST, false },
2142 kEmptyMatch, kEmptyMatch } }, 2369 kEmptyMatch, kEmptyMatch } },
2143 }; 2370 };
2144 2371
2145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2372 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2146 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); 2373 // Send the query twice in order to have a synchronous pass after the first
2147 net::TestURLFetcher* fetcher = 2374 // response is received. This is necessary because SearchProvider doesn't
2148 test_factory_.GetFetcherByID( 2375 // allow an asynchronous response to change the default match.
2149 SearchProvider::kDefaultProviderURLFetcherID); 2376 for (size_t j = 0; j < 2; ++j) {
2150 ASSERT_TRUE(fetcher); 2377 QueryForInputAndWaitForFetcherResponses(
2151 fetcher->set_response_code(200); 2378 ASCIIToUTF16(cases[i].input), false, cases[i].json, "");
2152 fetcher->SetResponseString(cases[i].json); 2379 }
2153 fetcher->delegate()->OnURLFetchComplete(fetcher);
2154 RunTillProviderDone();
2155 2380
2381 SCOPED_TRACE("input=" + cases[i].input + " json=" + cases[i].json);
2156 size_t j = 0; 2382 size_t j = 0;
2157 const ACMatches& matches = provider_->matches(); 2383 const ACMatches& matches = provider_->matches();
2158 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output)); 2384 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output));
2159 // Ensure that the returned matches equal the expectations. 2385 // Ensure that the returned matches equal the expectations.
2160 for (; j < matches.size(); ++j) { 2386 for (; j < matches.size(); ++j) {
2161 EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents), 2387 EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents),
2162 matches[j].contents); 2388 matches[j].contents);
2163 EXPECT_EQ(cases[i].output[j].match_type, matches[j].type); 2389 EXPECT_EQ(cases[i].output[j].match_type, matches[j].type);
2164 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match, 2390 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match,
2165 matches[j].allowed_to_be_default_match); 2391 matches[j].allowed_to_be_default_match);
2166 } 2392 }
2167 // Ensure that no expected matches are missing. 2393 // Ensure that no expected matches are missing.
2168 for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) { 2394 for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) {
2169 EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents); 2395 EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents);
2170 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES, 2396 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES,
2171 cases[i].output[j].match_type); 2397 cases[i].output[j].match_type);
2172 EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match); 2398 EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match);
2173 } 2399 }
2174 } 2400 }
2175 } 2401 }
2176 2402
2177 // A basic test that verifies the field trial triggered parsing logic. 2403 // A basic test that verifies the field trial triggered parsing logic.
2178 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) { 2404 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) {
2179 QueryForInput(ASCIIToUTF16("foo"), false, false); 2405 QueryForInputAndWaitForFetcherResponses(
2180 2406 ASCIIToUTF16("foo"), false,
2181 // Make sure the default providers suggest service was queried.
2182 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
2183 SearchProvider::kDefaultProviderURLFetcherID);
2184 ASSERT_TRUE(fetcher);
2185
2186 // Tell the SearchProvider the suggest query is done.
2187 fetcher->set_response_code(200);
2188 fetcher->SetResponseString(
2189 "[\"foo\",[\"foo bar\"],[\"\"],[]," 2407 "[\"foo\",[\"foo bar\"],[\"\"],[],"
2190 "{\"google:suggesttype\":[\"QUERY\"]," 2408 "{\"google:suggesttype\":[\"QUERY\"],"
2191 "\"google:fieldtrialtriggered\":true}]"); 2409 "\"google:fieldtrialtriggered\":true}]",
2192 fetcher->delegate()->OnURLFetchComplete(fetcher); 2410 "");
2193 fetcher = NULL;
2194
2195 // Run till the history results complete.
2196 RunTillProviderDone();
2197 2411
2198 { 2412 {
2199 // Check for the match and field trial triggered bits. 2413 // Check for the match and field trial triggered bits.
2200 AutocompleteMatch match; 2414 AutocompleteMatch match;
2201 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("foo bar"), &match)); 2415 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("foo bar"), &match));
2202 ProvidersInfo providers_info; 2416 ProvidersInfo providers_info;
2203 provider_->AddProviderInfo(&providers_info); 2417 provider_->AddProviderInfo(&providers_info);
2204 ASSERT_EQ(1U, providers_info.size()); 2418 ASSERT_EQ(1U, providers_info.size());
2205 EXPECT_EQ(1, providers_info[0].field_trial_triggered_size()); 2419 EXPECT_EQ(1, providers_info[0].field_trial_triggered_size());
2206 EXPECT_EQ(1, providers_info[0].field_trial_triggered_in_session_size()); 2420 EXPECT_EQ(1, providers_info[0].field_trial_triggered_in_session_size());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 { "?http://www.ab", "http://www.abc.com", 2586 { "?http://www.ab", "http://www.abc.com",
2373 "?http://www.abc.com", "c.com", true, false }, 2587 "?http://www.abc.com", "c.com", true, false },
2374 { "?www.ab", "http://www.abc.com", 2588 { "?www.ab", "http://www.abc.com",
2375 "?www.abc.com", "c.com", true, false }, 2589 "?www.abc.com", "c.com", true, false },
2376 { "?ab", "http://www.abc.com", 2590 { "?ab", "http://www.abc.com",
2377 "?www.abc.com", "c.com", true, false }, 2591 "?www.abc.com", "c.com", true, false },
2378 { "?abc.com", "http://www.abc.com", 2592 { "?abc.com", "http://www.abc.com",
2379 "?www.abc.com", "", true, true }, 2593 "?www.abc.com", "", true, true },
2380 }; 2594 };
2381 2595
2382 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2596 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2383 // First test regular mode. 2597 // First test regular mode.
2384 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); 2598 QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
2385 AutocompleteMatch match( 2599 SearchSuggestionParser::NavigationResult result(
2386 provider_->NavigationToMatch(SearchSuggestionParser::NavigationResult( 2600 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
2387 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), 2601 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
2388 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), 2602 false, 0, false, ASCIIToUTF16(cases[i].input), std::string());
2389 false, 0, false, ASCIIToUTF16(cases[i].input), std::string()))); 2603 result.set_received_after_last_keystroke(false);
2604 AutocompleteMatch match(provider_->NavigationToMatch(result));
2390 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 2605 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
2391 match.inline_autocompletion); 2606 match.inline_autocompletion);
2392 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); 2607 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit);
2393 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, 2608 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode,
2394 match.allowed_to_be_default_match); 2609 match.allowed_to_be_default_match);
2395 2610
2396 // Then test prevent-inline-autocomplete mode. 2611 // Then test prevent-inline-autocomplete mode.
2397 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); 2612 QueryForInput(ASCIIToUTF16(cases[i].input), true, false);
2613 SearchSuggestionParser::NavigationResult result_prevent_inline(
2614 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
2615 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
2616 false, 0, false, ASCIIToUTF16(cases[i].input), std::string());
2617 result_prevent_inline.set_received_after_last_keystroke(false);
2398 AutocompleteMatch match_prevent_inline( 2618 AutocompleteMatch match_prevent_inline(
2399 provider_->NavigationToMatch(SearchSuggestionParser::NavigationResult( 2619 provider_->NavigationToMatch(result_prevent_inline));
2400 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
2401 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
2402 false, 0, false, ASCIIToUTF16(cases[i].input), std::string())));
2403 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 2620 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
2404 match_prevent_inline.inline_autocompletion); 2621 match_prevent_inline.inline_autocompletion);
2405 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), 2622 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit),
2406 match_prevent_inline.fill_into_edit); 2623 match_prevent_inline.fill_into_edit);
2407 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, 2624 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode,
2408 match_prevent_inline.allowed_to_be_default_match); 2625 match_prevent_inline.allowed_to_be_default_match);
2409 } 2626 }
2410 } 2627 }
2411 2628
2412 // Verifies that "http://" is not trimmed for input that is a leading substring. 2629 // Verifies that "http://" is not trimmed for input that is a leading substring.
2413 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { 2630 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) {
2414 const base::string16 input(ASCIIToUTF16("ht")); 2631 const base::string16 input(ASCIIToUTF16("ht"));
2415 const base::string16 url(ASCIIToUTF16("http://a.com")); 2632 const base::string16 url(ASCIIToUTF16("http://a.com"));
2416 const SearchSuggestionParser::NavigationResult result( 2633 SearchSuggestionParser::NavigationResult result(
2417 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), 2634 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url),
2418 AutocompleteMatchType::NAVSUGGEST, 2635 AutocompleteMatchType::NAVSUGGEST,
2419 base::string16(), std::string(), false, 0, false, input, std::string()); 2636 base::string16(), std::string(), false, 0, false, input, std::string());
2637 result.set_received_after_last_keystroke(false);
2420 2638
2421 // Check the offset and strings when inline autocompletion is allowed. 2639 // Check the offset and strings when inline autocompletion is allowed.
2422 QueryForInput(input, false, false); 2640 QueryForInput(input, false, false);
2423 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); 2641 AutocompleteMatch match_inline(provider_->NavigationToMatch(result));
2424 EXPECT_EQ(url, match_inline.fill_into_edit); 2642 EXPECT_EQ(url, match_inline.fill_into_edit);
2425 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); 2643 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion);
2426 EXPECT_TRUE(match_inline.allowed_to_be_default_match); 2644 EXPECT_TRUE(match_inline.allowed_to_be_default_match);
2427 EXPECT_EQ(url, match_inline.contents); 2645 EXPECT_EQ(url, match_inline.contents);
2428 2646
2429 // Check the same strings when inline autocompletion is prevented. 2647 // Check the same strings when inline autocompletion is prevented.
2430 QueryForInput(input, true, false); 2648 QueryForInput(input, true, false);
2431 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); 2649 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result));
2432 EXPECT_EQ(url, match_prevent.fill_into_edit); 2650 EXPECT_EQ(url, match_prevent.fill_into_edit);
2433 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); 2651 EXPECT_FALSE(match_prevent.allowed_to_be_default_match);
2434 EXPECT_EQ(url, match_prevent.contents); 2652 EXPECT_EQ(url, match_prevent.contents);
2435 } 2653 }
2436 2654
2437 // Verifies that input "w" marks a more significant domain label than "www.". 2655 // Verifies that input "w" marks a more significant domain label than "www.".
2438 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { 2656 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) {
2439 QueryForInput(ASCIIToUTF16("w"), false, false); 2657 QueryForInput(ASCIIToUTF16("w"), false, false);
2440 AutocompleteMatch match( 2658 SearchSuggestionParser::NavigationResult result(
2441 provider_->NavigationToMatch(SearchSuggestionParser::NavigationResult( 2659 ChromeAutocompleteSchemeClassifier(&profile_),
2442 ChromeAutocompleteSchemeClassifier(&profile_), 2660 GURL("http://www.wow.com"), AutocompleteMatchType::NAVSUGGEST,
2443 GURL("http://www.wow.com"), 2661 base::string16(), std::string(), false, 0, false, ASCIIToUTF16("w"),
2444 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), 2662 std::string());
2445 false, 0, false, ASCIIToUTF16("w"), std::string()))); 2663 result.set_received_after_last_keystroke(false);
2664 AutocompleteMatch match(provider_->NavigationToMatch(result));
2446 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); 2665 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion);
2447 EXPECT_TRUE(match.allowed_to_be_default_match); 2666 EXPECT_TRUE(match.allowed_to_be_default_match);
2448 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); 2667 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit);
2449 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); 2668 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents);
2450 2669
2451 // Ensure that the match for input "w" is marked on "wow" and not "www". 2670 // Ensure that the match for input "w" is marked on "wow" and not "www".
2452 ASSERT_EQ(3U, match.contents_class.size()); 2671 ASSERT_EQ(3U, match.contents_class.size());
2453 EXPECT_EQ(0U, match.contents_class[0].offset); 2672 EXPECT_EQ(0U, match.contents_class[0].offset);
2454 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 2673 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
2455 match.contents_class[0].style); 2674 match.contents_class[0].style);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 "\"google:suggesttype\":[\"QUERY\",\"ENTITY\"]}]", 2722 "\"google:suggesttype\":[\"QUERY\",\"ENTITY\"]}]",
2504 { { "x", "", "", "x", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, 2723 { { "x", "", "", "x", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED },
2505 { "xy", "", "", "xy", AutocompleteMatchType::SEARCH_SUGGEST }, 2724 { "xy", "", "", "xy", AutocompleteMatchType::SEARCH_SUGGEST },
2506 { "xy", "A", "p=v", "xy", 2725 { "xy", "A", "p=v", "xy",
2507 AutocompleteMatchType::SEARCH_SUGGEST_ENTITY }, 2726 AutocompleteMatchType::SEARCH_SUGGEST_ENTITY },
2508 kEmptyMatch, 2727 kEmptyMatch,
2509 kEmptyMatch 2728 kEmptyMatch
2510 }, 2729 },
2511 }, 2730 },
2512 }; 2731 };
2513 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2732 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2514 QueryForInput(ASCIIToUTF16(cases[i].input_text), false, false); 2733 QueryForInputAndWaitForFetcherResponses(
2515 2734 ASCIIToUTF16(cases[i].input_text), false, cases[i].response_json, "");
2516 // Set up a default fetcher with provided results.
2517 net::TestURLFetcher* fetcher =
2518 test_factory_.GetFetcherByID(
2519 SearchProvider::kDefaultProviderURLFetcherID);
2520 ASSERT_TRUE(fetcher);
2521 fetcher->set_response_code(200);
2522 fetcher->SetResponseString(cases[i].response_json);
2523 fetcher->delegate()->OnURLFetchComplete(fetcher);
2524
2525 RunTillProviderDone();
2526 2735
2527 const ACMatches& matches = provider_->matches(); 2736 const ACMatches& matches = provider_->matches();
2528 ASSERT_FALSE(matches.empty()); 2737 ASSERT_FALSE(matches.empty());
2529 2738
2530 SCOPED_TRACE("for input with json = " + cases[i].response_json); 2739 SCOPED_TRACE("for input with json = " + cases[i].response_json);
2531 2740
2532 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 2741 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
2533 size_t j = 0; 2742 size_t j = 0;
2534 // Ensure that the returned matches equal the expectations. 2743 // Ensure that the returned matches equal the expectations.
2535 for (; j < matches.size(); ++j) { 2744 for (; j < matches.size(); ++j) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", 2847 "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
2639 { { "a", false, AutocompleteMatchType::SEARCH_OTHER_ENGINE, true}, 2848 { { "a", false, AutocompleteMatchType::SEARCH_OTHER_ENGINE, true},
2640 { "k a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false }, 2849 { "k a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false },
2641 { "ab", false, AutocompleteMatchType::SEARCH_SUGGEST, false }, 2850 { "ab", false, AutocompleteMatchType::SEARCH_SUGGEST, false },
2642 { "c", false, AutocompleteMatchType::SEARCH_SUGGEST, true }, 2851 { "c", false, AutocompleteMatchType::SEARCH_SUGGEST, true },
2643 { "b", false, AutocompleteMatchType::SEARCH_SUGGEST, true } 2852 { "b", false, AutocompleteMatchType::SEARCH_SUGGEST, true }
2644 }, 2853 },
2645 } 2854 }
2646 }; 2855 };
2647 2856
2648 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2857 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2649 QueryForInput(ASCIIToUTF16(cases[i].input_text), false, 2858 QueryForInputAndWaitForFetcherResponses(
2650 cases[i].prefer_keyword_provider_results); 2859 ASCIIToUTF16(cases[i].input_text),
2651 2860 cases[i].prefer_keyword_provider_results,
2652 // Set up a default fetcher with provided results. 2861 cases[i].default_provider_response_json,
2653 net::TestURLFetcher* fetcher = 2862 cases[i].prefer_keyword_provider_results ?
2654 test_factory_.GetFetcherByID( 2863 cases[i].keyword_provider_response_json : "");
2655 SearchProvider::kDefaultProviderURLFetcherID);
2656 ASSERT_TRUE(fetcher);
2657 fetcher->set_response_code(200);
2658 fetcher->SetResponseString(cases[i].default_provider_response_json);
2659 fetcher->delegate()->OnURLFetchComplete(fetcher);
2660
2661 if (cases[i].prefer_keyword_provider_results) {
2662 // Set up a keyword fetcher with provided results.
2663 net::TestURLFetcher* keyword_fetcher =
2664 test_factory_.GetFetcherByID(
2665 SearchProvider::kKeywordProviderURLFetcherID);
2666 ASSERT_TRUE(keyword_fetcher);
2667 keyword_fetcher->set_response_code(200);
2668 keyword_fetcher->SetResponseString(
2669 cases[i].keyword_provider_response_json);
2670 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
2671 keyword_fetcher = NULL;
2672 }
2673
2674 RunTillProviderDone();
2675 2864
2676 const std::string description = 2865 const std::string description =
2677 "for input with json =" + cases[i].default_provider_response_json; 2866 "for input with json =" + cases[i].default_provider_response_json;
2678 const ACMatches& matches = provider_->matches(); 2867 const ACMatches& matches = provider_->matches();
2679 // The top match must inline and score as highly as calculated verbatim. 2868 // The top match must inline and score as highly as calculated verbatim.
2680 ASSERT_FALSE(matches.empty()); 2869 ASSERT_FALSE(matches.empty());
2681 EXPECT_GE(matches[0].relevance, 1300); 2870 EXPECT_GE(matches[0].relevance, 1300);
2682 2871
2683 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 2872 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
2684 // Ensure that the returned matches equal the expectations. 2873 // Ensure that the returned matches equal the expectations.
2685 for (size_t j = 0; j < matches.size(); ++j) { 2874 for (size_t j = 0; j < matches.size(); ++j) {
2686 SCOPED_TRACE(description); 2875 SCOPED_TRACE(description);
2687 EXPECT_EQ(cases[i].matches[j].contents, 2876 EXPECT_EQ(cases[i].matches[j].contents,
2688 base::UTF16ToUTF8(matches[j].contents)); 2877 base::UTF16ToUTF8(matches[j].contents));
2689 EXPECT_EQ(cases[i].matches[j].allowed_to_be_prefetched, 2878 EXPECT_EQ(cases[i].matches[j].allowed_to_be_prefetched,
2690 SearchProvider::ShouldPrefetch(matches[j])); 2879 SearchProvider::ShouldPrefetch(matches[j]));
2691 EXPECT_EQ(cases[i].matches[j].type, matches[j].type); 2880 EXPECT_EQ(cases[i].matches[j].type, matches[j].type);
2692 EXPECT_EQ(cases[i].matches[j].from_keyword, 2881 EXPECT_EQ(cases[i].matches[j].from_keyword,
2693 matches[j].keyword == ASCIIToUTF16("k")); 2882 matches[j].keyword == ASCIIToUTF16("k"));
2694 } 2883 }
2695 } 2884 }
2696 } 2885 }
2697 2886
2698 TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_InvalidResponse) { 2887 TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_InvalidResponse) {
2699 ClearAllResults(); 2888 ClearAllResults();
2700 2889
2701 std::string input_str("abc"); 2890 std::string input_str("abc");
2702 QueryForInput(ASCIIToUTF16(input_str), false, false); 2891 QueryForInputAndWaitForFetcherResponses(
2703 2892 ASCIIToUTF16(input_str), false, "this is a bad non-json response", "");
2704 // Set up a default fetcher with provided results.
2705 net::TestURLFetcher* fetcher =
2706 test_factory_.GetFetcherByID(
2707 SearchProvider::kDefaultProviderURLFetcherID);
2708 ASSERT_TRUE(fetcher);
2709 fetcher->set_response_code(200);
2710 fetcher->SetResponseString("this is a bad non-json response");
2711 fetcher->delegate()->OnURLFetchComplete(fetcher);
2712
2713 RunTillProviderDone();
2714 2893
2715 const ACMatches& matches = provider_->matches(); 2894 const ACMatches& matches = provider_->matches();
2716 2895
2717 // Should have exactly one "search what you typed" match 2896 // Should have exactly one "search what you typed" match
2718 ASSERT_TRUE(matches.size() == 1); 2897 ASSERT_TRUE(matches.size() == 1);
2719 EXPECT_EQ(input_str, base::UTF16ToUTF8(matches[0].contents)); 2898 EXPECT_EQ(input_str, base::UTF16ToUTF8(matches[0].contents));
2720 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 2899 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
2721 matches[0].type); 2900 matches[0].type);
2722 } 2901 }
2723 2902
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2765 "{\"google:suggesttype\":[\"QUERY\",\"QUERY\"]," 2944 "{\"google:suggesttype\":[\"QUERY\",\"QUERY\"],"
2766 "\"google:suggestrelevance\":[1, 2]}]", 2945 "\"google:suggestrelevance\":[1, 2]}]",
2767 { { "a", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, 2946 { { "a", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED },
2768 { "c", AutocompleteMatchType::SEARCH_SUGGEST }, 2947 { "c", AutocompleteMatchType::SEARCH_SUGGEST },
2769 { "b", AutocompleteMatchType::SEARCH_SUGGEST }, 2948 { "b", AutocompleteMatchType::SEARCH_SUGGEST },
2770 kEmptyMatch, 2949 kEmptyMatch,
2771 }, 2950 },
2772 }, 2951 },
2773 }; 2952 };
2774 2953
2775 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2954 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2776 ClearAllResults(); 2955 ClearAllResults();
2777 QueryForInput(ASCIIToUTF16(cases[i].input_text), false, false); 2956 QueryForInputAndWaitForFetcherResponses(
2778 2957 ASCIIToUTF16(cases[i].input_text), false,
2779 // Set up a default fetcher with provided results. 2958 cases[i].default_provider_response_json, "");
2780 net::TestURLFetcher* fetcher =
2781 test_factory_.GetFetcherByID(
2782 SearchProvider::kDefaultProviderURLFetcherID);
2783 ASSERT_TRUE(fetcher);
2784 fetcher->set_response_code(200);
2785 fetcher->SetResponseString(cases[i].default_provider_response_json);
2786 fetcher->delegate()->OnURLFetchComplete(fetcher);
2787
2788 RunTillProviderDone();
2789 2959
2790 const ACMatches& matches = provider_->matches(); 2960 const ACMatches& matches = provider_->matches();
2791 // The top match must inline and score as highly as calculated verbatim. 2961 // The top match must inline and score as highly as calculated verbatim.
2792 ASSERT_FALSE(matches.empty()); 2962 ASSERT_FALSE(matches.empty());
2793 EXPECT_GE(matches[0].relevance, 1300); 2963 EXPECT_GE(matches[0].relevance, 1300);
2794 2964
2795 SCOPED_TRACE("for case: " + base::IntToString(i)); 2965 SCOPED_TRACE("for case: " + base::IntToString(i));
2796 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 2966 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
2797 size_t j = 0; 2967 size_t j = 0;
2798 // Ensure that the returned matches equal the expectations. 2968 // Ensure that the returned matches equal the expectations.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2881 { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, 3051 { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED },
2882 { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST }, 3052 { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST },
2883 { "ab", "", AutocompleteMatchType::SEARCH_SUGGEST }, 3053 { "ab", "", AutocompleteMatchType::SEARCH_SUGGEST },
2884 { "www.amazon.com", "", 3054 { "www.amazon.com", "",
2885 AutocompleteMatchType::NAVSUGGEST_PERSONALIZED }, 3055 AutocompleteMatchType::NAVSUGGEST_PERSONALIZED },
2886 kEmptyMatch, 3056 kEmptyMatch,
2887 }, 3057 },
2888 }, 3058 },
2889 }; 3059 };
2890 3060
2891 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 3061 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2892 QueryForInput(ASCIIToUTF16(cases[i].input_text), false, false); 3062 QueryForInputAndWaitForFetcherResponses(
2893 3063 ASCIIToUTF16(cases[i].input_text), false, cases[i].response_json,
2894 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 3064 "");
2895 SearchProvider::kDefaultProviderURLFetcherID);
2896 ASSERT_TRUE(fetcher);
2897 fetcher->set_response_code(200);
2898 fetcher->SetResponseString(cases[i].response_json);
2899 fetcher->delegate()->OnURLFetchComplete(fetcher);
2900
2901 RunTillProviderDone();
2902 3065
2903 const ACMatches& matches = provider_->matches(); 3066 const ACMatches& matches = provider_->matches();
2904 ASSERT_FALSE(matches.empty()); 3067 ASSERT_FALSE(matches.empty());
2905 3068
2906 SCOPED_TRACE("for input with json = " + cases[i].response_json); 3069 SCOPED_TRACE("for input with json = " + cases[i].response_json);
2907 3070
2908 for (size_t j = 0; j < matches.size(); ++j) { 3071 for (size_t j = 0; j < matches.size(); ++j) {
2909 const Match& match = cases[i].matches[j]; 3072 const Match& match = cases[i].matches[j];
2910 SCOPED_TRACE(" and match index: " + base::IntToString(j)); 3073 SCOPED_TRACE(" and match index: " + base::IntToString(j));
2911 EXPECT_EQ(match.contents, base::UTF16ToUTF8(matches[j].contents)); 3074 EXPECT_EQ(match.contents, base::UTF16ToUTF8(matches[j].contents));
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
3126 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("flash games"), &games)); 3289 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("flash games"), &games));
3127 } 3290 }
3128 3291
3129 // Verifies that duplicates are preserved in AddMatchToMap(). 3292 // Verifies that duplicates are preserved in AddMatchToMap().
3130 TEST_F(SearchProviderTest, CheckDuplicateMatchesSaved) { 3293 TEST_F(SearchProviderTest, CheckDuplicateMatchesSaved) {
3131 AddSearchToHistory(default_t_url_, ASCIIToUTF16("a"), 1); 3294 AddSearchToHistory(default_t_url_, ASCIIToUTF16("a"), 1);
3132 AddSearchToHistory(default_t_url_, ASCIIToUTF16("alpha"), 1); 3295 AddSearchToHistory(default_t_url_, ASCIIToUTF16("alpha"), 1);
3133 AddSearchToHistory(default_t_url_, ASCIIToUTF16("avid"), 1); 3296 AddSearchToHistory(default_t_url_, ASCIIToUTF16("avid"), 1);
3134 3297
3135 profile_.BlockUntilHistoryProcessesPendingRequests(); 3298 profile_.BlockUntilHistoryProcessesPendingRequests();
3136 QueryForInput(ASCIIToUTF16("a"), false, false); 3299 QueryForInputAndWaitForFetcherResponses(
3137 3300 ASCIIToUTF16("a"), false,
3138 // Make sure the default provider's suggest service was queried.
3139 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
3140 SearchProvider::kDefaultProviderURLFetcherID);
3141 ASSERT_TRUE(fetcher);
3142
3143 // Tell the SearchProvider the suggest query is done.
3144 fetcher->set_response_code(200);
3145 fetcher->SetResponseString(
3146 "[\"a\",[\"a\", \"alpha\", \"avid\", \"apricot\"],[],[]," 3301 "[\"a\",[\"a\", \"alpha\", \"avid\", \"apricot\"],[],[],"
3147 "{\"google:suggestrelevance\":[1450, 1200, 1150, 1100]," 3302 "{\"google:suggestrelevance\":[1450, 1200, 1150, 1100],"
3148 "\"google:verbatimrelevance\":1350}]"); 3303 "\"google:verbatimrelevance\":1350}]",
3149 fetcher->delegate()->OnURLFetchComplete(fetcher); 3304 "");
3150 fetcher = NULL;
3151
3152 // Run till the history results complete.
3153 RunTillProviderDone();
3154 3305
3155 AutocompleteMatch verbatim, match_alpha, match_apricot, match_avid; 3306 AutocompleteMatch verbatim, match_alpha, match_apricot, match_avid;
3156 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim)); 3307 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim));
3157 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("alpha"), &match_alpha)); 3308 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("alpha"), &match_alpha));
3158 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("apricot"), &match_apricot)); 3309 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("apricot"), &match_apricot));
3159 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("avid"), &match_avid)); 3310 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("avid"), &match_avid));
3160 3311
3161 // Verbatim match duplicates are added such that each one has a higher 3312 // Verbatim match duplicates are added such that each one has a higher
3162 // relevance than the previous one. 3313 // relevance than the previous one.
3163 EXPECT_EQ(2U, verbatim.duplicate_matches.size()); 3314 EXPECT_EQ(2U, verbatim.duplicate_matches.size());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
3259 AutocompleteInput input(base::ASCIIToUTF16("weather l"), 3410 AutocompleteInput input(base::ASCIIToUTF16("weather l"),
3260 base::string16::npos, base::string16(), GURL(), 3411 base::string16::npos, base::string16(), GURL(),
3261 metrics::OmniboxEventProto::INVALID_SPEC, false, 3412 metrics::OmniboxEventProto::INVALID_SPEC, false,
3262 false, true, true, 3413 false, true, true,
3263 ChromeAutocompleteSchemeClassifier(&profile_)); 3414 ChromeAutocompleteSchemeClassifier(&profile_));
3264 provider_->DoAnswersQuery(input); 3415 provider_->DoAnswersQuery(input);
3265 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), 3416 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"),
3266 provider_->prefetch_data_.full_query_text); 3417 provider_->prefetch_data_.full_query_text);
3267 EXPECT_EQ(base::ASCIIToUTF16("2334"), provider_->prefetch_data_.query_type); 3418 EXPECT_EQ(base::ASCIIToUTF16("2334"), provider_->prefetch_data_.query_type);
3268 } 3419 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698