Chromium Code Reviews| 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 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 817 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 818 EXPECT_CALL( | 818 EXPECT_CALL( |
| 819 *observer(), | 819 *observer(), |
| 820 OnNewSuggestions(_, downloads_category(), | 820 OnNewSuggestions(_, downloads_category(), |
| 821 UnorderedElementsAre(HasUrl("http://download.com/1"), | 821 UnorderedElementsAre(HasUrl("http://download.com/1"), |
| 822 HasUrl("http://download.com/2")))); | 822 HasUrl("http://download.com/2")))); |
| 823 CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); | 823 CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| 824 } | 824 } |
| 825 | 825 |
| 826 TEST_F(DownloadSuggestionsProviderTest, | 826 TEST_F(DownloadSuggestionsProviderTest, |
| 827 ShouldFetchOfflinePageDownloadsOnStartupButOnlyOnce) { | |
|
Marc Treib
2017/02/01 16:37:31
nit: I'd remove the "ButOnlyOnce". That should be
vitaliii
2017/02/02 11:09:07
Done.
| |
| 828 IgnoreOnCategoryStatusChangedToAvailable(); | |
| 829 | |
| 830 *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); | |
| 831 offline_pages_model()->set_is_loaded(true); | |
| 832 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), | |
| 833 UnorderedElementsAre( | |
| 834 HasUrl("http://dummy.com/1"), | |
| 835 HasUrl("http://dummy.com/2")))); | |
| 836 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); | |
| 837 FireOfflinePageModelLoaded(); | |
| 838 } | |
| 839 | |
| 840 TEST_F(DownloadSuggestionsProviderTest, | |
| 827 ShouldFetchAssetDownloadsOnHistoryQueryComplete) { | 841 ShouldFetchAssetDownloadsOnHistoryQueryComplete) { |
| 828 IgnoreOnCategoryStatusChangedToAvailable(); | 842 IgnoreOnCategoryStatusChangedToAvailable(); |
| 829 | 843 |
| 830 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); | 844 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); |
| 831 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); | 845 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| 832 | 846 |
| 833 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 847 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 834 EXPECT_CALL( | 848 EXPECT_CALL( |
| 835 *observer(), | 849 *observer(), |
| 836 OnNewSuggestions(_, downloads_category(), | 850 OnNewSuggestions(_, downloads_category(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 HasUrl("http://dummy.com/2")))); | 903 HasUrl("http://dummy.com/2")))); |
| 890 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); | 904 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); |
| 891 downloads_manager()->NotifyDownloadCreated( | 905 downloads_manager()->NotifyDownloadCreated( |
| 892 downloads_manager()->items()[0].get()); | 906 downloads_manager()->items()[0].get()); |
| 893 // This notification should not reach the provider, because the asset | 907 // 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 | 908 // 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. | 909 // the notification, the test will fail because the observer is a strict mock. |
| 896 (*downloads_manager()->mutable_items())[0]->NotifyDownloadUpdated(); | 910 (*downloads_manager()->mutable_items())[0]->NotifyDownloadUpdated(); |
| 897 } | 911 } |
| 898 | 912 |
| 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, | 913 TEST_F(DownloadSuggestionsProviderTest, |
| 932 ShouldLoadAndSubmitMissedAssetsEvenIfOfflinePagesAreTurnedOff) { | 914 ShouldLoadAndSubmitMissedAssetsEvenIfOfflinePagesAreTurnedOff) { |
| 933 IgnoreOnCategoryStatusChangedToAvailable(); | 915 IgnoreOnCategoryStatusChangedToAvailable(); |
| 934 IgnoreOnSuggestionInvalidated(); | 916 IgnoreOnSuggestionInvalidated(); |
| 935 | 917 |
| 936 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 918 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 937 EXPECT_CALL( | 919 EXPECT_CALL( |
| 938 *observer(), | 920 *observer(), |
| 939 OnNewSuggestions(_, downloads_category(), | 921 OnNewSuggestions(_, downloads_category(), |
| 940 UnorderedElementsAre(HasUrl("http://download.com/1"), | 922 UnorderedElementsAre(HasUrl("http://download.com/1"), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 | 990 |
| 1009 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)); | 991 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)); |
| 1010 | 992 |
| 1011 downloads_manager()->mutable_items()->clear(); | 993 downloads_manager()->mutable_items()->clear(); |
| 1012 FireHistoryQueryComplete(); | 994 FireHistoryQueryComplete(); |
| 1013 | 995 |
| 1014 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); | 996 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); |
| 1015 // Once the manager has been loaded, the ids should be pruned. | 997 // Once the manager has been loaded, the ids should be pruned. |
| 1016 EXPECT_THAT(GetDismissedSuggestions(), IsEmpty()); | 998 EXPECT_THAT(GetDismissedSuggestions(), IsEmpty()); |
| 1017 } | 999 } |
| OLD | NEW |