| 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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 provider()->DismissSuggestion( | 803 provider()->DismissSuggestion( |
| 804 GetDummySuggestionId(1, /*is_offline_page=*/false)); | 804 GetDummySuggestionId(1, /*is_offline_page=*/false)); |
| 805 provider()->DismissSuggestion( | 805 provider()->DismissSuggestion( |
| 806 GetDummySuggestionId(2, /*is_offline_page=*/false)); | 806 GetDummySuggestionId(2, /*is_offline_page=*/false)); |
| 807 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(2)); | 807 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(2)); |
| 808 | 808 |
| 809 downloads_manager()->items()[0]->NotifyDownloadDestroyed(); | 809 downloads_manager()->items()[0]->NotifyDownloadDestroyed(); |
| 810 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(1)); | 810 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(1)); |
| 811 } | 811 } |
| 812 | 812 |
| 813 TEST_F(DownloadSuggestionsProviderTest, | 813 TEST_F(DownloadSuggestionsProviderTest, ShouldFetchAssetDownloadsOnStartup) { |
| 814 ShouldFetchAssetDownloadsOnStartupButOnlyOnce) { | |
| 815 IgnoreOnCategoryStatusChangedToAvailable(); | 814 IgnoreOnCategoryStatusChangedToAvailable(); |
| 816 | 815 |
| 817 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 816 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 818 EXPECT_CALL( | 817 EXPECT_CALL( |
| 819 *observer(), | 818 *observer(), |
| 820 OnNewSuggestions(_, downloads_category(), | 819 OnNewSuggestions(_, downloads_category(), |
| 821 UnorderedElementsAre(HasUrl("http://download.com/1"), | 820 UnorderedElementsAre(HasUrl("http://download.com/1"), |
| 822 HasUrl("http://download.com/2")))); | 821 HasUrl("http://download.com/2")))); |
| 823 CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); | 822 CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| 824 } | 823 } |
| 825 | 824 |
| 826 TEST_F(DownloadSuggestionsProviderTest, | 825 TEST_F(DownloadSuggestionsProviderTest, |
| 826 ShouldFetchOfflinePageDownloadsOnStartup) { |
| 827 IgnoreOnCategoryStatusChangedToAvailable(); |
| 828 |
| 829 *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| 830 offline_pages_model()->set_is_loaded(true); |
| 831 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), |
| 832 UnorderedElementsAre( |
| 833 HasUrl("http://dummy.com/1"), |
| 834 HasUrl("http://dummy.com/2")))); |
| 835 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); |
| 836 FireOfflinePageModelLoaded(); |
| 837 } |
| 838 |
| 839 TEST_F(DownloadSuggestionsProviderTest, |
| 827 ShouldFetchAssetDownloadsOnHistoryQueryComplete) { | 840 ShouldFetchAssetDownloadsOnHistoryQueryComplete) { |
| 828 IgnoreOnCategoryStatusChangedToAvailable(); | 841 IgnoreOnCategoryStatusChangedToAvailable(); |
| 829 | 842 |
| 830 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); | 843 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); |
| 831 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); | 844 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| 832 | 845 |
| 833 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 846 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 834 EXPECT_CALL( | 847 EXPECT_CALL( |
| 835 *observer(), | 848 *observer(), |
| 836 OnNewSuggestions(_, downloads_category(), | 849 OnNewSuggestions(_, downloads_category(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 HasUrl("http://dummy.com/2")))); | 902 HasUrl("http://dummy.com/2")))); |
| 890 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); | 903 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); |
| 891 downloads_manager()->NotifyDownloadCreated( | 904 downloads_manager()->NotifyDownloadCreated( |
| 892 downloads_manager()->items()[0].get()); | 905 downloads_manager()->items()[0].get()); |
| 893 // This notification should not reach the provider, because the asset | 906 // This notification should not reach the provider, because the asset |
| 894 // downloads data source is not provided. If it is and the provider reacts to | 907 // downloads data source is not provided. If it is and the provider reacts to |
| 895 // the notification, the test will fail because the observer is a strict mock. | 908 // the notification, the test will fail because the observer is a strict mock. |
| 896 (*downloads_manager()->mutable_items())[0]->NotifyDownloadUpdated(); | 909 (*downloads_manager()->mutable_items())[0]->NotifyDownloadUpdated(); |
| 897 } | 910 } |
| 898 | 911 |
| 899 TEST_F(DownloadSuggestionsProviderTest, ShouldLoadOfflinePagesOnModelLoaded) { | |
| 900 IgnoreOnCategoryStatusChangedToAvailable(); | |
| 901 IgnoreOnSuggestionInvalidated(); | |
| 902 | |
| 903 offline_pages_model()->set_is_loaded(false); | |
| 904 EXPECT_CALL(*observer(), | |
| 905 OnNewSuggestions(_, downloads_category(), IsEmpty())); | |
| 906 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); | |
| 907 | |
| 908 *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); | |
| 909 offline_pages_model()->set_is_loaded(true); | |
| 910 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), | |
| 911 UnorderedElementsAre( | |
| 912 HasUrl("http://dummy.com/1"), | |
| 913 HasUrl("http://dummy.com/2")))); | |
| 914 FireOfflinePageModelLoaded(); | |
| 915 } | |
| 916 | |
| 917 TEST_F(DownloadSuggestionsProviderTest, | |
| 918 ShouldLoadOfflinePagesIfMissesOnModelLoaded) { | |
| 919 IgnoreOnCategoryStatusChangedToAvailable(); | |
| 920 IgnoreOnSuggestionInvalidated(); | |
| 921 | |
| 922 *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); | |
| 923 offline_pages_model()->set_is_loaded(true); | |
| 924 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), | |
| 925 UnorderedElementsAre( | |
| 926 HasUrl("http://dummy.com/1"), | |
| 927 HasUrl("http://dummy.com/2")))); | |
| 928 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); | |
| 929 } | |
| 930 | |
| 931 TEST_F(DownloadSuggestionsProviderTest, | 912 TEST_F(DownloadSuggestionsProviderTest, |
| 932 ShouldLoadAndSubmitMissedAssetsEvenIfOfflinePagesAreTurnedOff) { | 913 ShouldLoadAndSubmitMissedAssetsEvenIfOfflinePagesAreTurnedOff) { |
| 933 IgnoreOnCategoryStatusChangedToAvailable(); | 914 IgnoreOnCategoryStatusChangedToAvailable(); |
| 934 IgnoreOnSuggestionInvalidated(); | 915 IgnoreOnSuggestionInvalidated(); |
| 935 | 916 |
| 936 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 917 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 937 EXPECT_CALL( | 918 EXPECT_CALL( |
| 938 *observer(), | 919 *observer(), |
| 939 OnNewSuggestions(_, downloads_category(), | 920 OnNewSuggestions(_, downloads_category(), |
| 940 UnorderedElementsAre(HasUrl("http://download.com/1"), | 921 UnorderedElementsAre(HasUrl("http://download.com/1"), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 | 989 |
| 1009 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)); | 990 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)); |
| 1010 | 991 |
| 1011 downloads_manager()->mutable_items()->clear(); | 992 downloads_manager()->mutable_items()->clear(); |
| 1012 FireHistoryQueryComplete(); | 993 FireHistoryQueryComplete(); |
| 1013 | 994 |
| 1014 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); | 995 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); |
| 1015 // Once the manager has been loaded, the ids should be pruned. | 996 // Once the manager has been loaded, the ids should be pruned. |
| 1016 EXPECT_THAT(GetDismissedSuggestions(), IsEmpty()); | 997 EXPECT_THAT(GetDismissedSuggestions(), IsEmpty()); |
| 1017 } | 998 } |
| OLD | NEW |