Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_provider_impl.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "components/image_fetcher/image_decoder.h" | 26 #include "components/image_fetcher/image_decoder.h" |
| 27 #include "components/image_fetcher/image_fetcher.h" | 27 #include "components/image_fetcher/image_fetcher.h" |
| 28 #include "components/image_fetcher/image_fetcher_delegate.h" | 28 #include "components/image_fetcher/image_fetcher_delegate.h" |
| 29 #include "components/ntp_snippets/category.h" | 29 #include "components/ntp_snippets/category.h" |
| 30 #include "components/ntp_snippets/category_info.h" | 30 #include "components/ntp_snippets/category_info.h" |
| 31 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 31 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
| 32 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" | 32 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" |
| 33 #include "components/ntp_snippets/category_rankers/mock_category_ranker.h" | 33 #include "components/ntp_snippets/category_rankers/mock_category_ranker.h" |
| 34 #include "components/ntp_snippets/fake_content_suggestions_provider_observer.h" | 34 #include "components/ntp_snippets/fake_content_suggestions_provider_observer.h" |
| 35 #include "components/ntp_snippets/features.h" | |
| 35 #include "components/ntp_snippets/ntp_snippets_constants.h" | 36 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 36 #include "components/ntp_snippets/pref_names.h" | 37 #include "components/ntp_snippets/pref_names.h" |
| 37 #include "components/ntp_snippets/remote/persistent_scheduler.h" | 38 #include "components/ntp_snippets/remote/persistent_scheduler.h" |
| 38 #include "components/ntp_snippets/remote/remote_suggestion.h" | 39 #include "components/ntp_snippets/remote/remote_suggestion.h" |
| 39 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 40 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
| 40 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" | 41 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
| 41 #include "components/ntp_snippets/remote/test_utils.h" | 42 #include "components/ntp_snippets/remote/test_utils.h" |
| 42 #include "components/ntp_snippets/user_classifier.h" | 43 #include "components/ntp_snippets/user_classifier.h" |
| 43 #include "components/prefs/testing_pref_service.h" | 44 #include "components/prefs/testing_pref_service.h" |
| 44 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 45 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 MATCHER_P(IsCategory, id, "") { | 85 MATCHER_P(IsCategory, id, "") { |
| 85 return arg.id() == static_cast<int>(id); | 86 return arg.id() == static_cast<int>(id); |
| 86 } | 87 } |
| 87 | 88 |
| 88 MATCHER_P(HasCode, code, "") { | 89 MATCHER_P(HasCode, code, "") { |
| 89 return arg.code == code; | 90 return arg.code == code; |
| 90 } | 91 } |
| 91 | 92 |
| 92 const base::Time::Exploded kDefaultCreationTime = {2015, 11, 4, 25, 13, 46, 45}; | 93 const base::Time::Exploded kDefaultCreationTime = {2015, 11, 4, 25, 13, 46, 45}; |
| 93 const char kTestContentSuggestionsServerEndpoint[] = | 94 const char kTestContentSuggestionsServerEndpoint[] = |
| 94 "https://localunittest-chromecontentsuggestions-pa.googleapis.com/v1/" | 95 "https://alpha-chromecontentsuggestions-pa.sandbox.googleapis.com/v1/" |
|
jkrcal
2017/02/03 10:17:49
Changed this to avoid warnings from RemoteSuggesti
| |
| 95 "suggestions/fetch"; | 96 "suggestions/fetch"; |
| 96 const char kAPIKey[] = "fakeAPIkey"; | 97 const char kAPIKey[] = "fakeAPIkey"; |
| 97 const char kTestContentSuggestionsServerWithAPIKey[] = | 98 const char kTestContentSuggestionsServerWithAPIKey[] = |
| 98 "https://localunittest-chromecontentsuggestions-pa.googleapis.com/v1/" | 99 "https://alpha-chromecontentsuggestions-pa.sandbox.googleapis.com/v1/" |
| 99 "suggestions/fetch?key=fakeAPIkey"; | 100 "suggestions/fetch?key=fakeAPIkey"; |
| 100 | 101 |
| 101 const char kSuggestionUrl[] = "http://localhost/foobar"; | 102 const char kSuggestionUrl[] = "http://localhost/foobar"; |
| 102 const char kSuggestionTitle[] = "Title"; | 103 const char kSuggestionTitle[] = "Title"; |
| 103 const char kSuggestionText[] = "Suggestion"; | 104 const char kSuggestionText[] = "Suggestion"; |
| 104 const char kSuggestionSalientImage[] = "http://localhost/salient_image"; | 105 const char kSuggestionSalientImage[] = "http://localhost/salient_image"; |
| 105 const char kSuggestionPublisherName[] = "Foo News"; | 106 const char kSuggestionPublisherName[] = "Foo News"; |
| 106 const char kSuggestionAmpUrl[] = "http://localhost/amp"; | 107 const char kSuggestionAmpUrl[] = "http://localhost/amp"; |
| 107 | 108 |
| 108 const char kSuggestionUrl2[] = "http://foo.com/bar"; | 109 const char kSuggestionUrl2[] = "http://foo.com/bar"; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 gfx::Image decoded_image_; | 362 gfx::Image decoded_image_; |
| 362 }; | 363 }; |
| 363 | 364 |
| 364 } // namespace | 365 } // namespace |
| 365 | 366 |
| 366 class RemoteSuggestionsProviderImplTest : public ::testing::Test { | 367 class RemoteSuggestionsProviderImplTest : public ::testing::Test { |
| 367 public: | 368 public: |
| 368 RemoteSuggestionsProviderImplTest() | 369 RemoteSuggestionsProviderImplTest() |
| 369 : params_manager_(ntp_snippets::kStudyName, | 370 : params_manager_(ntp_snippets::kStudyName, |
| 370 {{"content_suggestions_backend", | 371 {{"content_suggestions_backend", |
| 371 kTestContentSuggestionsServerEndpoint}, | 372 kTestContentSuggestionsServerEndpoint}}, |
| 372 {"fetching_personalization", "non_personal"}}), | 373 {ntp_snippets::kArticleSuggestionsFeature.name}), |
| 373 fake_url_fetcher_factory_( | 374 fake_url_fetcher_factory_( |
| 374 /*default_factory=*/&failing_url_fetcher_factory_), | 375 /*default_factory=*/&failing_url_fetcher_factory_), |
| 375 test_url_(kTestContentSuggestionsServerWithAPIKey), | 376 test_url_(kTestContentSuggestionsServerWithAPIKey), |
| 377 fake_token_service_(nullptr), | |
|
jkrcal
2017/02/03 10:17:49
Added to increase clarity that null token service
| |
| 376 category_ranker_(base::MakeUnique<ConstantCategoryRanker>()), | 378 category_ranker_(base::MakeUnique<ConstantCategoryRanker>()), |
| 377 user_classifier_(/*pref_service=*/nullptr), | 379 user_classifier_(/*pref_service=*/nullptr), |
| 378 suggestions_fetcher_(nullptr), | 380 suggestions_fetcher_(nullptr), |
| 379 image_fetcher_(nullptr), | 381 image_fetcher_(nullptr), |
| 380 image_decoder_(nullptr), | 382 image_decoder_(nullptr), |
| 381 database_(nullptr) { | 383 database_(nullptr) { |
| 382 RemoteSuggestionsProviderImpl::RegisterProfilePrefs( | 384 RemoteSuggestionsProviderImpl::RegisterProfilePrefs( |
| 383 utils_.pref_service()->registry()); | 385 utils_.pref_service()->registry()); |
| 384 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); | 386 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); |
| 385 | 387 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 409 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter = | 411 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter = |
| 410 new net::TestURLRequestContextGetter(task_runner.get()); | 412 new net::TestURLRequestContextGetter(task_runner.get()); |
| 411 | 413 |
| 412 utils_.ResetSigninManager(); | 414 utils_.ResetSigninManager(); |
| 413 auto suggestions_fetcher = base::MakeUnique<RemoteSuggestionsFetcher>( | 415 auto suggestions_fetcher = base::MakeUnique<RemoteSuggestionsFetcher>( |
| 414 utils_.fake_signin_manager(), fake_token_service_.get(), | 416 utils_.fake_signin_manager(), fake_token_service_.get(), |
| 415 std::move(request_context_getter), utils_.pref_service(), nullptr, | 417 std::move(request_context_getter), utils_.pref_service(), nullptr, |
| 416 base::Bind(&ParseJson), kAPIKey, &user_classifier_); | 418 base::Bind(&ParseJson), kAPIKey, &user_classifier_); |
| 417 suggestions_fetcher_ = suggestions_fetcher.get(); | 419 suggestions_fetcher_ = suggestions_fetcher.get(); |
| 418 | 420 |
| 419 utils_.fake_signin_manager()->SignIn("foo@bar.com"); | |
|
jkrcal
2017/02/03 10:17:49
I emulate the previous (not-signed-in) behaviour)
Marc Treib
2017/02/03 10:52:08
So the previous state was signed-in, but personali
| |
| 420 | |
| 421 auto image_fetcher = base::MakeUnique<NiceMock<MockImageFetcher>>(); | 421 auto image_fetcher = base::MakeUnique<NiceMock<MockImageFetcher>>(); |
| 422 | 422 |
| 423 image_fetcher_ = image_fetcher.get(); | 423 image_fetcher_ = image_fetcher.get(); |
| 424 EXPECT_CALL(*image_fetcher, SetImageFetcherDelegate(_)); | 424 EXPECT_CALL(*image_fetcher, SetImageFetcherDelegate(_)); |
| 425 auto image_decoder = base::MakeUnique<FakeImageDecoder>(); | 425 auto image_decoder = base::MakeUnique<FakeImageDecoder>(); |
| 426 image_decoder_ = image_decoder.get(); | 426 image_decoder_ = image_decoder.get(); |
| 427 EXPECT_FALSE(observer_); | 427 EXPECT_FALSE(observer_); |
| 428 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); | 428 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); |
| 429 auto database = base::MakeUnique<RemoteSuggestionsDatabase>( | 429 auto database = base::MakeUnique<RemoteSuggestionsDatabase>( |
| 430 database_dir_.GetPath(), task_runner); | 430 database_dir_.GetPath(), task_runner); |
| (...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1816 RemoteSuggestionsProvider::ProviderStatus)>::Call, | 1816 RemoteSuggestionsProvider::ProviderStatus)>::Call, |
| 1817 base::Unretained(&status_callback)))); | 1817 base::Unretained(&status_callback)))); |
| 1818 | 1818 |
| 1819 // Should be called when becoming disabled. | 1819 // Should be called when becoming disabled. |
| 1820 EXPECT_CALL(status_callback, | 1820 EXPECT_CALL(status_callback, |
| 1821 Call(RemoteSuggestionsProvider::ProviderStatus::INACTIVE)); | 1821 Call(RemoteSuggestionsProvider::ProviderStatus::INACTIVE)); |
| 1822 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); | 1822 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); |
| 1823 } | 1823 } |
| 1824 | 1824 |
| 1825 } // namespace ntp_snippets | 1825 } // namespace ntp_snippets |
| OLD | NEW |