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 94d78f2ee078be2526a3a9cd570dbe7b34619cc0..29fb83b13f2afe54d339aefe391ff80a586324d1 100644 |
| --- a/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc |
| +++ b/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc |
| @@ -23,12 +23,12 @@ |
| using content::DownloadItem; |
| using content::MockDownloadManager; |
| using ntp_snippets::Category; |
| +using ntp_snippets::CategoryStatus; |
| using ntp_snippets::ContentSuggestion; |
| using ntp_snippets::ContentSuggestionsProvider; |
| using ntp_snippets::MockContentSuggestionsProviderObserver; |
| using ntp_snippets::test::CaptureDismissedSuggestions; |
| using ntp_snippets::test::FakeOfflinePageModel; |
| -using ntp_snippets::CategoryStatus; |
| using offline_pages::ClientId; |
| using offline_pages::OfflinePageItem; |
| using test::FakeDownloadItem; |
| @@ -251,13 +251,21 @@ class DownloadSuggestionsProviderTest : public testing::Test { |
| EXPECT_CALL(observer_, OnSuggestionInvalidated(_, _)).Times(AnyNumber()); |
| } |
| + DownloadSuggestionsProvider* CreateLoadedProvider(bool show_assets, |
| + bool show_offline_pages) { |
| + CreateProvider(show_assets, show_offline_pages); |
| + FireHistoryQueryComplete(); |
| + return provider_.get(); |
| + } |
| + |
| DownloadSuggestionsProvider* CreateProvider(bool show_assets, |
| bool show_offline_pages) { |
| DCHECK(!provider_); |
| DCHECK(show_assets || show_offline_pages); |
| provider_ = base::MakeUnique<DownloadSuggestionsProvider>( |
| &observer_, show_offline_pages ? &offline_pages_model_ : nullptr, |
| - show_assets ? &downloads_manager_ : nullptr, pref_service(), |
| + show_assets ? &downloads_manager_ : nullptr, |
| + /*download_history=*/nullptr, pref_service(), |
|
vitaliii
2017/01/16 14:32:39
treib@,
do you have any idea how I could test this
Marc Treib
2017/01/16 14:51:07
There are some tests that instantiate a DownloadHi
vitaliii
2017/01/17 08:33:28
Thank you for the links.
Constructing it happened
Marc Treib
2017/01/17 08:50:04
What exactly do you mean by "requires UI thread"?
vitaliii
2017/01/17 16:12:41
The issue was in |DCHECK_CURRENTLY_ON(content::Bro
|
| /*download_manager_ui_enabled=*/false); |
| return provider_.get(); |
| } |
| @@ -297,6 +305,8 @@ class DownloadSuggestionsProviderTest : public testing::Test { |
| } |
| } |
| + void FireHistoryQueryComplete() { provider_->OnHistoryQueryComplete(); } |
| + |
| ContentSuggestion::ID GetDummySuggestionId(int id, bool is_offline_page) { |
| return ContentSuggestion::ID( |
| downloads_category(), |
| @@ -350,7 +360,7 @@ TEST_F(DownloadSuggestionsProviderTest, |
| HasDownloadSuggestionExtra( |
| /*is_download_asset=*/false, |
| FILE_PATH_LITERAL(""), ""))))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| } |
| TEST_F(DownloadSuggestionsProviderTest, |
| @@ -360,7 +370,7 @@ TEST_F(DownloadSuggestionsProviderTest, |
| EXPECT_CALL(*observer(), |
| OnNewSuggestions(_, downloads_category(), SizeIs(0))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| std::vector<std::unique_ptr<FakeDownloadItem>> asset_downloads = |
| CreateDummyAssetDownloads({1, 2}); |
| @@ -401,7 +411,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldMixInBothSources) { |
| UnorderedElementsAre( |
| HasUrl("http://dummy.com/1"), |
| HasUrl("http://dummy.com/2")))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| std::vector<std::unique_ptr<FakeDownloadItem>> asset_downloads = |
| CreateDummyAssetDownloads({1, 2}); |
| @@ -442,7 +452,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldSortSuggestions) { |
| OnNewSuggestions(_, downloads_category(), |
| ElementsAre(HasUrl("http://dummy.com/2"), |
| HasUrl("http://dummy.com/1")))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| std::vector<std::unique_ptr<FakeDownloadItem>> asset_downloads; |
| asset_downloads.push_back(CreateDummyAssetDownload(3, next_week)); |
| @@ -468,9 +478,8 @@ TEST_F(DownloadSuggestionsProviderTest, |
| ShouldDismissWithoutNotifyingObservers) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(4ul)))) |
| - .Times(2); |
| + *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| EXPECT_CALL( |
| *observer(), |
| OnNewSuggestions(_, downloads_category(), |
| @@ -478,11 +487,7 @@ TEST_F(DownloadSuggestionsProviderTest, |
| HasUrl("http://dummy.com/2"), |
| HasUrl("http://download.com/1"), |
| HasUrl("http://download.com/2")))); |
| - |
| - *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| - *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); |
| EXPECT_CALL(*observer(), OnSuggestionInvalidated(_, _)).Times(0); |
| @@ -499,9 +504,8 @@ TEST_F(DownloadSuggestionsProviderTest, |
| ShouldNotReportDismissedSuggestionsOnNewData) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(4ul)))) |
| - .Times(2); |
| + *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| EXPECT_CALL( |
| *observer(), |
| OnNewSuggestions(_, downloads_category(), |
| @@ -509,10 +513,7 @@ TEST_F(DownloadSuggestionsProviderTest, |
| HasUrl("http://dummy.com/2"), |
| HasUrl("http://download.com/1"), |
| HasUrl("http://download.com/2")))); |
| - *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| - *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| provider()->DismissSuggestion( |
| GetDummySuggestionId(1, /*is_offline_page=*/true)); |
| @@ -531,9 +532,8 @@ TEST_F(DownloadSuggestionsProviderTest, |
| TEST_F(DownloadSuggestionsProviderTest, ShouldReturnDismissedSuggestions) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(4ul)))) |
| - .Times(2); |
| + *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| EXPECT_CALL( |
| *observer(), |
| OnNewSuggestions(_, downloads_category(), |
| @@ -541,10 +541,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldReturnDismissedSuggestions) { |
| HasUrl("http://dummy.com/2"), |
| HasUrl("http://download.com/1"), |
| HasUrl("http://download.com/2")))); |
| - *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| - *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| provider()->DismissSuggestion( |
| GetDummySuggestionId(1, /*is_offline_page=*/true)); |
| @@ -559,9 +556,8 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldReturnDismissedSuggestions) { |
| TEST_F(DownloadSuggestionsProviderTest, ShouldClearDismissedSuggestions) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(4ul)))) |
| - .Times(2); |
| + *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| EXPECT_CALL( |
| *observer(), |
| OnNewSuggestions(_, downloads_category(), |
| @@ -569,10 +565,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldClearDismissedSuggestions) { |
| HasUrl("http://dummy.com/2"), |
| HasUrl("http://download.com/1"), |
| HasUrl("http://download.com/2")))); |
| - *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| - *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| provider()->DismissSuggestion( |
| GetDummySuggestionId(1, /*is_offline_page=*/true)); |
| @@ -594,9 +587,8 @@ TEST_F(DownloadSuggestionsProviderTest, |
| ShouldNotDismissOtherTypeWithTheSameID) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(4ul)))) |
| - .Times(2); |
| + *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| EXPECT_CALL( |
| *observer(), |
| OnNewSuggestions(_, downloads_category(), |
| @@ -604,10 +596,7 @@ TEST_F(DownloadSuggestionsProviderTest, |
| HasUrl("http://dummy.com/2"), |
| HasUrl("http://download.com/1"), |
| HasUrl("http://download.com/2")))); |
| - *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| - *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| provider()->DismissSuggestion( |
| GetDummySuggestionId(1, /*is_offline_page=*/true)); |
| @@ -625,9 +614,10 @@ TEST_F(DownloadSuggestionsProviderTest, |
| TEST_F(DownloadSuggestionsProviderTest, ShouldReplaceDismissedItemWithNewData) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(5ul)))) |
| - .Times(5); |
| + // Currently the provider stores five items in its internal cache, so six |
| + // items are needed to check whether all downloads are fetched on dismissal. |
| + *(downloads_manager()->mutable_items()) = |
| + CreateDummyAssetDownloads({1, 2, 3, 4, 5, 6}); |
| EXPECT_CALL( |
| *observer(), |
| OnNewSuggestions(_, downloads_category(), |
| @@ -636,12 +626,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldReplaceDismissedItemWithNewData) { |
| HasUrl("http://download.com/3"), |
| HasUrl("http://download.com/4"), |
| HasUrl("http://download.com/5")))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| - // Currently the provider stores five items in its internal cache, so six |
| - // items are needed to check whether all downloads are fetched on dismissal. |
| - *(downloads_manager()->mutable_items()) = |
| - CreateDummyAssetDownloads({1, 2, 3, 4, 5, 6}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| provider()->DismissSuggestion( |
| GetDummySuggestionId(1, /*is_offline_page=*/false)); |
| @@ -665,18 +650,15 @@ TEST_F(DownloadSuggestionsProviderTest, |
| ShouldInvalidateWhenUnderlyingItemDeleted) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(3ul)))); |
| + *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| + *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); |
| EXPECT_CALL( |
| *observer(), |
| OnNewSuggestions(_, downloads_category(), |
| UnorderedElementsAre(HasUrl("http://dummy.com/1"), |
| HasUrl("http://dummy.com/2"), |
| HasUrl("http://download.com/1")))); |
| - *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| - *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| // We add another item manually, so that when it gets deleted it is not |
| // present in DownloadsManager list. |
| @@ -706,9 +688,8 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldReplaceRemovedItemWithNewData) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| IgnoreOnSuggestionInvalidated(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(5ul)))) |
| - .Times(5); |
| + *(downloads_manager()->mutable_items()) = |
| + CreateDummyAssetDownloads({1, 2, 3, 4, 5}); |
| EXPECT_CALL( |
| *observer(), |
| OnNewSuggestions(_, downloads_category(), |
| @@ -717,10 +698,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldReplaceRemovedItemWithNewData) { |
| HasUrl("http://download.com/3"), |
| HasUrl("http://download.com/4"), |
| HasUrl("http://download.com/5")))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| - *(downloads_manager()->mutable_items()) = |
| - CreateDummyAssetDownloads({1, 2, 3, 4, 5}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| // Note that |CreateDummyAssetDownloads| creates items "downloaded" before |
| // |base::Time::Now()|, so for a new item the time is set in future to enforce |
| @@ -764,7 +742,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldPruneOfflinePagesDismissedIDs) { |
| HasUrl("http://dummy.com/1"), |
| HasUrl("http://dummy.com/2"), |
| HasUrl("http://dummy.com/3")))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| provider()->DismissSuggestion( |
| GetDummySuggestionId(1, /*is_offline_page=*/true)); |
| @@ -788,12 +766,13 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldPruneAssetDownloadsDismissedIDs) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| IgnoreOnSuggestionInvalidated(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(Lt(3ul)))) |
| - .Times(3); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + EXPECT_CALL( |
| + *observer(), |
| + OnNewSuggestions(_, downloads_category(), |
| + UnorderedElementsAre(HasUrl("http://download.com/1"), |
| + HasUrl("http://download.com/2")))); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| provider()->DismissSuggestion( |
| GetDummySuggestionId(1, /*is_offline_page=*/false)); |
| @@ -812,11 +791,11 @@ TEST_F(DownloadSuggestionsProviderTest, |
| // Downloads manager was created before the provider, so |OnDownloadCreated| |
| // calls "were" missed, but the provider must show missed items anyway. |
| *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| - EXPECT_CALL( |
| - *observer(), |
| - OnNewSuggestions(_, downloads_category(), |
| - UnorderedElementsAre(HasUrl("http://download.com/1"), |
| - HasUrl("http://download.com/2")))); |
| + EXPECT_CALL(*observer(), |
| + OnNewSuggestions( |
| + _, downloads_category(), |
| + UnorderedElementsAre(HasUrl("http://download.com/1"), |
| + HasUrl("http://download.com/2!!!!!")))); |
| CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| } |
| @@ -824,13 +803,12 @@ TEST_F(DownloadSuggestionsProviderTest, |
| ShouldInvalidateAssetDownloadWhenItsFileRemoved) { |
| IgnoreOnCategoryStatusChangedToAvailable(); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), IsEmpty())); |
| - EXPECT_CALL(*observer(), |
| - OnNewSuggestions(_, downloads_category(), SizeIs(1))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); |
| - FireDownloadsCreated(downloads_manager()->items()); |
| + EXPECT_CALL( |
| + *observer(), |
| + OnNewSuggestions(_, downloads_category(), |
| + UnorderedElementsAre(HasUrl("http://download.com/1")))); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| EXPECT_CALL(*observer(), |
| OnSuggestionInvalidated( |
| @@ -847,7 +825,7 @@ TEST_F(DownloadSuggestionsProviderTest, |
| *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| EXPECT_CALL(*observer(), |
| OnNewSuggestions(_, downloads_category(), IsEmpty())); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| std::vector<std::unique_ptr<FakeDownloadItem>> asset_downloads = |
| CreateDummyAssetDownloads({1}); |
| @@ -885,7 +863,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldLoadOfflinePagesOnModelLoaded) { |
| offline_pages_model()->set_is_loaded(false); |
| EXPECT_CALL(*observer(), |
| OnNewSuggestions(_, downloads_category(), IsEmpty())); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| + CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); |
| *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| offline_pages_model()->set_is_loaded(true); |
| @@ -907,7 +885,7 @@ TEST_F(DownloadSuggestionsProviderTest, |
| UnorderedElementsAre( |
| HasUrl("http://dummy.com/1"), |
| HasUrl("http://dummy.com/2")))); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| + CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); |
| } |
| TEST_F(DownloadSuggestionsProviderTest, |
| @@ -921,35 +899,7 @@ TEST_F(DownloadSuggestionsProviderTest, |
| OnNewSuggestions(_, downloads_category(), |
| UnorderedElementsAre(HasUrl("http://download.com/1"), |
| 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. |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| } |
| TEST_F(DownloadSuggestionsProviderTest, ShouldStoreDismissedSuggestions) { |
| @@ -960,7 +910,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldStoreDismissedSuggestions) { |
| *(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); |
| + CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| provider()->DismissSuggestion( |
| GetDummySuggestionId(1, /*is_offline_page=*/true)); |
| provider()->DismissSuggestion( |
| @@ -969,41 +919,8 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldStoreDismissedSuggestions) { |
| DestroyProvider(); |
| EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); |
| - CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| + CreateLoadedProvider(/*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); |
| -} |