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

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: Add title logic 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
« no previous file with comments | « components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6f91ed2ef8b244c5c9aeea090885910f9dcf47db 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,29 @@ namespace ntp_snippets {
namespace {
+using ::testing::_;
+using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+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(),
+ OnCategoryStatusChanged(_, ReadingListCategory(),
CategoryStatus::AVAILABLE_LOADING))
.RetiresOnSaturation();
-
+ EXPECT_CALL(observer_, OnCategoryStatusChanged(_, ReadingListCategory(),
+ CategoryStatus::AVAILABLE))
+ .RetiresOnSaturation();
provider_ = base::MakeUnique<ReadingListSuggestionsProvider>(&observer_,
model_.get());
}
@@ -35,16 +47,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(_, ReadingListCategory(), IsEmpty()))
+ .RetiresOnSaturation();
+ CreateProvider();
+
CategoryInfo categoryInfo = provider_->GetCategoryInfo(ReadingListCategory());
EXPECT_EQ(ContentSuggestionsAdditionalAction::VIEW_ALL,
categoryInfo.additional_action());
}
+TEST_F(ReadingListSuggestionsProviderTest, ReturnsThreeLatestUnreadSuggestion) {
+ GURL url_unread1 = GURL("http://www.foo1.bar");
+ GURL url_unread2 = GURL("http://www.foo2.bar");
+ GURL url_unread3 = GURL("http://www.foo3.bar");
+ GURL url_unread4 = GURL("http://www.foo4.bar");
+ GURL url_read1 = GURL("http://www.bar.foor");
+ std::string title_unread1 = "title1";
+ std::string title_unread2 = "title2";
+ std::string title_unread3 = "title3";
+ std::string title_unread4 = "title4";
+ std::string title_read1 = "title_read1";
+ model_->AddEntry(url_unread1, title_unread1,
+ reading_list::ADDED_VIA_CURRENT_APP);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(url_unread2, title_unread2,
+ reading_list::ADDED_VIA_CURRENT_APP);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(url_read1, title_read1, reading_list::ADDED_VIA_CURRENT_APP);
+ model_->SetReadStatus(url_read1, true);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(url_unread3, title_unread3,
+ reading_list::ADDED_VIA_CURRENT_APP);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(url_unread4, title_unread4,
+ reading_list::ADDED_VIA_CURRENT_APP);
+
+ EXPECT_CALL(observer_,
+ OnNewSuggestions(
+ _, ReadingListCategory(),
+ ElementsAre(Property(&ContentSuggestion::url, url_unread4),
+ Property(&ContentSuggestion::url, url_unread3),
+ Property(&ContentSuggestion::url, url_unread2))));
+
+ CreateProvider();
+}
+
+// Tests that the provider returns only unread suggestions even if there is less
+// unread suggestions than the maximum number of suggestions.
+TEST_F(ReadingListSuggestionsProviderTest, ReturnsOnlyUnreadSuggestion) {
+ GURL url_unread1 = GURL("http://www.foo1.bar");
+ GURL url_read1 = GURL("http://www.bar.foor");
+ std::string title_unread1 = "title1";
+ std::string title_read1 = "title_read1";
+ model_->AddEntry(url_unread1, title_unread1,
+ reading_list::ADDED_VIA_CURRENT_APP);
+ clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ model_->AddEntry(url_read1, title_read1, reading_list::ADDED_VIA_CURRENT_APP);
+ model_->SetReadStatus(url_read1, true);
+
+ EXPECT_CALL(observer_,
+ OnNewSuggestions(
+ _, ReadingListCategory(),
+ ElementsAre(Property(&ContentSuggestion::url, url_unread1))));
+
+ CreateProvider();
+}
+
} // namespace
+
} // namespace ntp_snippets
« no previous file with comments | « components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698