Chromium Code Reviews| 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 //TODO: uncomment me! 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) << |
|
msw
2013/08/07 20:09:21
Can you just EXPECT_EQ(kEmptyMatch, cases[i].match
Mark P
2013/08/07 22:13:05
I can't use EXPECT_EQ because the compiler complai
| |
| 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 }, | |
|
msw
2013/08/07 20:09:21
This is the first difference I notice from the tes
Mark P
2013/08/07 22:13:05
I like this approach, duplicating as necessary and
| |
| 1218 std::string() }, | |
| 1219 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," | |
| 1220 "\"google:verbatimrelevance\":0}]", | |
| 1221 { { "a", true}, { "b", false }, kEmptyMatch, kEmptyMatch }, | |
|
msw
2013/08/07 20:09:21
nit: space after true
Mark P
2013/08/07 22:13:05
Done.
| |
| 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 // Must be the same as kBundledExperimentFieldTrialName | |
|
msw
2013/08/07 20:09:21
Ditto to comment in AutocompleteResultTest.
Mark P
2013/08/07 22:13:05
Noted. See discussion there.
| |
| 1324 // defined in omnibox_field_trial.cc. | |
| 1325 const std::string kTrialName = "OmniboxBundledExperimentV1"; | |
| 1326 // Must be the same as kReorderForLegalDefaultMatchRule defined in | |
| 1327 // omnibox_field_trial.cc. | |
| 1328 const std::string kRuleName = "ReorderForLegalDefaultMatch"; | |
| 1329 std::map<std::string, std::string> params; | |
| 1330 params[kRuleName + ":*"] = "ReorderForLegalDefaultMatch"; | |
| 1331 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | |
| 1332 kTrialName, "A", params)); | |
| 1333 base::FieldTrialList::CreateFieldTrial(kTrialName, "A"); | |
| 1334 | |
| 1335 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | |
| 1336 QueryForInput(ASCIIToUTF16("a"), false, false); | |
| 1337 net::TestURLFetcher* fetcher = | |
| 1338 test_factory_.GetFetcherByID( | |
| 1339 SearchProvider::kDefaultProviderURLFetcherID); | |
| 1340 ASSERT_TRUE(fetcher); | |
| 1341 fetcher->set_response_code(200); | |
| 1342 fetcher->SetResponseString(cases[i].json); | |
| 1343 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 1344 RunTillProviderDone(); | |
| 1345 | |
| 1346 const std::string description = "for input with json=" + cases[i].json; | |
| 1347 const ACMatches& matches = provider_->matches(); | |
| 1348 // The top match must inline and score as highly as calculated verbatim. | |
| 1349 ASSERT_FALSE(matches.empty()); | |
| 1350 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | |
| 1351 matches[0].inline_autocompletion) << description; | |
| 1352 | |
| 1353 size_t j = 0; | |
| 1354 // Ensure that the returned matches equal the expectations. | |
| 1355 for (; j < matches.size(); ++j) { | |
| 1356 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), | |
| 1357 matches[j].contents) << description; | |
| 1358 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, | |
| 1359 matches[j].allowed_to_be_default_match) << description; | |
| 1360 } | |
| 1361 // Ensure that no expected matches are missing. | |
| 1362 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) | |
| 1363 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << | |
|
msw
2013/08/07 20:09:21
Can you just EXPECT_EQ(kEmptyMatch, cases[i].match
Mark P
2013/08/07 22:13:05
See discussion above.
| |
| 1364 "Case # " << i << " " << description; | |
| 1365 } | |
| 1366 } | |
| 1055 | 1367 |
| 1056 // Verifies that suggest results with relevance scores are added | 1368 // Verifies that suggest results with relevance scores are added |
| 1057 // properly when using the keyword fetcher. This is similar to the | 1369 // properly when using the keyword fetcher. This is similar to the |
| 1058 // test DefaultFetcherSuggestRelevance above but this uses inputs that | 1370 // test DefaultFetcherSuggestRelevance above but this uses inputs that |
| 1059 // trigger keyword suggestions (i.e., "k a" rather than "a") and has | 1371 // trigger keyword suggestions (i.e., "k a" rather than "a") and has |
| 1060 // different expectations (because now the results are a mix of | 1372 // different expectations (because now the results are a mix of |
| 1061 // keyword suggestions and default provider suggestions). When a new | 1373 // keyword suggestions and default provider suggestions). When a new |
| 1062 // test is added to this TEST_F, please consider if it would be | 1374 // test is added to this TEST_F, please consider if it would be |
| 1063 // appropriate to add to DefaultFetcherSuggestRelevance as well. | 1375 // appropriate to add to DefaultFetcherSuggestRelevance as well. |
| 1064 TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) { | 1376 TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) { |
| 1377 struct KeywordFetcherMatch { | |
| 1378 std::string contents; | |
| 1379 bool from_keyword; | |
| 1380 bool allowed_to_be_default_match; | |
| 1381 }; | |
| 1382 const KeywordFetcherMatch kEmptyMatch = { kNotApplicable, false, false }; | |
| 1065 struct { | 1383 struct { |
| 1066 const std::string json; | 1384 const std::string json; |
| 1067 const struct { | 1385 const KeywordFetcherMatch matches[5]; |
| 1068 const std::string contents; | |
| 1069 const bool from_keyword; | |
| 1070 } matches[5]; | |
| 1071 const std::string inline_autocompletion; | 1386 const std::string inline_autocompletion; |
| 1072 } cases[] = { | 1387 } cases[] = { |
| 1073 // Ensure that suggest relevance scores reorder matches and that | 1388 // Ensure that suggest relevance scores reorder matches and that |
| 1074 // the keyword verbatim (lacking a suggested verbatim score) beats | 1389 // the keyword verbatim (lacking a suggested verbatim score) beats |
| 1075 // the default provider verbatim. | 1390 // the default provider verbatim. |
| 1076 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", | 1391 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", |
| 1077 { { "a", true }, | 1392 { { "a", true, true }, |
|
msw
2013/08/07 20:09:21
nit: consider using space indentation to make the
Mark P
2013/08/07 22:13:05
Will do a later patchset. Uploading the current p
| |
| 1078 { "k a", false }, | 1393 { "k a", false, true }, |
| 1079 { "c", true }, | 1394 { "c", true, false }, |
| 1080 { "b", true }, | 1395 { "b", true, false }, |
| 1081 { kNotApplicable, false } }, | 1396 kEmptyMatch }, |
| 1082 std::string() }, | 1397 std::string() }, |
| 1083 // Again, check that relevance scores reorder matches, just this | 1398 // Again, check that relevance scores reorder matches, just this |
| 1084 // time with navigation matches. This also checks that with | 1399 // time with navigation matches. This also checks that with |
| 1085 // suggested relevance scores we allow multiple navsuggest results. | 1400 // suggested relevance scores we allow multiple navsuggest results. |
| 1086 // It's odd that navsuggest results that come from a keyword | 1401 // It's odd that navsuggest results that come from a keyword |
| 1087 // provider are marked as not a keyword result. I think this | 1402 // provider are marked as not a keyword result. I think this |
| 1088 // comes from them not going to a keyword search engine). | 1403 // comes from them not going to a keyword search engine). |
| 1089 // TODO(mpearson): Investigate the implications (if any) of | 1404 // TODO(mpearson): Investigate the implications (if any) of |
| 1090 // tagging these results appropriately. If so, do it because it | 1405 // tagging these results appropriately. If so, do it because it |
| 1091 // makes more sense. | 1406 // makes more sense. |
| 1092 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[]," | 1407 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[]," |
| 1093 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1408 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1094 "\"google:suggestrelevance\":[1301, 1302, 1303]}]", | 1409 "\"google:suggestrelevance\":[1301, 1302, 1303]}]", |
| 1095 { { "a", true }, | 1410 { { "a", true, true }, |
| 1096 { "d", true }, | 1411 { "d", true, false }, |
| 1097 { "c.com", false }, | 1412 { "c.com", false, false }, |
| 1098 { "b.com", false }, | 1413 { "b.com", false, false }, |
| 1099 { "k a", false }, }, | 1414 { "k a", false, true }, }, |
| 1100 std::string() }, | 1415 std::string() }, |
| 1101 | 1416 |
| 1102 // Without suggested relevance scores, we should only allow one | 1417 // Without suggested relevance scores, we should only allow one |
| 1103 // navsuggest result to be be displayed. | 1418 // navsuggest result to be be displayed. |
| 1104 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," | 1419 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," |
| 1105 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", | 1420 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", |
| 1106 { { "a", true }, | 1421 { { "a", true, true }, |
| 1107 { "b.com", false }, | 1422 { "b.com", false, false }, |
| 1108 { "k a", false }, | 1423 { "k a", false, true }, |
| 1109 { kNotApplicable, false }, | 1424 kEmptyMatch, |
|
msw
2013/08/07 20:09:21
nit: consider packing multiple empties onto the sa
Mark P
2013/08/07 22:13:05
I went with this approach throughout this file:
If
| |
| 1110 { kNotApplicable, false } }, | 1425 kEmptyMatch }, |
| 1111 std::string() }, | 1426 std::string() }, |
| 1112 | 1427 |
| 1113 // Ensure that verbatimrelevance scores reorder or suppress verbatim. | 1428 // Ensure that verbatimrelevance scores reorder or suppress verbatim. |
| 1114 // Negative values will have no effect; the calculated value will be used. | 1429 // Negative values will have no effect; the calculated value will be used. |
| 1115 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," | 1430 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," |
| 1116 "\"google:suggestrelevance\":[9998]}]", | 1431 "\"google:suggestrelevance\":[9998]}]", |
| 1117 { { "a", true }, | 1432 { { "a", true, true }, |
| 1118 { "a1", true }, | 1433 { "a1", true, true }, |
| 1119 { "k a", false }, | 1434 { "k a", false, true }, |
| 1120 { kNotApplicable, false }, | 1435 kEmptyMatch, |
| 1121 { kNotApplicable, false } }, | 1436 kEmptyMatch }, |
| 1122 std::string() }, | 1437 std::string() }, |
| 1123 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," | 1438 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," |
| 1124 "\"google:suggestrelevance\":[9999]}]", | 1439 "\"google:suggestrelevance\":[9999]}]", |
| 1125 { { "a1", true }, | 1440 { { "a1", true, true }, |
| 1126 { "a", true }, | 1441 { "a", true, true }, |
| 1127 { "k a", false }, | 1442 { "k a", false, true }, |
| 1128 { kNotApplicable, false }, | 1443 kEmptyMatch, |
| 1129 { kNotApplicable, false } }, | 1444 kEmptyMatch }, |
| 1130 "1" }, | 1445 "1" }, |
| 1131 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," | 1446 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," |
| 1132 "\"google:suggestrelevance\":[9999]}]", | 1447 "\"google:suggestrelevance\":[9999]}]", |
| 1133 { { "a1", true }, | 1448 { { "a1", true, true }, |
| 1134 { "k a", false }, | 1449 { "k a", false, true }, |
| 1135 { kNotApplicable, false }, | 1450 kEmptyMatch, |
| 1136 { kNotApplicable, false }, | 1451 kEmptyMatch, |
| 1137 { kNotApplicable, false } }, | 1452 kEmptyMatch }, |
| 1138 "1" }, | 1453 "1" }, |
| 1139 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," | 1454 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," |
| 1140 "\"google:suggestrelevance\":[9999]}]", | 1455 "\"google:suggestrelevance\":[9999]}]", |
| 1141 { { "a1", true }, | 1456 { { "a1", true, true }, |
| 1142 { "a", true }, | 1457 { "a", true, true }, |
| 1143 { "k a", false }, | 1458 { "k a", false, true }, |
| 1144 { kNotApplicable, false }, | 1459 kEmptyMatch, |
| 1145 { kNotApplicable, false } }, | 1460 kEmptyMatch }, |
| 1146 "1" }, | 1461 "1" }, |
| 1147 { "[\"a\",[\"http://a.com\"],[],[]," | 1462 { "[\"a\",[\"http://a.com\"],[],[]," |
| 1148 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1463 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1149 "\"google:verbatimrelevance\":9999," | 1464 "\"google:verbatimrelevance\":9999," |
| 1150 "\"google:suggestrelevance\":[9998]}]", | 1465 "\"google:suggestrelevance\":[9998]}]", |
| 1151 { { "a", true }, | 1466 { { "a", true, true }, |
| 1152 { "a.com", false }, | 1467 { "a.com", false, true }, |
| 1153 { "k a", false }, | 1468 { "k a", false, true }, |
| 1154 { kNotApplicable, false }, | 1469 kEmptyMatch, |
| 1155 { kNotApplicable, false } }, | 1470 kEmptyMatch }, |
| 1156 std::string() }, | 1471 std::string() }, |
| 1157 | 1472 |
| 1158 // Ensure that both types of relevance scores reorder matches together. | 1473 // Ensure that both types of relevance scores reorder matches together. |
| 1159 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," | 1474 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," |
| 1160 "\"google:verbatimrelevance\":9998}]", | 1475 "\"google:verbatimrelevance\":9998}]", |
| 1161 { { "a1", true }, | 1476 { { "a1", true, true }, |
| 1162 { "a", true }, | 1477 { "a", true, true }, |
| 1163 { "a2", true }, | 1478 { "a2", true, true }, |
| 1164 { "k a", false }, | 1479 { "k a", false, true }, |
| 1165 { kNotApplicable, false } }, | 1480 kEmptyMatch }, |
| 1166 "1" }, | 1481 "1" }, |
| 1167 | 1482 |
| 1168 // Ensure that only inlinable matches may be ranked as the highest result. | 1483 // Ensure that only inlinable matches may be ranked as the highest result. |
| 1169 // Ignore all suggested relevance scores if this constraint is violated. | 1484 // Ignore all suggested relevance scores if this constraint is violated. |
| 1170 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", | 1485 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", |
| 1171 { { "a", true }, | 1486 { { "a", true, true }, |
| 1172 { "b", true }, | 1487 { "b", true, false }, |
| 1173 { "k a", false }, | 1488 { "k a", false, true }, |
| 1174 { kNotApplicable, false }, | 1489 kEmptyMatch, |
| 1175 { kNotApplicable, false } }, | 1490 kEmptyMatch }, |
| 1176 std::string() }, | 1491 std::string() }, |
| 1177 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," | 1492 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," |
| 1178 "\"google:verbatimrelevance\":0}]", | 1493 "\"google:verbatimrelevance\":0}]", |
| 1179 { { "a", true }, | 1494 { { "a", true, true }, |
| 1180 { "b", true }, | 1495 { "b", true, false }, |
| 1181 { "k a", false }, | 1496 { "k a", false, true }, |
| 1182 { kNotApplicable, false }, | 1497 kEmptyMatch, |
| 1183 { kNotApplicable, false } }, | 1498 kEmptyMatch }, |
| 1184 std::string() }, | 1499 std::string() }, |
| 1185 { "[\"a\",[\"http://b.com\"],[],[]," | 1500 { "[\"a\",[\"http://b.com\"],[],[]," |
| 1186 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1501 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1187 "\"google:suggestrelevance\":[9999]}]", | 1502 "\"google:suggestrelevance\":[9999]}]", |
| 1188 { { "a", true }, | 1503 { { "a", true, true }, |
| 1189 { "b.com", false }, | 1504 { "b.com", false, false }, |
| 1190 { "k a", false }, | 1505 { "k a", false, true }, |
| 1191 { kNotApplicable, false }, | 1506 kEmptyMatch, |
| 1192 { kNotApplicable, false } }, | 1507 kEmptyMatch }, |
| 1193 std::string() }, | 1508 std::string() }, |
| 1194 { "[\"a\",[\"http://b.com\"],[],[]," | 1509 { "[\"a\",[\"http://b.com\"],[],[]," |
| 1195 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1510 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1196 "\"google:suggestrelevance\":[9999]," | 1511 "\"google:suggestrelevance\":[9999]," |
| 1197 "\"google:verbatimrelevance\":0}]", | 1512 "\"google:verbatimrelevance\":0}]", |
| 1198 { { "a", true }, | 1513 { { "a", true, true }, |
| 1199 { "b.com", false }, | 1514 { "b.com", false, false }, |
| 1200 { "k a", false }, | 1515 { "k a", false, true }, |
| 1201 { kNotApplicable, false }, | 1516 kEmptyMatch, |
| 1202 { kNotApplicable, false } }, | 1517 kEmptyMatch }, |
| 1203 std::string() }, | 1518 std::string() }, |
| 1204 | 1519 |
| 1205 // Ensure that the top result is ranked as highly as calculated verbatim. | 1520 // Ensure that the top result is ranked as highly as calculated verbatim. |
| 1206 // Ignore the suggested verbatim relevance if this constraint is violated. | 1521 // Ignore the suggested verbatim relevance if this constraint is violated. |
| 1207 // Note that keyword suggestions by default (not in suggested relevance | 1522 // Note that keyword suggestions by default (not in suggested relevance |
| 1208 // mode) score more highly than the default verbatim. | 1523 // mode) score more highly than the default verbatim. |
| 1209 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", | 1524 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", |
| 1210 { { "a", true }, | 1525 { { "a", true, true }, |
| 1211 { "a1", true }, | 1526 { "a1", true, true }, |
| 1212 { "k a", false }, | 1527 { "k a", false, true }, |
| 1213 { kNotApplicable, false }, | 1528 kEmptyMatch, |
| 1214 { kNotApplicable, false } }, | 1529 kEmptyMatch }, |
| 1215 std::string() }, | 1530 std::string() }, |
| 1216 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", | 1531 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", |
| 1217 { { "a", true }, | 1532 { { "a", true, true }, |
| 1218 { "a1", true }, | 1533 { "a1", true, true }, |
| 1219 { "k a", false }, | 1534 { "k a", false, true }, |
| 1220 { kNotApplicable, false }, | 1535 kEmptyMatch, |
| 1221 { kNotApplicable, false } }, | 1536 kEmptyMatch }, |
| 1222 std::string() }, | 1537 std::string() }, |
| 1223 // Continuing the same category of tests, but make sure we keep the | 1538 // Continuing the same category of tests, but make sure we keep the |
| 1224 // suggested relevance scores even as we discard the verbatim relevance | 1539 // suggested relevance scores even as we discard the verbatim relevance |
| 1225 // scores. | 1540 // scores. |
| 1226 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," | 1541 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," |
| 1227 "\"google:verbatimrelevance\":0}]", | 1542 "\"google:verbatimrelevance\":0}]", |
| 1228 { { "a", true }, | 1543 { { "a", true, true }, |
| 1229 { "k a", false }, | 1544 { "k a", false, true }, |
| 1230 { "a1", true }, | 1545 { "a1", true, true }, |
| 1231 { kNotApplicable, false }, | 1546 kEmptyMatch, |
| 1232 { kNotApplicable, false } }, | 1547 kEmptyMatch }, |
| 1233 std::string() }, | 1548 std::string() }, |
| 1234 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," | 1549 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," |
| 1235 "\"google:verbatimrelevance\":0}]", | 1550 "\"google:verbatimrelevance\":0}]", |
| 1236 { { "a", true }, | 1551 { { "a", true, true }, |
| 1237 { "k a", false }, | 1552 { "k a", false, true }, |
| 1238 { "a2", true }, | 1553 { "a2", true, true }, |
| 1239 { "a1", true }, | 1554 { "a1", true, true }, |
| 1240 { kNotApplicable, false } }, | 1555 kEmptyMatch }, |
| 1241 std::string() }, | 1556 std::string() }, |
| 1242 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," | 1557 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," |
| 1243 "\"google:verbatimrelevance\":2}]", | 1558 "\"google:verbatimrelevance\":2}]", |
| 1244 { { "a", true }, | 1559 { { "a", true, true }, |
| 1245 { "k a", false }, | 1560 { "k a", false, true }, |
| 1246 { "a2", true }, | 1561 { "a2", true, true }, |
| 1247 { "a1", true }, | 1562 { "a1", true, true }, |
| 1248 { kNotApplicable, false } }, | 1563 kEmptyMatch }, |
| 1249 std::string() }, | 1564 std::string() }, |
| 1250 | 1565 |
| 1251 // Ensure that all suggestions are considered, regardless of order. | 1566 // Ensure that all suggestions are considered, regardless of order. |
| 1252 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," | 1567 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," |
| 1253 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 1568 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
| 1254 { { "a", true }, | 1569 { { "a", true, true }, |
| 1255 { "k a", false }, | 1570 { "k a", false, true }, |
| 1256 { "h", true }, | 1571 { "h", true, false }, |
| 1257 { "g", true }, | 1572 { "g", true, false }, |
| 1258 { "f", true } }, | 1573 { "f", true, false } }, |
| 1259 std::string() }, | 1574 std::string() }, |
| 1260 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," | 1575 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," |
| 1261 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," | 1576 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," |
| 1262 "\"http://h.com\"],[],[]," | 1577 "\"http://h.com\"],[],[]," |
| 1263 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," | 1578 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," |
| 1264 "\"NAVIGATION\", \"NAVIGATION\"," | 1579 "\"NAVIGATION\", \"NAVIGATION\"," |
| 1265 "\"NAVIGATION\", \"NAVIGATION\"," | 1580 "\"NAVIGATION\", \"NAVIGATION\"," |
| 1266 "\"NAVIGATION\"]," | 1581 "\"NAVIGATION\"]," |
| 1267 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 1582 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
| 1268 { { "a", true }, | 1583 { { "a", true, true }, |
| 1269 { "k a", false }, | 1584 { "k a", false, true }, |
| 1270 { "h.com", false }, | 1585 { "h.com", false, false }, |
| 1271 { "g.com", false }, | 1586 { "g.com", false, false }, |
| 1272 { "f.com", false } }, | 1587 { "f.com", false, false } }, |
| 1273 std::string() }, | 1588 std::string() }, |
| 1274 | 1589 |
| 1275 // Ensure that incorrectly sized suggestion relevance lists are ignored. | 1590 // Ensure that incorrectly sized suggestion relevance lists are ignored. |
| 1276 // Note that keyword suggestions by default (not in suggested relevance | 1591 // Note that keyword suggestions by default (not in suggested relevance |
| 1277 // mode) score more highly than the default verbatim. | 1592 // mode) score more highly than the default verbatim. |
| 1278 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", | 1593 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", |
| 1279 { { "a", true }, | 1594 { { "a", true, true }, |
| 1280 { "a1", true }, | 1595 { "a1", true, true }, |
| 1281 { "a2", true }, | 1596 { "a2", true, true }, |
| 1282 { "k a", false }, | 1597 { "k a", false, true }, |
| 1283 { kNotApplicable, false } }, | 1598 kEmptyMatch }, |
| 1284 std::string() }, | 1599 std::string() }, |
| 1285 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", | 1600 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", |
| 1286 { { "a", true }, | 1601 { { "a", true, true }, |
| 1287 { "a1", true }, | 1602 { "a1", true, true }, |
| 1288 { "k a", false }, | 1603 { "k a", false, true }, |
| 1289 { kNotApplicable, false }, | 1604 kEmptyMatch, |
| 1290 { kNotApplicable, false } }, | 1605 kEmptyMatch }, |
| 1291 std::string() }, | 1606 std::string() }, |
| 1292 // In this case, ignored the suggested relevance scores means we keep | 1607 // In this case, ignored the suggested relevance scores means we keep |
| 1293 // only one navsuggest result. | 1608 // only one navsuggest result. |
| 1294 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1609 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
| 1295 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1610 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 1296 "\"google:suggestrelevance\":[1]}]", | 1611 "\"google:suggestrelevance\":[1]}]", |
| 1297 { { "a", true }, | 1612 { { "a", true, true }, |
| 1298 { "a1.com", false }, | 1613 { "a1.com", false, true }, |
| 1299 { "k a", false }, | 1614 { "k a", false, true }, |
| 1300 { kNotApplicable, false }, | 1615 kEmptyMatch, |
| 1301 { kNotApplicable, false } }, | 1616 kEmptyMatch }, |
| 1302 std::string() }, | 1617 std::string() }, |
| 1303 { "[\"a\",[\"http://a1.com\"],[],[]," | 1618 { "[\"a\",[\"http://a1.com\"],[],[]," |
| 1304 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1619 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1305 "\"google:suggestrelevance\":[9999, 1]}]", | 1620 "\"google:suggestrelevance\":[9999, 1]}]", |
| 1306 { { "a", true }, | 1621 { { "a", true, true }, |
| 1307 { "a1.com", false }, | 1622 { "a1.com", false, true }, |
| 1308 { "k a", false }, | 1623 { "k a", false, true }, |
| 1309 { kNotApplicable, false }, | 1624 kEmptyMatch, |
| 1310 { kNotApplicable, false } }, | 1625 kEmptyMatch }, |
| 1311 std::string() }, | 1626 std::string() }, |
| 1312 | 1627 |
| 1313 // Ensure that all 'verbatim' results are merged with their maximum score. | 1628 // Ensure that all 'verbatim' results are merged with their maximum score. |
| 1314 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1629 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
| 1315 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", | 1630 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", |
| 1316 { { "a2", true }, | 1631 { { "a2", true, true }, |
| 1317 { "a", true }, | 1632 { "a", true, true }, |
| 1318 { "a1", true }, | 1633 { "a1", true, true }, |
| 1319 { "k a", false }, | 1634 { "k a", false, true }, |
| 1320 { kNotApplicable, false } }, | 1635 kEmptyMatch }, |
| 1321 "2" }, | 1636 "2" }, |
| 1322 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1637 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
| 1323 "{\"google:suggestrelevance\":[9998, 9997, 9999]," | 1638 "{\"google:suggestrelevance\":[9998, 9997, 9999]," |
| 1324 "\"google:verbatimrelevance\":0}]", | 1639 "\"google:verbatimrelevance\":0}]", |
| 1325 { { "a2", true }, | 1640 { { "a2", true, true }, |
| 1326 { "a", true }, | 1641 { "a", true, true }, |
| 1327 { "a1", true }, | 1642 { "a1", true, true }, |
| 1328 { "k a", false }, | 1643 { "k a", false, true }, |
| 1329 { kNotApplicable, false } }, | 1644 kEmptyMatch }, |
| 1330 "2" }, | 1645 "2" }, |
| 1331 | 1646 |
| 1332 // Ensure that verbatim is always generated without other suggestions. | 1647 // Ensure that verbatim is always generated without other suggestions. |
| 1333 // TODO(mpearson): Ensure the value of verbatimrelevance is respected | 1648 // TODO(mpearson): Ensure the value of verbatimrelevance is respected |
| 1334 // (except when suggested relevances are ignored). | 1649 // (except when suggested relevances are ignored). |
| 1335 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", | 1650 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", |
| 1336 { { "a", true }, | 1651 { { "a", true, true }, |
| 1337 { "k a", false }, | 1652 { "k a", false, true }, |
| 1338 { kNotApplicable, false }, | 1653 kEmptyMatch, |
| 1339 { kNotApplicable, false }, | 1654 kEmptyMatch, |
| 1340 { kNotApplicable, false } }, | 1655 kEmptyMatch }, |
| 1341 std::string() }, | 1656 std::string() }, |
| 1342 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", | 1657 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", |
| 1343 { { "a", true }, | 1658 { { "a", true, true }, |
| 1344 { "k a", false }, | 1659 { "k a", false, true }, |
| 1345 { kNotApplicable, false }, | 1660 kEmptyMatch, |
| 1346 { kNotApplicable, false }, | 1661 kEmptyMatch, |
| 1347 { kNotApplicable, false } }, | 1662 kEmptyMatch }, |
| 1348 std::string() }, | 1663 std::string() }, |
| 1349 | 1664 |
| 1350 // Check that navsuggestions will be demoted below queries. | 1665 // Check that navsuggestions will be demoted below queries. |
| 1351 // (Navsuggestions are not allowed to appear first.) In the process, | 1666 // (Navsuggestions are not allowed to appear first.) In the process, |
| 1352 // make sure the navsuggestions still remain in the same order. | 1667 // make sure the navsuggestions still remain in the same order. |
| 1353 // First, check the situation where navsuggest scores more than verbatim | 1668 // First, check the situation where navsuggest scores more than verbatim |
| 1354 // and there are no query suggestions. | 1669 // and there are no query suggestions. |
| 1355 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1670 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
| 1356 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1671 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 1357 "\"google:verbatimrelevance\":9990," | 1672 "\"google:verbatimrelevance\":9990," |
| 1358 "\"google:suggestrelevance\":[9998, 9999]}]", | 1673 "\"google:suggestrelevance\":[9998, 9999]}]", |
| 1359 { { "a", true }, | 1674 { { "a", true, true }, |
| 1360 { "a2.com", false }, | 1675 { "a2.com", false, true }, |
| 1361 { "a1.com", false }, | 1676 { "a1.com", false, true }, |
| 1362 { "k a", false }, | 1677 { "k a", false, true }, |
| 1363 { kNotApplicable, false } }, | 1678 kEmptyMatch }, |
| 1364 std::string() }, | 1679 std::string() }, |
| 1365 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1680 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
| 1366 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1681 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 1367 "\"google:verbatimrelevance\":9990," | 1682 "\"google:verbatimrelevance\":9990," |
| 1368 "\"google:suggestrelevance\":[9999, 9998]}]", | 1683 "\"google:suggestrelevance\":[9999, 9998]}]", |
| 1369 { { "a", true }, | 1684 { { "a", true, true }, |
| 1370 { "a1.com", false }, | 1685 { "a1.com", false, true }, |
| 1371 { "a2.com", false }, | 1686 { "a2.com", false, true }, |
| 1372 { "k a", false }, | 1687 { "k a", false, true }, |
| 1373 { kNotApplicable, false } }, | 1688 kEmptyMatch }, |
| 1374 std::string() }, | 1689 std::string() }, |
| 1375 // Check when navsuggest scores more than verbatim and there is query | 1690 // Check when navsuggest scores more than verbatim and there is query |
| 1376 // suggestion but it scores lower. | 1691 // suggestion but it scores lower. |
| 1377 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1692 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1378 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1693 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1379 "\"google:verbatimrelevance\":9990," | 1694 "\"google:verbatimrelevance\":9990," |
| 1380 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", | 1695 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", |
| 1381 { { "a", true }, | 1696 { { "a", true, true }, |
| 1382 { "a2.com", false }, | 1697 { "a2.com", false, true }, |
| 1383 { "a1.com", false }, | 1698 { "a1.com", false, true }, |
| 1384 { "a3", true }, | 1699 { "a3", true, true }, |
| 1385 { "k a", false } }, | 1700 { "k a", false, true } }, |
| 1386 std::string() }, | 1701 std::string() }, |
| 1387 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1702 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1388 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1703 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1389 "\"google:verbatimrelevance\":9990," | 1704 "\"google:verbatimrelevance\":9990," |
| 1390 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", | 1705 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", |
| 1391 { { "a", true }, | 1706 { { "a", true, true }, |
| 1392 { "a1.com", false }, | 1707 { "a1.com", false, true }, |
| 1393 { "a2.com", false }, | 1708 { "a2.com", false, true }, |
| 1394 { "a3", true }, | 1709 { "a3", true, true }, |
| 1395 { "k a", false } }, | 1710 { "k a", false, true } }, |
| 1396 std::string() }, | 1711 std::string() }, |
| 1397 // Check when navsuggest scores more than a query suggestion. There is | 1712 // Check when navsuggest scores more than a query suggestion. There is |
| 1398 // a verbatim but it scores lower. | 1713 // a verbatim but it scores lower. |
| 1399 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1714 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1400 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1715 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1401 "\"google:verbatimrelevance\":9990," | 1716 "\"google:verbatimrelevance\":9990," |
| 1402 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", | 1717 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", |
| 1403 { { "a3", true }, | 1718 { { "a3", true, true }, |
| 1404 { "a2.com", false }, | 1719 { "a2.com", false, true }, |
| 1405 { "a1.com", false }, | 1720 { "a1.com", false, true }, |
| 1406 { "a", true }, | 1721 { "a", true, true }, |
| 1407 { "k a", false } }, | 1722 { "k a", false, true } }, |
| 1408 "3" }, | 1723 "3" }, |
| 1409 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1724 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1410 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1725 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1411 "\"google:verbatimrelevance\":9990," | 1726 "\"google:verbatimrelevance\":9990," |
| 1412 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", | 1727 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", |
| 1413 { { "a3", true }, | 1728 { { "a3", true, true }, |
| 1414 { "a1.com", false }, | 1729 { "a1.com", false, true }, |
| 1415 { "a2.com", false }, | 1730 { "a2.com", false, true }, |
| 1416 { "a", true }, | 1731 { "a", true, true }, |
| 1417 { "k a", false } }, | 1732 { "k a", false, true } }, |
| 1418 "3" }, | 1733 "3" }, |
| 1419 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1734 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1420 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1735 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1421 "\"google:verbatimrelevance\":0," | 1736 "\"google:verbatimrelevance\":0," |
| 1422 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", | 1737 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", |
| 1423 { { "a3", true }, | 1738 { { "a3", true, true }, |
| 1424 { "a2.com", false }, | 1739 { "a2.com", false, true }, |
| 1425 { "a1.com", false }, | 1740 { "a1.com", false, true }, |
| 1426 { "k a", false }, | 1741 { "k a", false, true }, |
| 1427 { kNotApplicable, false } }, | 1742 kEmptyMatch }, |
| 1428 "3" }, | 1743 "3" }, |
| 1429 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1744 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1430 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1745 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1431 "\"google:verbatimrelevance\":0," | 1746 "\"google:verbatimrelevance\":0," |
| 1432 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", | 1747 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", |
| 1433 { { "a3", true }, | 1748 { { "a3", true, true }, |
| 1434 { "a1.com", false }, | 1749 { "a1.com", false, true }, |
| 1435 { "a2.com", false }, | 1750 { "a2.com", false, true }, |
| 1436 { "k a", false }, | 1751 { "k a", false, true }, |
| 1437 { kNotApplicable, false } }, | 1752 kEmptyMatch }, |
| 1438 "3" }, | 1753 "3" }, |
| 1439 // Check when there is neither verbatim nor a query suggestion that, | 1754 // Check when there is neither verbatim nor a query suggestion that, |
| 1440 // because we can't demote navsuggestions below a query suggestion, | 1755 // because we can't demote navsuggestions below a query suggestion, |
| 1441 // we abandon suggested relevance scores entirely. One consequence is | 1756 // we abandon suggested relevance scores entirely. One consequence is |
| 1442 // that this means we restore the keyword verbatim match. Note | 1757 // that this means we restore the keyword verbatim match. Note |
| 1443 // that in this case of abandoning suggested relevance scores, we still | 1758 // 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 | 1759 // keep the navsuggestions in the same order, but we revert to only allowing |
| 1445 // one navigation to appear because the scores are completely local. | 1760 // one navigation to appear because the scores are completely local. |
| 1446 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1761 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
| 1447 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1762 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 1448 "\"google:verbatimrelevance\":0," | 1763 "\"google:verbatimrelevance\":0," |
| 1449 "\"google:suggestrelevance\":[9998, 9999]}]", | 1764 "\"google:suggestrelevance\":[9998, 9999]}]", |
| 1450 { { "a", true }, | 1765 { { "a", true, true }, |
| 1451 { "a2.com", false }, | 1766 { "a2.com", false, true }, |
| 1452 { "k a", false }, | 1767 { "k a", false, true }, |
| 1453 { kNotApplicable, false }, | 1768 kEmptyMatch, |
| 1454 { kNotApplicable, false } }, | 1769 kEmptyMatch }, |
| 1455 std::string() }, | 1770 std::string() }, |
| 1456 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1771 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
| 1457 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1772 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 1458 "\"google:verbatimrelevance\":0," | 1773 "\"google:verbatimrelevance\":0," |
| 1459 "\"google:suggestrelevance\":[9999, 9998]}]", | 1774 "\"google:suggestrelevance\":[9999, 9998]}]", |
| 1460 { { "a", true }, | 1775 { { "a", true, true }, |
| 1461 { "a1.com", false }, | 1776 { "a1.com", false, true }, |
| 1462 { "k a", false }, | 1777 { "k a", false, true }, |
| 1463 { kNotApplicable, false }, | 1778 kEmptyMatch, |
| 1464 { kNotApplicable, false } }, | 1779 kEmptyMatch }, |
| 1465 std::string() }, | 1780 std::string() }, |
| 1466 // More checks that everything works when it's not necessary to demote. | 1781 // More checks that everything works when it's not necessary to demote. |
| 1467 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1782 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1468 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1783 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1469 "\"google:verbatimrelevance\":9990," | 1784 "\"google:verbatimrelevance\":9990," |
| 1470 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", | 1785 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", |
| 1471 { { "a3", true }, | 1786 { { "a3", true, true }, |
| 1472 { "a2.com", false }, | 1787 { "a2.com", false, true }, |
| 1473 { "a1.com", false }, | 1788 { "a1.com", false, true }, |
| 1474 { "a", true }, | 1789 { "a", true, true }, |
| 1475 { "k a", false } }, | 1790 { "k a", false, true } }, |
| 1476 "3" }, | 1791 "3" }, |
| 1477 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1792 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1478 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1793 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1479 "\"google:verbatimrelevance\":9990," | 1794 "\"google:verbatimrelevance\":9990," |
| 1480 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", | 1795 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", |
| 1481 { { "a3", true }, | 1796 { { "a3", true, true }, |
| 1482 { "a1.com", false }, | 1797 { "a1.com", false, true }, |
| 1483 { "a2.com", false }, | 1798 { "a2.com", false, true }, |
| 1484 { "a", true }, | 1799 { "a", true, true }, |
| 1485 { "k a", false } }, | 1800 { "k a", false, true } }, |
| 1486 "3" }, | 1801 "3" }, |
| 1487 }; | 1802 }; |
| 1488 | 1803 |
| 1489 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1804 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1490 QueryForInput(ASCIIToUTF16("k a"), false, true); | 1805 QueryForInput(ASCIIToUTF16("k a"), false, true); |
| 1491 | 1806 |
| 1492 // Set up a default fetcher with no results. | 1807 // Set up a default fetcher with no results. |
| 1493 net::TestURLFetcher* default_fetcher = | 1808 net::TestURLFetcher* default_fetcher = |
| 1494 test_factory_.GetFetcherByID( | 1809 test_factory_.GetFetcherByID( |
| 1495 SearchProvider::kDefaultProviderURLFetcherID); | 1810 SearchProvider::kDefaultProviderURLFetcherID); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1517 matches[0].inline_autocompletion) << description; | 1832 matches[0].inline_autocompletion) << description; |
| 1518 EXPECT_GE(matches[0].relevance, 1300) << description; | 1833 EXPECT_GE(matches[0].relevance, 1300) << description; |
| 1519 | 1834 |
| 1520 size_t j = 0; | 1835 size_t j = 0; |
| 1521 // Ensure that the returned matches equal the expectations. | 1836 // Ensure that the returned matches equal the expectations. |
| 1522 for (; j < matches.size(); ++j) { | 1837 for (; j < matches.size(); ++j) { |
| 1523 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), | 1838 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), |
| 1524 matches[j].contents) << description; | 1839 matches[j].contents) << description; |
| 1525 EXPECT_EQ(cases[i].matches[j].from_keyword, | 1840 EXPECT_EQ(cases[i].matches[j].from_keyword, |
| 1526 matches[j].keyword == ASCIIToUTF16("k")) << description; | 1841 matches[j].keyword == ASCIIToUTF16("k")) << description; |
| 1842 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, | |
| 1843 matches[j].allowed_to_be_default_match) << description; | |
| 1527 } | 1844 } |
| 1528 // Ensure that no expected matches are missing. | 1845 // Ensure that no expected matches are missing. |
| 1529 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) | 1846 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) |
| 1530 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << | 1847 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << |
|
msw
2013/08/07 20:09:21
Can you just EXPECT_EQ(kEmptyMatch, cases[i].match
Mark P
2013/08/07 22:13:05
See discussion above.
| |
| 1531 "Case # " << i << " " << description; | 1848 "Case # " << i << " " << description; |
| 1532 } | 1849 } |
| 1533 } | 1850 } |
| 1534 | 1851 |
| 1535 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { | 1852 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { |
| 1536 // Enable Instant Extended in order to allow an increased number of | 1853 // Enable Instant Extended in order to allow an increased number of |
| 1537 // suggestions. | 1854 // suggestions. |
| 1538 chrome::EnableInstantExtendedAPIForTesting(); | 1855 chrome::EnableInstantExtendedAPIForTesting(); |
| 1539 | 1856 |
| 1540 // We hardcode the string "term1" below, so ensure that the search term that | 1857 // We hardcode the string "term1" below, so ensure that the search term that |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1634 matches[j].contents) << description; | 1951 matches[j].contents) << description; |
| 1635 // Ensure that no expected matches are missing. | 1952 // Ensure that no expected matches are missing. |
| 1636 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) | 1953 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) |
| 1637 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) << | 1954 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) << |
| 1638 "Case # " << i << " " << description; | 1955 "Case # " << i << " " << description; |
| 1639 } | 1956 } |
| 1640 } | 1957 } |
| 1641 | 1958 |
| 1642 // Verifies suggest relevance behavior for URL input. | 1959 // Verifies suggest relevance behavior for URL input. |
| 1643 TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) { | 1960 TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) { |
| 1961 struct DefaultFetcherUrlInputMatch { | |
| 1962 const std::string match_contents; | |
| 1963 AutocompleteMatch::Type match_type; | |
| 1964 bool allowed_to_be_default_match; | |
| 1965 }; | |
| 1966 const DefaultFetcherUrlInputMatch kEmptyMatch = | |
| 1967 { kNotApplicable, AutocompleteMatchType::NUM_TYPES, false }; | |
| 1644 struct { | 1968 struct { |
| 1645 const std::string input; | 1969 const std::string input; |
| 1646 const std::string json; | 1970 const std::string json; |
| 1647 const std::string match_contents[4]; | 1971 const DefaultFetcherUrlInputMatch output[4]; |
| 1648 const AutocompleteMatch::Type match_types[4]; | |
| 1649 } cases[] = { | 1972 } cases[] = { |
| 1650 // Ensure topmost NAVIGATION matches are allowed for URL input. | 1973 // Ensure topmost NAVIGATION matches are allowed for URL input. |
| 1651 { "a.com", "[\"a.com\",[\"http://a.com/a\"],[],[]," | 1974 { "a.com", "[\"a.com\",[\"http://a.com/a\"],[],[]," |
| 1652 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1975 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1653 "\"google:suggestrelevance\":[9999]}]", | 1976 "\"google:suggestrelevance\":[9999]}]", |
| 1654 { "a.com/a", "a.com", kNotApplicable, kNotApplicable }, | 1977 { { "a.com/a", AutocompleteMatchType::NAVSUGGEST, true }, |
| 1655 { AutocompleteMatchType::NAVSUGGEST, | 1978 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 1656 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1979 kEmptyMatch, kEmptyMatch } }, |
| 1657 AutocompleteMatchType::NUM_TYPES, | |
| 1658 AutocompleteMatchType::NUM_TYPES } }, | |
| 1659 | 1980 |
| 1660 // Ensure topmost SUGGEST matches are not allowed for URL input. | 1981 // Ensure topmost SUGGEST matches are not allowed for URL input. |
| 1661 // SearchProvider disregards search and verbatim suggested relevances. | 1982 // SearchProvider disregards search and verbatim suggested relevances. |
| 1662 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," | 1983 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," |
| 1663 "{\"google:suggestrelevance\":[9999]}]", | 1984 "{\"google:suggestrelevance\":[9999]}]", |
| 1664 { "a.com", "a.com info", kNotApplicable, kNotApplicable }, | 1985 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 1665 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1986 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, |
| 1666 AutocompleteMatchType::SEARCH_SUGGEST, | 1987 kEmptyMatch, |
| 1667 AutocompleteMatchType::NUM_TYPES, AutocompleteMatchType::NUM_TYPES } }, | 1988 kEmptyMatch } }, |
|
msw
2013/08/07 20:09:21
nit: wrap empties here, like in the cases above an
Mark P
2013/08/07 22:13:05
Done.
| |
| 1668 { "a.com", "[\"a.com\",[\"a.com/a\"],[],[]," | 1989 { "a.com", "[\"a.com\",[\"a.com/a\"],[],[]," |
| 1669 "{\"google:suggestrelevance\":[9999]}]", | 1990 "{\"google:suggestrelevance\":[9999]}]", |
| 1670 { "a.com", "a.com/a", kNotApplicable, kNotApplicable }, | 1991 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 1671 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1992 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true }, |
| 1672 AutocompleteMatchType::SEARCH_SUGGEST, | 1993 kEmptyMatch, kEmptyMatch } }, |
| 1673 AutocompleteMatchType::NUM_TYPES, AutocompleteMatchType::NUM_TYPES } }, | |
| 1674 | 1994 |
| 1675 // Ensure the fallback mechanism allows inlinable NAVIGATION matches. | 1995 // Ensure the fallback mechanism allows inlinable NAVIGATION matches. |
| 1676 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://a.com/b\"],[],[]," | 1996 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://a.com/b\"],[],[]," |
| 1677 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," | 1997 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 1678 "\"google:suggestrelevance\":[9999, 9998]}]", | 1998 "\"google:suggestrelevance\":[9999, 9998]}]", |
| 1679 { "a.com/b", "a.com", "a.com/a", kNotApplicable }, | 1999 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, |
| 1680 { AutocompleteMatchType::NAVSUGGEST, | 2000 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 1681 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 2001 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true }, |
| 1682 AutocompleteMatchType::SEARCH_SUGGEST, | 2002 kEmptyMatch } }, |
| 1683 AutocompleteMatchType::NUM_TYPES } }, | |
| 1684 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://a.com/b\"],[],[]," | 2003 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://a.com/b\"],[],[]," |
| 1685 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," | 2004 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 1686 "\"google:suggestrelevance\":[9998, 9997]," | 2005 "\"google:suggestrelevance\":[9998, 9997]," |
| 1687 "\"google:verbatimrelevance\":9999}]", | 2006 "\"google:verbatimrelevance\":9999}]", |
| 1688 { "a.com/b", "a.com", "a.com/a", kNotApplicable }, | 2007 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, |
| 1689 { AutocompleteMatchType::NAVSUGGEST, | 2008 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 1690 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 2009 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true }, |
| 1691 AutocompleteMatchType::SEARCH_SUGGEST, | 2010 kEmptyMatch } }, |
| 1692 AutocompleteMatchType::NUM_TYPES } }, | |
| 1693 | 2011 |
| 1694 // Ensure the fallback mechanism disallows non-inlinable NAVIGATION matches. | 2012 // Ensure the fallback mechanism disallows non-inlinable NAVIGATION matches. |
| 1695 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://abc.com\"],[],[]," | 2013 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://abc.com\"],[],[]," |
| 1696 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," | 2014 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 1697 "\"google:suggestrelevance\":[9999, 9998]}]", | 2015 "\"google:suggestrelevance\":[9999, 9998]}]", |
| 1698 { "a.com", "abc.com", "a.com/a", kNotApplicable }, | 2016 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 1699 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 2017 { "abc.com", AutocompleteMatchType::NAVSUGGEST, false }, |
| 1700 AutocompleteMatchType::NAVSUGGEST, | 2018 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true }, |
| 1701 AutocompleteMatchType::SEARCH_SUGGEST, | 2019 kEmptyMatch } }, |
| 1702 AutocompleteMatchType::NUM_TYPES } }, | |
| 1703 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://abc.com\"],[],[]," | 2020 { "a.com", "[\"a.com\",[\"a.com/a\", \"http://abc.com\"],[],[]," |
| 1704 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," | 2021 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 1705 "\"google:suggestrelevance\":[9998, 9997]," | 2022 "\"google:suggestrelevance\":[9998, 9997]," |
| 1706 "\"google:verbatimrelevance\":9999}]", | 2023 "\"google:verbatimrelevance\":9999}]", |
| 1707 { "a.com", "abc.com", "a.com/a", kNotApplicable }, | 2024 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 1708 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 2025 { "abc.com", AutocompleteMatchType::NAVSUGGEST, false }, |
| 1709 AutocompleteMatchType::NAVSUGGEST, | 2026 { "a.com/a", AutocompleteMatchType::SEARCH_SUGGEST, true }, |
| 1710 AutocompleteMatchType::SEARCH_SUGGEST, | 2027 kEmptyMatch } }, |
| 1711 AutocompleteMatchType::NUM_TYPES } }, | |
| 1712 }; | 2028 }; |
| 1713 | 2029 |
| 1714 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 2030 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1715 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 2031 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
| 1716 net::TestURLFetcher* fetcher = | 2032 net::TestURLFetcher* fetcher = |
| 1717 test_factory_.GetFetcherByID( | 2033 test_factory_.GetFetcherByID( |
| 1718 SearchProvider::kDefaultProviderURLFetcherID); | 2034 SearchProvider::kDefaultProviderURLFetcherID); |
| 1719 ASSERT_TRUE(fetcher); | 2035 ASSERT_TRUE(fetcher); |
| 1720 fetcher->set_response_code(200); | 2036 fetcher->set_response_code(200); |
| 1721 fetcher->SetResponseString(cases[i].json); | 2037 fetcher->SetResponseString(cases[i].json); |
| 1722 fetcher->delegate()->OnURLFetchComplete(fetcher); | 2038 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1723 RunTillProviderDone(); | 2039 RunTillProviderDone(); |
| 1724 | 2040 |
| 1725 size_t j = 0; | 2041 size_t j = 0; |
| 1726 const ACMatches& matches = provider_->matches(); | 2042 const ACMatches& matches = provider_->matches(); |
| 1727 // Ensure that the returned matches equal the expectations. | 2043 // Ensure that the returned matches equal the expectations. |
| 1728 for (; j < matches.size(); ++j) { | 2044 for (; j < matches.size(); ++j) { |
| 1729 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents[j]), matches[j].contents); | 2045 EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents), |
| 1730 EXPECT_EQ(cases[i].match_types[j], matches[j].type); | 2046 matches[j].contents); |
| 2047 EXPECT_EQ(cases[i].output[j].match_type, matches[j].type); | |
| 2048 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match, | |
| 2049 matches[j].allowed_to_be_default_match); | |
| 1731 } | 2050 } |
| 1732 // Ensure that no expected matches are missing. | 2051 // Ensure that no expected matches are missing. |
| 1733 for (; j < ARRAYSIZE_UNSAFE(cases[i].match_contents); ++j) { | 2052 for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) { |
| 1734 EXPECT_EQ(kNotApplicable, cases[i].match_contents[j]); | 2053 EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents); |
|
msw
2013/08/07 20:09:21
Can you just EXPECT_EQ(kEmptyMatch, cases[i].outpu
Mark P
2013/08/07 22:13:05
See discussion above.
| |
| 1735 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES, cases[i].match_types[j]); | 2054 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES, |
| 2055 cases[i].output[j].match_type); | |
| 2056 EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match); | |
| 1736 } | 2057 } |
| 1737 } | 2058 } |
| 1738 } | 2059 } |
| 1739 | 2060 |
| 1740 // A basic test that verifies the field trial triggered parsing logic. | 2061 // A basic test that verifies the field trial triggered parsing logic. |
| 1741 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) { | 2062 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) { |
| 1742 QueryForInput(ASCIIToUTF16("foo"), false, false); | 2063 QueryForInput(ASCIIToUTF16("foo"), false, false); |
| 1743 | 2064 |
| 1744 // Make sure the default providers suggest service was queried. | 2065 // Make sure the default providers suggest service was queried. |
| 1745 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 2066 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1781 | 2102 |
| 1782 // Verifies inline autocompletion of navigational results. | 2103 // Verifies inline autocompletion of navigational results. |
| 1783 TEST_F(SearchProviderTest, NavigationInline) { | 2104 TEST_F(SearchProviderTest, NavigationInline) { |
| 1784 struct { | 2105 struct { |
| 1785 const std::string input; | 2106 const std::string input; |
| 1786 const std::string url; | 2107 const std::string url; |
| 1787 // Test the expected fill_into_edit, which may drop "http://". | 2108 // 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. | 2109 // Some cases do not trim "http://" to match from the start of the scheme. |
| 1789 const std::string fill_into_edit; | 2110 const std::string fill_into_edit; |
| 1790 const std::string inline_autocompletion; | 2111 const std::string inline_autocompletion; |
| 2112 const bool allowed_to_be_default_match; | |
| 1791 } cases[] = { | 2113 } cases[] = { |
| 1792 // Do not inline matches that do not contain the input; trim http as needed. | 2114 // Do not inline matches that do not contain the input; trim http as needed. |
| 1793 { "x", "http://www.abc.com", | 2115 { "x", "http://www.abc.com", |
| 1794 "www.abc.com", std::string() }, | 2116 "www.abc.com", std::string(), false }, |
| 1795 { "https:", "http://www.abc.com", | 2117 { "https:", "http://www.abc.com", |
| 1796 "www.abc.com", std::string() }, | 2118 "www.abc.com", std::string(), false }, |
| 1797 { "abc.com/", "http://www.abc.com", | 2119 { "abc.com/", "http://www.abc.com", |
| 1798 "www.abc.com", std::string() }, | 2120 "www.abc.com", std::string(), false }, |
| 1799 { "http://www.abc.com/a", "http://www.abc.com", | 2121 { "http://www.abc.com/a", "http://www.abc.com", |
| 1800 "http://www.abc.com", std::string() }, | 2122 "http://www.abc.com", std::string(), false }, |
| 1801 { "http://www.abc.com", "https://www.abc.com", | 2123 { "http://www.abc.com", "https://www.abc.com", |
| 1802 "https://www.abc.com", std::string() }, | 2124 "https://www.abc.com", std::string(), false }, |
| 1803 { "http://abc.com", "ftp://abc.com", | 2125 { "http://abc.com", "ftp://abc.com", |
| 1804 "ftp://abc.com", std::string() }, | 2126 "ftp://abc.com", std::string(), false }, |
| 1805 { "https://www.abc.com", "http://www.abc.com", | 2127 { "https://www.abc.com", "http://www.abc.com", |
| 1806 "www.abc.com", std::string() }, | 2128 "www.abc.com", std::string(), false }, |
| 1807 { "ftp://abc.com", "http://abc.com", | 2129 { "ftp://abc.com", "http://abc.com", |
| 1808 "abc.com", std::string() }, | 2130 "abc.com", std::string(), false }, |
| 1809 | 2131 |
| 1810 // Do not inline matches with invalid input prefixes; trim http as needed. | 2132 // Do not inline matches with invalid input prefixes; trim http as needed. |
| 1811 { "ttp", "http://www.abc.com", | 2133 { "ttp", "http://www.abc.com", |
| 1812 "www.abc.com", std::string() }, | 2134 "www.abc.com", std::string(), false }, |
| 1813 { "://w", "http://www.abc.com", | 2135 { "://w", "http://www.abc.com", |
| 1814 "www.abc.com", std::string() }, | 2136 "www.abc.com", std::string(), false }, |
| 1815 { "ww.", "http://www.abc.com", | 2137 { "ww.", "http://www.abc.com", |
| 1816 "www.abc.com", std::string() }, | 2138 "www.abc.com", std::string(), false }, |
| 1817 { ".ab", "http://www.abc.com", | 2139 { ".ab", "http://www.abc.com", |
| 1818 "www.abc.com", std::string() }, | 2140 "www.abc.com", std::string(), false }, |
| 1819 { "bc", "http://www.abc.com", | 2141 { "bc", "http://www.abc.com", |
| 1820 "www.abc.com", std::string() }, | 2142 "www.abc.com", std::string(), false }, |
| 1821 { ".com", "http://www.abc.com", | 2143 { ".com", "http://www.abc.com", |
| 1822 "www.abc.com", std::string() }, | 2144 "www.abc.com", std::string(), false }, |
| 1823 | 2145 |
| 1824 // Do not inline matches that omit input domain labels; trim http as needed. | 2146 // Do not inline matches that omit input domain labels; trim http as needed. |
| 1825 { "www.a", "http://a.com", | 2147 { "www.a", "http://a.com", |
| 1826 "a.com", std::string() }, | 2148 "a.com", std::string(), false }, |
| 1827 { "http://www.a", "http://a.com", | 2149 { "http://www.a", "http://a.com", |
| 1828 "http://a.com", std::string() }, | 2150 "http://a.com", std::string(), false }, |
| 1829 { "www.a", "ftp://a.com", | 2151 { "www.a", "ftp://a.com", |
| 1830 "ftp://a.com", std::string() }, | 2152 "ftp://a.com", std::string(), false }, |
| 1831 { "ftp://www.a", "ftp://a.com", | 2153 { "ftp://www.a", "ftp://a.com", |
| 1832 "ftp://a.com", std::string() }, | 2154 "ftp://a.com", std::string(), false }, |
| 1833 | 2155 |
| 1834 // Input matching but with nothing to inline will not yield an offset. | 2156 // Input matching but with nothing to inline will not yield an offset. |
| 1835 { "abc.com", "http://www.abc.com", | 2157 { "abc.com", "http://www.abc.com", |
| 1836 "www.abc.com", std::string() }, | 2158 "www.abc.com", std::string(), false }, |
| 1837 { "http://www.abc.com", "http://www.abc.com", | 2159 { "http://www.abc.com", "http://www.abc.com", |
| 1838 "http://www.abc.com", std::string() }, | 2160 "http://www.abc.com", std::string(), false }, |
| 1839 | 2161 |
| 1840 // Inline matches when the input is a leading substring of the scheme. | 2162 // Inline matches when the input is a leading substring of the scheme. |
| 1841 { "h", "http://www.abc.com", | 2163 { "h", "http://www.abc.com", |
| 1842 "http://www.abc.com", "ttp://www.abc.com" }, | 2164 "http://www.abc.com", "ttp://www.abc.com", true }, |
| 1843 { "http", "http://www.abc.com", | 2165 { "http", "http://www.abc.com", |
| 1844 "http://www.abc.com", "://www.abc.com" }, | 2166 "http://www.abc.com", "://www.abc.com", true }, |
| 1845 | 2167 |
| 1846 // Inline matches when the input is a leading substring of the full URL. | 2168 // Inline matches when the input is a leading substring of the full URL. |
| 1847 { "http:", "http://www.abc.com", | 2169 { "http:", "http://www.abc.com", |
| 1848 "http://www.abc.com", "//www.abc.com" }, | 2170 "http://www.abc.com", "//www.abc.com", true }, |
| 1849 { "http://w", "http://www.abc.com", | 2171 { "http://w", "http://www.abc.com", |
| 1850 "http://www.abc.com", "ww.abc.com" }, | 2172 "http://www.abc.com", "ww.abc.com", true }, |
| 1851 { "http://www.", "http://www.abc.com", | 2173 { "http://www.", "http://www.abc.com", |
| 1852 "http://www.abc.com", "abc.com" }, | 2174 "http://www.abc.com", "abc.com", true }, |
| 1853 { "http://www.ab", "http://www.abc.com", | 2175 { "http://www.ab", "http://www.abc.com", |
| 1854 "http://www.abc.com", "c.com" }, | 2176 "http://www.abc.com", "c.com", true }, |
| 1855 { "http://www.abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", | 2177 { "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", | 2178 "http://www.abc.com/path/file.htm?q=x#foo", |
| 1857 "ath/file.htm?q=x#foo" }, | 2179 "ath/file.htm?q=x#foo", |
| 2180 true }, | |
| 1858 { "http://abc.com/p", "http://abc.com/path/file.htm?q=x#foo", | 2181 { "http://abc.com/p", "http://abc.com/path/file.htm?q=x#foo", |
| 1859 "http://abc.com/path/file.htm?q=x#foo", | 2182 "http://abc.com/path/file.htm?q=x#foo", |
| 1860 "ath/file.htm?q=x#foo"}, | 2183 "ath/file.htm?q=x#foo", true}, |
| 1861 | 2184 |
| 1862 // Inline matches with valid URLPrefixes; only trim "http://". | 2185 // Inline matches with valid URLPrefixes; only trim "http://". |
| 1863 { "w", "http://www.abc.com", | 2186 { "w", "http://www.abc.com", |
| 1864 "www.abc.com", "ww.abc.com" }, | 2187 "www.abc.com", "ww.abc.com", true }, |
| 1865 { "www.a", "http://www.abc.com", | 2188 { "www.a", "http://www.abc.com", |
| 1866 "www.abc.com", "bc.com" }, | 2189 "www.abc.com", "bc.com", true }, |
| 1867 { "abc", "http://www.abc.com", | 2190 { "abc", "http://www.abc.com", |
| 1868 "www.abc.com", ".com" }, | 2191 "www.abc.com", ".com", true }, |
| 1869 { "abc.c", "http://www.abc.com", | 2192 { "abc.c", "http://www.abc.com", |
| 1870 "www.abc.com", "om" }, | 2193 "www.abc.com", "om", true }, |
| 1871 { "abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", | 2194 { "abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", |
| 1872 "www.abc.com/path/file.htm?q=x#foo", | 2195 "www.abc.com/path/file.htm?q=x#foo", |
| 1873 "ath/file.htm?q=x#foo" }, | 2196 "ath/file.htm?q=x#foo", |
| 2197 true }, | |
| 1874 { "abc.com/p", "http://abc.com/path/file.htm?q=x#foo", | 2198 { "abc.com/p", "http://abc.com/path/file.htm?q=x#foo", |
| 1875 "abc.com/path/file.htm?q=x#foo", | 2199 "abc.com/path/file.htm?q=x#foo", |
| 1876 "ath/file.htm?q=x#foo" }, | 2200 "ath/file.htm?q=x#foo", true }, |
| 1877 | 2201 |
| 1878 // Inline matches using the maximal URLPrefix components. | 2202 // Inline matches using the maximal URLPrefix components. |
| 1879 { "h", "http://help.com", | 2203 { "h", "http://help.com", |
| 1880 "help.com", "elp.com" }, | 2204 "help.com", "elp.com", true }, |
| 1881 { "http", "http://http.com", | 2205 { "http", "http://http.com", |
| 1882 "http.com", ".com" }, | 2206 "http.com", ".com", true }, |
| 1883 { "h", "http://www.help.com", | 2207 { "h", "http://www.help.com", |
| 1884 "www.help.com", "elp.com" }, | 2208 "www.help.com", "elp.com", true }, |
| 1885 { "http", "http://www.http.com", | 2209 { "http", "http://www.http.com", |
| 1886 "www.http.com", ".com" }, | 2210 "www.http.com", ".com", true }, |
| 1887 { "w", "http://www.www.com", | 2211 { "w", "http://www.www.com", |
| 1888 "www.www.com", "ww.com" }, | 2212 "www.www.com", "ww.com", true }, |
| 1889 | 2213 |
| 1890 // Test similar behavior for the ftp and https schemes. | 2214 // Test similar behavior for the ftp and https schemes. |
| 1891 { "ftp://www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", | 2215 { "ftp://www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", |
| 1892 "ftp://www.abc.com/path/file.htm?q=x#foo", | 2216 "ftp://www.abc.com/path/file.htm?q=x#foo", |
| 1893 "c.com/path/file.htm?q=x#foo" }, | 2217 "c.com/path/file.htm?q=x#foo", true }, |
| 1894 { "www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", | 2218 { "www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", |
| 1895 "ftp://www.abc.com/path/file.htm?q=x#foo", | 2219 "ftp://www.abc.com/path/file.htm?q=x#foo", |
| 1896 "c.com/path/file.htm?q=x#foo" }, | 2220 "c.com/path/file.htm?q=x#foo", true }, |
| 1897 { "ab", "ftp://www.abc.com/path/file.htm?q=x#foo", | 2221 { "ab", "ftp://www.abc.com/path/file.htm?q=x#foo", |
| 1898 "ftp://www.abc.com/path/file.htm?q=x#foo", | 2222 "ftp://www.abc.com/path/file.htm?q=x#foo", |
| 1899 "c.com/path/file.htm?q=x#foo" }, | 2223 "c.com/path/file.htm?q=x#foo", true }, |
| 1900 { "ab", "ftp://abc.com/path/file.htm?q=x#foo", | 2224 { "ab", "ftp://abc.com/path/file.htm?q=x#foo", |
| 1901 "ftp://abc.com/path/file.htm?q=x#foo", | 2225 "ftp://abc.com/path/file.htm?q=x#foo", |
| 1902 "c.com/path/file.htm?q=x#foo" }, | 2226 "c.com/path/file.htm?q=x#foo", true }, |
| 1903 { "https://www.ab", "https://www.abc.com/path/file.htm?q=x#foo", | 2227 { "https://www.ab", "https://www.abc.com/path/file.htm?q=x#foo", |
| 1904 "https://www.abc.com/path/file.htm?q=x#foo", | 2228 "https://www.abc.com/path/file.htm?q=x#foo", |
| 1905 "c.com/path/file.htm?q=x#foo" }, | 2229 "c.com/path/file.htm?q=x#foo", |
| 2230 true }, | |
| 1906 { "www.ab", "https://www.abc.com/path/file.htm?q=x#foo", | 2231 { "www.ab", "https://www.abc.com/path/file.htm?q=x#foo", |
| 1907 "https://www.abc.com/path/file.htm?q=x#foo", | 2232 "https://www.abc.com/path/file.htm?q=x#foo", |
| 1908 "c.com/path/file.htm?q=x#foo" }, | 2233 "c.com/path/file.htm?q=x#foo", |
| 2234 true }, | |
| 1909 { "ab", "https://www.abc.com/path/file.htm?q=x#foo", | 2235 { "ab", "https://www.abc.com/path/file.htm?q=x#foo", |
| 1910 "https://www.abc.com/path/file.htm?q=x#foo", | 2236 "https://www.abc.com/path/file.htm?q=x#foo", |
| 1911 "c.com/path/file.htm?q=x#foo" }, | 2237 "c.com/path/file.htm?q=x#foo", |
| 2238 true }, | |
| 1912 { "ab", "https://abc.com/path/file.htm?q=x#foo", | 2239 { "ab", "https://abc.com/path/file.htm?q=x#foo", |
| 1913 "https://abc.com/path/file.htm?q=x#foo", | 2240 "https://abc.com/path/file.htm?q=x#foo", |
| 1914 "c.com/path/file.htm?q=x#foo"}, | 2241 "c.com/path/file.htm?q=x#foo", |
| 2242 true }, | |
| 1915 | 2243 |
| 1916 // Forced query input should inline and retain the "?" prefix. | 2244 // Forced query input should inline and retain the "?" prefix. |
| 1917 { "?http://www.ab", "http://www.abc.com", | 2245 { "?http://www.ab", "http://www.abc.com", |
| 1918 "?http://www.abc.com", "c.com" }, | 2246 "?http://www.abc.com", "c.com", true }, |
| 1919 { "?www.ab", "http://www.abc.com", | 2247 { "?www.ab", "http://www.abc.com", |
| 1920 "?www.abc.com", "c.com" }, | 2248 "?www.abc.com", "c.com", true }, |
| 1921 { "?ab", "http://www.abc.com", | 2249 { "?ab", "http://www.abc.com", |
| 1922 "?www.abc.com", "c.com" }, | 2250 "?www.abc.com", "c.com", true }, |
| 1923 }; | 2251 }; |
| 1924 | 2252 |
| 1925 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 2253 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1926 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 2254 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
| 1927 AutocompleteMatch match( | 2255 AutocompleteMatch match( |
| 1928 provider_->NavigationToMatch(SearchProvider::NavigationResult( | 2256 provider_->NavigationToMatch(SearchProvider::NavigationResult( |
| 1929 *provider_.get(), GURL(cases[i].url), string16(), false, 0, | 2257 *provider_.get(), GURL(cases[i].url), string16(), false, 0, |
| 1930 false))); | 2258 false))); |
| 1931 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2259 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 1932 match.inline_autocompletion); | 2260 match.inline_autocompletion); |
| 1933 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); | 2261 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); |
| 2262 EXPECT_EQ(cases[i].allowed_to_be_default_match, | |
| 2263 match.allowed_to_be_default_match); | |
| 1934 } | 2264 } |
| 1935 } | 2265 } |
| 1936 | 2266 |
| 1937 // Verifies that "http://" is not trimmed for input that is a leading substring. | 2267 // Verifies that "http://" is not trimmed for input that is a leading substring. |
| 1938 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { | 2268 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { |
| 1939 const string16 input(ASCIIToUTF16("ht")); | 2269 const string16 input(ASCIIToUTF16("ht")); |
| 1940 const string16 url(ASCIIToUTF16("http://a.com")); | 2270 const string16 url(ASCIIToUTF16("http://a.com")); |
| 1941 const SearchProvider::NavigationResult result( | 2271 const SearchProvider::NavigationResult result( |
| 1942 *provider_.get(), GURL(url), string16(), false, 0, false); | 2272 *provider_.get(), GURL(url), string16(), false, 0, false); |
| 1943 | 2273 |
| 1944 // Check the offset and strings when inline autocompletion is allowed. | 2274 // Check the offset and strings when inline autocompletion is allowed. |
| 1945 QueryForInput(input, false, false); | 2275 QueryForInput(input, false, false); |
| 1946 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); | 2276 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); |
| 1947 EXPECT_EQ(url, match_inline.fill_into_edit); | 2277 EXPECT_EQ(url, match_inline.fill_into_edit); |
| 1948 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); | 2278 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); |
| 2279 EXPECT_TRUE(match_inline.allowed_to_be_default_match); | |
| 1949 EXPECT_EQ(url, match_inline.contents); | 2280 EXPECT_EQ(url, match_inline.contents); |
| 1950 | 2281 |
| 1951 // Check the same offset and strings when inline autocompletion is prevented. | 2282 // Check the same offset and strings when inline autocompletion is prevented. |
| 1952 QueryForInput(input, true, false); | 2283 QueryForInput(input, true, false); |
| 1953 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); | 2284 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); |
| 2285 EXPECT_EQ(url, match_prevent.fill_into_edit); | |
| 1954 EXPECT_TRUE(match_prevent.inline_autocompletion.empty()); | 2286 EXPECT_TRUE(match_prevent.inline_autocompletion.empty()); |
| 1955 EXPECT_EQ(url, match_prevent.fill_into_edit); | 2287 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); |
| 1956 EXPECT_EQ(url, match_prevent.contents); | 2288 EXPECT_EQ(url, match_prevent.contents); |
| 1957 } | 2289 } |
| 1958 | 2290 |
| 1959 // Verifies that input "w" marks a more significant domain label than "www.". | 2291 // Verifies that input "w" marks a more significant domain label than "www.". |
| 1960 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { | 2292 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { |
| 1961 QueryForInput(ASCIIToUTF16("w"), false, false); | 2293 QueryForInput(ASCIIToUTF16("w"), false, false); |
| 1962 AutocompleteMatch match( | 2294 AutocompleteMatch match( |
| 1963 provider_->NavigationToMatch(SearchProvider::NavigationResult( | 2295 provider_->NavigationToMatch(SearchProvider::NavigationResult( |
| 1964 *provider_.get(), GURL("http://www.wow.com"), string16(), false, 0, | 2296 *provider_.get(), GURL("http://www.wow.com"), string16(), false, 0, |
| 1965 false))); | 2297 false))); |
| 1966 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); | 2298 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); |
| 2299 EXPECT_TRUE(match.allowed_to_be_default_match); | |
| 1967 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); | 2300 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); |
| 1968 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); | 2301 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); |
| 1969 | 2302 |
| 1970 // Ensure that the match for input "w" is marked on "wow" and not "www". | 2303 // Ensure that the match for input "w" is marked on "wow" and not "www". |
| 1971 ASSERT_EQ(3U, match.contents_class.size()); | 2304 ASSERT_EQ(3U, match.contents_class.size()); |
| 1972 EXPECT_EQ(0U, match.contents_class[0].offset); | 2305 EXPECT_EQ(0U, match.contents_class[0].offset); |
| 1973 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, | 2306 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, |
| 1974 match.contents_class[0].style); | 2307 match.contents_class[0].style); |
| 1975 EXPECT_EQ(4U, match.contents_class[1].offset); | 2308 EXPECT_EQ(4U, match.contents_class[1].offset); |
| 1976 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | | 2309 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2161 } else { | 2494 } else { |
| 2162 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; | 2495 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; |
| 2163 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); | 2496 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); |
| 2164 ++sug_it; | 2497 ++sug_it; |
| 2165 } | 2498 } |
| 2166 } | 2499 } |
| 2167 EXPECT_EQ(sug_end, sug_it); | 2500 EXPECT_EQ(sug_end, sug_it); |
| 2168 EXPECT_EQ(nav_end, nav_it); | 2501 EXPECT_EQ(nav_end, nav_it); |
| 2169 } | 2502 } |
| 2170 } | 2503 } |
| OLD | NEW |