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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 void CreatePersonalizedFieldTrial(); | 136 void CreatePersonalizedFieldTrial(); |
136 void CreateMostVisitedFieldTrial(); | 137 void CreateMostVisitedFieldTrial(); |
137 | 138 |
138 // Set up threads for testing; this needs to be instantiated before | 139 // Set up threads for testing; this needs to be instantiated before |
139 // |profile_|. | 140 // |profile_|. |
140 content::TestBrowserThreadBundle thread_bundle_; | 141 content::TestBrowserThreadBundle thread_bundle_; |
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 net::TestURLFetcherFactory test_factory_; | 146 net::TestURLFetcherFactory test_factory_; |
147 | |
148 // Profile we use. | |
149 TestingProfile profile_; | 147 TestingProfile profile_; |
150 | 148 scoped_ptr<ChromeAutocompleteProviderClient> client_; |
151 // ZeroSuggestProvider object under test. | |
152 scoped_refptr<ZeroSuggestProvider> provider_; | 149 scoped_refptr<ZeroSuggestProvider> provider_; |
153 | |
154 // Default template URL. | |
155 TemplateURL* default_t_url_; | 150 TemplateURL* default_t_url_; |
156 }; | 151 }; |
157 | 152 |
158 ZeroSuggestProviderTest::ZeroSuggestProviderTest() { | 153 ZeroSuggestProviderTest::ZeroSuggestProviderTest() { |
159 ResetFieldTrialList(); | 154 ResetFieldTrialList(); |
160 } | 155 } |
161 | 156 |
162 void ZeroSuggestProviderTest::SetUp() { | 157 void ZeroSuggestProviderTest::SetUp() { |
163 // Make sure that fetchers are automatically ungregistered upon destruction. | 158 // Make sure that fetchers are automatically ungregistered upon destruction. |
164 test_factory_.set_remove_fetcher_on_delete(true); | 159 test_factory_.set_remove_fetcher_on_delete(true); |
165 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 160 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
166 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 161 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
167 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 162 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
168 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); | 163 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); |
169 | 164 |
| 165 client_.reset(new ChromeAutocompleteProviderClient(&profile_)); |
| 166 |
170 TemplateURLService* turl_model = | 167 TemplateURLService* turl_model = |
171 TemplateURLServiceFactory::GetForProfile(&profile_); | 168 TemplateURLServiceFactory::GetForProfile(&profile_); |
172 turl_model->Load(); | 169 turl_model->Load(); |
173 | 170 |
174 TemplateURLData data; | 171 TemplateURLData data; |
175 data.SetShortName(base::ASCIIToUTF16("t")); | 172 data.SetShortName(base::ASCIIToUTF16("t")); |
176 data.SetURL("https://www.google.com/?q={searchTerms}"); | 173 data.SetURL("https://www.google.com/?q={searchTerms}"); |
177 data.suggestions_url = "https://www.google.com/complete/?q={searchTerms}"; | 174 data.suggestions_url = "https://www.google.com/complete/?q={searchTerms}"; |
178 data.instant_url = "https://does/not/exist?strk=1"; | 175 data.instant_url = "https://does/not/exist?strk=1"; |
179 data.search_terms_replacement_key = "strk"; | 176 data.search_terms_replacement_key = "strk"; |
180 default_t_url_ = new TemplateURL(data); | 177 default_t_url_ = new TemplateURL(data); |
181 turl_model->Add(default_t_url_); | 178 turl_model->Add(default_t_url_); |
182 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 179 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
183 | 180 |
184 TopSitesFactory* top_sites_factory = TopSitesFactory::GetInstance(); | 181 TopSitesFactory* top_sites_factory = TopSitesFactory::GetInstance(); |
185 top_sites_factory->SetTestingFactory(&profile_, BuildFakeEmptyTopSites); | 182 top_sites_factory->SetTestingFactory(&profile_, BuildFakeEmptyTopSites); |
186 provider_ = ZeroSuggestProvider::Create(this, turl_model, &profile_); | 183 provider_ = |
| 184 ZeroSuggestProvider::Create(client_.get(), this, turl_model, &profile_); |
187 } | 185 } |
188 | 186 |
189 void ZeroSuggestProviderTest::TearDown() { | 187 void ZeroSuggestProviderTest::TearDown() { |
190 // Shutdown the provider before the profile. | 188 // Shutdown the provider before the profile. |
191 provider_ = NULL; | 189 provider_ = NULL; |
192 } | 190 } |
193 | 191 |
194 void ZeroSuggestProviderTest::OnProviderUpdate(bool updated_matches) { | 192 void ZeroSuggestProviderTest::OnProviderUpdate(bool updated_matches) { |
195 } | 193 } |
196 | 194 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 441 |
444 base::RunLoop().RunUntilIdle(); | 442 base::RunLoop().RunUntilIdle(); |
445 | 443 |
446 // Expect that the matches have been cleared. | 444 // Expect that the matches have been cleared. |
447 ASSERT_TRUE(provider_->matches().empty()); | 445 ASSERT_TRUE(provider_->matches().empty()); |
448 | 446 |
449 // Expect the new results have been stored. | 447 // Expect the new results have been stored. |
450 EXPECT_EQ(empty_response, | 448 EXPECT_EQ(empty_response, |
451 prefs->GetString(prefs::kZeroSuggestCachedResults)); | 449 prefs->GetString(prefs::kZeroSuggestCachedResults)); |
452 } | 450 } |
OLD | NEW |