OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/content_suggestions_service.h" | 5 #include "components/ntp_snippets/content_suggestions_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 ADD_FAILURE() << "Suggestion number " << number | 157 ADD_FAILURE() << "Suggestion number " << number |
158 << " not present, though expected"; | 158 << " not present, though expected"; |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 const std::map<Category, ContentSuggestionsProvider*, Category::CompareByID>& | 162 const std::map<Category, ContentSuggestionsProvider*, Category::CompareByID>& |
163 providers() { | 163 providers() { |
164 return service()->providers_by_category_; | 164 return service()->providers_by_category_; |
165 } | 165 } |
166 | 166 |
| 167 const std::map<Category, ContentSuggestionsProvider*, Category::CompareByID>& |
| 168 dismissed_providers() { |
| 169 return service()->dismissed_providers_by_category_; |
| 170 } |
| 171 |
167 CategoryFactory* category_factory() { return service()->category_factory(); } | 172 CategoryFactory* category_factory() { return service()->category_factory(); } |
168 | 173 |
169 Category FromKnownCategory(KnownCategories known_category) { | 174 Category FromKnownCategory(KnownCategories known_category) { |
170 return service()->category_factory()->FromKnownCategory(known_category); | 175 return service()->category_factory()->FromKnownCategory(known_category); |
171 } | 176 } |
172 | 177 |
173 Category FromRemoteCategory(int remote_category) { | 178 Category FromRemoteCategory(int remote_category) { |
174 return service()->category_factory()->FromRemoteCategory(remote_category); | 179 return service()->category_factory()->FromRemoteCategory(remote_category); |
175 } | 180 } |
176 | 181 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 TEST_F(ContentSuggestionsServiceTest, ShouldForwardClearHistory) { | 599 TEST_F(ContentSuggestionsServiceTest, ShouldForwardClearHistory) { |
595 Category category = FromKnownCategory(KnownCategories::DOWNLOADS); | 600 Category category = FromKnownCategory(KnownCategories::DOWNLOADS); |
596 MockProvider* provider = RegisterProvider(category); | 601 MockProvider* provider = RegisterProvider(category); |
597 base::Time begin = base::Time::FromTimeT(123), | 602 base::Time begin = base::Time::FromTimeT(123), |
598 end = base::Time::FromTimeT(456); | 603 end = base::Time::FromTimeT(456); |
599 EXPECT_CALL(*provider, ClearHistory(begin, end, _)); | 604 EXPECT_CALL(*provider, ClearHistory(begin, end, _)); |
600 base::Callback<bool(const GURL& url)> filter; | 605 base::Callback<bool(const GURL& url)> filter; |
601 service()->ClearHistory(begin, end, filter); | 606 service()->ClearHistory(begin, end, filter); |
602 } | 607 } |
603 | 608 |
| 609 TEST_F(ContentSuggestionsServiceTest, DismissAndRestoreCategory) { |
| 610 // Register a category with one suggestion. |
| 611 Category category = FromKnownCategory(KnownCategories::ARTICLES); |
| 612 MockProvider* provider = RegisterProvider(category); |
| 613 provider->FireCategoryStatusChangedWithCurrentStatus(category); |
| 614 provider->FireSuggestionsChanged(category, CreateSuggestions(category, {42})); |
| 615 |
| 616 EXPECT_THAT(service()->GetCategories(), ElementsAre(category)); |
| 617 EXPECT_THAT(service()->GetCategoryStatus(category), |
| 618 Eq(CategoryStatus::AVAILABLE)); |
| 619 ExpectThatSuggestionsAre(category, {42}); |
| 620 EXPECT_THAT(providers().count(category), Eq(1ul)); |
| 621 EXPECT_THAT(dismissed_providers(), IsEmpty()); |
| 622 |
| 623 // Dismissing the category clears the suggestions for it. |
| 624 service()->DismissCategory(category); |
| 625 |
| 626 EXPECT_THAT(service()->GetCategories(), IsEmpty()); |
| 627 EXPECT_THAT(service()->GetCategoryStatus(category), |
| 628 Eq(CategoryStatus::NOT_PROVIDED)); |
| 629 EXPECT_THAT(service()->GetSuggestionsForCategory(category), IsEmpty()); |
| 630 EXPECT_THAT(providers(), IsEmpty()); |
| 631 EXPECT_THAT(dismissed_providers().count(category), Eq(1ul)); |
| 632 |
| 633 // Restoring the dismissed category makes it available again but it is still |
| 634 // empty. |
| 635 service()->RestoreDismissedCategories(); |
| 636 |
| 637 EXPECT_THAT(service()->GetCategories(), ElementsAre(category)); |
| 638 EXPECT_THAT(service()->GetCategoryStatus(category), |
| 639 Eq(CategoryStatus::AVAILABLE)); |
| 640 EXPECT_THAT(service()->GetSuggestionsForCategory(category), IsEmpty()); |
| 641 EXPECT_THAT(providers().count(category), Eq(1ul)); |
| 642 EXPECT_THAT(dismissed_providers(), IsEmpty()); |
| 643 } |
| 644 |
604 } // namespace ntp_snippets | 645 } // namespace ntp_snippets |
OLD | NEW |