OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/zero_suggest_provider.h" | 5 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
12 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | |
12 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 13 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
13 #include "chrome/browser/history/top_sites_factory.h" | 14 #include "chrome/browser/history/top_sites_factory.h" |
14 #include "chrome/browser/search_engines/template_url_service_factory.h" | 15 #include "chrome/browser/search_engines/template_url_service_factory.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
17 #include "components/history/core/browser/top_sites.h" | 18 #include "components/history/core/browser/top_sites.h" |
18 #include "components/metrics/proto/omnibox_event.pb.h" | 19 #include "components/metrics/proto/omnibox_event.pb.h" |
19 #include "components/omnibox/autocomplete_provider_listener.h" | 20 #include "components/omnibox/autocomplete_provider_listener.h" |
20 #include "components/omnibox/omnibox_field_trial.h" | 21 #include "components/omnibox/omnibox_field_trial.h" |
21 #include "components/search_engines/template_url.h" | 22 #include "components/search_engines/template_url.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 142 |
142 // Needed for OmniboxFieldTrial::ActivateStaticTrials(). | 143 // Needed for OmniboxFieldTrial::ActivateStaticTrials(). |
143 scoped_ptr<base::FieldTrialList> field_trial_list_; | 144 scoped_ptr<base::FieldTrialList> field_trial_list_; |
144 | 145 |
145 // URLFetcherFactory implementation registered. | 146 // URLFetcherFactory implementation registered. |
146 net::TestURLFetcherFactory test_factory_; | 147 net::TestURLFetcherFactory test_factory_; |
147 | 148 |
148 // Profile we use. | 149 // Profile we use. |
149 TestingProfile profile_; | 150 TestingProfile profile_; |
150 | 151 |
152 // ProviderClient we use. | |
Peter Kasting
2015/06/16 00:03:42
Nit: Same comment as in search_provider_unittest.c
blundell
2015/06/16 07:21:25
Done.
| |
153 scoped_ptr<ChromeAutocompleteProviderClient> client_; | |
154 | |
151 // ZeroSuggestProvider object under test. | 155 // ZeroSuggestProvider object under test. |
152 scoped_refptr<ZeroSuggestProvider> provider_; | 156 scoped_refptr<ZeroSuggestProvider> provider_; |
153 | 157 |
154 // Default template URL. | 158 // Default template URL. |
155 TemplateURL* default_t_url_; | 159 TemplateURL* default_t_url_; |
156 }; | 160 }; |
157 | 161 |
158 ZeroSuggestProviderTest::ZeroSuggestProviderTest() { | 162 ZeroSuggestProviderTest::ZeroSuggestProviderTest() { |
159 ResetFieldTrialList(); | 163 ResetFieldTrialList(); |
160 } | 164 } |
161 | 165 |
162 void ZeroSuggestProviderTest::SetUp() { | 166 void ZeroSuggestProviderTest::SetUp() { |
163 // Make sure that fetchers are automatically ungregistered upon destruction. | 167 // Make sure that fetchers are automatically ungregistered upon destruction. |
164 test_factory_.set_remove_fetcher_on_delete(true); | 168 test_factory_.set_remove_fetcher_on_delete(true); |
165 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 169 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
166 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 170 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
167 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 171 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
168 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); | 172 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); |
169 | 173 |
174 client_.reset(new ChromeAutocompleteProviderClient(&profile_)); | |
175 | |
170 TemplateURLService* turl_model = | 176 TemplateURLService* turl_model = |
171 TemplateURLServiceFactory::GetForProfile(&profile_); | 177 TemplateURLServiceFactory::GetForProfile(&profile_); |
172 turl_model->Load(); | 178 turl_model->Load(); |
173 | 179 |
174 TemplateURLData data; | 180 TemplateURLData data; |
175 data.SetShortName(base::ASCIIToUTF16("t")); | 181 data.SetShortName(base::ASCIIToUTF16("t")); |
176 data.SetURL("https://www.google.com/?q={searchTerms}"); | 182 data.SetURL("https://www.google.com/?q={searchTerms}"); |
177 data.suggestions_url = "https://www.google.com/complete/?q={searchTerms}"; | 183 data.suggestions_url = "https://www.google.com/complete/?q={searchTerms}"; |
178 data.instant_url = "https://does/not/exist?strk=1"; | 184 data.instant_url = "https://does/not/exist?strk=1"; |
179 data.search_terms_replacement_key = "strk"; | 185 data.search_terms_replacement_key = "strk"; |
180 default_t_url_ = new TemplateURL(data); | 186 default_t_url_ = new TemplateURL(data); |
181 turl_model->Add(default_t_url_); | 187 turl_model->Add(default_t_url_); |
182 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 188 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
183 | 189 |
184 TopSitesFactory* top_sites_factory = TopSitesFactory::GetInstance(); | 190 TopSitesFactory* top_sites_factory = TopSitesFactory::GetInstance(); |
185 top_sites_factory->SetTestingFactory(&profile_, BuildFakeEmptyTopSites); | 191 top_sites_factory->SetTestingFactory(&profile_, BuildFakeEmptyTopSites); |
186 provider_ = ZeroSuggestProvider::Create(this, turl_model, &profile_); | 192 provider_ = |
193 ZeroSuggestProvider::Create(this, turl_model, &profile_, client_.get()); | |
187 } | 194 } |
188 | 195 |
189 void ZeroSuggestProviderTest::TearDown() { | 196 void ZeroSuggestProviderTest::TearDown() { |
190 // Shutdown the provider before the profile. | 197 // Shutdown the provider before the profile. |
191 provider_ = NULL; | 198 provider_ = NULL; |
192 } | 199 } |
193 | 200 |
194 void ZeroSuggestProviderTest::OnProviderUpdate(bool updated_matches) { | 201 void ZeroSuggestProviderTest::OnProviderUpdate(bool updated_matches) { |
195 } | 202 } |
196 | 203 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 | 450 |
444 base::RunLoop().RunUntilIdle(); | 451 base::RunLoop().RunUntilIdle(); |
445 | 452 |
446 // Expect that the matches have been cleared. | 453 // Expect that the matches have been cleared. |
447 ASSERT_TRUE(provider_->matches().empty()); | 454 ASSERT_TRUE(provider_->matches().empty()); |
448 | 455 |
449 // Expect the new results have been stored. | 456 // Expect the new results have been stored. |
450 EXPECT_EQ(empty_response, | 457 EXPECT_EQ(empty_response, |
451 prefs->GetString(prefs::kZeroSuggestCachedResults)); | 458 prefs->GetString(prefs::kZeroSuggestCachedResults)); |
452 } | 459 } |
OLD | NEW |