| 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 "chrome/browser/ntp_snippets/download_suggestions_provider.h" | 5 #include "chrome/browser/ntp_snippets/download_suggestions_provider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); | 764 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| 765 | 765 |
| 766 provider()->DismissSuggestion( | 766 provider()->DismissSuggestion( |
| 767 GetDummySuggestionId(1, /*is_offline_page=*/true)); | 767 GetDummySuggestionId(1, /*is_offline_page=*/true)); |
| 768 provider()->DismissSuggestion( | 768 provider()->DismissSuggestion( |
| 769 GetDummySuggestionId(2, /*is_offline_page=*/true)); | 769 GetDummySuggestionId(2, /*is_offline_page=*/true)); |
| 770 provider()->DismissSuggestion( | 770 provider()->DismissSuggestion( |
| 771 GetDummySuggestionId(3, /*is_offline_page=*/true)); | 771 GetDummySuggestionId(3, /*is_offline_page=*/true)); |
| 772 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(3)); | 772 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(3)); |
| 773 | 773 |
| 774 // Prune on getting all offline pages. Note that the first suggestion is not | 774 // Prune on getting all offline pages. |
| 775 // removed from |offline_pages_model| storage, because otherwise | |
| 776 // |GetDismissedSuggestions| cannot return it. | |
| 777 EXPECT_CALL(*observer(), | 775 EXPECT_CALL(*observer(), |
| 778 OnNewSuggestions(_, downloads_category(), IsEmpty())); | 776 OnNewSuggestions(_, downloads_category(), IsEmpty())); |
| 779 | 777 |
| 780 // TODO(vitaliii): Add the first suggestion back, so that | |
| 781 // GetDismissedSuggestions can return it. | |
| 782 *(offline_pages_model()->mutable_items()) = | 778 *(offline_pages_model()->mutable_items()) = |
| 783 CreateDummyOfflinePages({2, 3}); | 779 CreateDummyOfflinePages({2, 3}); |
| 784 FireOfflinePageModelChanged(); | 780 FireOfflinePageModelChanged(); |
| 781 |
| 782 // The first suggestion is added back to the |offline_pages_model| storage, |
| 783 // because otherwise |GetDismissedSuggestions| cannot return it. |
| 784 *(offline_pages_model()->mutable_items()) = |
| 785 CreateDummyOfflinePages({1, 2, 3}); |
| 785 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(2)); | 786 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(2)); |
| 786 | 787 |
| 787 // Prune when offline page is deleted. | 788 // Prune when offline page is deleted. |
| 788 FireOfflinePageDeleted(offline_pages_model()->items()[1]); | 789 FireOfflinePageDeleted(offline_pages_model()->items()[1]); |
| 789 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(1)); | 790 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(1)); |
| 790 } | 791 } |
| 791 | 792 |
| 792 TEST_F(DownloadSuggestionsProviderTest, ShouldPruneAssetDownloadsDismissedIDs) { | 793 TEST_F(DownloadSuggestionsProviderTest, ShouldPruneAssetDownloadsDismissedIDs) { |
| 793 IgnoreOnCategoryStatusChangedToAvailable(); | 794 IgnoreOnCategoryStatusChangedToAvailable(); |
| 794 IgnoreOnSuggestionInvalidated(); | 795 IgnoreOnSuggestionInvalidated(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 IgnoreOnSuggestionInvalidated(); | 922 IgnoreOnSuggestionInvalidated(); |
| 922 | 923 |
| 923 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 924 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 924 EXPECT_CALL( | 925 EXPECT_CALL( |
| 925 *observer(), | 926 *observer(), |
| 926 OnNewSuggestions(_, downloads_category(), | 927 OnNewSuggestions(_, downloads_category(), |
| 927 UnorderedElementsAre(HasUrl("http://download.com/1"), | 928 UnorderedElementsAre(HasUrl("http://download.com/1"), |
| 928 HasUrl("http://download.com/2")))); | 929 HasUrl("http://download.com/2")))); |
| 929 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); | 930 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| 930 } | 931 } |
| OLD | NEW |