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

Unified Diff: chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc

Issue 2562073002: [NTP::Downloads] Limit number of dismissed IDs instead of pruning. (Closed)
Patch Set: rebase & treib@ comments. Created 4 years 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 | « chrome/browser/ntp_snippets/download_suggestions_provider.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..90f654ff3b3da04de361d00693eb253174112144 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,87 @@ 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.
+}
+
+TEST_F(DownloadSuggestionsProviderTest, ShouldStoreDismissedSuggestions) {
+ IgnoreOnCategoryStatusChangedToAvailable();
+ IgnoreOnSuggestionInvalidated();
+
+ // Dismiss items to store them in the list of dismissed items.
+ *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1});
+ *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1});
+ EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _));
+ CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true);
+ provider()->DismissSuggestion(
+ GetDummySuggestionId(1, /*is_offline_page=*/true));
+ provider()->DismissSuggestion(
+ GetDummySuggestionId(1, /*is_offline_page=*/false));
+ // Destroy and create provider to simulate turning off Chrome.
+ DestroyProvider();
+
+ EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _));
+ CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true);
+ EXPECT_THAT(GetDismissedSuggestions(),
+ UnorderedElementsAre(HasUrl("http://dummy.com/1"),
+ HasUrl("http://download.com/1")));
+}
+
+// TODO(vitaliii): Remove this test once the dismissed ids are pruned. See
+// crbug.com/672758.
+TEST_F(DownloadSuggestionsProviderTest, ShouldRemoveOldDismissedIdsIfTooMany) {
+ IgnoreOnCategoryStatusChangedToAvailable();
+ IgnoreOnSuggestionInvalidated();
+
+ const int kMaxDismissedIdCount =
+ DownloadSuggestionsProvider::GetMaxDismissedCountForTesting();
+ std::vector<int> ids;
+ for (int i = 0; i < kMaxDismissedIdCount + 1; ++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(kMaxDismissedIdCount));
+ DestroyProvider();
+ // The oldest dismissed suggestion must become undismissed now. This is a
+ // temporary workaround and not what we want in long term. This test must be
+ // removed once we start pruning dismissed asset downloads on startup.
+ EXPECT_CALL(*observer(),
+ OnNewSuggestions(_, downloads_category(),
+ ElementsAre(HasUrl("http://download.com/0"))));
+ CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false);
+}
« no previous file with comments | « chrome/browser/ntp_snippets/download_suggestions_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698