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" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 167 |
168 TemplateURLData data; | 168 TemplateURLData data; |
169 data.short_name = base::ASCIIToUTF16("t"); | 169 data.short_name = base::ASCIIToUTF16("t"); |
170 data.SetURL("https://www.google.com/?q={searchTerms}"); | 170 data.SetURL("https://www.google.com/?q={searchTerms}"); |
171 data.suggestions_url = "https://www.google.com/complete/?q={searchTerms}"; | 171 data.suggestions_url = "https://www.google.com/complete/?q={searchTerms}"; |
172 data.instant_url = "https://does/not/exist?strk=1"; | 172 data.instant_url = "https://does/not/exist?strk=1"; |
173 data.search_terms_replacement_key = "strk"; | 173 data.search_terms_replacement_key = "strk"; |
174 default_t_url_ = new TemplateURL(data); | 174 default_t_url_ = new TemplateURL(data); |
175 turl_model->Add(default_t_url_); | 175 turl_model->Add(default_t_url_); |
176 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 176 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
177 | 177 scoped_refptr<history::TopSites> top_sites = new FakeEmptyTopSites(); |
178 profile_.SetTopSites(new FakeEmptyTopSites()); | 178 profile_.CreateTopSitesService(top_sites.get()); |
179 | 179 |
180 provider_ = ZeroSuggestProvider::Create(this, turl_model, &profile_); | 180 provider_ = ZeroSuggestProvider::Create(this, turl_model, &profile_); |
181 } | 181 } |
182 | 182 |
183 void ZeroSuggestProviderTest::TearDown() { | 183 void ZeroSuggestProviderTest::TearDown() { |
184 // Shutdown the provider before the profile. | 184 // Shutdown the provider before the profile. |
185 provider_ = NULL; | 185 provider_ = NULL; |
186 } | 186 } |
187 | 187 |
188 void ZeroSuggestProviderTest::OnProviderUpdate(bool updated_matches) { | 188 void ZeroSuggestProviderTest::OnProviderUpdate(bool updated_matches) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 metrics::OmniboxEventProto::OTHER, false, false, | 229 metrics::OmniboxEventProto::OTHER, false, false, |
230 true, true, | 230 true, true, |
231 ChromeAutocompleteSchemeClassifier(&profile_)); | 231 ChromeAutocompleteSchemeClassifier(&profile_)); |
232 history::MostVisitedURLList urls; | 232 history::MostVisitedURLList urls; |
233 history::MostVisitedURL url(GURL("http://foo.com/"), | 233 history::MostVisitedURL url(GURL("http://foo.com/"), |
234 base::ASCIIToUTF16("Foo")); | 234 base::ASCIIToUTF16("Foo")); |
235 urls.push_back(url); | 235 urls.push_back(url); |
236 | 236 |
237 provider_->Start(input, false); | 237 provider_->Start(input, false); |
238 EXPECT_TRUE(provider_->matches().empty()); | 238 EXPECT_TRUE(provider_->matches().empty()); |
239 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run( | 239 scoped_refptr<history::TopSites> top_sites = |
240 urls); | 240 TopSitesServiceFactory::GetForProfile(profile_); |
241 static_cast<FakeEmptyTopSites*>(top_sites)->mv_callback.Run(urls); | |
sdefresne
2014/12/29 09:48:14
nit: "static_cast<FakeEmptyTopSites*>(top_sites.ge
Jitu( very slow this week)
2014/12/30 10:09:03
Done.
| |
241 // Should have verbatim match + most visited url match. | 242 // Should have verbatim match + most visited url match. |
242 EXPECT_EQ(2U, provider_->matches().size()); | 243 EXPECT_EQ(2U, provider_->matches().size()); |
243 provider_->Stop(false); | 244 provider_->Stop(false); |
244 | 245 |
245 provider_->Start(input, false); | 246 provider_->Start(input, false); |
246 provider_->Stop(false); | 247 provider_->Stop(false); |
247 EXPECT_TRUE(provider_->matches().empty()); | 248 EXPECT_TRUE(provider_->matches().empty()); |
248 // Most visited results arriving after Stop() has been called, ensure they | 249 // Most visited results arriving after Stop() has been called, ensure they |
249 // are not displayed. | 250 // are not displayed. |
250 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run( | 251 static_cast<FakeEmptyTopSites*>(top_sites)->mv_callback.Run(urls); |
251 urls); | |
252 EXPECT_TRUE(provider_->matches().empty()); | 252 EXPECT_TRUE(provider_->matches().empty()); |
253 } | 253 } |
254 | 254 |
255 TEST_F(ZeroSuggestProviderTest, TestMostVisitedNavigateToSearchPage) { | 255 TEST_F(ZeroSuggestProviderTest, TestMostVisitedNavigateToSearchPage) { |
256 CreateMostVisitedFieldTrial(); | 256 CreateMostVisitedFieldTrial(); |
257 | 257 |
258 std::string current_url("http://www.foxnews.com/"); | 258 std::string current_url("http://www.foxnews.com/"); |
259 std::string input_url("http://www.cnn.com/"); | 259 std::string input_url("http://www.cnn.com/"); |
260 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos, | 260 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos, |
261 std::string(), GURL(current_url), | 261 std::string(), GURL(current_url), |
(...skipping 19 matching lines...) Expand all Loading... | |
281 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT, | 281 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT, |
282 false, | 282 false, |
283 false, | 283 false, |
284 true, | 284 true, |
285 true, | 285 true, |
286 ChromeAutocompleteSchemeClassifier(&profile_)); | 286 ChromeAutocompleteSchemeClassifier(&profile_)); |
287 | 287 |
288 provider_->Start(srp_input, false); | 288 provider_->Start(srp_input, false); |
289 EXPECT_TRUE(provider_->matches().empty()); | 289 EXPECT_TRUE(provider_->matches().empty()); |
290 // Most visited results arriving after a new request has been started. | 290 // Most visited results arriving after a new request has been started. |
291 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run( | 291 scoped_refptr<history::TopSites> top_sites = |
292 urls); | 292 TopSitesServiceFactory::GetForProfile(profile_); |
293 static_cast<FakeEmptyTopSites*>(top_sites)->mv_callback.Run(urls); | |
293 EXPECT_TRUE(provider_->matches().empty()); | 294 EXPECT_TRUE(provider_->matches().empty()); |
294 } | 295 } |
295 | 296 |
296 TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestCachingFirstRun) { | 297 TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestCachingFirstRun) { |
297 CreatePersonalizedFieldTrial(); | 298 CreatePersonalizedFieldTrial(); |
298 | 299 |
299 // Ensure the cache is empty. | 300 // Ensure the cache is empty. |
300 PrefService* prefs = profile_.GetPrefs(); | 301 PrefService* prefs = profile_.GetPrefs(); |
301 prefs->SetString(prefs::kZeroSuggestCachedResults, std::string()); | 302 prefs->SetString(prefs::kZeroSuggestCachedResults, std::string()); |
302 | 303 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 | 409 |
409 base::RunLoop().RunUntilIdle(); | 410 base::RunLoop().RunUntilIdle(); |
410 | 411 |
411 // Expect that the matches have been cleared. | 412 // Expect that the matches have been cleared. |
412 ASSERT_TRUE(provider_->matches().empty()); | 413 ASSERT_TRUE(provider_->matches().empty()); |
413 | 414 |
414 // Expect the new results have been stored. | 415 // Expect the new results have been stored. |
415 EXPECT_EQ(empty_response, | 416 EXPECT_EQ(empty_response, |
416 prefs->GetString(prefs::kZeroSuggestCachedResults)); | 417 prefs->GetString(prefs::kZeroSuggestCachedResults)); |
417 } | 418 } |
OLD | NEW |