OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_snippets/remote/ntp_snippets_fetcher.h" | 5 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 const std::map<std::string, std::string>& params) | 149 const std::map<std::string, std::string>& params) |
150 : params_manager_(ntp_snippets::kStudyName, params), | 150 : params_manager_(ntp_snippets::kStudyName, params), |
151 mock_task_runner_(new base::TestMockTimeTaskRunner()), | 151 mock_task_runner_(new base::TestMockTimeTaskRunner()), |
152 mock_task_runner_handle_(mock_task_runner_), | 152 mock_task_runner_handle_(mock_task_runner_), |
153 signin_client_(new TestSigninClient(nullptr)), | 153 signin_client_(new TestSigninClient(nullptr)), |
154 account_tracker_(new AccountTrackerService()), | 154 account_tracker_(new AccountTrackerService()), |
155 fake_signin_manager_(new FakeSigninManagerBase(signin_client_.get(), | 155 fake_signin_manager_(new FakeSigninManagerBase(signin_client_.get(), |
156 account_tracker_.get())), | 156 account_tracker_.get())), |
157 fake_token_service_(new FakeProfileOAuth2TokenService()), | 157 fake_token_service_(new FakeProfileOAuth2TokenService()), |
158 pref_service_(new TestingPrefServiceSimple()), | 158 pref_service_(new TestingPrefServiceSimple()), |
| 159 user_classifier_(pref_service_.get()), |
159 test_lang_("en-US"), | 160 test_lang_("en-US"), |
160 test_url_(gurl) { | 161 test_url_(gurl) { |
161 RequestThrottler::RegisterProfilePrefs(pref_service_->registry()); | 162 RequestThrottler::RegisterProfilePrefs(pref_service_->registry()); |
162 | 163 |
163 snippets_fetcher_ = base::MakeUnique<NTPSnippetsFetcher>( | 164 snippets_fetcher_ = base::MakeUnique<NTPSnippetsFetcher>( |
164 fake_signin_manager_.get(), fake_token_service_.get(), | 165 fake_signin_manager_.get(), fake_token_service_.get(), |
165 scoped_refptr<net::TestURLRequestContextGetter>( | 166 scoped_refptr<net::TestURLRequestContextGetter>( |
166 new net::TestURLRequestContextGetter(mock_task_runner_.get())), | 167 new net::TestURLRequestContextGetter(mock_task_runner_.get())), |
167 pref_service_.get(), &category_factory_, base::Bind(&ParseJsonDelayed), | 168 pref_service_.get(), &category_factory_, base::Bind(&ParseJsonDelayed), |
168 kAPIKey); | 169 kAPIKey, &user_classifier_); |
169 | 170 |
170 snippets_fetcher_->SetCallback( | 171 snippets_fetcher_->SetCallback( |
171 base::Bind(&MockSnippetsAvailableCallback::WrappedRun, | 172 base::Bind(&MockSnippetsAvailableCallback::WrappedRun, |
172 base::Unretained(&mock_callback_))); | 173 base::Unretained(&mock_callback_))); |
173 snippets_fetcher_->SetTickClockForTesting( | 174 snippets_fetcher_->SetTickClockForTesting( |
174 mock_task_runner_->GetMockTickClock()); | 175 mock_task_runner_->GetMockTickClock()); |
175 test_hosts_.insert("www.somehost.com"); | 176 test_hosts_.insert("www.somehost.com"); |
176 test_excluded_.insert("1234567890"); | 177 test_excluded_.insert("1234567890"); |
177 // Increase initial time such that ticks are non-zero. | 178 // Increase initial time such that ticks are non-zero. |
178 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); | 179 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 base::ThreadTaskRunnerHandle mock_task_runner_handle_; | 213 base::ThreadTaskRunnerHandle mock_task_runner_handle_; |
213 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; | 214 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; |
214 // Initialized lazily in SetFakeResponse(). | 215 // Initialized lazily in SetFakeResponse(). |
215 std::unique_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory_; | 216 std::unique_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory_; |
216 std::unique_ptr<TestSigninClient> signin_client_; | 217 std::unique_ptr<TestSigninClient> signin_client_; |
217 std::unique_ptr<AccountTrackerService> account_tracker_; | 218 std::unique_ptr<AccountTrackerService> account_tracker_; |
218 std::unique_ptr<SigninManagerBase> fake_signin_manager_; | 219 std::unique_ptr<SigninManagerBase> fake_signin_manager_; |
219 std::unique_ptr<OAuth2TokenService> fake_token_service_; | 220 std::unique_ptr<OAuth2TokenService> fake_token_service_; |
220 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; | 221 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; |
221 std::unique_ptr<TestingPrefServiceSimple> pref_service_; | 222 std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
| 223 UserClassifier user_classifier_; |
222 CategoryFactory category_factory_; | 224 CategoryFactory category_factory_; |
223 MockSnippetsAvailableCallback mock_callback_; | 225 MockSnippetsAvailableCallback mock_callback_; |
224 const std::string test_lang_; | 226 const std::string test_lang_; |
225 const GURL test_url_; | 227 const GURL test_url_; |
226 std::set<std::string> test_hosts_; | 228 std::set<std::string> test_hosts_; |
227 std::set<std::string> test_excluded_; | 229 std::set<std::string> test_excluded_; |
228 base::HistogramTester histogram_tester_; | 230 base::HistogramTester histogram_tester_; |
229 | 231 |
230 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest); | 232 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest); |
231 }; | 233 }; |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 const NTPSnippetsFetcher::OptionalSnippets& snippets) { | 801 const NTPSnippetsFetcher::OptionalSnippets& snippets) { |
800 if (snippets) { | 802 if (snippets) { |
801 // Matchers above aren't any more precise than this, so this is sufficient | 803 // Matchers above aren't any more precise than this, so this is sufficient |
802 // for test-failure diagnostics. | 804 // for test-failure diagnostics. |
803 return os << "list with " << snippets->size() << " elements"; | 805 return os << "list with " << snippets->size() << " elements"; |
804 } | 806 } |
805 return os << "null"; | 807 return os << "null"; |
806 } | 808 } |
807 | 809 |
808 } // namespace ntp_snippets | 810 } // namespace ntp_snippets |
OLD | NEW |