| 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/content_suggestions_service.h" | 5 #include "components/ntp_snippets/content_suggestions_service.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/time/default_clock.h" | 17 #include "base/time/default_clock.h" |
| 18 #include "components/ntp_snippets/category_info.h" | 18 #include "components/ntp_snippets/category_info.h" |
| 19 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" | 19 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" |
| 20 #include "components/ntp_snippets/category_rankers/fake_category_ranker.h" | 20 #include "components/ntp_snippets/category_rankers/fake_category_ranker.h" |
| 21 #include "components/ntp_snippets/category_rankers/mock_category_ranker.h" | 21 #include "components/ntp_snippets/category_rankers/mock_category_ranker.h" |
| 22 #include "components/ntp_snippets/category_status.h" | 22 #include "components/ntp_snippets/category_status.h" |
| 23 #include "components/ntp_snippets/content_suggestion.h" | 23 #include "components/ntp_snippets/content_suggestion.h" |
| 24 #include "components/ntp_snippets/content_suggestions_provider.h" | 24 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 25 #include "components/ntp_snippets/mock_content_suggestions_provider.h" | 25 #include "components/ntp_snippets/mock_content_suggestions_provider.h" |
| 26 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 26 #include "components/ntp_snippets/user_classifier.h" | 27 #include "components/ntp_snippets/user_classifier.h" |
| 27 #include "components/prefs/testing_pref_service.h" | 28 #include "components/prefs/testing_pref_service.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
| 31 | 32 |
| 32 using testing::_; | 33 using testing::_; |
| 33 using testing::ElementsAre; | 34 using testing::ElementsAre; |
| 34 using testing::Eq; | 35 using testing::Eq; |
| 35 using testing::InvokeWithoutArgs; | 36 using testing::InvokeWithoutArgs; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 135 |
| 135 void SetCategoryRanker(std::unique_ptr<CategoryRanker> category_ranker) { | 136 void SetCategoryRanker(std::unique_ptr<CategoryRanker> category_ranker) { |
| 136 category_ranker_ = std::move(category_ranker); | 137 category_ranker_ = std::move(category_ranker); |
| 137 } | 138 } |
| 138 | 139 |
| 139 MOCK_METHOD1(OnImageFetched, void(const gfx::Image&)); | 140 MOCK_METHOD1(OnImageFetched, void(const gfx::Image&)); |
| 140 | 141 |
| 141 protected: | 142 protected: |
| 142 void RegisterPrefs() { | 143 void RegisterPrefs() { |
| 143 ContentSuggestionsService::RegisterProfilePrefs(pref_service_->registry()); | 144 ContentSuggestionsService::RegisterProfilePrefs(pref_service_->registry()); |
| 145 RemoteSuggestionsProviderImpl::RegisterProfilePrefs( |
| 146 pref_service_->registry()); |
| 144 UserClassifier::RegisterProfilePrefs(pref_service_->registry()); | 147 UserClassifier::RegisterProfilePrefs(pref_service_->registry()); |
| 145 } | 148 } |
| 146 | 149 |
| 147 void CreateContentSuggestionsService( | 150 void CreateContentSuggestionsService( |
| 148 ContentSuggestionsService::State enabled) { | 151 ContentSuggestionsService::State enabled) { |
| 149 ASSERT_FALSE(service_); | 152 ASSERT_FALSE(service_); |
| 150 | 153 |
| 151 // TODO(jkrcal): Replace by a mock. | 154 // TODO(jkrcal): Replace by a mock. |
| 152 auto user_classifier = base::MakeUnique<UserClassifier>( | 155 auto user_classifier = base::MakeUnique<UserClassifier>( |
| 153 pref_service_.get(), base::MakeUnique<base::DefaultClock>()); | 156 pref_service_.get(), base::MakeUnique<base::DefaultClock>()); |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 Category category = Category::FromKnownCategory(KnownCategories::BOOKMARKS); | 811 Category category = Category::FromKnownCategory(KnownCategories::BOOKMARKS); |
| 809 MockContentSuggestionsProvider* provider = | 812 MockContentSuggestionsProvider* provider = |
| 810 MakeRegisteredMockProvider(category); | 813 MakeRegisteredMockProvider(category); |
| 811 provider->FireCategoryStatusChangedWithCurrentStatus(category); | 814 provider->FireCategoryStatusChangedWithCurrentStatus(category); |
| 812 | 815 |
| 813 EXPECT_CALL(*raw_mock_ranker, OnCategoryDismissed(category)); | 816 EXPECT_CALL(*raw_mock_ranker, OnCategoryDismissed(category)); |
| 814 service()->DismissCategory(category); | 817 service()->DismissCategory(category); |
| 815 } | 818 } |
| 816 | 819 |
| 817 } // namespace ntp_snippets | 820 } // namespace ntp_snippets |
| OLD | NEW |