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