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/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 return provider_.get(); | 264 return provider_.get(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void DestroyProvider() { provider_.reset(); } | 267 void DestroyProvider() { provider_.reset(); } |
| 268 | 268 |
| 269 Category downloads_category() { | 269 Category downloads_category() { |
| 270 return category_factory_.FromKnownCategory( | 270 return category_factory_.FromKnownCategory( |
| 271 ntp_snippets::KnownCategories::DOWNLOADS); | 271 ntp_snippets::KnownCategories::DOWNLOADS); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void FireOfflinePageModelLoaded() { | |
| 275 DCHECK(provider_); | |
| 276 provider_->OfflinePageModelLoaded(&offline_pages_model_); | |
| 277 } | |
| 278 | |
| 279 void AddOfflinePage(const offline_pages::OfflinePageItem& added_page) { | 274 void AddOfflinePage(const offline_pages::OfflinePageItem& added_page) { |
| 280 DCHECK(provider_); | 275 DCHECK(provider_); |
| 281 offline_pages_model_.mutable_items()->push_back(added_page); | 276 offline_pages_model_.mutable_items()->push_back(added_page); |
| 282 provider_->OfflinePageAdded(&offline_pages_model_, added_page); | 277 provider_->OfflinePageAdded(&offline_pages_model_, added_page); |
| 283 } | 278 } |
| 284 | 279 |
| 285 void FireOfflinePageDeleted(const OfflinePageItem& item) { | 280 void FireOfflinePageDeleted(const OfflinePageItem& item) { |
| 286 DCHECK(provider_); | 281 DCHECK(provider_); |
| 287 provider_->OfflinePageDeleted(item.offline_id, item.client_id); | 282 provider_->OfflinePageDeleted(item.offline_id, item.client_id); |
| 288 } | 283 } |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 HasUrl("http://dummy.com/2")))); | 869 HasUrl("http://dummy.com/2")))); |
| 875 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); | 870 CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true); |
| 876 downloads_manager()->NotifyDownloadCreated( | 871 downloads_manager()->NotifyDownloadCreated( |
| 877 downloads_manager()->items()[0].get()); | 872 downloads_manager()->items()[0].get()); |
| 878 // This notification should not reach the provider, because the asset | 873 // This notification should not reach the provider, because the asset |
| 879 // downloads data source is not provided. If it is and the provider reacts to | 874 // downloads data source is not provided. If it is and the provider reacts to |
| 880 // the notification, the test will fail because the observer is a strict mock. | 875 // the notification, the test will fail because the observer is a strict mock. |
| 881 (*downloads_manager()->mutable_items())[0]->NotifyDownloadUpdated(); | 876 (*downloads_manager()->mutable_items())[0]->NotifyDownloadUpdated(); |
| 882 } | 877 } |
| 883 | 878 |
| 884 TEST_F(DownloadSuggestionsProviderTest, ShouldLoadOfflinePagesOnModelLoaded) { | |
| 885 IgnoreOnCategoryStatusChangedToAvailable(); | |
| 886 IgnoreOnSuggestionInvalidated(); | |
| 887 | |
| 888 offline_pages_model()->set_is_loaded(false); | |
| 889 EXPECT_CALL(*observer(), | |
| 890 OnNewSuggestions(_, downloads_category(), IsEmpty())); | |
| 891 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); | |
| 892 | |
| 893 *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); | |
| 894 offline_pages_model()->set_is_loaded(true); | |
| 895 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), | |
| 896 UnorderedElementsAre( | |
| 897 HasUrl("http://dummy.com/1"), | |
| 898 HasUrl("http://dummy.com/2")))); | |
| 899 FireOfflinePageModelLoaded(); | |
| 900 } | |
| 901 | |
| 902 TEST_F(DownloadSuggestionsProviderTest, | 879 TEST_F(DownloadSuggestionsProviderTest, |
| 903 ShouldLoadOfflinePagesIfMissesOnModelLoaded) { | 880 ShouldLoadOfflinePagesIfMissesOnModelLoaded) { |
|
vitaliii
2016/12/15 10:20:37
This test must be renamed, since the OfflinePageMo
| |
| 904 IgnoreOnCategoryStatusChangedToAvailable(); | 881 IgnoreOnCategoryStatusChangedToAvailable(); |
| 905 IgnoreOnSuggestionInvalidated(); | 882 IgnoreOnSuggestionInvalidated(); |
| 906 | 883 |
| 907 *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); | 884 *(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({1, 2}); |
| 908 offline_pages_model()->set_is_loaded(true); | |
| 909 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), | 885 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), |
| 910 UnorderedElementsAre( | 886 UnorderedElementsAre( |
| 911 HasUrl("http://dummy.com/1"), | 887 HasUrl("http://dummy.com/1"), |
| 912 HasUrl("http://dummy.com/2")))); | 888 HasUrl("http://dummy.com/2")))); |
| 913 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); | 889 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/true); |
| 914 } | 890 } |
| 915 | 891 |
| 916 TEST_F(DownloadSuggestionsProviderTest, | 892 TEST_F(DownloadSuggestionsProviderTest, |
| 917 ShouldLoadAndSubmitMissedAssetsEvenIfOfflinePagesAreTurnedOff) { | 893 ShouldLoadAndSubmitMissedAssetsEvenIfOfflinePagesAreTurnedOff) { |
| 918 IgnoreOnCategoryStatusChangedToAvailable(); | 894 IgnoreOnCategoryStatusChangedToAvailable(); |
| 919 IgnoreOnSuggestionInvalidated(); | 895 IgnoreOnSuggestionInvalidated(); |
| 920 | 896 |
| 921 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 897 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 922 EXPECT_CALL( | 898 EXPECT_CALL( |
| 923 *observer(), | 899 *observer(), |
| 924 OnNewSuggestions(_, downloads_category(), | 900 OnNewSuggestions(_, downloads_category(), |
| 925 UnorderedElementsAre(HasUrl("http://download.com/1"), | 901 UnorderedElementsAre(HasUrl("http://download.com/1"), |
| 926 HasUrl("http://download.com/2")))); | 902 HasUrl("http://download.com/2")))); |
| 927 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); | 903 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| 928 } | 904 } |
| OLD | NEW |