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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/reading_list/reading_list_suggestions_provider_unittest.cc
diff --git a/components/ntp_snippets/reading_list/reading_list_suggestions_provider_unittest.cc b/components/ntp_snippets/reading_list/reading_list_suggestions_provider_unittest.cc
index 907a5c377eb5974c9df98433fa77e388533e7310..cdf962750611d2ace3702a99b3d741d55d222b64 100644
--- a/components/ntp_snippets/reading_list/reading_list_suggestions_provider_unittest.cc
+++ b/components/ntp_snippets/reading_list/reading_list_suggestions_provider_unittest.cc
@@ -15,17 +15,27 @@ namespace ntp_snippets {
namespace {
+using ::testing::Property;
+
class ReadingListSuggestionsProviderTest : public ::testing::Test {
public:
ReadingListSuggestionsProviderTest() {
+ std::unique_ptr<base::SimpleTestClock> clock =
+ base::MakeUnique<base::SimpleTestClock>();
+ clock_ = clock.get();
model_ = base::MakeUnique<ReadingListModelImpl>(
- /*storage_layer=*/nullptr, /*pref_service=*/nullptr,
- base::MakeUnique<base::SimpleTestClock>());
+ /*storage_layer=*/nullptr, /*pref_service=*/nullptr, std::move(clock));
+ }
+
+ void CreateProvider() {
EXPECT_CALL(observer_,
OnCategoryStatusChanged(testing::_, ReadingListCategory(),
CategoryStatus::AVAILABLE_LOADING))
.RetiresOnSaturation();
-
+ EXPECT_CALL(observer_,
+ OnCategoryStatusChanged(testing::_, ReadingListCategory(),
+ CategoryStatus::AVAILABLE))
+ .RetiresOnSaturation();
provider_ = base::MakeUnique<ReadingListSuggestionsProvider>(&observer_,
model_.get());
}
@@ -35,16 +45,79 @@ class ReadingListSuggestionsProviderTest : public ::testing::Test {
}
protected:
+ base::SimpleTestClock* clock_;
std::unique_ptr<ReadingListModelImpl> model_;
testing::StrictMock<MockContentSuggestionsProviderObserver> observer_;
std::unique_ptr<ReadingListSuggestionsProvider> provider_;
};
TEST_F(ReadingListSuggestionsProviderTest, CategoryInfo) {
+ EXPECT_CALL(observer_, OnNewSuggestions(testing::_, ReadingListCategory(),
+ 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.
+ .RetiresOnSaturation();
+ CreateProvider();
+
CategoryInfo categoryInfo = provider_->GetCategoryInfo(ReadingListCategory());
EXPECT_EQ(ContentSuggestionsAdditionalAction::VIEW_ALL,
categoryInfo.additional_action());
}
+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.
+ 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.
+ GURL urlUnread2 = GURL("http://www.foo2.bar");
+ GURL urlUnread3 = GURL("http://www.foo3.bar");
+ GURL urlUnread4 = GURL("http://www.foo4.bar");
+ GURL urlRead1 = GURL("http://www.bar.foor");
+ std::string unreadTitle1 = "title1";
+ std::string unreadTitle2 = "title2";
+ std::string unreadTitle3 = "title3";
+ std::string unreadTitle4 = "title3";
+ std::string readTitle1 = "readTitle4";
+ model_->AddEntry(urlUnread1, unreadTitle1,
+ reading_list::ADDED_VIA_CURRENT_APP);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(urlUnread2, unreadTitle2,
+ reading_list::ADDED_VIA_CURRENT_APP);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(urlRead1, readTitle1, reading_list::ADDED_VIA_CURRENT_APP);
+ model_->SetReadStatus(urlRead1, true);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(urlUnread3, unreadTitle3,
+ reading_list::ADDED_VIA_CURRENT_APP);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(urlUnread4, unreadTitle4,
+ reading_list::ADDED_VIA_CURRENT_APP);
+
+ EXPECT_CALL(
+ observer_,
+ OnNewSuggestions(
+ testing::_, ReadingListCategory(),
+ testing::ElementsAre(Property(&ContentSuggestion::url, urlUnread4),
+ Property(&ContentSuggestion::url, urlUnread3),
+ Property(&ContentSuggestion::url, urlUnread2))));
+
+ CreateProvider();
+}
+
+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.
+ GURL urlUnread1 = GURL("http://www.foo1.bar");
+ GURL urlRead1 = GURL("http://www.bar.foor");
+ std::string unreadTitle1 = "title1";
+ std::string readTitle1 = "readTitle4";
+ model_->AddEntry(urlUnread1, unreadTitle1,
+ reading_list::ADDED_VIA_CURRENT_APP);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(urlRead1, readTitle1, reading_list::ADDED_VIA_CURRENT_APP);
+ model_->SetReadStatus(urlRead1, true);
+
+ EXPECT_CALL(observer_,
+ OnNewSuggestions(testing::_, ReadingListCategory(),
+ testing::ElementsAre(Property(
+ &ContentSuggestion::url, urlUnread1))));
+
+ CreateProvider();
+}
+
} // namespace
+
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698