| 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/offline_pages/recent_tab_suggestions_provider.
h" | 5 #include "components/ntp_snippets/offline_pages/recent_tab_suggestions_provider.
h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "components/ntp_snippets/category.h" | 14 #include "components/ntp_snippets/category.h" |
| 15 #include "components/ntp_snippets/category_factory.h" | |
| 16 #include "components/ntp_snippets/content_suggestions_provider.h" | 15 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 17 #include "components/ntp_snippets/mock_content_suggestions_provider_observer.h" | 16 #include "components/ntp_snippets/mock_content_suggestions_provider_observer.h" |
| 18 #include "components/ntp_snippets/offline_pages/offline_pages_test_utils.h" | 17 #include "components/ntp_snippets/offline_pages/offline_pages_test_utils.h" |
| 19 #include "components/offline_pages/core/client_namespace_constants.h" | 18 #include "components/offline_pages/core/client_namespace_constants.h" |
| 20 #include "components/offline_pages/core/offline_page_item.h" | 19 #include "components/offline_pages/core/offline_page_item.h" |
| 21 #include "components/offline_pages/core/stub_offline_page_model.h" | 20 #include "components/offline_pages/core/stub_offline_page_model.h" |
| 22 #include "components/prefs/testing_pref_service.h" | 21 #include "components/prefs/testing_pref_service.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 24 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 60 |
| 62 } // namespace | 61 } // namespace |
| 63 | 62 |
| 64 class RecentTabSuggestionsProviderTest : public testing::Test { | 63 class RecentTabSuggestionsProviderTest : public testing::Test { |
| 65 public: | 64 public: |
| 66 RecentTabSuggestionsProviderTest() | 65 RecentTabSuggestionsProviderTest() |
| 67 : pref_service_(new TestingPrefServiceSimple()) { | 66 : pref_service_(new TestingPrefServiceSimple()) { |
| 68 RecentTabSuggestionsProvider::RegisterProfilePrefs( | 67 RecentTabSuggestionsProvider::RegisterProfilePrefs( |
| 69 pref_service()->registry()); | 68 pref_service()->registry()); |
| 70 | 69 |
| 71 provider_.reset(new RecentTabSuggestionsProvider( | 70 provider_.reset( |
| 72 &observer_, &category_factory_, &model_, pref_service())); | 71 new RecentTabSuggestionsProvider(&observer_, &model_, pref_service())); |
| 73 } | 72 } |
| 74 | 73 |
| 75 Category recent_tabs_category() { | 74 Category recent_tabs_category() { |
| 76 return category_factory_.FromKnownCategory(KnownCategories::RECENT_TABS); | 75 return Category::FromKnownCategory(KnownCategories::RECENT_TABS); |
| 77 } | 76 } |
| 78 | 77 |
| 79 ContentSuggestion::ID GetDummySuggestionId(int id) { | 78 ContentSuggestion::ID GetDummySuggestionId(int id) { |
| 80 return ContentSuggestion::ID(recent_tabs_category(), base::IntToString(id)); | 79 return ContentSuggestion::ID(recent_tabs_category(), base::IntToString(id)); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void AddOfflinePageToModel(const OfflinePageItem& item) { | 82 void AddOfflinePageToModel(const OfflinePageItem& item) { |
| 84 model_.mutable_items()->push_back(item); | 83 model_.mutable_items()->push_back(item); |
| 85 provider_->OfflinePageAdded(&model_, item); | 84 provider_->OfflinePageAdded(&model_, item); |
| 86 } | 85 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 99 } | 98 } |
| 100 | 99 |
| 101 RecentTabSuggestionsProvider* provider() { return provider_.get(); } | 100 RecentTabSuggestionsProvider* provider() { return provider_.get(); } |
| 102 FakeOfflinePageModel* model() { return &model_; } | 101 FakeOfflinePageModel* model() { return &model_; } |
| 103 MockContentSuggestionsProviderObserver* observer() { return &observer_; } | 102 MockContentSuggestionsProviderObserver* observer() { return &observer_; } |
| 104 TestingPrefServiceSimple* pref_service() { return pref_service_.get(); } | 103 TestingPrefServiceSimple* pref_service() { return pref_service_.get(); } |
| 105 | 104 |
| 106 private: | 105 private: |
| 107 FakeOfflinePageModel model_; | 106 FakeOfflinePageModel model_; |
| 108 MockContentSuggestionsProviderObserver observer_; | 107 MockContentSuggestionsProviderObserver observer_; |
| 109 CategoryFactory category_factory_; | |
| 110 std::unique_ptr<TestingPrefServiceSimple> pref_service_; | 108 std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
| 111 // Last so that the dependencies are deleted after the provider. | 109 // Last so that the dependencies are deleted after the provider. |
| 112 std::unique_ptr<RecentTabSuggestionsProvider> provider_; | 110 std::unique_ptr<RecentTabSuggestionsProvider> provider_; |
| 113 | 111 |
| 114 DISALLOW_COPY_AND_ASSIGN(RecentTabSuggestionsProviderTest); | 112 DISALLOW_COPY_AND_ASSIGN(RecentTabSuggestionsProviderTest); |
| 115 }; | 113 }; |
| 116 | 114 |
| 117 TEST_F(RecentTabSuggestionsProviderTest, ShouldConvertToSuggestions) { | 115 TEST_F(RecentTabSuggestionsProviderTest, ShouldConvertToSuggestions) { |
| 118 auto recent_tabs_list = CreateDummyRecentTabs({1, 2}); | 116 auto recent_tabs_list = CreateDummyRecentTabs({1, 2}); |
| 119 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(2); | 117 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(2); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 OnNewSuggestions( | 300 OnNewSuggestions( |
| 303 _, recent_tabs_category(), | 301 _, recent_tabs_category(), |
| 304 UnorderedElementsAre( | 302 UnorderedElementsAre( |
| 305 Property(&ContentSuggestion::publish_date, now), | 303 Property(&ContentSuggestion::publish_date, now), |
| 306 Property(&ContentSuggestion::publish_date, tomorrow)))); | 304 Property(&ContentSuggestion::publish_date, tomorrow)))); |
| 307 | 305 |
| 308 AddOfflinePageToModel(offline_pages[2]); | 306 AddOfflinePageToModel(offline_pages[2]); |
| 309 } | 307 } |
| 310 | 308 |
| 311 } // namespace ntp_snippets | 309 } // namespace ntp_snippets |
| OLD | NEW |