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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return false; | 91 return false; |
92 } | 92 } |
93 // content::NotificationObserver: | 93 // content::NotificationObserver: |
94 void Observe(int type, | 94 void Observe(int type, |
95 const content::NotificationSource& source, | 95 const content::NotificationSource& source, |
96 const content::NotificationDetails& details) override {} | 96 const content::NotificationDetails& details) override {} |
97 | 97 |
98 // A test-specific field for controlling when most visited callback is run | 98 // A test-specific field for controlling when most visited callback is run |
99 // after top sites have been requested. | 99 // after top sites have been requested. |
100 GetMostVisitedURLsCallback mv_callback; | 100 GetMostVisitedURLsCallback mv_callback; |
| 101 |
101 protected: | 102 protected: |
102 ~FakeEmptyTopSites() override {} | 103 ~FakeEmptyTopSites() override {} |
103 }; | 104 }; |
104 | 105 |
105 void FakeEmptyTopSites::GetMostVisitedURLs( | 106 void FakeEmptyTopSites::GetMostVisitedURLs( |
106 const GetMostVisitedURLsCallback& callback, | 107 const GetMostVisitedURLsCallback& callback, |
107 bool include_forced_urls) { | 108 bool include_forced_urls) { |
108 mv_callback = callback; | 109 mv_callback = callback; |
109 } | 110 } |
110 | 111 |
111 } // namespace | 112 } // namespace |
112 | 113 |
113 | 114 |
114 class ZeroSuggestProviderTest : public testing::Test, | 115 class ZeroSuggestProviderTest : public testing::Test, |
115 public AutocompleteProviderListener { | 116 public AutocompleteProviderListener { |
116 public: | 117 public: |
117 ZeroSuggestProviderTest(); | 118 ZeroSuggestProviderTest(); |
118 | 119 |
119 void SetUp() override; | 120 void SetUp() override; |
120 void TearDown() override; | 121 void TearDown() override; |
121 | 122 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 224 |
224 std::string current_url("http://www.foxnews.com/"); | 225 std::string current_url("http://www.foxnews.com/"); |
225 std::string input_url("http://www.cnn.com/"); | 226 std::string input_url("http://www.cnn.com/"); |
226 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos, | 227 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos, |
227 std::string(), GURL(current_url), | 228 std::string(), GURL(current_url), |
228 metrics::OmniboxEventProto::OTHER, false, false, | 229 metrics::OmniboxEventProto::OTHER, false, false, |
229 true, true, | 230 true, true, |
230 ChromeAutocompleteSchemeClassifier(&profile_)); | 231 ChromeAutocompleteSchemeClassifier(&profile_)); |
231 history::MostVisitedURLList urls; | 232 history::MostVisitedURLList urls; |
232 history::MostVisitedURL url(GURL("http://foo.com/"), | 233 history::MostVisitedURL url(GURL("http://foo.com/"), |
233 base::ASCIIToUTF16(std::string("Foo"))); | 234 base::ASCIIToUTF16("Foo")); |
234 urls.push_back(url); | 235 urls.push_back(url); |
235 | 236 |
236 provider_->Start(input, false); | 237 provider_->Start(input, false); |
237 EXPECT_TRUE(provider_->matches().empty()); | 238 EXPECT_TRUE(provider_->matches().empty()); |
238 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run( | 239 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run( |
239 urls); | 240 urls); |
240 // Should have verbatim match + most visited url match. | 241 // Should have verbatim match + most visited url match. |
241 EXPECT_EQ(2U, provider_->matches().size()); | 242 EXPECT_EQ(2U, provider_->matches().size()); |
242 provider_->Stop(false); | 243 provider_->Stop(false); |
243 | 244 |
(...skipping 12 matching lines...) Expand all Loading... |
256 | 257 |
257 std::string current_url("http://www.foxnews.com/"); | 258 std::string current_url("http://www.foxnews.com/"); |
258 std::string input_url("http://www.cnn.com/"); | 259 std::string input_url("http://www.cnn.com/"); |
259 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos, | 260 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos, |
260 std::string(), GURL(current_url), | 261 std::string(), GURL(current_url), |
261 metrics::OmniboxEventProto::OTHER, false, false, | 262 metrics::OmniboxEventProto::OTHER, false, false, |
262 true, true, | 263 true, true, |
263 ChromeAutocompleteSchemeClassifier(&profile_)); | 264 ChromeAutocompleteSchemeClassifier(&profile_)); |
264 history::MostVisitedURLList urls; | 265 history::MostVisitedURLList urls; |
265 history::MostVisitedURL url(GURL("http://foo.com/"), | 266 history::MostVisitedURL url(GURL("http://foo.com/"), |
266 base::ASCIIToUTF16(std::string("Foo"))); | 267 base::ASCIIToUTF16("Foo")); |
267 urls.push_back(url); | 268 urls.push_back(url); |
268 | 269 |
269 provider_->Start(input, false); | 270 provider_->Start(input, false); |
270 EXPECT_TRUE(provider_->matches().empty()); | 271 EXPECT_TRUE(provider_->matches().empty()); |
271 // Stop() doesn't always get called. | 272 // Stop() doesn't always get called. |
272 | 273 |
273 std::string search_url("https://www.google.com/?q=flowers"); | 274 std::string search_url("https://www.google.com/?q=flowers"); |
274 AutocompleteInput srp_input( | 275 AutocompleteInput srp_input( |
275 base::ASCIIToUTF16(search_url), | 276 base::ASCIIToUTF16(search_url), |
276 base::string16::npos, | 277 base::string16::npos, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 408 |
408 base::RunLoop().RunUntilIdle(); | 409 base::RunLoop().RunUntilIdle(); |
409 | 410 |
410 // Expect that the matches have been cleared. | 411 // Expect that the matches have been cleared. |
411 ASSERT_TRUE(provider_->matches().empty()); | 412 ASSERT_TRUE(provider_->matches().empty()); |
412 | 413 |
413 // Expect the new results have been stored. | 414 // Expect the new results have been stored. |
414 EXPECT_EQ(empty_response, | 415 EXPECT_EQ(empty_response, |
415 prefs->GetString(prefs::kZeroSuggestCachedResults)); | 416 prefs->GetString(prefs::kZeroSuggestCachedResults)); |
416 } | 417 } |
OLD | NEW |