Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1383)

Side by Side Diff: components/ntp_snippets/reading_list/reading_list_suggestions_provider_unittest.cc

Issue 2770893003: Add logic for fetching the Reading List entries (Closed)
Patch Set: Address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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::Property;
19
18 class ReadingListSuggestionsProviderTest : public ::testing::Test { 20 class ReadingListSuggestionsProviderTest : public ::testing::Test {
19 public: 21 public:
20 ReadingListSuggestionsProviderTest() { 22 ReadingListSuggestionsProviderTest() {
23 std::unique_ptr<base::SimpleTestClock> clock =
24 base::MakeUnique<base::SimpleTestClock>();
25 clock_ = clock.get();
21 model_ = base::MakeUnique<ReadingListModelImpl>( 26 model_ = base::MakeUnique<ReadingListModelImpl>(
22 /*storage_layer=*/nullptr, /*pref_service=*/nullptr, 27 /*storage_layer=*/nullptr, /*pref_service=*/nullptr, std::move(clock));
23 base::MakeUnique<base::SimpleTestClock>()); 28 }
29
30 void CreateProvider() {
24 EXPECT_CALL(observer_, 31 EXPECT_CALL(observer_,
25 OnCategoryStatusChanged(testing::_, ReadingListCategory(), 32 OnCategoryStatusChanged(testing::_, ReadingListCategory(),
26 CategoryStatus::AVAILABLE_LOADING)) 33 CategoryStatus::AVAILABLE_LOADING))
27 .RetiresOnSaturation(); 34 .RetiresOnSaturation();
28 35 EXPECT_CALL(observer_,
36 OnCategoryStatusChanged(testing::_, ReadingListCategory(),
37 CategoryStatus::AVAILABLE))
38 .RetiresOnSaturation();
29 provider_ = base::MakeUnique<ReadingListSuggestionsProvider>(&observer_, 39 provider_ = base::MakeUnique<ReadingListSuggestionsProvider>(&observer_,
30 model_.get()); 40 model_.get());
31 } 41 }
32 42
33 Category ReadingListCategory() { 43 Category ReadingListCategory() {
34 return Category::FromKnownCategory(KnownCategories::READING_LIST); 44 return Category::FromKnownCategory(KnownCategories::READING_LIST);
35 } 45 }
36 46
37 protected: 47 protected:
48 base::SimpleTestClock* clock_;
38 std::unique_ptr<ReadingListModelImpl> model_; 49 std::unique_ptr<ReadingListModelImpl> model_;
39 testing::StrictMock<MockContentSuggestionsProviderObserver> observer_; 50 testing::StrictMock<MockContentSuggestionsProviderObserver> observer_;
40 std::unique_ptr<ReadingListSuggestionsProvider> provider_; 51 std::unique_ptr<ReadingListSuggestionsProvider> provider_;
41 }; 52 };
42 53
43 TEST_F(ReadingListSuggestionsProviderTest, CategoryInfo) { 54 TEST_F(ReadingListSuggestionsProviderTest, CategoryInfo) {
55 EXPECT_CALL(observer_, OnNewSuggestions(testing::_, ReadingListCategory(),
56 testing::IsEmpty()))
Marc Treib 2017/03/28 13:25:16 Add using declarations for the testing:: things?
gambard 2017/03/28 15:10:09 Done.
57 .RetiresOnSaturation();
58 CreateProvider();
59
44 CategoryInfo categoryInfo = provider_->GetCategoryInfo(ReadingListCategory()); 60 CategoryInfo categoryInfo = provider_->GetCategoryInfo(ReadingListCategory());
45 EXPECT_EQ(ContentSuggestionsAdditionalAction::VIEW_ALL, 61 EXPECT_EQ(ContentSuggestionsAdditionalAction::VIEW_ALL,
46 categoryInfo.additional_action()); 62 categoryInfo.additional_action());
47 } 63 }
48 64
65 TEST_F(ReadingListSuggestionsProviderTest, ReturnedSuggestions) {
Marc Treib 2017/03/28 13:25:16 nit: What does this test actually test? "ReturnsTh
gambard 2017/03/28 15:10:08 Done.
66 GURL urlUnread1 = GURL("http://www.foo1.bar");
Marc Treib 2017/03/28 13:25:16 url_unread1 etc
gambard 2017/03/28 15:10:07 Done.
67 GURL urlUnread2 = GURL("http://www.foo2.bar");
68 GURL urlUnread3 = GURL("http://www.foo3.bar");
69 GURL urlUnread4 = GURL("http://www.foo4.bar");
70 GURL urlRead1 = GURL("http://www.bar.foor");
71 std::string unreadTitle1 = "title1";
72 std::string unreadTitle2 = "title2";
73 std::string unreadTitle3 = "title3";
74 std::string unreadTitle4 = "title3";
75 std::string readTitle1 = "readTitle4";
76 model_->AddEntry(urlUnread1, unreadTitle1,
77 reading_list::ADDED_VIA_CURRENT_APP);
78 clock_->Advance(base::TimeDelta::FromMilliseconds(10));
79 model_->AddEntry(urlUnread2, unreadTitle2,
80 reading_list::ADDED_VIA_CURRENT_APP);
81 clock_->Advance(base::TimeDelta::FromMilliseconds(10));
82 model_->AddEntry(urlRead1, readTitle1, reading_list::ADDED_VIA_CURRENT_APP);
83 model_->SetReadStatus(urlRead1, true);
84 clock_->Advance(base::TimeDelta::FromMilliseconds(10));
85 model_->AddEntry(urlUnread3, unreadTitle3,
86 reading_list::ADDED_VIA_CURRENT_APP);
87 clock_->Advance(base::TimeDelta::FromMilliseconds(10));
88 model_->AddEntry(urlUnread4, unreadTitle4,
89 reading_list::ADDED_VIA_CURRENT_APP);
90
91 EXPECT_CALL(
92 observer_,
93 OnNewSuggestions(
94 testing::_, ReadingListCategory(),
95 testing::ElementsAre(Property(&ContentSuggestion::url, urlUnread4),
96 Property(&ContentSuggestion::url, urlUnread3),
97 Property(&ContentSuggestion::url, urlUnread2))));
98
99 CreateProvider();
100 }
101
102 TEST_F(ReadingListSuggestionsProviderTest, OneReturnedSuggestions) {
Marc Treib 2017/03/28 13:25:16 Also here: The test name should say what the test
gambard 2017/03/28 15:10:07 Done.
103 GURL urlUnread1 = GURL("http://www.foo1.bar");
104 GURL urlRead1 = GURL("http://www.bar.foor");
105 std::string unreadTitle1 = "title1";
106 std::string readTitle1 = "readTitle4";
107 model_->AddEntry(urlUnread1, unreadTitle1,
108 reading_list::ADDED_VIA_CURRENT_APP);
109 clock_->Advance(base::TimeDelta::FromMilliseconds(10));
110 model_->AddEntry(urlRead1, readTitle1, reading_list::ADDED_VIA_CURRENT_APP);
111 model_->SetReadStatus(urlRead1, true);
112
113 EXPECT_CALL(observer_,
114 OnNewSuggestions(testing::_, ReadingListCategory(),
115 testing::ElementsAre(Property(
116 &ContentSuggestion::url, urlUnread1))));
117
118 CreateProvider();
119 }
120
49 } // namespace 121 } // namespace
122
50 } // namespace ntp_snippets 123 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698