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

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

Issue 1185723002: Prepare HistoryProvider for componentization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(AutocompleteProviderListener* listener,
76 TemplateURLService* template_url_service, 76 TemplateURLService* template_url_service,
77 Profile* profile); 77 Profile* profile,
78 ChromeAutocompleteProviderClient* client);
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(
90 AutocompleteProviderListener* listener, 91 AutocompleteProviderListener* listener,
91 TemplateURLService* template_url_service, 92 TemplateURLService* template_url_service,
92 Profile* profile) 93 Profile* profile,
93 : SearchProvider(listener, template_url_service, 94 ChromeAutocompleteProviderClient* client)
94 scoped_ptr<AutocompleteProviderClient>( 95 : SearchProvider(listener, template_url_service, client),
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 258 // URLFetcherFactory implementation registered.
259 net::TestURLFetcherFactory test_factory_; 259 net::TestURLFetcherFactory test_factory_;
260 260
261 // Profile we use. 261 // Profile we use.
262 TestingProfile profile_; 262 TestingProfile profile_;
263 263
264 // The provider client.
Peter Kasting 2015/06/16 00:03:42 Nit: This comment, as well as the similar ones nea
blundell 2015/06/16 07:21:25 Done.
265 scoped_ptr<ChromeAutocompleteProviderClient> client_;
266
264 // The provider. 267 // The provider.
265 scoped_refptr<SearchProviderForTest> provider_; 268 scoped_refptr<SearchProviderForTest> provider_;
266 269
267 // If non-NULL, OnProviderUpdate quits the current |run_loop_|. 270 // If non-NULL, OnProviderUpdate quits the current |run_loop_|.
268 base::RunLoop* run_loop_; 271 base::RunLoop* run_loop_;
269 272
270 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); 273 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
271 }; 274 };
272 275
273 // static 276 // static
274 const std::string SearchProviderTest::kNotApplicable = "Not Applicable"; 277 const std::string SearchProviderTest::kNotApplicable = "Not Applicable";
275 const SearchProviderTest::ExpectedMatch 278 const SearchProviderTest::ExpectedMatch
276 SearchProviderTest::kEmptyExpectedMatch = { kNotApplicable, false }; 279 SearchProviderTest::kEmptyExpectedMatch = { kNotApplicable, false };
277 280
278 void SearchProviderTest::SetUp() { 281 void SearchProviderTest::SetUp() {
279 // Make sure that fetchers are automatically ungregistered upon destruction. 282 // Make sure that fetchers are automatically ungregistered upon destruction.
280 test_factory_.set_remove_fetcher_on_delete(true); 283 test_factory_.set_remove_fetcher_on_delete(true);
281 284
282 // We need both the history service and template url model loaded. 285 // We need both the history service and template url model loaded.
283 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); 286 ASSERT_TRUE(profile_.CreateHistoryService(true, false));
284 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 287 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
285 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); 288 &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
286 289
290 client_.reset(new ChromeAutocompleteProviderClient(&profile_));
291
287 TemplateURLService* turl_model = 292 TemplateURLService* turl_model =
288 TemplateURLServiceFactory::GetForProfile(&profile_); 293 TemplateURLServiceFactory::GetForProfile(&profile_);
289 294
290 turl_model->Load(); 295 turl_model->Load();
291 296
292 // Reset the default TemplateURL. 297 // Reset the default TemplateURL.
293 TemplateURLData data; 298 TemplateURLData data;
294 data.SetShortName(ASCIIToUTF16("t")); 299 data.SetShortName(ASCIIToUTF16("t"));
295 data.SetURL("http://defaultturl/{searchTerms}"); 300 data.SetURL("http://defaultturl/{searchTerms}");
296 data.suggestions_url = "http://defaultturl2/{searchTerms}"; 301 data.suggestions_url = "http://defaultturl2/{searchTerms}";
(...skipping 21 matching lines...) Expand all
318 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); 323 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1);
319 324
320 // Keywords are updated by the InMemoryHistoryBackend only after the message 325 // Keywords are updated by the InMemoryHistoryBackend only after the message
321 // has been processed on the history thread. Block until history processes all 326 // has been processed on the history thread. Block until history processes all
322 // requests to ensure the InMemoryDatabase is the state we expect it. 327 // requests to ensure the InMemoryDatabase is the state we expect it.
323 profile_.BlockUntilHistoryProcessesPendingRequests(); 328 profile_.BlockUntilHistoryProcessesPendingRequests();
324 329
325 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( 330 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
326 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); 331 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor);
327 332
328 provider_ = new SearchProviderForTest(this, turl_model, &profile_); 333 provider_ =
334 new SearchProviderForTest(this, turl_model, &profile_, client_.get());
329 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0; 335 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0;
330 } 336 }
331 337
332 void SearchProviderTest::TearDown() { 338 void SearchProviderTest::TearDown() {
333 base::RunLoop().RunUntilIdle(); 339 base::RunLoop().RunUntilIdle();
334 340
335 // Shutdown the provider before the profile. 341 // Shutdown the provider before the profile.
336 provider_ = NULL; 342 provider_ = NULL;
337 } 343 }
338 344
(...skipping 3263 matching lines...) Expand 10 before | Expand all | Expand 10 after
3602 3608
3603 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { 3609 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) {
3604 AutocompleteInput input(base::ASCIIToUTF16("f"), base::string16::npos, 3610 AutocompleteInput input(base::ASCIIToUTF16("f"), base::string16::npos,
3605 std::string(), GURL(), 3611 std::string(), GURL(),
3606 metrics::OmniboxEventProto::INVALID_SPEC, false, 3612 metrics::OmniboxEventProto::INVALID_SPEC, false,
3607 true, true, true, 3613 true, true, true,
3608 ChromeAutocompleteSchemeClassifier(&profile_)); 3614 ChromeAutocompleteSchemeClassifier(&profile_));
3609 provider_->Start(input, false, true); 3615 provider_->Start(input, false, true);
3610 EXPECT_TRUE(provider_->matches().empty()); 3616 EXPECT_TRUE(provider_->matches().empty());
3611 } 3617 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698