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

Unified Diff: components/ntp_snippets/content_suggestions_service_unittest.cc

Issue 2406573002: 📰 Persist category dismissals (Closed)
Patch Set: rebase and rewrite Created 4 years, 2 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/content_suggestions_service_unittest.cc
diff --git a/components/ntp_snippets/content_suggestions_service_unittest.cc b/components/ntp_snippets/content_suggestions_service_unittest.cc
index 71de5fb68f21cd7c3a1492e51088869397f59642..97aead1ae3c77be6a6a26e78d58df199bed4a72b 100644
--- a/components/ntp_snippets/content_suggestions_service_unittest.cc
+++ b/components/ntp_snippets/content_suggestions_service_unittest.cc
@@ -19,6 +19,7 @@
#include "components/ntp_snippets/category_status.h"
#include "components/ntp_snippets/content_suggestion.h"
#include "components/ntp_snippets/content_suggestions_provider.h"
+#include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/image/image.h"
@@ -121,9 +122,11 @@ class MockServiceObserver : public ContentSuggestionsService::Observer {
class ContentSuggestionsServiceTest : public testing::Test {
public:
- ContentSuggestionsServiceTest() {}
+ ContentSuggestionsServiceTest()
+ : pref_service_(new TestingPrefServiceSimple()) {}
void SetUp() override {
+ RegisterPrefs();
CreateContentSuggestionsService(ContentSuggestionsService::State::ENABLED);
}
@@ -195,12 +198,16 @@ class ContentSuggestionsServiceTest : public testing::Test {
MOCK_METHOD1(OnImageFetched, void(const gfx::Image&));
protected:
+ void RegisterPrefs() {
+ ContentSuggestionsService::RegisterProfilePrefs(pref_service_->registry());
+ UserClassifier::RegisterProfilePrefs(pref_service_->registry());
+ }
+
void CreateContentSuggestionsService(
ContentSuggestionsService::State enabled) {
ASSERT_FALSE(service_);
- service_.reset(new ContentSuggestionsService(enabled,
- nullptr /* history_service */,
- nullptr /* pref_service */));
+ service_.reset(new ContentSuggestionsService(
+ enabled, nullptr /* history_service */, pref_service_.get()));
Marc Treib 2016/10/13 15:59:01 nit: /*history_service=*/nullptr (then clang-tidy
dgn 2016/10/14 21:20:29 Done.
}
ContentSuggestionsService* service() { return service_.get(); }
@@ -224,6 +231,7 @@ class ContentSuggestionsServiceTest : public testing::Test {
private:
std::unique_ptr<ContentSuggestionsService> service_;
+ std::unique_ptr<TestingPrefServiceSimple> pref_service_;
DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsServiceTest);
};
@@ -232,6 +240,7 @@ class ContentSuggestionsServiceDisabledTest
: public ContentSuggestionsServiceTest {
public:
void SetUp() override {
+ RegisterPrefs();
CreateContentSuggestionsService(ContentSuggestionsService::State::DISABLED);
}
};
@@ -642,4 +651,54 @@ TEST_F(ContentSuggestionsServiceTest, DismissAndRestoreCategory) {
EXPECT_THAT(dismissed_providers(), IsEmpty());
}
+TEST_F(ContentSuggestionsServiceTest, ShouldRestoreDismissedCategories) {
+ // Create and register provider
+ Category category1 = service()->category_factory()->FromIDValue(1);
+ Category category2 = service()->category_factory()->FromIDValue(2);
+
+ // Setup and verify initial state
+ MockProvider* provider = RegisterProvider({category1, category2});
+ provider->FireCategoryStatusChangedWithCurrentStatus(category1);
+ provider->FireCategoryStatusChangedWithCurrentStatus(category2);
+
+ ASSERT_THAT(service()->GetCategoryStatus(category1),
+ Eq(CategoryStatus::AVAILABLE));
+ ASSERT_THAT(service()->GetCategoryStatus(category2),
+ Eq(CategoryStatus::AVAILABLE));
+
+ // Dismiss all the categories. None should be provided now.
+ service()->DismissCategory(category1);
+ service()->DismissCategory(category2);
+
+ ASSERT_THAT(service()->GetCategoryStatus(category1),
+ Eq(CategoryStatus::NOT_PROVIDED));
+ ASSERT_THAT(service()->GetCategoryStatus(category2),
+ Eq(CategoryStatus::NOT_PROVIDED));
+
+ // Receiving a status change notification should not change anything.
+ provider->FireCategoryStatusChanged(category1, CategoryStatus::AVAILABLE);
+
+ ASSERT_THAT(service()->GetCategoryStatus(category1),
Marc Treib 2016/10/13 15:59:01 EXPECT_THAT from here on? (Rough rule: ASSERT for
dgn 2016/10/14 21:20:28 Done.
+ Eq(CategoryStatus::NOT_PROVIDED));
+ ASSERT_THAT(service()->GetCategoryStatus(category2),
+ Eq(CategoryStatus::NOT_PROVIDED));
+
+ // Receiving a notification without suggestions should not change anything.
+ provider->FireSuggestionsChanged(category1, std::vector<ContentSuggestion>());
+
+ ASSERT_THAT(service()->GetCategoryStatus(category1),
+ Eq(CategoryStatus::NOT_PROVIDED));
+ ASSERT_THAT(service()->GetCategoryStatus(category2),
+ Eq(CategoryStatus::NOT_PROVIDED));
+
+ // Receiving suggestions should make the notified category available.
+ provider->FireSuggestionsChanged(category1,
+ CreateSuggestions(category1, {1, 2}));
+
+ ASSERT_THAT(service()->GetCategoryStatus(category1),
+ Eq(CategoryStatus::AVAILABLE));
+ ASSERT_THAT(service()->GetCategoryStatus(category2),
+ Eq(CategoryStatus::NOT_PROVIDED));
+}
Marc Treib 2016/10/13 15:59:01 Could you also add a test for the actual persistin
+
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698