| 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 a2245bfd6cbe91ea5bae71ae8abed3cff4320fd8..5041446e0bce6b507a48cc716bc0ce0d808b6387 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 {
|
| + ContentSuggestionsService::RegisterProfilePrefs(pref_service_->registry());
|
| CreateContentSuggestionsService(ContentSuggestionsService::State::ENABLED);
|
| }
|
|
|
| @@ -219,6 +222,7 @@ class ContentSuggestionsServiceTest : public testing::Test {
|
|
|
| private:
|
| std::unique_ptr<ContentSuggestionsService> service_;
|
| + std::unique_ptr<TestingPrefServiceSimple> pref_service_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsServiceTest);
|
| };
|
| @@ -601,4 +605,67 @@ TEST_F(ContentSuggestionsServiceTest, ShouldForwardClearHistory) {
|
| service()->ClearHistory(begin, end, filter);
|
| }
|
|
|
| +TEST_F(ContentSuggestionsServiceTest, ShouldNotReturnDismissedCategories) {
|
| + Category category = FromKnownCategory(KnownCategories::ARTICLES);
|
| +
|
| + // Create and register providers
|
| + MockProvider* provider = RegisterProvider(category);
|
| + provider->FireCategoryStatusChangedWithCurrentStatus(category);
|
| + ASSERT_THAT(providers().count(category), Eq(1ul));
|
| + EXPECT_THAT(providers().at(category), Eq(provider));
|
| + ASSERT_THAT(service()->GetCategories(), ElementsAre(category));
|
| +
|
| + // Create and register observer
|
| + MockServiceObserver observer;
|
| + service()->AddObserver(&observer);
|
| +
|
| + ASSERT_THAT(service()->GetCategoryStatus(category),
|
| + Eq(CategoryStatus::AVAILABLE));
|
| + ASSERT_TRUE(service()->GetCategoryInfo(category));
|
| +
|
| + service()->DismissCategory(category);
|
| + ASSERT_THAT(service()->GetCategories(), ElementsAre(category));
|
| + ASSERT_THAT(service()->GetCategoryStatus(category),
|
| + Eq(CategoryStatus::NOT_PROVIDED));
|
| + ASSERT_FALSE(service()->GetCategoryInfo(category));
|
| + ASSERT_TRUE(service()->GetSuggestionsForCategory(category).empty());
|
| +
|
| + // OnCategoryStatusChanged
|
| + EXPECT_CALL(observer,
|
| + OnCategoryStatusChanged(
|
| + category, CategoryStatus::CATEGORY_EXPLICITLY_DISABLED));
|
| + provider->FireCategoryStatusChanged(
|
| + category, CategoryStatus::CATEGORY_EXPLICITLY_DISABLED);
|
| + Mock::VerifyAndClearExpectations(&observer);
|
| +
|
| + // OnNewSuggestions (empty)
|
| + EXPECT_CALL(observer, OnNewSuggestions(category)); // TODO or not?
|
| + provider->FireSuggestionsChanged(category, std::vector<ContentSuggestion>());
|
| + Mock::VerifyAndClearExpectations(&observer);
|
| +
|
| + ASSERT_THAT(service()->GetCategoryStatus(category),
|
| + Eq(CategoryStatus::NOT_PROVIDED));
|
| + ASSERT_FALSE(service()->GetCategoryInfo(category));
|
| + ASSERT_TRUE(service()->GetSuggestionsForCategory(category).empty());
|
| +
|
| + // OnNewSuggestions (with suggestions)
|
| + EXPECT_CALL(observer, OnNewSuggestions(category));
|
| + provider->FireSuggestionsChanged(category,
|
| + CreateSuggestions(category, {1, 2}));
|
| + ExpectThatSuggestionsAre(category, {1, 2});
|
| + Mock::VerifyAndClearExpectations(&observer);
|
| +
|
| + ASSERT_THAT(service()->GetCategoryStatus(category),
|
| + Eq(CategoryStatus::AVAILABLE));
|
| + ASSERT_TRUE(service()->GetCategoryInfo(category));
|
| + ASSERT_FALSE(service()->GetSuggestionsForCategory(category).empty());
|
| +
|
| + EXPECT_CALL(observer,
|
| + OnCategoryStatusChanged(
|
| + category, CategoryStatus::CATEGORY_EXPLICITLY_DISABLED));
|
| + provider->FireCategoryStatusChanged(
|
| + category, CategoryStatus::CATEGORY_EXPLICITLY_DISABLED);
|
| + Mock::VerifyAndClearExpectations(&observer);
|
| +}
|
| +
|
| } // namespace ntp_snippets
|
|
|