| 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/remote_suggestions_fetcher.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
| 17 #include "base/test/test_mock_time_task_runner.h" | 17 #include "base/test/test_mock_time_task_runner.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/time/default_clock.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "base/values.h" | 21 #include "base/values.h" |
| 21 #include "components/ntp_snippets/category.h" | 22 #include "components/ntp_snippets/category.h" |
| 22 #include "components/ntp_snippets/features.h" | 23 #include "components/ntp_snippets/features.h" |
| 23 #include "components/ntp_snippets/ntp_snippets_constants.h" | 24 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 24 #include "components/ntp_snippets/remote/remote_suggestion.h" | 25 #include "components/ntp_snippets/remote/remote_suggestion.h" |
| 25 #include "components/ntp_snippets/remote/request_params.h" | 26 #include "components/ntp_snippets/remote/request_params.h" |
| 26 #include "components/ntp_snippets/remote/test_utils.h" | 27 #include "components/ntp_snippets/remote/test_utils.h" |
| 27 #include "components/ntp_snippets/user_classifier.h" | 28 #include "components/ntp_snippets/user_classifier.h" |
| 28 #include "components/prefs/testing_pref_service.h" | 29 #include "components/prefs/testing_pref_service.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 explicit RemoteSuggestionsFetcherTestBase(const GURL& gurl) | 274 explicit RemoteSuggestionsFetcherTestBase(const GURL& gurl) |
| 274 : default_variation_params_( | 275 : default_variation_params_( |
| 275 {{"send_top_languages", "true"}, {"send_user_class", "true"}}), | 276 {{"send_top_languages", "true"}, {"send_user_class", "true"}}), |
| 276 params_manager_(ntp_snippets::kStudyName, | 277 params_manager_(ntp_snippets::kStudyName, |
| 277 default_variation_params_, | 278 default_variation_params_, |
| 278 {ntp_snippets::kArticleSuggestionsFeature.name}), | 279 {ntp_snippets::kArticleSuggestionsFeature.name}), |
| 279 mock_task_runner_(new base::TestMockTimeTaskRunner()), | 280 mock_task_runner_(new base::TestMockTimeTaskRunner()), |
| 280 mock_task_runner_handle_(mock_task_runner_), | 281 mock_task_runner_handle_(mock_task_runner_), |
| 281 test_url_(gurl) { | 282 test_url_(gurl) { |
| 282 UserClassifier::RegisterProfilePrefs(utils_.pref_service()->registry()); | 283 UserClassifier::RegisterProfilePrefs(utils_.pref_service()->registry()); |
| 283 user_classifier_ = base::MakeUnique<UserClassifier>(utils_.pref_service()); | 284 user_classifier_ = base::MakeUnique<UserClassifier>( |
| 285 utils_.pref_service(), base::MakeUnique<base::DefaultClock>()); |
| 284 // Increase initial time such that ticks are non-zero. | 286 // Increase initial time such that ticks are non-zero. |
| 285 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); | 287 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); |
| 286 ResetFetcher(); | 288 ResetFetcher(); |
| 287 } | 289 } |
| 288 | 290 |
| 289 void ResetFetcher() { ResetFetcherWithAPIKey(kAPIKey); } | 291 void ResetFetcher() { ResetFetcherWithAPIKey(kAPIKey); } |
| 290 | 292 |
| 291 void ResetFetcherWithAPIKey(const std::string& api_key) { | 293 void ResetFetcherWithAPIKey(const std::string& api_key) { |
| 292 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter = | 294 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter = |
| 293 new net::TestURLRequestContextGetter(mock_task_runner_.get()); | 295 new net::TestURLRequestContextGetter(mock_task_runner_.get()); |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 fetched_categories) { | 1036 fetched_categories) { |
| 1035 if (fetched_categories) { | 1037 if (fetched_categories) { |
| 1036 // Matchers above aren't any more precise than this, so this is sufficient | 1038 // Matchers above aren't any more precise than this, so this is sufficient |
| 1037 // for test-failure diagnostics. | 1039 // for test-failure diagnostics. |
| 1038 return os << "list with " << fetched_categories->size() << " elements"; | 1040 return os << "list with " << fetched_categories->size() << " elements"; |
| 1039 } | 1041 } |
| 1040 return os << "null"; | 1042 return os << "null"; |
| 1041 } | 1043 } |
| 1042 | 1044 |
| 1043 } // namespace ntp_snippets | 1045 } // namespace ntp_snippets |
| OLD | NEW |