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

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

Issue 18878007: Omnibox: Make the Controller Reorder Matches for Inlining (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: upload again Created 7 years, 4 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/autocomplete/history_url_provider.h" 21 #include "chrome/browser/autocomplete/history_url_provider.h"
22 #include "chrome/browser/history/history_service.h" 22 #include "chrome/browser/history/history_service.h"
23 #include "chrome/browser/history/history_service_factory.h" 23 #include "chrome/browser/history/history_service_factory.h"
24 #include "chrome/browser/omnibox/omnibox_field_trial.h" 24 #include "chrome/browser/omnibox/omnibox_field_trial.h"
25 #include "chrome/browser/search/search.h" 25 #include "chrome/browser/search/search.h"
26 #include "chrome/browser/search_engines/template_url.h" 26 #include "chrome/browser/search_engines/template_url.h"
27 #include "chrome/browser/search_engines/template_url_service.h" 27 #include "chrome/browser/search_engines/template_url_service.h"
28 #include "chrome/browser/search_engines/template_url_service_factory.h" 28 #include "chrome/browser/search_engines/template_url_service_factory.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/metrics/entropy_provider.h" 30 #include "chrome/common/metrics/entropy_provider.h"
31 #include "chrome/common/metrics/variations/variations_util.h"
31 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
32 #include "chrome/test/base/testing_browser_process.h" 33 #include "chrome/test/base/testing_browser_process.h"
33 #include "chrome/test/base/testing_profile.h" 34 #include "chrome/test/base/testing_profile.h"
34 #include "content/public/test/test_browser_thread_bundle.h" 35 #include "content/public/test/test_browser_thread_bundle.h"
35 #include "net/url_request/test_url_fetcher_factory.h" 36 #include "net/url_request/test_url_fetcher_factory.h"
36 #include "net/url_request/url_request_status.h" 37 #include "net/url_request/url_request_status.h"
37 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
38 39
39 40
40 // SearchProviderTest --------------------------------------------------------- 41 // SearchProviderTest ---------------------------------------------------------
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const size_t num_results; 73 const size_t num_results;
73 const ResultInfo output[3]; 74 const ResultInfo output[3];
74 }; 75 };
75 76
76 SearchProviderTest() 77 SearchProviderTest()
77 : default_t_url_(NULL), 78 : default_t_url_(NULL),
78 term1_(ASCIIToUTF16("term1")), 79 term1_(ASCIIToUTF16("term1")),
79 keyword_t_url_(NULL), 80 keyword_t_url_(NULL),
80 keyword_term_(ASCIIToUTF16("keyword")), 81 keyword_term_(ASCIIToUTF16("keyword")),
81 run_loop_(NULL) { 82 run_loop_(NULL) {
83 ResetFieldTrialList();
82 } 84 }
83 85
84 static void SetUpTestCase();
85 static void TearDownTestCase(); 86 static void TearDownTestCase();
86 87
87 // See description above class for what this registers. 88 // See description above class for what this registers.
88 virtual void SetUp() OVERRIDE; 89 virtual void SetUp() OVERRIDE;
89 virtual void TearDown() OVERRIDE; 90 virtual void TearDown() OVERRIDE;
90 91
91 void RunTest(TestData* cases, int num_cases, bool prefer_keyword); 92 void RunTest(TestData* cases, int num_cases, bool prefer_keyword);
92 93
93 protected: 94 protected:
94 // Needed for AutocompleteFieldTrial::ActivateStaticTrials(); 95 // Needed for AutocompleteFieldTrial::ActivateStaticTrials();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is 127 // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is
127 // non-NULL, sets it to the "what you typed" entry for |text|. 128 // non-NULL, sets it to the "what you typed" entry for |text|.
128 void QueryForInputAndSetWYTMatch(const string16& text, 129 void QueryForInputAndSetWYTMatch(const string16& text,
129 AutocompleteMatch* wyt_match); 130 AutocompleteMatch* wyt_match);
130 131
131 // Notifies the URLFetcher for the suggest query corresponding to the default 132 // Notifies the URLFetcher for the suggest query corresponding to the default
132 // search provider that it's done. 133 // search provider that it's done.
133 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE. 134 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE.
134 void FinishDefaultSuggestQuery(); 135 void FinishDefaultSuggestQuery();
135 136
137 static void ResetFieldTrialList();
138
136 // See description above class for details of these fields. 139 // See description above class for details of these fields.
137 TemplateURL* default_t_url_; 140 TemplateURL* default_t_url_;
138 const string16 term1_; 141 const string16 term1_;
139 GURL term1_url_; 142 GURL term1_url_;
140 TemplateURL* keyword_t_url_; 143 TemplateURL* keyword_t_url_;
141 const string16 keyword_term_; 144 const string16 keyword_term_;
142 GURL keyword_url_; 145 GURL keyword_url_;
143 146
144 content::TestBrowserThreadBundle thread_bundle_; 147 content::TestBrowserThreadBundle thread_bundle_;
145 148
(...skipping 10 matching lines...) Expand all
156 base::RunLoop* run_loop_; 159 base::RunLoop* run_loop_;
157 160
158 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); 161 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
159 }; 162 };
160 163
161 // static 164 // static
162 base::FieldTrialList* SearchProviderTest::field_trial_list_ = NULL; 165 base::FieldTrialList* SearchProviderTest::field_trial_list_ = NULL;
163 const std::string SearchProviderTest::kNotApplicable = "Not Applicable"; 166 const std::string SearchProviderTest::kNotApplicable = "Not Applicable";
164 167
165 // static 168 // static
166 void SearchProviderTest::SetUpTestCase() {
167 // Set up Suggest experiments.
168 field_trial_list_ = new base::FieldTrialList(
169 new metrics::SHA1EntropyProvider("foo"));
170 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial(
171 "AutocompleteDynamicTrial_0", "DefaultGroup");
172 trial->group();
173 }
174
175 // static
176 void SearchProviderTest::TearDownTestCase() { 169 void SearchProviderTest::TearDownTestCase() {
177 // Make sure the global instance of FieldTrialList is gone. 170 // Make sure the global instance of FieldTrialList is gone.
178 delete field_trial_list_; 171 delete field_trial_list_;
172 field_trial_list_ = NULL;
179 } 173 }
180 174
181 void SearchProviderTest::SetUp() { 175 void SearchProviderTest::SetUp() {
182 // Make sure that fetchers are automatically ungregistered upon destruction. 176 // Make sure that fetchers are automatically ungregistered upon destruction.
183 test_factory_.set_remove_fetcher_on_delete(true); 177 test_factory_.set_remove_fetcher_on_delete(true);
184 178
185 // We need both the history service and template url model loaded. 179 // We need both the history service and template url model loaded.
186 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); 180 ASSERT_TRUE(profile_.CreateHistoryService(true, false));
187 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 181 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
188 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); 182 &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details; 247 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details;
254 if (matches.size() == cases[i].num_results) { 248 if (matches.size() == cases[i].num_results) {
255 for (size_t j = 0; j < cases[i].num_results; ++j) { 249 for (size_t j = 0; j < cases[i].num_results; ++j) {
256 EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) << 250 EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) <<
257 diagnostic_details; 251 diagnostic_details;
258 EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) << 252 EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) <<
259 diagnostic_details; 253 diagnostic_details;
260 EXPECT_EQ(cases[i].output[j].fill_into_edit, 254 EXPECT_EQ(cases[i].output[j].fill_into_edit,
261 matches[j].fill_into_edit) << 255 matches[j].fill_into_edit) <<
262 diagnostic_details; 256 diagnostic_details;
257 // All callers that use this helper function at the moment produce
258 // matches that always allowed to be the default match.
259 EXPECT_TRUE(matches[j].allowed_to_be_default_match);
263 } 260 }
264 } 261 }
265 } 262 }
266 } 263 }
267 264
268 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { 265 void SearchProviderTest::OnProviderUpdate(bool updated_matches) {
269 if (run_loop_ && provider_->done()) { 266 if (run_loop_ && provider_->done()) {
270 run_loop_->Quit(); 267 run_loop_->Quit();
271 run_loop_ = NULL; 268 run_loop_ = NULL;
272 } 269 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 net::TestURLFetcher* default_fetcher = 353 net::TestURLFetcher* default_fetcher =
357 test_factory_.GetFetcherByID( 354 test_factory_.GetFetcherByID(
358 SearchProvider::kDefaultProviderURLFetcherID); 355 SearchProvider::kDefaultProviderURLFetcherID);
359 ASSERT_TRUE(default_fetcher); 356 ASSERT_TRUE(default_fetcher);
360 357
361 // Tell the SearchProvider the default suggest query is done. 358 // Tell the SearchProvider the default suggest query is done.
362 default_fetcher->set_response_code(200); 359 default_fetcher->set_response_code(200);
363 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 360 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
364 } 361 }
365 362
363 // static
364 void SearchProviderTest::ResetFieldTrialList() {
365 // It's important to delete the old pointer first which sets
366 // FieldTrialList::global_ to NULL.
367 if (field_trial_list_)
368 delete field_trial_list_;
369 field_trial_list_ = new base::FieldTrialList(
370 new metrics::SHA1EntropyProvider("foo"));
371 //TODO: uncomment me! chrome_variations::testing::ClearAllVariationParams();
H Fung 2013/08/06 22:03:17 Don't forget to uncomment/remove?
Mark P 2013/08/06 22:18:06 Good point. I cannot uncomment this until https:/
372 // OmniboxFieldTrial::ActivateDynamicTrials();
373 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial(
374 "AutocompleteDynamicTrial_0", "DefaultGroup");
375 trial->group();
376 }
366 377
367 // Actual Tests --------------------------------------------------------------- 378 // Actual Tests ---------------------------------------------------------------
368 379
369 // Make sure we query history for the default provider and a URLFetcher is 380 // Make sure we query history for the default provider and a URLFetcher is
370 // created for the default provider suggest results. 381 // created for the default provider suggest results.
371 TEST_F(SearchProviderTest, QueryDefaultProvider) { 382 TEST_F(SearchProviderTest, QueryDefaultProvider) {
372 string16 term = term1_.substr(0, term1_.length() - 1); 383 string16 term = term1_.substr(0, term1_.length() - 1);
373 QueryForInput(term, false, false); 384 QueryForInput(term, false, false);
374 385
375 // Make sure the default providers suggest service was queried. 386 // Make sure the default providers suggest service was queried.
(...skipping 20 matching lines...) Expand all
396 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match)); 407 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match));
397 // Term1 should not have a description, it's set later. 408 // Term1 should not have a description, it's set later.
398 EXPECT_TRUE(term1_match.description.empty()); 409 EXPECT_TRUE(term1_match.description.empty());
399 410
400 AutocompleteMatch wyt_match; 411 AutocompleteMatch wyt_match;
401 EXPECT_TRUE(FindMatchWithDestination( 412 EXPECT_TRUE(FindMatchWithDestination(
402 GURL(default_t_url_->url_ref().ReplaceSearchTerms( 413 GURL(default_t_url_->url_ref().ReplaceSearchTerms(
403 TemplateURLRef::SearchTermsArgs(term))), &wyt_match)); 414 TemplateURLRef::SearchTermsArgs(term))), &wyt_match));
404 EXPECT_TRUE(wyt_match.description.empty()); 415 EXPECT_TRUE(wyt_match.description.empty());
405 416
406 // The match for term1 should be more relevant than the what you typed result. 417 // The match for term1 should be more relevant than the what you typed match.
407 EXPECT_GT(term1_match.relevance, wyt_match.relevance); 418 EXPECT_GT(term1_match.relevance, wyt_match.relevance);
419 // This longer match should be inlineable.
420 EXPECT_TRUE(term1_match.allowed_to_be_default_match);
421 // The what you typed match should too of course.
422 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
408 } 423 }
409 424
410 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) { 425 TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) {
411 string16 term = term1_.substr(0, term1_.length() - 1); 426 string16 term = term1_.substr(0, term1_.length() - 1);
412 QueryForInput(term, true, false); 427 QueryForInput(term, true, false);
413 428
414 ASSERT_FALSE(provider_->matches().empty()); 429 ASSERT_FALSE(provider_->matches().empty());
415 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 430 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
416 provider_->matches()[0].type); 431 provider_->matches()[0].type);
432 EXPECT_TRUE(provider_->matches()[0].allowed_to_be_default_match);
417 } 433 }
418 434
419 // Issues a query that matches the registered keyword and makes sure history 435 // Issues a query that matches the registered keyword and makes sure history
420 // is queried as well as URLFetchers getting created. 436 // is queried as well as URLFetchers getting created.
421 TEST_F(SearchProviderTest, QueryKeywordProvider) { 437 TEST_F(SearchProviderTest, QueryKeywordProvider) {
422 string16 term = keyword_term_.substr(0, keyword_term_.length() - 1); 438 string16 term = keyword_term_.substr(0, keyword_term_.length() - 1);
423 QueryForInput(keyword_t_url_->keyword() + ASCIIToUTF16(" ") + term, 439 QueryForInput(keyword_t_url_->keyword() + ASCIIToUTF16(" ") + term,
424 false, 440 false,
425 false); 441 false);
426 442
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("docs"), 524 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("docs"),
509 &wyt_match)); 525 &wyt_match));
510 526
511 // There should be two matches, one for what you typed, the other for 527 // There should be two matches, one for what you typed, the other for
512 // 'docs.google.com'. The search term should have a lower priority than the 528 // 'docs.google.com'. The search term should have a lower priority than the
513 // what you typed match. 529 // what you typed match.
514 ASSERT_EQ(2u, provider_->matches().size()); 530 ASSERT_EQ(2u, provider_->matches().size());
515 AutocompleteMatch term_match; 531 AutocompleteMatch term_match;
516 EXPECT_TRUE(FindMatchWithDestination(url, &term_match)); 532 EXPECT_TRUE(FindMatchWithDestination(url, &term_match));
517 EXPECT_GT(wyt_match.relevance, term_match.relevance); 533 EXPECT_GT(wyt_match.relevance, term_match.relevance);
534 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
535 EXPECT_TRUE(term_match.allowed_to_be_default_match);
518 } 536 }
519 537
520 // A multiword search with one visit should not autocomplete until multiple 538 // A multiword search with one visit should not autocomplete until multiple
521 // words are typed. 539 // words are typed.
522 TEST_F(SearchProviderTest, DontAutocompleteUntilMultipleWordsTyped) { 540 TEST_F(SearchProviderTest, DontAutocompleteUntilMultipleWordsTyped) {
523 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("one search"), 541 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("one search"),
524 1)); 542 1));
525 profile_.BlockUntilHistoryProcessesPendingRequests(); 543 profile_.BlockUntilHistoryProcessesPendingRequests();
526 544
527 AutocompleteMatch wyt_match; 545 AutocompleteMatch wyt_match;
528 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("on"), 546 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("on"),
529 &wyt_match)); 547 &wyt_match));
530 ASSERT_EQ(2u, provider_->matches().size()); 548 ASSERT_EQ(2u, provider_->matches().size());
531 AutocompleteMatch term_match; 549 AutocompleteMatch term_match;
532 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); 550 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
533 EXPECT_GT(wyt_match.relevance, term_match.relevance); 551 EXPECT_GT(wyt_match.relevance, term_match.relevance);
552 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
553 EXPECT_TRUE(term_match.allowed_to_be_default_match);
534 554
535 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("one se"), 555 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("one se"),
536 &wyt_match)); 556 &wyt_match));
537 ASSERT_EQ(2u, provider_->matches().size()); 557 ASSERT_EQ(2u, provider_->matches().size());
538 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); 558 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
539 EXPECT_GT(term_match.relevance, wyt_match.relevance); 559 EXPECT_GT(term_match.relevance, wyt_match.relevance);
560 EXPECT_TRUE(term_match.allowed_to_be_default_match);
561 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
540 } 562 }
541 563
542 // A multiword search with more than one visit should autocomplete immediately. 564 // A multiword search with more than one visit should autocomplete immediately.
543 TEST_F(SearchProviderTest, AutocompleteMultipleVisitsImmediately) { 565 TEST_F(SearchProviderTest, AutocompleteMultipleVisitsImmediately) {
544 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("two searches"), 566 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("two searches"),
545 2)); 567 2));
546 profile_.BlockUntilHistoryProcessesPendingRequests(); 568 profile_.BlockUntilHistoryProcessesPendingRequests();
547 569
548 AutocompleteMatch wyt_match; 570 AutocompleteMatch wyt_match;
549 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("tw"), 571 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("tw"),
550 &wyt_match)); 572 &wyt_match));
551 ASSERT_EQ(2u, provider_->matches().size()); 573 ASSERT_EQ(2u, provider_->matches().size());
552 AutocompleteMatch term_match; 574 AutocompleteMatch term_match;
553 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); 575 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
554 EXPECT_GT(term_match.relevance, wyt_match.relevance); 576 EXPECT_GT(term_match.relevance, wyt_match.relevance);
577 EXPECT_TRUE(term_match.allowed_to_be_default_match);
578 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
555 } 579 }
556 580
557 // Autocompletion should work at a word boundary after a space. 581 // Autocompletion should work at a word boundary after a space.
558 TEST_F(SearchProviderTest, AutocompleteAfterSpace) { 582 TEST_F(SearchProviderTest, AutocompleteAfterSpace) {
559 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("two searches"), 583 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("two searches"),
560 2)); 584 2));
561 profile_.BlockUntilHistoryProcessesPendingRequests(); 585 profile_.BlockUntilHistoryProcessesPendingRequests();
562 586
563 AutocompleteMatch wyt_match; 587 AutocompleteMatch wyt_match;
564 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("two "), 588 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("two "),
565 &wyt_match)); 589 &wyt_match));
566 ASSERT_EQ(2u, provider_->matches().size()); 590 ASSERT_EQ(2u, provider_->matches().size());
567 AutocompleteMatch term_match; 591 AutocompleteMatch term_match;
568 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); 592 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
569 EXPECT_GT(term_match.relevance, wyt_match.relevance); 593 EXPECT_GT(term_match.relevance, wyt_match.relevance);
594 EXPECT_TRUE(term_match.allowed_to_be_default_match);
595 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
570 } 596 }
571 597
572 // Newer multiword searches should score more highly than older ones. 598 // Newer multiword searches should score more highly than older ones.
573 TEST_F(SearchProviderTest, ScoreNewerSearchesHigher) { 599 TEST_F(SearchProviderTest, ScoreNewerSearchesHigher) {
574 GURL term_url_a(AddSearchToHistory(default_t_url_, 600 GURL term_url_a(AddSearchToHistory(default_t_url_,
575 ASCIIToUTF16("three searches aaa"), 1)); 601 ASCIIToUTF16("three searches aaa"), 1));
576 GURL term_url_b(AddSearchToHistory(default_t_url_, 602 GURL term_url_b(AddSearchToHistory(default_t_url_,
577 ASCIIToUTF16("three searches bbb"), 1)); 603 ASCIIToUTF16("three searches bbb"), 1));
578 profile_.BlockUntilHistoryProcessesPendingRequests(); 604 profile_.BlockUntilHistoryProcessesPendingRequests();
579 605
580 AutocompleteMatch wyt_match; 606 AutocompleteMatch wyt_match;
581 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("three se"), 607 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("three se"),
582 &wyt_match)); 608 &wyt_match));
583 ASSERT_EQ(3u, provider_->matches().size()); 609 ASSERT_EQ(3u, provider_->matches().size());
584 AutocompleteMatch term_match_a; 610 AutocompleteMatch term_match_a;
585 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a)); 611 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
586 AutocompleteMatch term_match_b; 612 AutocompleteMatch term_match_b;
587 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b)); 613 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
588 EXPECT_GT(term_match_b.relevance, term_match_a.relevance); 614 EXPECT_GT(term_match_b.relevance, term_match_a.relevance);
589 EXPECT_GT(term_match_a.relevance, wyt_match.relevance); 615 EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
616 EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
617 EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
618 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
590 } 619 }
591 620
592 // An autocompleted multiword search should not be replaced by a different 621 // An autocompleted multiword search should not be replaced by a different
593 // autocompletion while the user is still typing a valid prefix. 622 // autocompletion while the user is still typing a valid prefix.
594 TEST_F(SearchProviderTest, DontReplacePreviousAutocompletion) { 623 TEST_F(SearchProviderTest, DontReplacePreviousAutocompletion) {
595 GURL term_url_a(AddSearchToHistory(default_t_url_, 624 GURL term_url_a(AddSearchToHistory(default_t_url_,
596 ASCIIToUTF16("four searches aaa"), 2)); 625 ASCIIToUTF16("four searches aaa"), 2));
597 GURL term_url_b(AddSearchToHistory(default_t_url_, 626 GURL term_url_b(AddSearchToHistory(default_t_url_,
598 ASCIIToUTF16("four searches bbb"), 1)); 627 ASCIIToUTF16("four searches bbb"), 1));
599 profile_.BlockUntilHistoryProcessesPendingRequests(); 628 profile_.BlockUntilHistoryProcessesPendingRequests();
600 629
601 AutocompleteMatch wyt_match; 630 AutocompleteMatch wyt_match;
602 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fo"), 631 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fo"),
603 &wyt_match)); 632 &wyt_match));
604 ASSERT_EQ(3u, provider_->matches().size()); 633 ASSERT_EQ(3u, provider_->matches().size());
605 AutocompleteMatch term_match_a; 634 AutocompleteMatch term_match_a;
606 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a)); 635 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
607 AutocompleteMatch term_match_b; 636 AutocompleteMatch term_match_b;
608 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b)); 637 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
609 EXPECT_GT(term_match_a.relevance, wyt_match.relevance); 638 EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
610 EXPECT_GT(wyt_match.relevance, term_match_b.relevance); 639 EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
640 EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
641 EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
642 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
611 643
612 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("four se"), 644 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("four se"),
613 &wyt_match)); 645 &wyt_match));
614 ASSERT_EQ(3u, provider_->matches().size()); 646 ASSERT_EQ(3u, provider_->matches().size());
615 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a)); 647 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
616 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b)); 648 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
617 EXPECT_GT(term_match_a.relevance, wyt_match.relevance); 649 EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
618 EXPECT_GT(wyt_match.relevance, term_match_b.relevance); 650 EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
651 EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
652 EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
653 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
619 } 654 }
620 655
621 // Non-completable multiword searches should not crowd out single-word searches. 656 // Non-completable multiword searches should not crowd out single-word searches.
622 TEST_F(SearchProviderTest, DontCrowdOutSingleWords) { 657 TEST_F(SearchProviderTest, DontCrowdOutSingleWords) {
623 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("five"), 1)); 658 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("five"), 1));
624 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches bbb"), 1); 659 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches bbb"), 1);
625 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ccc"), 1); 660 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ccc"), 1);
626 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ddd"), 1); 661 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ddd"), 1);
627 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches eee"), 1); 662 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches eee"), 1);
628 profile_.BlockUntilHistoryProcessesPendingRequests(); 663 profile_.BlockUntilHistoryProcessesPendingRequests();
629 664
630 AutocompleteMatch wyt_match; 665 AutocompleteMatch wyt_match;
631 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fi"), 666 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fi"),
632 &wyt_match)); 667 &wyt_match));
633 ASSERT_EQ(AutocompleteProvider::kMaxMatches + 1, provider_->matches().size()); 668 ASSERT_EQ(AutocompleteProvider::kMaxMatches + 1, provider_->matches().size());
634 AutocompleteMatch term_match; 669 AutocompleteMatch term_match;
635 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); 670 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
636 EXPECT_GT(term_match.relevance, wyt_match.relevance); 671 EXPECT_GT(term_match.relevance, wyt_match.relevance);
672 EXPECT_TRUE(term_match.allowed_to_be_default_match);
673 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
637 } 674 }
638 675
639 // Inline autocomplete matches regardless of case differences from the input. 676 // Inline autocomplete matches regardless of case differences from the input.
640 TEST_F(SearchProviderTest, InlineMixedCaseMatches) { 677 TEST_F(SearchProviderTest, InlineMixedCaseMatches) {
641 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("FOO"), 1)); 678 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("FOO"), 1));
642 profile_.BlockUntilHistoryProcessesPendingRequests(); 679 profile_.BlockUntilHistoryProcessesPendingRequests();
643 680
644 AutocompleteMatch wyt_match; 681 AutocompleteMatch wyt_match;
645 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("f"), 682 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("f"),
646 &wyt_match)); 683 &wyt_match));
647 ASSERT_EQ(2u, provider_->matches().size()); 684 ASSERT_EQ(2u, provider_->matches().size());
648 AutocompleteMatch term_match; 685 AutocompleteMatch term_match;
649 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); 686 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
650 EXPECT_GT(term_match.relevance, wyt_match.relevance); 687 EXPECT_GT(term_match.relevance, wyt_match.relevance);
651 EXPECT_EQ(ASCIIToUTF16("FOO"), term_match.fill_into_edit); 688 EXPECT_EQ(ASCIIToUTF16("FOO"), term_match.fill_into_edit);
652 EXPECT_EQ(ASCIIToUTF16("OO"), term_match.inline_autocompletion); 689 EXPECT_EQ(ASCIIToUTF16("OO"), term_match.inline_autocompletion);
690 EXPECT_TRUE(term_match.allowed_to_be_default_match);
653 } 691 }
654 692
655 // Verifies AutocompleteControllers return results (including keyword 693 // Verifies AutocompleteControllers return results (including keyword
656 // results) in the right order and set descriptions for them correctly. 694 // results) in the right order and set descriptions for them correctly.
657 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { 695 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) {
658 // Add an entry that corresponds to a keyword search with 'term2'. 696 // Add an entry that corresponds to a keyword search with 'term2'.
659 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); 697 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1);
660 profile_.BlockUntilHistoryProcessesPendingRequests(); 698 profile_.BlockUntilHistoryProcessesPendingRequests();
661 699
662 AutocompleteController controller(&profile_, NULL, 700 AutocompleteController controller(&profile_, NULL,
663 AutocompleteProvider::TYPE_SEARCH); 701 AutocompleteProvider::TYPE_SEARCH);
664 controller.Start(AutocompleteInput( 702 controller.Start(AutocompleteInput(
665 ASCIIToUTF16("k t"), string16::npos, string16(), GURL(), 703 ASCIIToUTF16("k t"), string16::npos, string16(), GURL(),
666 AutocompleteInput::INVALID_SPEC, false, false, true, 704 AutocompleteInput::INVALID_SPEC, false, false, true,
667 AutocompleteInput::ALL_MATCHES)); 705 AutocompleteInput::ALL_MATCHES));
668 const AutocompleteResult& result = controller.result(); 706 const AutocompleteResult& result = controller.result();
669 707
670 // There should be three matches, one for the keyword history, one for 708 // There should be three matches, one for the keyword history, one for
671 // keyword provider's what-you-typed, and one for the default provider's 709 // keyword provider's what-you-typed, and one for the default provider's
672 // what you typed, in that order. 710 // what you typed, in that order.
673 ASSERT_EQ(3u, result.size()); 711 ASSERT_EQ(3u, result.size());
674 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type); 712 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type);
675 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE, 713 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE,
676 result.match_at(1).type); 714 result.match_at(1).type);
677 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 715 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
678 result.match_at(2).type); 716 result.match_at(2).type);
679 EXPECT_GT(result.match_at(0).relevance, result.match_at(1).relevance); 717 EXPECT_GT(result.match_at(0).relevance, result.match_at(1).relevance);
680 EXPECT_GT(result.match_at(1).relevance, result.match_at(2).relevance); 718 EXPECT_GT(result.match_at(1).relevance, result.match_at(2).relevance);
719 EXPECT_TRUE(result.match_at(0).allowed_to_be_default_match);
720 EXPECT_TRUE(result.match_at(1).allowed_to_be_default_match);
721 EXPECT_TRUE(result.match_at(2).allowed_to_be_default_match);
681 722
682 // The two keyword results should come with the keyword we expect. 723 // The two keyword results should come with the keyword we expect.
683 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(0).keyword); 724 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(0).keyword);
684 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(1).keyword); 725 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(1).keyword);
685 // The default provider has a different keyword. (We don't explicitly 726 // The default provider has a different keyword. (We don't explicitly
686 // set it during this test, so all we do is assert that it's different.) 727 // set it during this test, so all we do is assert that it's different.)
687 EXPECT_NE(result.match_at(0).keyword, result.match_at(2).keyword); 728 EXPECT_NE(result.match_at(0).keyword, result.match_at(2).keyword);
688 729
689 // The top result will always have a description. The third result, 730 // The top result will always have a description. The third result,
690 // coming from a different provider than the first two, should also. 731 // coming from a different provider than the first two, should also.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 fetcher->delegate()->OnURLFetchComplete(fetcher); 871 fetcher->delegate()->OnURLFetchComplete(fetcher);
831 fetcher = NULL; 872 fetcher = NULL;
832 873
833 // Run till the history results complete. 874 // Run till the history results complete.
834 RunTillProviderDone(); 875 RunTillProviderDone();
835 876
836 // Make sure the only match is 'a.com' and it doesn't have a template_url. 877 // Make sure the only match is 'a.com' and it doesn't have a template_url.
837 AutocompleteMatch nav_match; 878 AutocompleteMatch nav_match;
838 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); 879 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match));
839 EXPECT_TRUE(nav_match.keyword.empty()); 880 EXPECT_TRUE(nav_match.keyword.empty());
881 EXPECT_TRUE(nav_match.allowed_to_be_default_match);
840 EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match)); 882 EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match));
841 } 883 }
842 884
843 // Verifies that the most relevant suggest results are added properly. 885 // Verifies that the most relevant suggest results are added properly.
844 TEST_F(SearchProviderTest, SuggestRelevance) { 886 TEST_F(SearchProviderTest, SuggestRelevance) {
845 QueryForInput(ASCIIToUTF16("a"), false, false); 887 QueryForInput(ASCIIToUTF16("a"), false, false);
846 888
847 // Make sure the default provider's suggest service was queried. 889 // Make sure the default provider's suggest service was queried.
848 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 890 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
849 SearchProvider::kDefaultProviderURLFetcherID); 891 SearchProvider::kDefaultProviderURLFetcherID);
(...skipping 11 matching lines...) Expand all
861 // Check the expected verbatim and (first 3) suggestions' relative relevances. 903 // Check the expected verbatim and (first 3) suggestions' relative relevances.
862 AutocompleteMatch verbatim, match_a1, match_a2, match_a3, match_a4; 904 AutocompleteMatch verbatim, match_a1, match_a2, match_a3, match_a4;
863 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim)); 905 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim));
864 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1)); 906 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1));
865 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2)); 907 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2));
866 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3)); 908 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3));
867 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4)); 909 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4));
868 EXPECT_GT(verbatim.relevance, match_a1.relevance); 910 EXPECT_GT(verbatim.relevance, match_a1.relevance);
869 EXPECT_GT(match_a1.relevance, match_a2.relevance); 911 EXPECT_GT(match_a1.relevance, match_a2.relevance);
870 EXPECT_GT(match_a2.relevance, match_a3.relevance); 912 EXPECT_GT(match_a2.relevance, match_a3.relevance);
913 EXPECT_TRUE(verbatim.allowed_to_be_default_match);
914 EXPECT_TRUE(match_a1.allowed_to_be_default_match);
915 EXPECT_TRUE(match_a2.allowed_to_be_default_match);
916 EXPECT_TRUE(match_a3.allowed_to_be_default_match);
871 } 917 }
872 918
873 // Verifies that suggest results with relevance scores are added 919 // Verifies that suggest results with relevance scores are added
874 // properly when using the default fetcher. When adding a new test 920 // properly when using the default fetcher. When adding a new test
875 // case to this test, please consider adding it to the tests in 921 // case to this test, please consider adding it to the tests in
876 // KeywordFetcherSuggestRelevance below. 922 // KeywordFetcherSuggestRelevance below.
877 TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) { 923 TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
924 struct DefaultFetcherMatch {
925 std::string contents;
926 bool allowed_to_be_default_match;
927 };
928 const DefaultFetcherMatch kEmptyMatch = { kNotApplicable, false };
878 struct { 929 struct {
879 const std::string json; 930 const std::string json;
880 const std::string matches[4]; 931 const DefaultFetcherMatch matches[4];
881 const std::string inline_autocompletion; 932 const std::string inline_autocompletion;
882 } cases[] = { 933 } cases[] = {
883 // Ensure that suggestrelevance scores reorder matches. 934 // Ensure that suggestrelevance scores reorder matches.
884 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", 935 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
885 { "a", "c", "b", kNotApplicable }, std::string() }, 936 { { "a", true }, { "c", false }, { "b", false }, kEmptyMatch },
937 std::string() },
886 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," 938 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
887 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 939 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
888 "\"google:suggestrelevance\":[1, 2]}]", 940 "\"google:suggestrelevance\":[1, 2]}]",
889 { "a", "c.com", "b.com", kNotApplicable }, std::string() }, 941 { { "a", true }, { "c.com", false }, { "b.com", false }, kEmptyMatch },
942 std::string() },
890 943
891 // Without suggested relevance scores, we should only allow one 944 // Without suggested relevance scores, we should only allow one
892 // navsuggest result to be be displayed. 945 // navsuggest result to be be displayed.
893 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," 946 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
894 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", 947 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]",
895 { "a", "b.com", kNotApplicable, kNotApplicable }, std::string() }, 948 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch },
949 std::string() },
896 950
897 // Ensure that verbatimrelevance scores reorder or suppress verbatim. 951 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
898 // Negative values will have no effect; the calculated value will be used. 952 // Negative values will have no effect; the calculated value will be used.
899 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," 953 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
900 "\"google:suggestrelevance\":[9998]}]", 954 "\"google:suggestrelevance\":[9998]}]",
901 { "a", "a1", kNotApplicable, kNotApplicable }, std::string() }, 955 { { "a", true}, { "a1", true }, kEmptyMatch, kEmptyMatch },
956 std::string() },
902 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," 957 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
903 "\"google:suggestrelevance\":[9999]}]", 958 "\"google:suggestrelevance\":[9999]}]",
904 { "a1", "a", kNotApplicable, kNotApplicable }, "1" }, 959 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
960 "1" },
905 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," 961 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0,"
906 "\"google:suggestrelevance\":[9999]}]", 962 "\"google:suggestrelevance\":[9999]}]",
907 { "a1", kNotApplicable, kNotApplicable, kNotApplicable }, "1" }, 963 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
964 "1" },
908 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," 965 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1,"
909 "\"google:suggestrelevance\":[9999]}]", 966 "\"google:suggestrelevance\":[9999]}]",
910 { "a1", "a", kNotApplicable, kNotApplicable }, "1" }, 967 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
968 "1" },
911 { "[\"a\",[\"http://a.com\"],[],[]," 969 { "[\"a\",[\"http://a.com\"],[],[],"
912 "{\"google:suggesttype\":[\"NAVIGATION\"]," 970 "{\"google:suggesttype\":[\"NAVIGATION\"],"
913 "\"google:verbatimrelevance\":9999," 971 "\"google:verbatimrelevance\":9999,"
914 "\"google:suggestrelevance\":[9998]}]", 972 "\"google:suggestrelevance\":[9998]}]",
915 { "a", "a.com", kNotApplicable, kNotApplicable }, std::string() }, 973 { { "a", true }, { "a.com", true }, kEmptyMatch, kEmptyMatch },
974 std::string() },
916 { "[\"a\",[\"http://a.com\"],[],[]," 975 { "[\"a\",[\"http://a.com\"],[],[],"
917 "{\"google:suggesttype\":[\"NAVIGATION\"]," 976 "{\"google:suggesttype\":[\"NAVIGATION\"],"
918 "\"google:verbatimrelevance\":9998," 977 "\"google:verbatimrelevance\":9998,"
919 "\"google:suggestrelevance\":[9999]}]", 978 "\"google:suggestrelevance\":[9999]}]",
920 { "a.com", "a", kNotApplicable, kNotApplicable }, ".com" }, 979 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
980 ".com" },
921 { "[\"a\",[\"http://a.com\"],[],[]," 981 { "[\"a\",[\"http://a.com\"],[],[],"
922 "{\"google:suggesttype\":[\"NAVIGATION\"]," 982 "{\"google:suggesttype\":[\"NAVIGATION\"],"
923 "\"google:verbatimrelevance\":0," 983 "\"google:verbatimrelevance\":0,"
924 "\"google:suggestrelevance\":[9999]}]", 984 "\"google:suggestrelevance\":[9999]}]",
925 { "a.com", kNotApplicable, kNotApplicable, kNotApplicable }, ".com" }, 985 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
986 ".com" },
926 { "[\"a\",[\"http://a.com\"],[],[]," 987 { "[\"a\",[\"http://a.com\"],[],[],"
927 "{\"google:suggesttype\":[\"NAVIGATION\"]," 988 "{\"google:suggesttype\":[\"NAVIGATION\"],"
928 "\"google:verbatimrelevance\":-1," 989 "\"google:verbatimrelevance\":-1,"
929 "\"google:suggestrelevance\":[9999]}]", 990 "\"google:suggestrelevance\":[9999]}]",
930 { "a.com", "a", kNotApplicable, kNotApplicable }, ".com" }, 991 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
992 ".com" },
931 993
932 // Ensure that both types of relevance scores reorder matches together. 994 // Ensure that both types of relevance scores reorder matches together.
933 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," 995 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
934 "\"google:verbatimrelevance\":9998}]", 996 "\"google:verbatimrelevance\":9998}]",
935 { "a1", "a", "a2", kNotApplicable }, "1" }, 997 { { "a1", true }, { "a", true }, { "a2", true }, kEmptyMatch },
998 "1" },
936 999
937 // Ensure that only inlinable matches may be ranked as the highest result. 1000 // Ensure that only inlinable matches may be ranked as the highest result.
938 // Ignore all suggested relevance scores if this constraint is violated. 1001 // Ignore all suggested relevance scores if this constraint is violated.
939 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", 1002 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
940 { "a", "b", kNotApplicable, kNotApplicable }, std::string() }, 1003 { { "a", true }, { "b", false }, kEmptyMatch, kEmptyMatch },
1004 std::string() },
941 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," 1005 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
942 "\"google:verbatimrelevance\":0}]", 1006 "\"google:verbatimrelevance\":0}]",
943 { "a", "b", kNotApplicable, kNotApplicable }, std::string() }, 1007 { { "a", true }, { "b", false }, kEmptyMatch, kEmptyMatch },
1008 std::string() },
944 { "[\"a\",[\"http://b.com\"],[],[]," 1009 { "[\"a\",[\"http://b.com\"],[],[],"
945 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1010 "{\"google:suggesttype\":[\"NAVIGATION\"],"
946 "\"google:suggestrelevance\":[9999]}]", 1011 "\"google:suggestrelevance\":[9999]}]",
947 { "a", "b.com", kNotApplicable, kNotApplicable }, std::string() }, 1012 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch },
1013 std::string() },
948 { "[\"a\",[\"http://b.com\"],[],[]," 1014 { "[\"a\",[\"http://b.com\"],[],[],"
949 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1015 "{\"google:suggesttype\":[\"NAVIGATION\"],"
950 "\"google:suggestrelevance\":[9999]," 1016 "\"google:suggestrelevance\":[9999],"
951 "\"google:verbatimrelevance\":0}]", 1017 "\"google:verbatimrelevance\":0}]",
952 { "a", "b.com", kNotApplicable, kNotApplicable }, std::string() }, 1018 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch },
1019 std::string() },
953 1020
954 // Ensure that the top result is ranked as highly as calculated verbatim. 1021 // Ensure that the top result is ranked as highly as calculated verbatim.
955 // Ignore the suggested verbatim relevance if this constraint is violated. 1022 // Ignore the suggested verbatim relevance if this constraint is violated.
956 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", 1023 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
957 { "a", "a1", kNotApplicable, kNotApplicable }, std::string() }, 1024 { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch },
1025 std::string() },
958 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", 1026 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]",
959 { "a", "a1", kNotApplicable, kNotApplicable }, std::string() }, 1027 { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch },
1028 std::string() },
960 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," 1029 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1],"
961 "\"google:verbatimrelevance\":0}]", 1030 "\"google:verbatimrelevance\":0}]",
962 { "a", "a1", kNotApplicable, kNotApplicable }, std::string() }, 1031 { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch },
1032 std::string() },
963 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," 1033 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2],"
964 "\"google:verbatimrelevance\":0}]", 1034 "\"google:verbatimrelevance\":0}]",
965 { "a", "a2", "a1", kNotApplicable }, std::string() }, 1035 { { "a", true }, { "a2", true }, { "a1", true }, kEmptyMatch },
1036 std::string() },
966 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," 1037 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3],"
967 "\"google:verbatimrelevance\":2}]", 1038 "\"google:verbatimrelevance\":2}]",
968 { "a", "a2", "a1", kNotApplicable }, std::string() }, 1039 { { "a", true }, { "a2", true }, { "a1", true }, kEmptyMatch },
1040 std::string() },
969 { "[\"a\",[\"http://a.com\"],[],[]," 1041 { "[\"a\",[\"http://a.com\"],[],[],"
970 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1042 "{\"google:suggesttype\":[\"NAVIGATION\"],"
971 "\"google:suggestrelevance\":[1]," 1043 "\"google:suggestrelevance\":[1],"
972 "\"google:verbatimrelevance\":0}]", 1044 "\"google:verbatimrelevance\":0}]",
973 { "a", "a.com", kNotApplicable, kNotApplicable }, std::string() }, 1045 { { "a", true }, { "a.com", true }, kEmptyMatch, kEmptyMatch },
1046 std::string() },
974 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1047 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
975 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1048 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
976 "\"google:suggestrelevance\":[1, 2]," 1049 "\"google:suggestrelevance\":[1, 2],"
977 "\"google:verbatimrelevance\":0}]", 1050 "\"google:verbatimrelevance\":0}]",
978 { "a", "a2.com", "a1.com", kNotApplicable }, std::string() }, 1051 { { "a", true }, { "a2.com", true }, { "a1.com", true }, kEmptyMatch },
1052 std::string() },
979 1053
980 // Ensure that all suggestions are considered, regardless of order. 1054 // Ensure that all suggestions are considered, regardless of order.
981 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," 1055 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
982 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1056 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
983 { "a", "h", "g", "f" }, std::string() }, 1057 { { "a", true }, { "h", false }, { "g", false }, { "f", false } },
1058 std::string() },
984 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," 1059 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
985 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," 1060 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
986 "\"http://h.com\"],[],[]," 1061 "\"http://h.com\"],[],[],"
987 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," 1062 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
988 "\"NAVIGATION\", \"NAVIGATION\"," 1063 "\"NAVIGATION\", \"NAVIGATION\","
989 "\"NAVIGATION\", \"NAVIGATION\"," 1064 "\"NAVIGATION\", \"NAVIGATION\","
990 "\"NAVIGATION\"]," 1065 "\"NAVIGATION\"],"
991 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1066 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
992 { "a", "h.com", "g.com", "f.com" }, std::string() }, 1067 { { "a", true }, { "h.com", false }, { "g.com", false },
1068 { "f.com", false } },
1069 std::string() },
993 1070
994 // Ensure that incorrectly sized suggestion relevance lists are ignored. 1071 // Ensure that incorrectly sized suggestion relevance lists are ignored.
995 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", 1072 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
996 { "a", "a1", "a2", kNotApplicable }, std::string() }, 1073 { { "a", true }, { "a1", true }, { "a2", true }, kEmptyMatch },
1074 std::string() },
997 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", 1075 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
998 { "a", "a1", kNotApplicable, kNotApplicable }, std::string() }, 1076 { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch },
1077 std::string() },
999 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1078 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1000 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1079 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1001 "\"google:suggestrelevance\":[1]}]", 1080 "\"google:suggestrelevance\":[1]}]",
1002 { "a", "a1.com", kNotApplicable, kNotApplicable }, std::string() }, 1081 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch },
1082 std::string() },
1003 { "[\"a\",[\"http://a1.com\"],[],[]," 1083 { "[\"a\",[\"http://a1.com\"],[],[],"
1004 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1084 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1005 "\"google:suggestrelevance\":[9999, 1]}]", 1085 "\"google:suggestrelevance\":[9999, 1]}]",
1006 { "a", "a1.com", kNotApplicable, kNotApplicable }, std::string() }, 1086 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch },
1087 std::string() },
1007 1088
1008 // Ensure that all 'verbatim' results are merged with their maximum score. 1089 // Ensure that all 'verbatim' results are merged with their maximum score.
1009 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1090 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1010 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1091 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1011 { "a2", "a", "a1", kNotApplicable }, "2" }, 1092 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch },
1093 "2" },
1012 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1094 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1013 "{\"google:suggestrelevance\":[9998, 9997, 9999]," 1095 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
1014 "\"google:verbatimrelevance\":0}]", 1096 "\"google:verbatimrelevance\":0}]",
1015 { "a2", "a", "a1", kNotApplicable }, "2" }, 1097 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch },
1098 "2" },
1016 1099
1017 // Ensure that verbatim is always generated without other suggestions. 1100 // Ensure that verbatim is always generated without other suggestions.
1018 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). 1101 // TODO(msw): Ensure verbatimrelevance is respected (except suppression).
1019 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", 1102 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
1020 { "a", kNotApplicable, kNotApplicable, kNotApplicable }, std::string() }, 1103 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1104 std::string() },
1021 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", 1105 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
1022 { "a", kNotApplicable, kNotApplicable, kNotApplicable }, std::string() }, 1106 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1107 std::string() },
1023 }; 1108 };
1024 1109
1025 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1110 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1026 QueryForInput(ASCIIToUTF16("a"), false, false); 1111 QueryForInput(ASCIIToUTF16("a"), false, false);
1027 net::TestURLFetcher* fetcher = 1112 net::TestURLFetcher* fetcher =
1028 test_factory_.GetFetcherByID( 1113 test_factory_.GetFetcherByID(
1029 SearchProvider::kDefaultProviderURLFetcherID); 1114 SearchProvider::kDefaultProviderURLFetcherID);
1030 ASSERT_TRUE(fetcher); 1115 ASSERT_TRUE(fetcher);
1031 fetcher->set_response_code(200); 1116 fetcher->set_response_code(200);
1032 fetcher->SetResponseString(cases[i].json); 1117 fetcher->SetResponseString(cases[i].json);
1033 fetcher->delegate()->OnURLFetchComplete(fetcher); 1118 fetcher->delegate()->OnURLFetchComplete(fetcher);
1034 RunTillProviderDone(); 1119 RunTillProviderDone();
1035 1120
1036 const std::string description = "for input with json=" + cases[i].json; 1121 const std::string description = "for input with json=" + cases[i].json;
1037 const ACMatches& matches = provider_->matches(); 1122 const ACMatches& matches = provider_->matches();
1038 // The top match must inline and score as highly as calculated verbatim. 1123 // The top match must inline and score as highly as calculated verbatim.
1039 ASSERT_FALSE(matches.empty()); 1124 ASSERT_FALSE(matches.empty());
1040 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 1125 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
1041 matches[0].inline_autocompletion) << description; 1126 matches[0].inline_autocompletion) << description;
1042 EXPECT_GE(matches[0].relevance, 1300) << description; 1127 EXPECT_GE(matches[0].relevance, 1300) << description;
1043 1128
1044 size_t j = 0; 1129 size_t j = 0;
1045 // Ensure that the returned matches equal the expectations. 1130 // Ensure that the returned matches equal the expectations.
1046 for (; j < matches.size(); ++j) 1131 for (; j < matches.size(); ++j) {
1047 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), 1132 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
1048 matches[j].contents) << description; 1133 matches[j].contents) << description;
1134 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
1135 matches[j].allowed_to_be_default_match) << description;
1136 }
1049 // Ensure that no expected matches are missing. 1137 // Ensure that no expected matches are missing.
1050 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 1138 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1051 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) << 1139 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) <<
1052 "Case # " << i << " " << description; 1140 "Case # " << i << " " << description;
1053 } 1141 }
1054 } 1142 }
1143
1144 // This test is like DefaultFetcherSuggestRelevance above except it enables
1145 // the field trial that causes the omnibox to be willing to reorder matches
1146 // to guarantee the top result is a legal default match. This field trial
1147 // causes SearchProvider to allow some constraints to be violated that it
1148 // wouldn't normally because the omnibox will fix the problems later.
1149 TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevanceWithReorder) {
1150 struct DefaultFetcherMatch {
1151 std::string contents;
1152 bool allowed_to_be_default_match;
1153 };
1154 const DefaultFetcherMatch kEmptyMatch = { kNotApplicable, false };
1155 struct {
1156 const std::string json;
1157 const DefaultFetcherMatch matches[4];
1158 const std::string inline_autocompletion;
1159 } cases[] = {
1160 // Ensure that suggestrelevance scores reorder matches.
1161 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
1162 { { "a", true }, { "c", false }, { "b", false }, kEmptyMatch },
1163 std::string() },
1164 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
1165 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1166 "\"google:suggestrelevance\":[1, 2]}]",
1167 { { "a", true }, { "c.com", false }, { "b.com", false }, kEmptyMatch },
1168 std::string() },
1169
1170 // Without suggested relevance scores, we should only allow one
1171 // navsuggest result to be be displayed.
1172 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
1173 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]",
1174 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch },
1175 std::string() },
1176
1177 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
1178 // Negative values will have no effect; the calculated value will be used.
1179 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
1180 "\"google:suggestrelevance\":[9998]}]",
1181 { { "a", true}, { "a1", true }, kEmptyMatch, kEmptyMatch },
1182 std::string() },
1183 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
1184 "\"google:suggestrelevance\":[9999]}]",
1185 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
1186 "1" },
1187 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0,"
1188 "\"google:suggestrelevance\":[9999]}]",
1189 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1190 "1" },
1191 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1,"
1192 "\"google:suggestrelevance\":[9999]}]",
1193 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
1194 "1" },
1195 { "[\"a\",[\"http://a.com\"],[],[],"
1196 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1197 "\"google:verbatimrelevance\":9999,"
1198 "\"google:suggestrelevance\":[9998]}]",
1199 { { "a", true }, { "a.com", true }, kEmptyMatch, kEmptyMatch },
1200 std::string() },
1201 { "[\"a\",[\"http://a.com\"],[],[],"
1202 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1203 "\"google:verbatimrelevance\":9998,"
1204 "\"google:suggestrelevance\":[9999]}]",
1205 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
1206 ".com" },
1207 { "[\"a\",[\"http://a.com\"],[],[],"
1208 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1209 "\"google:verbatimrelevance\":0,"
1210 "\"google:suggestrelevance\":[9999]}]",
1211 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1212 ".com" },
1213 { "[\"a\",[\"http://a.com\"],[],[],"
1214 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1215 "\"google:verbatimrelevance\":-1,"
1216 "\"google:suggestrelevance\":[9999]}]",
1217 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
1218 ".com" },
1219
1220 // Ensure that both types of relevance scores reorder matches together.
1221 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
1222 "\"google:verbatimrelevance\":9998}]",
1223 { { "a1", true }, { "a", true }, { "a2", true }, kEmptyMatch },
1224 "1" },
1225
1226 // Allow non-inlineable matches to be the highest-scoring match but,
1227 // if the result set lacks a single inlineable result, abandon suggested
1228 // relevance scores entirely.
1229 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
1230 { { "b", false }, { "a", true }, kEmptyMatch, kEmptyMatch },
1231 std::string() },
1232 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
1233 "\"google:verbatimrelevance\":0}]",
1234 { { "a", true}, { "b", false }, kEmptyMatch, kEmptyMatch },
1235 std::string() },
1236 { "[\"a\",[\"http://b.com\"],[],[],"
1237 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1238 "\"google:suggestrelevance\":[9999]}]",
1239 { { "b.com", false }, { "a", true }, kEmptyMatch, kEmptyMatch },
1240 std::string() },
1241 { "[\"a\",[\"http://b.com\"],[],[],"
1242 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1243 "\"google:suggestrelevance\":[9999],"
1244 "\"google:verbatimrelevance\":0}]",
1245 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch },
1246 std::string() },
1247
1248 // Allow low-scoring matches.
1249 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
1250 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1251 "1" },
1252 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]",
1253 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch },
1254 "1" },
1255 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1],"
1256 "\"google:verbatimrelevance\":0}]",
1257 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1258 "1" },
1259 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2],"
1260 "\"google:verbatimrelevance\":0}]",
1261 { { "a2", true }, { "a1", true }, kEmptyMatch, kEmptyMatch },
1262 "2" },
1263 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3],"
1264 "\"google:verbatimrelevance\":2}]",
1265 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch },
1266 "2" },
1267 { "[\"a\",[\"http://a.com\"],[],[],"
1268 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1269 "\"google:suggestrelevance\":[1],"
1270 "\"google:verbatimrelevance\":0}]",
1271 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1272 ".com" },
1273 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1274 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1275 "\"google:suggestrelevance\":[1, 2],"
1276 "\"google:verbatimrelevance\":0}]",
1277 { { "a2.com", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch },
1278 "2.com" },
1279
1280 // Ensure that all suggestions are considered, regardless of order.
1281 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
1282 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
1283 { { "a", true }, { "h", false }, { "g", false }, { "f", false } },
1284 std::string() },
1285 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
1286 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
1287 "\"http://h.com\"],[],[],"
1288 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
1289 "\"NAVIGATION\", \"NAVIGATION\","
1290 "\"NAVIGATION\", \"NAVIGATION\","
1291 "\"NAVIGATION\"],"
1292 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
1293 { { "a", true }, { "h.com", false }, { "g.com", false },
1294 { "f.com", false } },
1295 std::string() },
1296
1297 // Ensure that incorrectly sized suggestion relevance lists are ignored.
1298 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
1299 { { "a", true }, { "a1", true }, { "a2", true }, kEmptyMatch },
1300 std::string() },
1301 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
1302 { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch },
1303 std::string() },
1304 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1305 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1306 "\"google:suggestrelevance\":[1]}]",
1307 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch },
1308 std::string() },
1309 { "[\"a\",[\"http://a1.com\"],[],[],"
1310 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1311 "\"google:suggestrelevance\":[9999, 1]}]",
1312 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch },
1313 std::string() },
1314
1315 // Ensure that all 'verbatim' results are merged with their maximum score.
1316 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1317 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1318 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch },
1319 "2" },
1320 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1321 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
1322 "\"google:verbatimrelevance\":0}]",
1323 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch },
1324 "2" },
1325
1326 // Ensure that verbatim is always generated without other suggestions.
1327 // TODO(msw): Ensure verbatimrelevance is respected (except suppression).
1328 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
1329 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1330 std::string() },
1331 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
1332 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1333 std::string() },
1334 };
1335
1336 // Must be the same as kBundledExperimentFieldTrialName
1337 // defined in omnibox_field_trial.cc.
1338 const std::string kTrialName = "OmniboxBundledExperimentV1";
1339 // Must be the same as kReorderForLegalDefaultMatchRule defined in
1340 // omnibox_field_trial.cc.
1341 const std::string kRuleName = "ReorderForLegalDefaultMatch";
1342 std::map<std::string, std::string> params;
1343 params[kRuleName + ":*"] = "ReorderForLegalDefaultMatch";
1344 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
1345 kTrialName, "A", params));
1346 base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
1347
1348 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1349 QueryForInput(ASCIIToUTF16("a"), false, false);
1350 net::TestURLFetcher* fetcher =
1351 test_factory_.GetFetcherByID(
1352 SearchProvider::kDefaultProviderURLFetcherID);
1353 ASSERT_TRUE(fetcher);
1354 fetcher->set_response_code(200);
1355 fetcher->SetResponseString(cases[i].json);
1356 fetcher->delegate()->OnURLFetchComplete(fetcher);
1357 RunTillProviderDone();
1358
1359 const std::string description = "for input with json=" + cases[i].json;
1360 const ACMatches& matches = provider_->matches();
1361 // The top match must inline and score as highly as calculated verbatim.
1362 ASSERT_FALSE(matches.empty());
1363 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
1364 matches[0].inline_autocompletion) << description;
1365
1366 size_t j = 0;
1367 // Ensure that the returned matches equal the expectations.
1368 for (; j < matches.size(); ++j) {
1369 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
1370 matches[j].contents) << description;
1371 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
1372 matches[j].allowed_to_be_default_match) << description;
1373 }
1374 // Ensure that no expected matches are missing.
1375 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1376 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) <<
1377 "Case # " << i << " " << description;
1378 }
1379 }
1055 1380
1056 // Verifies that suggest results with relevance scores are added 1381 // Verifies that suggest results with relevance scores are added
1057 // properly when using the keyword fetcher. This is similar to the 1382 // properly when using the keyword fetcher. This is similar to the
1058 // test DefaultFetcherSuggestRelevance above but this uses inputs that 1383 // test DefaultFetcherSuggestRelevance above but this uses inputs that
1059 // trigger keyword suggestions (i.e., "k a" rather than "a") and has 1384 // trigger keyword suggestions (i.e., "k a" rather than "a") and has
1060 // different expectations (because now the results are a mix of 1385 // different expectations (because now the results are a mix of
1061 // keyword suggestions and default provider suggestions). When a new 1386 // keyword suggestions and default provider suggestions). When a new
1062 // test is added to this TEST_F, please consider if it would be 1387 // test is added to this TEST_F, please consider if it would be
1063 // appropriate to add to DefaultFetcherSuggestRelevance as well. 1388 // appropriate to add to DefaultFetcherSuggestRelevance as well.
1064 TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) { 1389 TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
1390 struct KeywordFetcherMatch {
1391 std::string contents;
1392 bool from_keyword;
1393 bool allowed_to_be_default_match;
1394 };
1395 const KeywordFetcherMatch kEmptyMatch = { kNotApplicable, false, false };
1065 struct { 1396 struct {
1066 const std::string json; 1397 const std::string json;
1067 const struct { 1398 const KeywordFetcherMatch matches[5];
1068 const std::string contents;
1069 const bool from_keyword;
1070 } matches[5];
1071 const std::string inline_autocompletion; 1399 const std::string inline_autocompletion;
1072 } cases[] = { 1400 } cases[] = {
1073 // Ensure that suggest relevance scores reorder matches and that 1401 // Ensure that suggest relevance scores reorder matches and that
1074 // the keyword verbatim (lacking a suggested verbatim score) beats 1402 // the keyword verbatim (lacking a suggested verbatim score) beats
1075 // the default provider verbatim. 1403 // the default provider verbatim.
1076 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", 1404 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
1077 { { "a", true }, 1405 { { "a", true, true },
1078 { "k a", false }, 1406 { "k a", false, true },
1079 { "c", true }, 1407 { "c", true, false },
1080 { "b", true }, 1408 { "b", true, false },
1081 { kNotApplicable, false } }, 1409 kEmptyMatch },
1082 std::string() }, 1410 std::string() },
1083 // Again, check that relevance scores reorder matches, just this 1411 // Again, check that relevance scores reorder matches, just this
1084 // time with navigation matches. This also checks that with 1412 // time with navigation matches. This also checks that with
1085 // suggested relevance scores we allow multiple navsuggest results. 1413 // suggested relevance scores we allow multiple navsuggest results.
1086 // It's odd that navsuggest results that come from a keyword 1414 // It's odd that navsuggest results that come from a keyword
1087 // provider are marked as not a keyword result. I think this 1415 // provider are marked as not a keyword result. I think this
1088 // comes from them not going to a keyword search engine). 1416 // comes from them not going to a keyword search engine).
1089 // TODO(mpearson): Investigate the implications (if any) of 1417 // TODO(mpearson): Investigate the implications (if any) of
1090 // tagging these results appropriately. If so, do it because it 1418 // tagging these results appropriately. If so, do it because it
1091 // makes more sense. 1419 // makes more sense.
1092 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[]," 1420 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[],"
1093 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1421 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1094 "\"google:suggestrelevance\":[1301, 1302, 1303]}]", 1422 "\"google:suggestrelevance\":[1301, 1302, 1303]}]",
1095 { { "a", true }, 1423 { { "a", true, true },
1096 { "d", true }, 1424 { "d", true, false },
1097 { "c.com", false }, 1425 { "c.com", false, false },
1098 { "b.com", false }, 1426 { "b.com", false, false },
1099 { "k a", false }, }, 1427 { "k a", false, true }, },
1100 std::string() }, 1428 std::string() },
1101 1429
1102 // Without suggested relevance scores, we should only allow one 1430 // Without suggested relevance scores, we should only allow one
1103 // navsuggest result to be be displayed. 1431 // navsuggest result to be be displayed.
1104 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," 1432 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
1105 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", 1433 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]",
1106 { { "a", true }, 1434 { { "a", true, true },
1107 { "b.com", false }, 1435 { "b.com", false, false },
1108 { "k a", false }, 1436 { "k a", false, true },
1109 { kNotApplicable, false }, 1437 kEmptyMatch,
1110 { kNotApplicable, false } }, 1438 kEmptyMatch },
1111 std::string() }, 1439 std::string() },
1112 1440
1113 // Ensure that verbatimrelevance scores reorder or suppress verbatim. 1441 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
1114 // Negative values will have no effect; the calculated value will be used. 1442 // Negative values will have no effect; the calculated value will be used.
1115 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," 1443 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
1116 "\"google:suggestrelevance\":[9998]}]", 1444 "\"google:suggestrelevance\":[9998]}]",
1117 { { "a", true }, 1445 { { "a", true, true },
1118 { "a1", true }, 1446 { "a1", true, true },
1119 { "k a", false }, 1447 { "k a", false, true },
1120 { kNotApplicable, false }, 1448 kEmptyMatch,
1121 { kNotApplicable, false } }, 1449 kEmptyMatch },
1122 std::string() }, 1450 std::string() },
1123 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," 1451 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
1124 "\"google:suggestrelevance\":[9999]}]", 1452 "\"google:suggestrelevance\":[9999]}]",
1125 { { "a1", true }, 1453 { { "a1", true, true },
1126 { "a", true }, 1454 { "a", true, true },
1127 { "k a", false }, 1455 { "k a", false, true },
1128 { kNotApplicable, false }, 1456 kEmptyMatch,
1129 { kNotApplicable, false } }, 1457 kEmptyMatch },
1130 "1" }, 1458 "1" },
1131 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," 1459 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0,"
1132 "\"google:suggestrelevance\":[9999]}]", 1460 "\"google:suggestrelevance\":[9999]}]",
1133 { { "a1", true }, 1461 { { "a1", true, true },
1134 { "k a", false }, 1462 { "k a", false, true },
1135 { kNotApplicable, false }, 1463 kEmptyMatch,
1136 { kNotApplicable, false }, 1464 kEmptyMatch,
1137 { kNotApplicable, false } }, 1465 kEmptyMatch },
1138 "1" }, 1466 "1" },
1139 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," 1467 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1,"
1140 "\"google:suggestrelevance\":[9999]}]", 1468 "\"google:suggestrelevance\":[9999]}]",
1141 { { "a1", true }, 1469 { { "a1", true, true },
1142 { "a", true }, 1470 { "a", true, true },
1143 { "k a", false }, 1471 { "k a", false, true },
1144 { kNotApplicable, false }, 1472 kEmptyMatch,
1145 { kNotApplicable, false } }, 1473 kEmptyMatch },
1146 "1" }, 1474 "1" },
1147 { "[\"a\",[\"http://a.com\"],[],[]," 1475 { "[\"a\",[\"http://a.com\"],[],[],"
1148 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1476 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1149 "\"google:verbatimrelevance\":9999," 1477 "\"google:verbatimrelevance\":9999,"
1150 "\"google:suggestrelevance\":[9998]}]", 1478 "\"google:suggestrelevance\":[9998]}]",
1151 { { "a", true }, 1479 { { "a", true, true },
1152 { "a.com", false }, 1480 { "a.com", false, true },
1153 { "k a", false }, 1481 { "k a", false, true },
1154 { kNotApplicable, false }, 1482 kEmptyMatch,
1155 { kNotApplicable, false } }, 1483 kEmptyMatch },
1156 std::string() }, 1484 std::string() },
1157 1485
1158 // Ensure that both types of relevance scores reorder matches together. 1486 // Ensure that both types of relevance scores reorder matches together.
1159 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," 1487 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
1160 "\"google:verbatimrelevance\":9998}]", 1488 "\"google:verbatimrelevance\":9998}]",
1161 { { "a1", true }, 1489 { { "a1", true, true },
1162 { "a", true }, 1490 { "a", true, true },
1163 { "a2", true }, 1491 { "a2", true, true },
1164 { "k a", false }, 1492 { "k a", false, true },
1165 { kNotApplicable, false } }, 1493 kEmptyMatch },
1166 "1" }, 1494 "1" },
1167 1495
1168 // Ensure that only inlinable matches may be ranked as the highest result. 1496 // Ensure that only inlinable matches may be ranked as the highest result.
1169 // Ignore all suggested relevance scores if this constraint is violated. 1497 // Ignore all suggested relevance scores if this constraint is violated.
1170 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", 1498 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
1171 { { "a", true }, 1499 { { "a", true, true },
1172 { "b", true }, 1500 { "b", true, false },
1173 { "k a", false }, 1501 { "k a", false, true },
1174 { kNotApplicable, false }, 1502 kEmptyMatch,
1175 { kNotApplicable, false } }, 1503 kEmptyMatch },
1176 std::string() }, 1504 std::string() },
1177 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," 1505 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
1178 "\"google:verbatimrelevance\":0}]", 1506 "\"google:verbatimrelevance\":0}]",
1179 { { "a", true }, 1507 { { "a", true, true },
1180 { "b", true }, 1508 { "b", true, false },
1181 { "k a", false }, 1509 { "k a", false, true },
1182 { kNotApplicable, false }, 1510 kEmptyMatch,
1183 { kNotApplicable, false } }, 1511 kEmptyMatch },
1184 std::string() }, 1512 std::string() },
1185 { "[\"a\",[\"http://b.com\"],[],[]," 1513 { "[\"a\",[\"http://b.com\"],[],[],"
1186 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1514 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1187 "\"google:suggestrelevance\":[9999]}]", 1515 "\"google:suggestrelevance\":[9999]}]",
1188 { { "a", true }, 1516 { { "a", true, true },
1189 { "b.com", false }, 1517 { "b.com", false, false },
1190 { "k a", false }, 1518 { "k a", false, true },
1191 { kNotApplicable, false }, 1519 kEmptyMatch,
1192 { kNotApplicable, false } }, 1520 kEmptyMatch },
1193 std::string() }, 1521 std::string() },
1194 { "[\"a\",[\"http://b.com\"],[],[]," 1522 { "[\"a\",[\"http://b.com\"],[],[],"
1195 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1523 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1196 "\"google:suggestrelevance\":[9999]," 1524 "\"google:suggestrelevance\":[9999],"
1197 "\"google:verbatimrelevance\":0}]", 1525 "\"google:verbatimrelevance\":0}]",
1198 { { "a", true }, 1526 { { "a", true, true },
1199 { "b.com", false }, 1527 { "b.com", false, false },
1200 { "k a", false }, 1528 { "k a", false, true },
1201 { kNotApplicable, false }, 1529 kEmptyMatch,
1202 { kNotApplicable, false } }, 1530 kEmptyMatch },
1203 std::string() }, 1531 std::string() },
1204 1532
1205 // Ensure that the top result is ranked as highly as calculated verbatim. 1533 // Ensure that the top result is ranked as highly as calculated verbatim.
1206 // Ignore the suggested verbatim relevance if this constraint is violated. 1534 // Ignore the suggested verbatim relevance if this constraint is violated.
1207 // Note that keyword suggestions by default (not in suggested relevance 1535 // Note that keyword suggestions by default (not in suggested relevance
1208 // mode) score more highly than the default verbatim. 1536 // mode) score more highly than the default verbatim.
1209 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", 1537 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
1210 { { "a", true }, 1538 { { "a", true, true },
1211 { "a1", true }, 1539 { "a1", true, true },
1212 { "k a", false }, 1540 { "k a", false, true },
1213 { kNotApplicable, false }, 1541 kEmptyMatch,
1214 { kNotApplicable, false } }, 1542 kEmptyMatch },
1215 std::string() }, 1543 std::string() },
1216 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", 1544 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]",
1217 { { "a", true }, 1545 { { "a", true, true },
1218 { "a1", true }, 1546 { "a1", true, true },
1219 { "k a", false }, 1547 { "k a", false, true },
1220 { kNotApplicable, false }, 1548 kEmptyMatch,
1221 { kNotApplicable, false } }, 1549 kEmptyMatch },
1222 std::string() }, 1550 std::string() },
1223 // Continuing the same category of tests, but make sure we keep the 1551 // Continuing the same category of tests, but make sure we keep the
1224 // suggested relevance scores even as we discard the verbatim relevance 1552 // suggested relevance scores even as we discard the verbatim relevance
1225 // scores. 1553 // scores.
1226 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," 1554 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1],"
1227 "\"google:verbatimrelevance\":0}]", 1555 "\"google:verbatimrelevance\":0}]",
1228 { { "a", true }, 1556 { { "a", true, true },
1229 { "k a", false }, 1557 { "k a", false, true },
1230 { "a1", true }, 1558 { "a1", true, true },
1231 { kNotApplicable, false }, 1559 kEmptyMatch,
1232 { kNotApplicable, false } }, 1560 kEmptyMatch },
1233 std::string() }, 1561 std::string() },
1234 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," 1562 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2],"
1235 "\"google:verbatimrelevance\":0}]", 1563 "\"google:verbatimrelevance\":0}]",
1236 { { "a", true }, 1564 { { "a", true, true },
1237 { "k a", false }, 1565 { "k a", false, true },
1238 { "a2", true }, 1566 { "a2", true, true },
1239 { "a1", true }, 1567 { "a1", true, true },
1240 { kNotApplicable, false } }, 1568 kEmptyMatch },
1241 std::string() }, 1569 std::string() },
1242 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," 1570 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3],"
1243 "\"google:verbatimrelevance\":2}]", 1571 "\"google:verbatimrelevance\":2}]",
1244 { { "a", true }, 1572 { { "a", true, true },
1245 { "k a", false }, 1573 { "k a", false, true },
1246 { "a2", true }, 1574 { "a2", true, true },
1247 { "a1", true }, 1575 { "a1", true, true },
1248 { kNotApplicable, false } }, 1576 kEmptyMatch },
1249 std::string() }, 1577 std::string() },
1250 1578
1251 // Ensure that all suggestions are considered, regardless of order. 1579 // Ensure that all suggestions are considered, regardless of order.
1252 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," 1580 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
1253 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1581 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
1254 { { "a", true }, 1582 { { "a", true, true },
1255 { "k a", false }, 1583 { "k a", false, true },
1256 { "h", true }, 1584 { "h", true, false },
1257 { "g", true }, 1585 { "g", true, false },
1258 { "f", true } }, 1586 { "f", true, false } },
1259 std::string() }, 1587 std::string() },
1260 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," 1588 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
1261 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," 1589 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
1262 "\"http://h.com\"],[],[]," 1590 "\"http://h.com\"],[],[],"
1263 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," 1591 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
1264 "\"NAVIGATION\", \"NAVIGATION\"," 1592 "\"NAVIGATION\", \"NAVIGATION\","
1265 "\"NAVIGATION\", \"NAVIGATION\"," 1593 "\"NAVIGATION\", \"NAVIGATION\","
1266 "\"NAVIGATION\"]," 1594 "\"NAVIGATION\"],"
1267 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1595 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
1268 { { "a", true }, 1596 { { "a", true, true },
1269 { "k a", false }, 1597 { "k a", false, true },
1270 { "h.com", false }, 1598 { "h.com", false, false },
1271 { "g.com", false }, 1599 { "g.com", false, false },
1272 { "f.com", false } }, 1600 { "f.com", false, false } },
1273 std::string() }, 1601 std::string() },
1274 1602
1275 // Ensure that incorrectly sized suggestion relevance lists are ignored. 1603 // Ensure that incorrectly sized suggestion relevance lists are ignored.
1276 // Note that keyword suggestions by default (not in suggested relevance 1604 // Note that keyword suggestions by default (not in suggested relevance
1277 // mode) score more highly than the default verbatim. 1605 // mode) score more highly than the default verbatim.
1278 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", 1606 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
1279 { { "a", true }, 1607 { { "a", true, true },
1280 { "a1", true }, 1608 { "a1", true, true },
1281 { "a2", true }, 1609 { "a2", true, true },
1282 { "k a", false }, 1610 { "k a", false, true },
1283 { kNotApplicable, false } }, 1611 kEmptyMatch },
1284 std::string() }, 1612 std::string() },
1285 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", 1613 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
1286 { { "a", true }, 1614 { { "a", true, true },
1287 { "a1", true }, 1615 { "a1", true, true },
1288 { "k a", false }, 1616 { "k a", false, true },
1289 { kNotApplicable, false }, 1617 kEmptyMatch,
1290 { kNotApplicable, false } }, 1618 kEmptyMatch },
1291 std::string() }, 1619 std::string() },
1292 // In this case, ignored the suggested relevance scores means we keep 1620 // In this case, ignored the suggested relevance scores means we keep
1293 // only one navsuggest result. 1621 // only one navsuggest result.
1294 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1622 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1295 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1623 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1296 "\"google:suggestrelevance\":[1]}]", 1624 "\"google:suggestrelevance\":[1]}]",
1297 { { "a", true }, 1625 { { "a", true, true },
1298 { "a1.com", false }, 1626 { "a1.com", false, true },
1299 { "k a", false }, 1627 { "k a", false, true },
1300 { kNotApplicable, false }, 1628 kEmptyMatch,
1301 { kNotApplicable, false } }, 1629 kEmptyMatch },
1302 std::string() }, 1630 std::string() },
1303 { "[\"a\",[\"http://a1.com\"],[],[]," 1631 { "[\"a\",[\"http://a1.com\"],[],[],"
1304 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1632 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1305 "\"google:suggestrelevance\":[9999, 1]}]", 1633 "\"google:suggestrelevance\":[9999, 1]}]",
1306 { { "a", true }, 1634 { { "a", true, true },
1307 { "a1.com", false }, 1635 { "a1.com", false, true },
1308 { "k a", false }, 1636 { "k a", false, true },
1309 { kNotApplicable, false }, 1637 kEmptyMatch,
1310 { kNotApplicable, false } }, 1638 kEmptyMatch },
1311 std::string() }, 1639 std::string() },
1312 1640
1313 // Ensure that all 'verbatim' results are merged with their maximum score. 1641 // Ensure that all 'verbatim' results are merged with their maximum score.
1314 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1642 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1315 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1643 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1316 { { "a2", true }, 1644 { { "a2", true, true },
1317 { "a", true }, 1645 { "a", true, true },
1318 { "a1", true }, 1646 { "a1", true, true },
1319 { "k a", false }, 1647 { "k a", false, true },
1320 { kNotApplicable, false } }, 1648 kEmptyMatch },
1321 "2" }, 1649 "2" },
1322 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1650 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1323 "{\"google:suggestrelevance\":[9998, 9997, 9999]," 1651 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
1324 "\"google:verbatimrelevance\":0}]", 1652 "\"google:verbatimrelevance\":0}]",
1325 { { "a2", true }, 1653 { { "a2", true, true },
1326 { "a", true }, 1654 { "a", true, true },
1327 { "a1", true }, 1655 { "a1", true, true },
1328 { "k a", false }, 1656 { "k a", false, true },
1329 { kNotApplicable, false } }, 1657 kEmptyMatch },
1330 "2" }, 1658 "2" },
1331 1659
1332 // Ensure that verbatim is always generated without other suggestions. 1660 // Ensure that verbatim is always generated without other suggestions.
1333 // TODO(mpearson): Ensure the value of verbatimrelevance is respected 1661 // TODO(mpearson): Ensure the value of verbatimrelevance is respected
1334 // (except when suggested relevances are ignored). 1662 // (except when suggested relevances are ignored).
1335 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", 1663 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
1336 { { "a", true }, 1664 { { "a", true, true },
1337 { "k a", false }, 1665 { "k a", false, true },
1338 { kNotApplicable, false }, 1666 kEmptyMatch,
1339 { kNotApplicable, false }, 1667 kEmptyMatch,
1340 { kNotApplicable, false } }, 1668 kEmptyMatch },
1341 std::string() }, 1669 std::string() },
1342 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", 1670 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
1343 { { "a", true }, 1671 { { "a", true, true },
1344 { "k a", false }, 1672 { "k a", false, true },
1345 { kNotApplicable, false }, 1673 kEmptyMatch,
1346 { kNotApplicable, false }, 1674 kEmptyMatch,
1347 { kNotApplicable, false } }, 1675 kEmptyMatch },
1348 std::string() }, 1676 std::string() },
1349 1677
1350 // Check that navsuggestions will be demoted below queries. 1678 // Check that navsuggestions will be demoted below queries.
1351 // (Navsuggestions are not allowed to appear first.) In the process, 1679 // (Navsuggestions are not allowed to appear first.) In the process,
1352 // make sure the navsuggestions still remain in the same order. 1680 // make sure the navsuggestions still remain in the same order.
1353 // First, check the situation where navsuggest scores more than verbatim 1681 // First, check the situation where navsuggest scores more than verbatim
1354 // and there are no query suggestions. 1682 // and there are no query suggestions.
1355 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1683 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1356 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1684 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1357 "\"google:verbatimrelevance\":9990," 1685 "\"google:verbatimrelevance\":9990,"
1358 "\"google:suggestrelevance\":[9998, 9999]}]", 1686 "\"google:suggestrelevance\":[9998, 9999]}]",
1359 { { "a", true }, 1687 { { "a", true, true },
1360 { "a2.com", false }, 1688 { "a2.com", false, true },
1361 { "a1.com", false }, 1689 { "a1.com", false, true },
1362 { "k a", false }, 1690 { "k a", false, true },
1363 { kNotApplicable, false } }, 1691 kEmptyMatch },
1364 std::string() }, 1692 std::string() },
1365 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1693 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1366 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1694 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1367 "\"google:verbatimrelevance\":9990," 1695 "\"google:verbatimrelevance\":9990,"
1368 "\"google:suggestrelevance\":[9999, 9998]}]", 1696 "\"google:suggestrelevance\":[9999, 9998]}]",
1369 { { "a", true }, 1697 { { "a", true, true },
1370 { "a1.com", false }, 1698 { "a1.com", false, true },
1371 { "a2.com", false }, 1699 { "a2.com", false, true },
1372 { "k a", false }, 1700 { "k a", false, true },
1373 { kNotApplicable, false } }, 1701 kEmptyMatch },
1374 std::string() }, 1702 std::string() },
1375 // Check when navsuggest scores more than verbatim and there is query 1703 // Check when navsuggest scores more than verbatim and there is query
1376 // suggestion but it scores lower. 1704 // suggestion but it scores lower.
1377 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1705 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1378 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1706 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1379 "\"google:verbatimrelevance\":9990," 1707 "\"google:verbatimrelevance\":9990,"
1380 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", 1708 "\"google:suggestrelevance\":[9998, 9999, 1300]}]",
1381 { { "a", true }, 1709 { { "a", true, true },
1382 { "a2.com", false }, 1710 { "a2.com", false, true },
1383 { "a1.com", false }, 1711 { "a1.com", false, true },
1384 { "a3", true }, 1712 { "a3", true, true },
1385 { "k a", false } }, 1713 { "k a", false, true } },
1386 std::string() }, 1714 std::string() },
1387 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1715 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1388 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1716 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1389 "\"google:verbatimrelevance\":9990," 1717 "\"google:verbatimrelevance\":9990,"
1390 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", 1718 "\"google:suggestrelevance\":[9999, 9998, 1300]}]",
1391 { { "a", true }, 1719 { { "a", true, true },
1392 { "a1.com", false }, 1720 { "a1.com", false, true },
1393 { "a2.com", false }, 1721 { "a2.com", false, true },
1394 { "a3", true }, 1722 { "a3", true, true },
1395 { "k a", false } }, 1723 { "k a", false, true } },
1396 std::string() }, 1724 std::string() },
1397 // Check when navsuggest scores more than a query suggestion. There is 1725 // Check when navsuggest scores more than a query suggestion. There is
1398 // a verbatim but it scores lower. 1726 // a verbatim but it scores lower.
1399 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1727 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1400 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1728 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1401 "\"google:verbatimrelevance\":9990," 1729 "\"google:verbatimrelevance\":9990,"
1402 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 1730 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
1403 { { "a3", true }, 1731 { { "a3", true, true },
1404 { "a2.com", false }, 1732 { "a2.com", false, true },
1405 { "a1.com", false }, 1733 { "a1.com", false, true },
1406 { "a", true }, 1734 { "a", true, true },
1407 { "k a", false } }, 1735 { "k a", false, true } },
1408 "3" }, 1736 "3" },
1409 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1737 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1410 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1738 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1411 "\"google:verbatimrelevance\":9990," 1739 "\"google:verbatimrelevance\":9990,"
1412 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 1740 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
1413 { { "a3", true }, 1741 { { "a3", true, true },
1414 { "a1.com", false }, 1742 { "a1.com", false, true },
1415 { "a2.com", false }, 1743 { "a2.com", false, true },
1416 { "a", true }, 1744 { "a", true, true },
1417 { "k a", false } }, 1745 { "k a", false, true } },
1418 "3" }, 1746 "3" },
1419 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1747 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1420 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1748 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1421 "\"google:verbatimrelevance\":0," 1749 "\"google:verbatimrelevance\":0,"
1422 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 1750 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
1423 { { "a3", true }, 1751 { { "a3", true, true },
1424 { "a2.com", false }, 1752 { "a2.com", false, true },
1425 { "a1.com", false }, 1753 { "a1.com", false, true },
1426 { "k a", false }, 1754 { "k a", false, true },
1427 { kNotApplicable, false } }, 1755 kEmptyMatch },
1428 "3" }, 1756 "3" },
1429 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1757 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1430 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1758 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1431 "\"google:verbatimrelevance\":0," 1759 "\"google:verbatimrelevance\":0,"
1432 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 1760 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
1433 { { "a3", true }, 1761 { { "a3", true, true },
1434 { "a1.com", false }, 1762 { "a1.com", false, true },
1435 { "a2.com", false }, 1763 { "a2.com", false, true },
1436 { "k a", false }, 1764 { "k a", false, true },
1437 { kNotApplicable, false } }, 1765 kEmptyMatch },
1438 "3" }, 1766 "3" },
1439 // Check when there is neither verbatim nor a query suggestion that, 1767 // Check when there is neither verbatim nor a query suggestion that,
1440 // because we can't demote navsuggestions below a query suggestion, 1768 // because we can't demote navsuggestions below a query suggestion,
1441 // we abandon suggested relevance scores entirely. One consequence is 1769 // we abandon suggested relevance scores entirely. One consequence is
1442 // that this means we restore the keyword verbatim match. Note 1770 // that this means we restore the keyword verbatim match. Note
1443 // that in this case of abandoning suggested relevance scores, we still 1771 // that in this case of abandoning suggested relevance scores, we still
1444 // keep the navsuggestions in the same order, but we revert to only allowing 1772 // keep the navsuggestions in the same order, but we revert to only allowing
1445 // one navigation to appear because the scores are completely local. 1773 // one navigation to appear because the scores are completely local.
1446 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1774 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1447 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1775 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1448 "\"google:verbatimrelevance\":0," 1776 "\"google:verbatimrelevance\":0,"
1449 "\"google:suggestrelevance\":[9998, 9999]}]", 1777 "\"google:suggestrelevance\":[9998, 9999]}]",
1450 { { "a", true }, 1778 { { "a", true, true },
1451 { "a2.com", false }, 1779 { "a2.com", false, true },
1452 { "k a", false }, 1780 { "k a", false, true },
1453 { kNotApplicable, false }, 1781 kEmptyMatch,
1454 { kNotApplicable, false } }, 1782 kEmptyMatch },
1455 std::string() }, 1783 std::string() },
1456 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1784 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1457 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1785 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1458 "\"google:verbatimrelevance\":0," 1786 "\"google:verbatimrelevance\":0,"
1459 "\"google:suggestrelevance\":[9999, 9998]}]", 1787 "\"google:suggestrelevance\":[9999, 9998]}]",
1460 { { "a", true }, 1788 { { "a", true, true },
1461 { "a1.com", false }, 1789 { "a1.com", false, true },
1462 { "k a", false }, 1790 { "k a", false, true },
1463 { kNotApplicable, false }, 1791 kEmptyMatch,
1464 { kNotApplicable, false } }, 1792 kEmptyMatch },
1465 std::string() }, 1793 std::string() },
1466 // More checks that everything works when it's not necessary to demote. 1794 // More checks that everything works when it's not necessary to demote.
1467 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1795 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1468 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1796 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1469 "\"google:verbatimrelevance\":9990," 1797 "\"google:verbatimrelevance\":9990,"
1470 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", 1798 "\"google:suggestrelevance\":[9997, 9998, 9999]}]",
1471 { { "a3", true }, 1799 { { "a3", true, true },
1472 { "a2.com", false }, 1800 { "a2.com", false, true },
1473 { "a1.com", false }, 1801 { "a1.com", false, true },
1474 { "a", true }, 1802 { "a", true, true },
1475 { "k a", false } }, 1803 { "k a", false, true } },
1476 "3" }, 1804 "3" },
1477 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1805 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1478 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1806 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1479 "\"google:verbatimrelevance\":9990," 1807 "\"google:verbatimrelevance\":9990,"
1480 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1808 "\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1481 { { "a3", true }, 1809 { { "a3", true, true },
1482 { "a1.com", false }, 1810 { "a1.com", false, true },
1483 { "a2.com", false }, 1811 { "a2.com", false, true },
1484 { "a", true }, 1812 { "a", true, true },
1485 { "k a", false } }, 1813 { "k a", false, true } },
1486 "3" }, 1814 "3" },
1487 }; 1815 };
1488 1816
1489 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1817 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1490 QueryForInput(ASCIIToUTF16("k a"), false, true); 1818 QueryForInput(ASCIIToUTF16("k a"), false, true);
1491 1819
1492 // Set up a default fetcher with no results. 1820 // Set up a default fetcher with no results.
1493 net::TestURLFetcher* default_fetcher = 1821 net::TestURLFetcher* default_fetcher =
1494 test_factory_.GetFetcherByID( 1822 test_factory_.GetFetcherByID(
1495 SearchProvider::kDefaultProviderURLFetcherID); 1823 SearchProvider::kDefaultProviderURLFetcherID);
(...skipping 21 matching lines...) Expand all
1517 matches[0].inline_autocompletion) << description; 1845 matches[0].inline_autocompletion) << description;
1518 EXPECT_GE(matches[0].relevance, 1300) << description; 1846 EXPECT_GE(matches[0].relevance, 1300) << description;
1519 1847
1520 size_t j = 0; 1848 size_t j = 0;
1521 // Ensure that the returned matches equal the expectations. 1849 // Ensure that the returned matches equal the expectations.
1522 for (; j < matches.size(); ++j) { 1850 for (; j < matches.size(); ++j) {
1523 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), 1851 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
1524 matches[j].contents) << description; 1852 matches[j].contents) << description;
1525 EXPECT_EQ(cases[i].matches[j].from_keyword, 1853 EXPECT_EQ(cases[i].matches[j].from_keyword,
1526 matches[j].keyword == ASCIIToUTF16("k")) << description; 1854 matches[j].keyword == ASCIIToUTF16("k")) << description;
1855 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
1856 matches[j].allowed_to_be_default_match) << description;
1527 } 1857 }
1528 // Ensure that no expected matches are missing. 1858 // Ensure that no expected matches are missing.
1529 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 1859 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1530 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << 1860 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) <<
1531 "Case # " << i << " " << description; 1861 "Case # " << i << " " << description;
1532 } 1862 }
1533 } 1863 }
1534 1864
1535 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { 1865 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
1536 // Enable Instant Extended in order to allow an increased number of 1866 // Enable Instant Extended in order to allow an increased number of
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 matches[j].contents) << description; 1964 matches[j].contents) << description;
1635 // Ensure that no expected matches are missing. 1965 // Ensure that no expected matches are missing.
1636 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) 1966 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
1637 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) << 1967 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) <<
1638 "Case # " << i << " " << description; 1968 "Case # " << i << " " << description;
1639 } 1969 }
1640 } 1970 }
1641 1971
1642 // Verifies suggest relevance behavior for URL input. 1972 // Verifies suggest relevance behavior for URL input.
1643 TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) { 1973 TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) {
1974 struct DefaultFetcherUrlInputMatch {
1975 const std::string match_contents;
1976 AutocompleteMatch::Type match_type;
1977 bool allowed_to_be_default_match;
1978 };
1979 const DefaultFetcherUrlInputMatch kEmptyMatch =
1980 { kNotApplicable, AutocompleteMatchType::NUM_TYPES, false };
1644 struct { 1981 struct {
1645 const std::string input; 1982 const std::string input;
1646 const std::string json; 1983 const std::string json;
1647 const std::string match_contents[4]; 1984 const DefaultFetcherUrlInputMatch output[4];
1648 const AutocompleteMatch::Type match_types[4];
1649 } cases[] = { 1985 } cases[] = {
1650 // Ensure topmost NAVIGATION matches are allowed for URL input. 1986 // Ensure topmost NAVIGATION matches are allowed for URL input.
1651 { "a.com", "[\"a.com\",[\"http://a.com/a\"],[],[]," 1987 { "a.com", "[\"a.com\",[\"http://a.com/a\"],[],[],"
1652 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1988 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1653 "\"google:suggestrelevance\":[9999]}]", 1989 "\"google:suggestrelevance\":[9999]}]",
1654 { "a.com/a", "a.com", kNotApplicable, kNotApplicable }, 1990 { { "a.com/a", AutocompleteMatchType::NAVSUGGEST, true },
1655 { AutocompleteMatchType::NAVSUGGEST, 1991 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
1656 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 1992 kEmptyMatch, kEmptyMatch } },
1657 AutocompleteMatchType::NUM_TYPES,
1658 AutocompleteMatchType::NUM_TYPES } },
1659 1993
1660 // Ensure topmost SUGGEST matches are not allowed for URL input. 1994 // Ensure topmost SUGGEST matches are not allowed for URL input.
1661 // SearchProvider disregards search and verbatim suggested relevances. 1995 // SearchProvider disregards search and verbatim suggested relevances.
1662 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," 1996 { "a.com", "[\"a.com\",[\"a.com info\"],[],[],"
1663 "{\"google:suggestrelevance\":[9999]}]", 1997 "{\"google:suggestrelevance\":[9999]}]",
1664 { "a.com", "a.com info", kNotApplicable, kNotApplicable }, 1998 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
1665 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 1999 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true },
1666 AutocompleteMatchType::SEARCH_SUGGEST, 2000 kEmptyMatch,
1667 AutocompleteMatchType::NUM_TYPES, AutocompleteMatchType::NUM_TYPES } }, 2001 kEmptyMatch } },
1668 { "a.com", "[\"a.com\",[\"a.com/a\"],[],[]," 2002 { "a.com", "[\"a.com\",[\"a.com/a\"],[],[],"
1669 "{\"google:suggestrelevance\":[9999]}]", 2003 "{\"google:suggestrelevance\":[9999]}]",
1670 { "a.com", "a.com/a", kNotApplicable, kNotApplicable }, 2004 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
1671 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 2005 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true },
1672 AutocompleteMatchType::SEARCH_SUGGEST, 2006 kEmptyMatch, kEmptyMatch } },
1673 AutocompleteMatchType::NUM_TYPES, AutocompleteMatchType::NUM_TYPES } },
1674 2007
1675 // Ensure the fallback mechanism allows inlinable NAVIGATION matches. 2008 // Ensure the fallback mechanism allows inlinable NAVIGATION matches.
1676 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://a.com/b\"],[],[]," 2009 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://a.com/b\"],[],[],"
1677 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 2010 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
1678 "\"google:suggestrelevance\":[9999, 9998]}]", 2011 "\"google:suggestrelevance\":[9999, 9998]}]",
1679 { "a.com/b", "a.com", "a.com/a", kNotApplicable }, 2012 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true },
1680 { AutocompleteMatchType::NAVSUGGEST, 2013 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
1681 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 2014 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true },
1682 AutocompleteMatchType::SEARCH_SUGGEST, 2015 kEmptyMatch } },
1683 AutocompleteMatchType::NUM_TYPES } },
1684 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://a.com/b\"],[],[]," 2016 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://a.com/b\"],[],[],"
1685 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 2017 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
1686 "\"google:suggestrelevance\":[9998, 9997]," 2018 "\"google:suggestrelevance\":[9998, 9997],"
1687 "\"google:verbatimrelevance\":9999}]", 2019 "\"google:verbatimrelevance\":9999}]",
1688 { "a.com/b", "a.com", "a.com/a", kNotApplicable }, 2020 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true },
1689 { AutocompleteMatchType::NAVSUGGEST, 2021 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
1690 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 2022 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true },
1691 AutocompleteMatchType::SEARCH_SUGGEST, 2023 kEmptyMatch } },
1692 AutocompleteMatchType::NUM_TYPES } },
1693 2024
1694 // Ensure the fallback mechanism disallows non-inlinable NAVIGATION matches. 2025 // Ensure the fallback mechanism disallows non-inlinable NAVIGATION matches.
1695 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://abc.com\"],[],[]," 2026 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://abc.com\"],[],[],"
1696 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 2027 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
1697 "\"google:suggestrelevance\":[9999, 9998]}]", 2028 "\"google:suggestrelevance\":[9999, 9998]}]",
1698 { "a.com", "abc.com", "a.com/a", kNotApplicable }, 2029 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
1699 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 2030 { "abc.com", AutocompleteMatchType::NAVSUGGEST, false },
1700 AutocompleteMatchType::NAVSUGGEST, 2031 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true },
1701 AutocompleteMatchType::SEARCH_SUGGEST, 2032 kEmptyMatch } },
1702 AutocompleteMatchType::NUM_TYPES } },
1703 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://abc.com\"],[],[]," 2033 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://abc.com\"],[],[],"
1704 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," 2034 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"],"
1705 "\"google:suggestrelevance\":[9998, 9997]," 2035 "\"google:suggestrelevance\":[9998, 9997],"
1706 "\"google:verbatimrelevance\":9999}]", 2036 "\"google:verbatimrelevance\":9999}]",
1707 { "a.com", "abc.com", "a.com/a", kNotApplicable }, 2037 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true },
1708 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 2038 { "abc.com", AutocompleteMatchType::NAVSUGGEST, false },
1709 AutocompleteMatchType::NAVSUGGEST, 2039 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true },
1710 AutocompleteMatchType::SEARCH_SUGGEST, 2040 kEmptyMatch } },
1711 AutocompleteMatchType::NUM_TYPES } },
1712 }; 2041 };
1713 2042
1714 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2043 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1715 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); 2044 QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
1716 net::TestURLFetcher* fetcher = 2045 net::TestURLFetcher* fetcher =
1717 test_factory_.GetFetcherByID( 2046 test_factory_.GetFetcherByID(
1718 SearchProvider::kDefaultProviderURLFetcherID); 2047 SearchProvider::kDefaultProviderURLFetcherID);
1719 ASSERT_TRUE(fetcher); 2048 ASSERT_TRUE(fetcher);
1720 fetcher->set_response_code(200); 2049 fetcher->set_response_code(200);
1721 fetcher->SetResponseString(cases[i].json); 2050 fetcher->SetResponseString(cases[i].json);
1722 fetcher->delegate()->OnURLFetchComplete(fetcher); 2051 fetcher->delegate()->OnURLFetchComplete(fetcher);
1723 RunTillProviderDone(); 2052 RunTillProviderDone();
1724 2053
1725 size_t j = 0; 2054 size_t j = 0;
1726 const ACMatches& matches = provider_->matches(); 2055 const ACMatches& matches = provider_->matches();
1727 // Ensure that the returned matches equal the expectations. 2056 // Ensure that the returned matches equal the expectations.
1728 for (; j < matches.size(); ++j) { 2057 for (; j < matches.size(); ++j) {
1729 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents[j]), matches[j].contents); 2058 EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents),
1730 EXPECT_EQ(cases[i].match_types[j], matches[j].type); 2059 matches[j].contents);
2060 EXPECT_EQ(cases[i].output[j].match_type, matches[j].type);
2061 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match,
2062 matches[j].allowed_to_be_default_match);
1731 } 2063 }
1732 // Ensure that no expected matches are missing. 2064 // Ensure that no expected matches are missing.
1733 for (; j < ARRAYSIZE_UNSAFE(cases[i].match_contents); ++j) { 2065 for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) {
1734 EXPECT_EQ(kNotApplicable, cases[i].match_contents[j]); 2066 EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents);
1735 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES, cases[i].match_types[j]); 2067 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES,
2068 cases[i].output[j].match_type);
2069 EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match);
1736 } 2070 }
1737 } 2071 }
1738 } 2072 }
1739 2073
1740 // A basic test that verifies the field trial triggered parsing logic. 2074 // A basic test that verifies the field trial triggered parsing logic.
1741 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) { 2075 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) {
1742 QueryForInput(ASCIIToUTF16("foo"), false, false); 2076 QueryForInput(ASCIIToUTF16("foo"), false, false);
1743 2077
1744 // Make sure the default providers suggest service was queried. 2078 // Make sure the default providers suggest service was queried.
1745 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 2079 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 2115
1782 // Verifies inline autocompletion of navigational results. 2116 // Verifies inline autocompletion of navigational results.
1783 TEST_F(SearchProviderTest, NavigationInline) { 2117 TEST_F(SearchProviderTest, NavigationInline) {
1784 struct { 2118 struct {
1785 const std::string input; 2119 const std::string input;
1786 const std::string url; 2120 const std::string url;
1787 // Test the expected fill_into_edit, which may drop "http://". 2121 // Test the expected fill_into_edit, which may drop "http://".
1788 // Some cases do not trim "http://" to match from the start of the scheme. 2122 // Some cases do not trim "http://" to match from the start of the scheme.
1789 const std::string fill_into_edit; 2123 const std::string fill_into_edit;
1790 const std::string inline_autocompletion; 2124 const std::string inline_autocompletion;
2125 const bool allowed_to_be_default_match;
1791 } cases[] = { 2126 } cases[] = {
1792 // Do not inline matches that do not contain the input; trim http as needed. 2127 // Do not inline matches that do not contain the input; trim http as needed.
1793 { "x", "http://www.abc.com", 2128 { "x", "http://www.abc.com",
1794 "www.abc.com", std::string() }, 2129 "www.abc.com", std::string(), false },
1795 { "https:", "http://www.abc.com", 2130 { "https:", "http://www.abc.com",
1796 "www.abc.com", std::string() }, 2131 "www.abc.com", std::string(), false },
1797 { "abc.com/", "http://www.abc.com", 2132 { "abc.com/", "http://www.abc.com",
1798 "www.abc.com", std::string() }, 2133 "www.abc.com", std::string(), false },
1799 { "http://www.abc.com/a", "http://www.abc.com", 2134 { "http://www.abc.com/a", "http://www.abc.com",
1800 "http://www.abc.com", std::string() }, 2135 "http://www.abc.com", std::string(), false },
1801 { "http://www.abc.com", "https://www.abc.com", 2136 { "http://www.abc.com", "https://www.abc.com",
1802 "https://www.abc.com", std::string() }, 2137 "https://www.abc.com", std::string(), false },
1803 { "http://abc.com", "ftp://abc.com", 2138 { "http://abc.com", "ftp://abc.com",
1804 "ftp://abc.com", std::string() }, 2139 "ftp://abc.com", std::string(), false },
1805 { "https://www.abc.com", "http://www.abc.com", 2140 { "https://www.abc.com", "http://www.abc.com",
1806 "www.abc.com", std::string() }, 2141 "www.abc.com", std::string(), false },
1807 { "ftp://abc.com", "http://abc.com", 2142 { "ftp://abc.com", "http://abc.com",
1808 "abc.com", std::string() }, 2143 "abc.com", std::string(), false },
1809 2144
1810 // Do not inline matches with invalid input prefixes; trim http as needed. 2145 // Do not inline matches with invalid input prefixes; trim http as needed.
1811 { "ttp", "http://www.abc.com", 2146 { "ttp", "http://www.abc.com",
1812 "www.abc.com", std::string() }, 2147 "www.abc.com", std::string(), false },
1813 { "://w", "http://www.abc.com", 2148 { "://w", "http://www.abc.com",
1814 "www.abc.com", std::string() }, 2149 "www.abc.com", std::string(), false },
1815 { "ww.", "http://www.abc.com", 2150 { "ww.", "http://www.abc.com",
1816 "www.abc.com", std::string() }, 2151 "www.abc.com", std::string(), false },
1817 { ".ab", "http://www.abc.com", 2152 { ".ab", "http://www.abc.com",
1818 "www.abc.com", std::string() }, 2153 "www.abc.com", std::string(), false },
1819 { "bc", "http://www.abc.com", 2154 { "bc", "http://www.abc.com",
1820 "www.abc.com", std::string() }, 2155 "www.abc.com", std::string(), false },
1821 { ".com", "http://www.abc.com", 2156 { ".com", "http://www.abc.com",
1822 "www.abc.com", std::string() }, 2157 "www.abc.com", std::string(), false },
1823 2158
1824 // Do not inline matches that omit input domain labels; trim http as needed. 2159 // Do not inline matches that omit input domain labels; trim http as needed.
1825 { "www.a", "http://a.com", 2160 { "www.a", "http://a.com",
1826 "a.com", std::string() }, 2161 "a.com", std::string(), false },
1827 { "http://www.a", "http://a.com", 2162 { "http://www.a", "http://a.com",
1828 "http://a.com", std::string() }, 2163 "http://a.com", std::string(), false },
1829 { "www.a", "ftp://a.com", 2164 { "www.a", "ftp://a.com",
1830 "ftp://a.com", std::string() }, 2165 "ftp://a.com", std::string(), false },
1831 { "ftp://www.a", "ftp://a.com", 2166 { "ftp://www.a", "ftp://a.com",
1832 "ftp://a.com", std::string() }, 2167 "ftp://a.com", std::string(), false },
1833 2168
1834 // Input matching but with nothing to inline will not yield an offset. 2169 // Input matching but with nothing to inline will not yield an offset.
1835 { "abc.com", "http://www.abc.com", 2170 { "abc.com", "http://www.abc.com",
1836 "www.abc.com", std::string() }, 2171 "www.abc.com", std::string(), false },
1837 { "http://www.abc.com", "http://www.abc.com", 2172 { "http://www.abc.com", "http://www.abc.com",
1838 "http://www.abc.com", std::string() }, 2173 "http://www.abc.com", std::string(), false },
1839 2174
1840 // Inline matches when the input is a leading substring of the scheme. 2175 // Inline matches when the input is a leading substring of the scheme.
1841 { "h", "http://www.abc.com", 2176 { "h", "http://www.abc.com",
1842 "http://www.abc.com", "ttp://www.abc.com" }, 2177 "http://www.abc.com", "ttp://www.abc.com", true },
1843 { "http", "http://www.abc.com", 2178 { "http", "http://www.abc.com",
1844 "http://www.abc.com", "://www.abc.com" }, 2179 "http://www.abc.com", "://www.abc.com", true },
1845 2180
1846 // Inline matches when the input is a leading substring of the full URL. 2181 // Inline matches when the input is a leading substring of the full URL.
1847 { "http:", "http://www.abc.com", 2182 { "http:", "http://www.abc.com",
1848 "http://www.abc.com", "//www.abc.com" }, 2183 "http://www.abc.com", "//www.abc.com", true },
1849 { "http://w", "http://www.abc.com", 2184 { "http://w", "http://www.abc.com",
1850 "http://www.abc.com", "ww.abc.com" }, 2185 "http://www.abc.com", "ww.abc.com", true },
1851 { "http://www.", "http://www.abc.com", 2186 { "http://www.", "http://www.abc.com",
1852 "http://www.abc.com", "abc.com" }, 2187 "http://www.abc.com", "abc.com", true },
1853 { "http://www.ab", "http://www.abc.com", 2188 { "http://www.ab", "http://www.abc.com",
1854 "http://www.abc.com", "c.com" }, 2189 "http://www.abc.com", "c.com", true },
1855 { "http://www.abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", 2190 { "http://www.abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo",
1856 "http://www.abc.com/path/file.htm?q=x#foo", 2191 "http://www.abc.com/path/file.htm?q=x#foo",
1857 "ath/file.htm?q=x#foo" }, 2192 "ath/file.htm?q=x#foo",
2193 true },
1858 { "http://abc.com/p", "http://abc.com/path/file.htm?q=x#foo", 2194 { "http://abc.com/p", "http://abc.com/path/file.htm?q=x#foo",
1859 "http://abc.com/path/file.htm?q=x#foo", 2195 "http://abc.com/path/file.htm?q=x#foo",
1860 "ath/file.htm?q=x#foo"}, 2196 "ath/file.htm?q=x#foo", true},
1861 2197
1862 // Inline matches with valid URLPrefixes; only trim "http://". 2198 // Inline matches with valid URLPrefixes; only trim "http://".
1863 { "w", "http://www.abc.com", 2199 { "w", "http://www.abc.com",
1864 "www.abc.com", "ww.abc.com" }, 2200 "www.abc.com", "ww.abc.com", true },
1865 { "www.a", "http://www.abc.com", 2201 { "www.a", "http://www.abc.com",
1866 "www.abc.com", "bc.com" }, 2202 "www.abc.com", "bc.com", true },
1867 { "abc", "http://www.abc.com", 2203 { "abc", "http://www.abc.com",
1868 "www.abc.com", ".com" }, 2204 "www.abc.com", ".com", true },
1869 { "abc.c", "http://www.abc.com", 2205 { "abc.c", "http://www.abc.com",
1870 "www.abc.com", "om" }, 2206 "www.abc.com", "om", true },
1871 { "abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", 2207 { "abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo",
1872 "www.abc.com/path/file.htm?q=x#foo", 2208 "www.abc.com/path/file.htm?q=x#foo",
1873 "ath/file.htm?q=x#foo" }, 2209 "ath/file.htm?q=x#foo",
2210 true },
1874 { "abc.com/p", "http://abc.com/path/file.htm?q=x#foo", 2211 { "abc.com/p", "http://abc.com/path/file.htm?q=x#foo",
1875 "abc.com/path/file.htm?q=x#foo", 2212 "abc.com/path/file.htm?q=x#foo",
1876 "ath/file.htm?q=x#foo" }, 2213 "ath/file.htm?q=x#foo", true },
1877 2214
1878 // Inline matches using the maximal URLPrefix components. 2215 // Inline matches using the maximal URLPrefix components.
1879 { "h", "http://help.com", 2216 { "h", "http://help.com",
1880 "help.com", "elp.com" }, 2217 "help.com", "elp.com", true },
1881 { "http", "http://http.com", 2218 { "http", "http://http.com",
1882 "http.com", ".com" }, 2219 "http.com", ".com", true },
1883 { "h", "http://www.help.com", 2220 { "h", "http://www.help.com",
1884 "www.help.com", "elp.com" }, 2221 "www.help.com", "elp.com", true },
1885 { "http", "http://www.http.com", 2222 { "http", "http://www.http.com",
1886 "www.http.com", ".com" }, 2223 "www.http.com", ".com", true },
1887 { "w", "http://www.www.com", 2224 { "w", "http://www.www.com",
1888 "www.www.com", "ww.com" }, 2225 "www.www.com", "ww.com", true },
1889 2226
1890 // Test similar behavior for the ftp and https schemes. 2227 // Test similar behavior for the ftp and https schemes.
1891 { "ftp://www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", 2228 { "ftp://www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo",
1892 "ftp://www.abc.com/path/file.htm?q=x#foo", 2229 "ftp://www.abc.com/path/file.htm?q=x#foo",
1893 "c.com/path/file.htm?q=x#foo" }, 2230 "c.com/path/file.htm?q=x#foo", true },
1894 { "www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", 2231 { "www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo",
1895 "ftp://www.abc.com/path/file.htm?q=x#foo", 2232 "ftp://www.abc.com/path/file.htm?q=x#foo",
1896 "c.com/path/file.htm?q=x#foo" }, 2233 "c.com/path/file.htm?q=x#foo", true },
1897 { "ab", "ftp://www.abc.com/path/file.htm?q=x#foo", 2234 { "ab", "ftp://www.abc.com/path/file.htm?q=x#foo",
1898 "ftp://www.abc.com/path/file.htm?q=x#foo", 2235 "ftp://www.abc.com/path/file.htm?q=x#foo",
1899 "c.com/path/file.htm?q=x#foo" }, 2236 "c.com/path/file.htm?q=x#foo", true },
1900 { "ab", "ftp://abc.com/path/file.htm?q=x#foo", 2237 { "ab", "ftp://abc.com/path/file.htm?q=x#foo",
1901 "ftp://abc.com/path/file.htm?q=x#foo", 2238 "ftp://abc.com/path/file.htm?q=x#foo",
1902 "c.com/path/file.htm?q=x#foo" }, 2239 "c.com/path/file.htm?q=x#foo", true },
1903 { "https://www.ab", "https://www.abc.com/path/file.htm?q=x#foo", 2240 { "https://www.ab", "https://www.abc.com/path/file.htm?q=x#foo",
1904 "https://www.abc.com/path/file.htm?q=x#foo", 2241 "https://www.abc.com/path/file.htm?q=x#foo",
1905 "c.com/path/file.htm?q=x#foo" }, 2242 "c.com/path/file.htm?q=x#foo",
2243 true },
1906 { "www.ab", "https://www.abc.com/path/file.htm?q=x#foo", 2244 { "www.ab", "https://www.abc.com/path/file.htm?q=x#foo",
1907 "https://www.abc.com/path/file.htm?q=x#foo", 2245 "https://www.abc.com/path/file.htm?q=x#foo",
1908 "c.com/path/file.htm?q=x#foo" }, 2246 "c.com/path/file.htm?q=x#foo",
2247 true },
1909 { "ab", "https://www.abc.com/path/file.htm?q=x#foo", 2248 { "ab", "https://www.abc.com/path/file.htm?q=x#foo",
1910 "https://www.abc.com/path/file.htm?q=x#foo", 2249 "https://www.abc.com/path/file.htm?q=x#foo",
1911 "c.com/path/file.htm?q=x#foo" }, 2250 "c.com/path/file.htm?q=x#foo",
2251 true },
1912 { "ab", "https://abc.com/path/file.htm?q=x#foo", 2252 { "ab", "https://abc.com/path/file.htm?q=x#foo",
1913 "https://abc.com/path/file.htm?q=x#foo", 2253 "https://abc.com/path/file.htm?q=x#foo",
1914 "c.com/path/file.htm?q=x#foo"}, 2254 "c.com/path/file.htm?q=x#foo",
2255 true },
1915 2256
1916 // Forced query input should inline and retain the "?" prefix. 2257 // Forced query input should inline and retain the "?" prefix.
1917 { "?http://www.ab", "http://www.abc.com", 2258 { "?http://www.ab", "http://www.abc.com",
1918 "?http://www.abc.com", "c.com" }, 2259 "?http://www.abc.com", "c.com", true },
1919 { "?www.ab", "http://www.abc.com", 2260 { "?www.ab", "http://www.abc.com",
1920 "?www.abc.com", "c.com" }, 2261 "?www.abc.com", "c.com", true },
1921 { "?ab", "http://www.abc.com", 2262 { "?ab", "http://www.abc.com",
1922 "?www.abc.com", "c.com" }, 2263 "?www.abc.com", "c.com", true },
1923 }; 2264 };
1924 2265
1925 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2266 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1926 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); 2267 QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
1927 AutocompleteMatch match( 2268 AutocompleteMatch match(
1928 provider_->NavigationToMatch(SearchProvider::NavigationResult( 2269 provider_->NavigationToMatch(SearchProvider::NavigationResult(
1929 *provider_.get(), GURL(cases[i].url), string16(), false, 0, 2270 *provider_.get(), GURL(cases[i].url), string16(), false, 0,
1930 false))); 2271 false)));
1931 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 2272 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
1932 match.inline_autocompletion); 2273 match.inline_autocompletion);
1933 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); 2274 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit);
2275 EXPECT_EQ(cases[i].allowed_to_be_default_match,
2276 match.allowed_to_be_default_match);
1934 } 2277 }
1935 } 2278 }
1936 2279
1937 // Verifies that "http://" is not trimmed for input that is a leading substring. 2280 // Verifies that "http://" is not trimmed for input that is a leading substring.
1938 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { 2281 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) {
1939 const string16 input(ASCIIToUTF16("ht")); 2282 const string16 input(ASCIIToUTF16("ht"));
1940 const string16 url(ASCIIToUTF16("http://a.com")); 2283 const string16 url(ASCIIToUTF16("http://a.com"));
1941 const SearchProvider::NavigationResult result( 2284 const SearchProvider::NavigationResult result(
1942 *provider_.get(), GURL(url), string16(), false, 0, false); 2285 *provider_.get(), GURL(url), string16(), false, 0, false);
1943 2286
1944 // Check the offset and strings when inline autocompletion is allowed. 2287 // Check the offset and strings when inline autocompletion is allowed.
1945 QueryForInput(input, false, false); 2288 QueryForInput(input, false, false);
1946 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); 2289 AutocompleteMatch match_inline(provider_->NavigationToMatch(result));
1947 EXPECT_EQ(url, match_inline.fill_into_edit); 2290 EXPECT_EQ(url, match_inline.fill_into_edit);
1948 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); 2291 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion);
2292 EXPECT_TRUE(match_inline.allowed_to_be_default_match);
1949 EXPECT_EQ(url, match_inline.contents); 2293 EXPECT_EQ(url, match_inline.contents);
1950 2294
1951 // Check the same offset and strings when inline autocompletion is prevented. 2295 // Check the same offset and strings when inline autocompletion is prevented.
1952 QueryForInput(input, true, false); 2296 QueryForInput(input, true, false);
1953 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); 2297 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result));
2298 EXPECT_EQ(url, match_prevent.fill_into_edit);
1954 EXPECT_TRUE(match_prevent.inline_autocompletion.empty()); 2299 EXPECT_TRUE(match_prevent.inline_autocompletion.empty());
1955 EXPECT_EQ(url, match_prevent.fill_into_edit); 2300 EXPECT_FALSE(match_prevent.allowed_to_be_default_match);
1956 EXPECT_EQ(url, match_prevent.contents); 2301 EXPECT_EQ(url, match_prevent.contents);
1957 } 2302 }
1958 2303
1959 // Verifies that input "w" marks a more significant domain label than "www.". 2304 // Verifies that input "w" marks a more significant domain label than "www.".
1960 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { 2305 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) {
1961 QueryForInput(ASCIIToUTF16("w"), false, false); 2306 QueryForInput(ASCIIToUTF16("w"), false, false);
1962 AutocompleteMatch match( 2307 AutocompleteMatch match(
1963 provider_->NavigationToMatch(SearchProvider::NavigationResult( 2308 provider_->NavigationToMatch(SearchProvider::NavigationResult(
1964 *provider_.get(), GURL("http://www.wow.com"), string16(), false, 0, 2309 *provider_.get(), GURL("http://www.wow.com"), string16(), false, 0,
1965 false))); 2310 false)));
1966 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); 2311 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion);
2312 EXPECT_TRUE(match.allowed_to_be_default_match);
1967 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); 2313 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit);
1968 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); 2314 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents);
1969 2315
1970 // Ensure that the match for input "w" is marked on "wow" and not "www". 2316 // Ensure that the match for input "w" is marked on "wow" and not "www".
1971 ASSERT_EQ(3U, match.contents_class.size()); 2317 ASSERT_EQ(3U, match.contents_class.size());
1972 EXPECT_EQ(0U, match.contents_class[0].offset); 2318 EXPECT_EQ(0U, match.contents_class[0].offset);
1973 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 2319 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1974 match.contents_class[0].style); 2320 match.contents_class[0].style);
1975 EXPECT_EQ(4U, match.contents_class[1].offset); 2321 EXPECT_EQ(4U, match.contents_class[1].offset);
1976 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | 2322 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 } else { 2507 } else {
2162 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; 2508 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion;
2163 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); 2509 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion());
2164 ++sug_it; 2510 ++sug_it;
2165 } 2511 }
2166 } 2512 }
2167 EXPECT_EQ(sug_end, sug_it); 2513 EXPECT_EQ(sug_end, sug_it);
2168 EXPECT_EQ(nav_end, nav_it); 2514 EXPECT_EQ(nav_end, nav_it);
2169 } 2515 }
2170 } 2516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698