OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/reading_list/reading_list_suggestions_provider .h" | 5 #include "components/ntp_snippets/reading_list/reading_list_suggestions_provider .h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/test/simple_test_clock.h" | 8 #include "base/test/simple_test_clock.h" |
9 #include "components/ntp_snippets/mock_content_suggestions_provider_observer.h" | 9 #include "components/ntp_snippets/mock_content_suggestions_provider_observer.h" |
10 #include "components/reading_list/core/reading_list_model_impl.h" | 10 #include "components/reading_list/core/reading_list_model_impl.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace ntp_snippets { | 14 namespace ntp_snippets { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 using ::testing::_; | |
19 using ::testing::ElementsAre; | |
20 using ::testing::IsEmpty; | |
21 using ::testing::Property; | |
22 | |
18 class ReadingListSuggestionsProviderTest : public ::testing::Test { | 23 class ReadingListSuggestionsProviderTest : public ::testing::Test { |
19 public: | 24 public: |
20 ReadingListSuggestionsProviderTest() { | 25 ReadingListSuggestionsProviderTest() { |
26 std::unique_ptr<base::SimpleTestClock> clock = | |
27 base::MakeUnique<base::SimpleTestClock>(); | |
28 clock_ = clock.get(); | |
21 model_ = base::MakeUnique<ReadingListModelImpl>( | 29 model_ = base::MakeUnique<ReadingListModelImpl>( |
22 /*storage_layer=*/nullptr, /*pref_service=*/nullptr, | 30 /*storage_layer=*/nullptr, /*pref_service=*/nullptr, std::move(clock)); |
23 base::MakeUnique<base::SimpleTestClock>()); | 31 } |
32 | |
33 void CreateProvider() { | |
24 EXPECT_CALL(observer_, | 34 EXPECT_CALL(observer_, |
25 OnCategoryStatusChanged(testing::_, ReadingListCategory(), | 35 OnCategoryStatusChanged(_, ReadingListCategory(), |
26 CategoryStatus::AVAILABLE_LOADING)) | 36 CategoryStatus::AVAILABLE_LOADING)) |
27 .RetiresOnSaturation(); | 37 .RetiresOnSaturation(); |
28 | 38 EXPECT_CALL(observer_, OnCategoryStatusChanged(_, ReadingListCategory(), |
39 CategoryStatus::AVAILABLE)) | |
40 .RetiresOnSaturation(); | |
29 provider_ = base::MakeUnique<ReadingListSuggestionsProvider>(&observer_, | 41 provider_ = base::MakeUnique<ReadingListSuggestionsProvider>(&observer_, |
30 model_.get()); | 42 model_.get()); |
31 } | 43 } |
32 | 44 |
33 Category ReadingListCategory() { | 45 Category ReadingListCategory() { |
34 return Category::FromKnownCategory(KnownCategories::READING_LIST); | 46 return Category::FromKnownCategory(KnownCategories::READING_LIST); |
35 } | 47 } |
36 | 48 |
37 protected: | 49 protected: |
50 base::SimpleTestClock* clock_; | |
38 std::unique_ptr<ReadingListModelImpl> model_; | 51 std::unique_ptr<ReadingListModelImpl> model_; |
39 testing::StrictMock<MockContentSuggestionsProviderObserver> observer_; | 52 testing::StrictMock<MockContentSuggestionsProviderObserver> observer_; |
40 std::unique_ptr<ReadingListSuggestionsProvider> provider_; | 53 std::unique_ptr<ReadingListSuggestionsProvider> provider_; |
41 }; | 54 }; |
42 | 55 |
43 TEST_F(ReadingListSuggestionsProviderTest, CategoryInfo) { | 56 TEST_F(ReadingListSuggestionsProviderTest, CategoryInfo) { |
57 EXPECT_CALL(observer_, OnNewSuggestions(_, ReadingListCategory(), IsEmpty())) | |
58 .RetiresOnSaturation(); | |
59 CreateProvider(); | |
60 | |
44 CategoryInfo categoryInfo = provider_->GetCategoryInfo(ReadingListCategory()); | 61 CategoryInfo categoryInfo = provider_->GetCategoryInfo(ReadingListCategory()); |
45 EXPECT_EQ(ContentSuggestionsAdditionalAction::VIEW_ALL, | 62 EXPECT_EQ(ContentSuggestionsAdditionalAction::VIEW_ALL, |
46 categoryInfo.additional_action()); | 63 categoryInfo.additional_action()); |
47 } | 64 } |
48 | 65 |
66 TEST_F(ReadingListSuggestionsProviderTest, ReturnsThreeLatestUnreadSuggestion) { | |
67 GURL url_unread1 = GURL("http://www.foo1.bar"); | |
68 GURL url_unread2 = GURL("http://www.foo2.bar"); | |
69 GURL url_unread3 = GURL("http://www.foo3.bar"); | |
70 GURL url_unread4 = GURL("http://www.foo4.bar"); | |
71 GURL urlRead1 = GURL("http://www.bar.foor"); | |
Marc Treib
2017/03/28 15:31:29
url_read
also, nitty nit: url_unread vs unread_ti
gambard
2017/03/28 15:40:10
I missed this one :)
Done and done.
| |
72 std::string unread_title1 = "title1"; | |
73 std::string unread_title2 = "title2"; | |
74 std::string unread_title3 = "title3"; | |
75 std::string unread_title4 = "title4"; | |
76 std::string read_title1 = "read_title1"; | |
77 model_->AddEntry(url_unread1, unread_title1, | |
78 reading_list::ADDED_VIA_CURRENT_APP); | |
79 clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
80 model_->AddEntry(url_unread2, unread_title2, | |
81 reading_list::ADDED_VIA_CURRENT_APP); | |
82 clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
83 model_->AddEntry(urlRead1, read_title1, reading_list::ADDED_VIA_CURRENT_APP); | |
84 model_->SetReadStatus(urlRead1, true); | |
85 clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
86 model_->AddEntry(url_unread3, unread_title3, | |
87 reading_list::ADDED_VIA_CURRENT_APP); | |
88 clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
89 model_->AddEntry(url_unread4, unread_title4, | |
90 reading_list::ADDED_VIA_CURRENT_APP); | |
91 | |
92 EXPECT_CALL(observer_, | |
93 OnNewSuggestions( | |
94 _, ReadingListCategory(), | |
95 ElementsAre(Property(&ContentSuggestion::url, url_unread4), | |
96 Property(&ContentSuggestion::url, url_unread3), | |
97 Property(&ContentSuggestion::url, url_unread2)))); | |
98 | |
99 CreateProvider(); | |
100 } | |
101 | |
102 TEST_F(ReadingListSuggestionsProviderTest, ReturnsOneUnreadSuggestion) { | |
Marc Treib
2017/03/28 15:31:29
It's still not clear to me what exactly this tests
gambard
2017/03/28 15:40:10
It tests that if you have less than kMaxEntries un
| |
103 GURL url_unread1 = GURL("http://www.foo1.bar"); | |
104 GURL urlRead1 = GURL("http://www.bar.foor"); | |
Marc Treib
2017/03/28 15:31:29
url_read
gambard
2017/03/28 15:40:10
Done.
| |
105 std::string unread_title1 = "title1"; | |
106 std::string read_title1 = "read_title1"; | |
107 model_->AddEntry(url_unread1, unread_title1, | |
108 reading_list::ADDED_VIA_CURRENT_APP); | |
109 clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
110 model_->AddEntry(urlRead1, read_title1, reading_list::ADDED_VIA_CURRENT_APP); | |
111 model_->SetReadStatus(urlRead1, true); | |
112 | |
113 EXPECT_CALL(observer_, | |
114 OnNewSuggestions( | |
115 _, ReadingListCategory(), | |
116 ElementsAre(Property(&ContentSuggestion::url, url_unread1)))); | |
117 | |
118 CreateProvider(); | |
119 } | |
120 | |
49 } // namespace | 121 } // namespace |
122 | |
50 } // namespace ntp_snippets | 123 } // namespace ntp_snippets |
OLD | NEW |