| 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 "components/omnibox/search_provider.h" | 5 #include "components/omnibox/search_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ACMatches::const_iterator FindDefaultMatch(const ACMatches& matches) { | 65 ACMatches::const_iterator FindDefaultMatch(const ACMatches& matches) { |
| 66 ACMatches::const_iterator it = matches.begin(); | 66 ACMatches::const_iterator it = matches.begin(); |
| 67 while ((it != matches.end()) && !it->allowed_to_be_default_match) | 67 while ((it != matches.end()) && !it->allowed_to_be_default_match) |
| 68 ++it; | 68 ++it; |
| 69 return it; | 69 return it; |
| 70 } | 70 } |
| 71 | 71 |
| 72 class SuggestionDeletionHandler; | 72 class SuggestionDeletionHandler; |
| 73 class SearchProviderForTest : public SearchProvider { | 73 class SearchProviderForTest : public SearchProvider { |
| 74 public: | 74 public: |
| 75 SearchProviderForTest(AutocompleteProviderListener* listener, | 75 SearchProviderForTest(ChromeAutocompleteProviderClient* client, |
| 76 AutocompleteProviderListener* listener, |
| 76 TemplateURLService* template_url_service, | 77 TemplateURLService* template_url_service, |
| 77 Profile* profile); | 78 Profile* profile); |
| 78 bool is_success() { return is_success_; } | 79 bool is_success() { return is_success_; } |
| 79 | 80 |
| 80 protected: | 81 protected: |
| 81 ~SearchProviderForTest() override; | 82 ~SearchProviderForTest() override; |
| 82 | 83 |
| 83 private: | 84 private: |
| 84 void RecordDeletionResult(bool success) override; | 85 void RecordDeletionResult(bool success) override; |
| 85 bool is_success_; | 86 bool is_success_; |
| 86 DISALLOW_COPY_AND_ASSIGN(SearchProviderForTest); | 87 DISALLOW_COPY_AND_ASSIGN(SearchProviderForTest); |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 SearchProviderForTest::SearchProviderForTest( | 90 SearchProviderForTest::SearchProviderForTest( |
| 91 ChromeAutocompleteProviderClient* client, |
| 90 AutocompleteProviderListener* listener, | 92 AutocompleteProviderListener* listener, |
| 91 TemplateURLService* template_url_service, | 93 TemplateURLService* template_url_service, |
| 92 Profile* profile) | 94 Profile* profile) |
| 93 : SearchProvider(listener, template_url_service, | 95 : SearchProvider(client, listener, template_url_service), |
| 94 scoped_ptr<AutocompleteProviderClient>( | |
| 95 new ChromeAutocompleteProviderClient(profile))), | |
| 96 is_success_(false) { | 96 is_success_(false) { |
| 97 } | 97 } |
| 98 | 98 |
| 99 SearchProviderForTest::~SearchProviderForTest() { | 99 SearchProviderForTest::~SearchProviderForTest() { |
| 100 } | 100 } |
| 101 | 101 |
| 102 void SearchProviderForTest::RecordDeletionResult(bool success) { | 102 void SearchProviderForTest::RecordDeletionResult(bool success) { |
| 103 is_success_ = success; | 103 is_success_ = success; |
| 104 } | 104 } |
| 105 | 105 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // See description above class for details of these fields. | 248 // See description above class for details of these fields. |
| 249 TemplateURL* default_t_url_; | 249 TemplateURL* default_t_url_; |
| 250 const base::string16 term1_; | 250 const base::string16 term1_; |
| 251 GURL term1_url_; | 251 GURL term1_url_; |
| 252 TemplateURL* keyword_t_url_; | 252 TemplateURL* keyword_t_url_; |
| 253 const base::string16 keyword_term_; | 253 const base::string16 keyword_term_; |
| 254 GURL keyword_url_; | 254 GURL keyword_url_; |
| 255 | 255 |
| 256 content::TestBrowserThreadBundle thread_bundle_; | 256 content::TestBrowserThreadBundle thread_bundle_; |
| 257 | 257 |
| 258 // URLFetcherFactory implementation registered. | |
| 259 net::TestURLFetcherFactory test_factory_; | 258 net::TestURLFetcherFactory test_factory_; |
| 260 | |
| 261 // Profile we use. | |
| 262 TestingProfile profile_; | 259 TestingProfile profile_; |
| 263 | 260 scoped_ptr<ChromeAutocompleteProviderClient> client_; |
| 264 // The provider. | |
| 265 scoped_refptr<SearchProviderForTest> provider_; | 261 scoped_refptr<SearchProviderForTest> provider_; |
| 266 | 262 |
| 267 // If non-NULL, OnProviderUpdate quits the current |run_loop_|. | 263 // If non-NULL, OnProviderUpdate quits the current |run_loop_|. |
| 268 base::RunLoop* run_loop_; | 264 base::RunLoop* run_loop_; |
| 269 | 265 |
| 270 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); | 266 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); |
| 271 }; | 267 }; |
| 272 | 268 |
| 273 // static | 269 // static |
| 274 const std::string SearchProviderTest::kNotApplicable = "Not Applicable"; | 270 const std::string SearchProviderTest::kNotApplicable = "Not Applicable"; |
| 275 const SearchProviderTest::ExpectedMatch | 271 const SearchProviderTest::ExpectedMatch |
| 276 SearchProviderTest::kEmptyExpectedMatch = { kNotApplicable, false }; | 272 SearchProviderTest::kEmptyExpectedMatch = { kNotApplicable, false }; |
| 277 | 273 |
| 278 void SearchProviderTest::SetUp() { | 274 void SearchProviderTest::SetUp() { |
| 279 // Make sure that fetchers are automatically ungregistered upon destruction. | 275 // Make sure that fetchers are automatically ungregistered upon destruction. |
| 280 test_factory_.set_remove_fetcher_on_delete(true); | 276 test_factory_.set_remove_fetcher_on_delete(true); |
| 281 | 277 |
| 282 // We need both the history service and template url model loaded. | 278 // We need both the history service and template url model loaded. |
| 283 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); | 279 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); |
| 284 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 280 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 285 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 281 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
| 286 | 282 |
| 283 client_.reset(new ChromeAutocompleteProviderClient(&profile_)); |
| 284 |
| 287 TemplateURLService* turl_model = | 285 TemplateURLService* turl_model = |
| 288 TemplateURLServiceFactory::GetForProfile(&profile_); | 286 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 289 | 287 |
| 290 turl_model->Load(); | 288 turl_model->Load(); |
| 291 | 289 |
| 292 // Reset the default TemplateURL. | 290 // Reset the default TemplateURL. |
| 293 TemplateURLData data; | 291 TemplateURLData data; |
| 294 data.SetShortName(ASCIIToUTF16("t")); | 292 data.SetShortName(ASCIIToUTF16("t")); |
| 295 data.SetURL("http://defaultturl/{searchTerms}"); | 293 data.SetURL("http://defaultturl/{searchTerms}"); |
| 296 data.suggestions_url = "http://defaultturl2/{searchTerms}"; | 294 data.suggestions_url = "http://defaultturl2/{searchTerms}"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 318 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); | 316 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); |
| 319 | 317 |
| 320 // Keywords are updated by the InMemoryHistoryBackend only after the message | 318 // Keywords are updated by the InMemoryHistoryBackend only after the message |
| 321 // has been processed on the history thread. Block until history processes all | 319 // has been processed on the history thread. Block until history processes all |
| 322 // requests to ensure the InMemoryDatabase is the state we expect it. | 320 // requests to ensure the InMemoryDatabase is the state we expect it. |
| 323 profile_.BlockUntilHistoryProcessesPendingRequests(); | 321 profile_.BlockUntilHistoryProcessesPendingRequests(); |
| 324 | 322 |
| 325 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 323 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
| 326 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); | 324 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); |
| 327 | 325 |
| 328 provider_ = new SearchProviderForTest(this, turl_model, &profile_); | 326 provider_ = |
| 327 new SearchProviderForTest(client_.get(), this, turl_model, &profile_); |
| 329 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0; | 328 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0; |
| 330 } | 329 } |
| 331 | 330 |
| 332 void SearchProviderTest::TearDown() { | 331 void SearchProviderTest::TearDown() { |
| 333 base::RunLoop().RunUntilIdle(); | 332 base::RunLoop().RunUntilIdle(); |
| 334 | 333 |
| 335 // Shutdown the provider before the profile. | 334 // Shutdown the provider before the profile. |
| 336 provider_ = NULL; | 335 provider_ = NULL; |
| 337 } | 336 } |
| 338 | 337 |
| (...skipping 3263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3602 | 3601 |
| 3603 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { | 3602 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { |
| 3604 AutocompleteInput input(base::ASCIIToUTF16("f"), base::string16::npos, | 3603 AutocompleteInput input(base::ASCIIToUTF16("f"), base::string16::npos, |
| 3605 std::string(), GURL(), | 3604 std::string(), GURL(), |
| 3606 metrics::OmniboxEventProto::INVALID_SPEC, false, | 3605 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 3607 true, true, true, | 3606 true, true, true, |
| 3608 ChromeAutocompleteSchemeClassifier(&profile_)); | 3607 ChromeAutocompleteSchemeClassifier(&profile_)); |
| 3609 provider_->Start(input, false, true); | 3608 provider_->Start(input, false, true); |
| 3610 EXPECT_TRUE(provider_->matches().empty()); | 3609 EXPECT_TRUE(provider_->matches().empty()); |
| 3611 } | 3610 } |
| OLD | NEW |