Chromium Code Reviews| Index: chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc |
| diff --git a/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc b/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc |
| index c68d1d3c382eb1462b51d0a8deee19fda15ea4c6..fe96ca84258be039a3a32bd94de7e154d7f6d407 100644 |
| --- a/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc |
| +++ b/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc |
| @@ -38,12 +38,12 @@ using testing::AllOf; |
| using testing::AnyNumber; |
| using testing::ElementsAre; |
| using testing::IsEmpty; |
| +using testing::Lt; |
| using testing::Mock; |
| using testing::Return; |
| using testing::SizeIs; |
| using testing::StrictMock; |
| using testing::UnorderedElementsAre; |
| -using testing::Lt; |
| namespace ntp_snippets { |
| // These functions are implicitly used to print out values during the tests. |
| @@ -926,3 +926,54 @@ TEST_F(DownloadSuggestionsProviderTest, |
| HasUrl("http://download.com/2")))); |
| CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| } |
| + |
| +TEST_F(DownloadSuggestionsProviderTest, |
| + ShouldNotPruneDismissedSuggestionsOnStartup) { |
| + IgnoreOnCategoryStatusChangedToAvailable(); |
| + IgnoreOnSuggestionInvalidated(); |
| + |
| + // We dismiss an item to store it in the list of dismissed items. |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); |
| + EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); |
| + CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| + provider()->DismissSuggestion( |
| + GetDummySuggestionId(1, /*is_offline_page=*/false)); |
| + DestroyProvider(); |
| + |
| + // We simulate current DownloadManager behaviour; |
| + // The download manager has not started reading the list yet, so it is empty. |
| + downloads_manager()->mutable_items()->clear(); |
| + EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); |
| + CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| + Mock::VerifyAndClearExpectations(observer()); |
| + |
| + // The first download is being read. |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); |
| + EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)) |
| + .Times(0); |
| + FireDownloadCreated(downloads_manager()->items()[0].get()); |
| + // The first download should not be reported, because it is dismissed. |
| +} |
| + |
| +// TODO(vitaliii): Remove this test once the dismissed ids are pruned. See |
| +// crbug.com/672758. |
| +TEST_F(DownloadSuggestionsProviderTest, ShouldRemoveDismissedIdsIfTooMany) { |
| + IgnoreOnCategoryStatusChangedToAvailable(); |
| + IgnoreOnSuggestionInvalidated(); |
| + |
| + std::vector<int> ids; |
| + for (int i = 0; i < 200; ++i) { |
| + ids.push_back(i); |
| + } |
| + |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads(ids); |
| + EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); |
| + CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| + |
| + for (int i = 0; i < static_cast<int>(ids.size()); ++i) { |
| + provider()->DismissSuggestion( |
| + GetDummySuggestionId(i, /*is_offline_page=*/false)); |
| + } |
| + |
| + EXPECT_THAT(GetDismissedSuggestions(), SizeIs(Lt(ids.size()))); |
|
Marc Treib
2016/12/09 16:37:26
You could expose the actual max count (e.g. via a
vitaliii
2016/12/09 17:30:36
Done.
|
| +} |