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 20 matching lines...) Expand all Loading... | |
| 31 using ntp_snippets::test::FakeOfflinePageModel; | 31 using ntp_snippets::test::FakeOfflinePageModel; |
| 32 using ntp_snippets::CategoryStatus; | 32 using ntp_snippets::CategoryStatus; |
| 33 using offline_pages::ClientId; | 33 using offline_pages::ClientId; |
| 34 using offline_pages::OfflinePageItem; | 34 using offline_pages::OfflinePageItem; |
| 35 using test::FakeDownloadItem; | 35 using test::FakeDownloadItem; |
| 36 using testing::_; | 36 using testing::_; |
| 37 using testing::AllOf; | 37 using testing::AllOf; |
| 38 using testing::AnyNumber; | 38 using testing::AnyNumber; |
| 39 using testing::ElementsAre; | 39 using testing::ElementsAre; |
| 40 using testing::IsEmpty; | 40 using testing::IsEmpty; |
| 41 using testing::Lt; | |
| 41 using testing::Mock; | 42 using testing::Mock; |
| 42 using testing::Return; | 43 using testing::Return; |
| 43 using testing::SizeIs; | 44 using testing::SizeIs; |
| 44 using testing::StrictMock; | 45 using testing::StrictMock; |
| 45 using testing::UnorderedElementsAre; | 46 using testing::UnorderedElementsAre; |
| 46 using testing::Lt; | |
| 47 | 47 |
| 48 namespace ntp_snippets { | 48 namespace ntp_snippets { |
| 49 // These functions are implicitly used to print out values during the tests. | 49 // These functions are implicitly used to print out values during the tests. |
| 50 std::ostream& operator<<(std::ostream& os, const ContentSuggestion& value) { | 50 std::ostream& operator<<(std::ostream& os, const ContentSuggestion& value) { |
| 51 os << "{ url: " << value.url() << ", publish_date: " << value.publish_date() | 51 os << "{ url: " << value.url() << ", publish_date: " << value.publish_date() |
| 52 << "}"; | 52 << "}"; |
| 53 return os; | 53 return os; |
| 54 } | 54 } |
| 55 | 55 |
| 56 std::ostream& operator<<(std::ostream& os, const CategoryStatus& value) { | 56 std::ostream& operator<<(std::ostream& os, const CategoryStatus& value) { |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 IgnoreOnSuggestionInvalidated(); | 919 IgnoreOnSuggestionInvalidated(); |
| 920 | 920 |
| 921 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); | 921 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1, 2}); |
| 922 EXPECT_CALL( | 922 EXPECT_CALL( |
| 923 *observer(), | 923 *observer(), |
| 924 OnNewSuggestions(_, downloads_category(), | 924 OnNewSuggestions(_, downloads_category(), |
| 925 UnorderedElementsAre(HasUrl("http://download.com/1"), | 925 UnorderedElementsAre(HasUrl("http://download.com/1"), |
| 926 HasUrl("http://download.com/2")))); | 926 HasUrl("http://download.com/2")))); |
| 927 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); | 927 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); |
| 928 } | 928 } |
| 929 | |
| 930 TEST_F(DownloadSuggestionsProviderTest, | |
| 931 ShouldNotPruneDismissedSuggestionsOnStartup) { | |
| 932 IgnoreOnCategoryStatusChangedToAvailable(); | |
| 933 IgnoreOnSuggestionInvalidated(); | |
| 934 | |
| 935 // We dismiss an item to store it in the list of dismissed items. | |
| 936 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); | |
| 937 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); | |
| 938 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); | |
| 939 provider()->DismissSuggestion( | |
| 940 GetDummySuggestionId(1, /*is_offline_page=*/false)); | |
| 941 DestroyProvider(); | |
| 942 | |
| 943 // We simulate current DownloadManager behaviour; | |
| 944 // The download manager has not started reading the list yet, so it is empty. | |
| 945 downloads_manager()->mutable_items()->clear(); | |
| 946 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); | |
| 947 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); | |
| 948 Mock::VerifyAndClearExpectations(observer()); | |
| 949 | |
| 950 // The first download is being read. | |
| 951 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({1}); | |
| 952 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)) | |
| 953 .Times(0); | |
| 954 FireDownloadCreated(downloads_manager()->items()[0].get()); | |
| 955 // The first download should not be reported, because it is dismissed. | |
| 956 } | |
| 957 | |
| 958 // TODO(vitaliii): Remove this test once the dismissed ids are pruned. See | |
| 959 // crbug.com/672758. | |
| 960 TEST_F(DownloadSuggestionsProviderTest, ShouldRemoveDismissedIdsIfTooMany) { | |
| 961 IgnoreOnCategoryStatusChangedToAvailable(); | |
| 962 IgnoreOnSuggestionInvalidated(); | |
| 963 | |
| 964 std::vector<int> ids; | |
| 965 for (int i = 0; i < 200; ++i) { | |
| 966 ids.push_back(i); | |
| 967 } | |
| 968 | |
| 969 *(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads(ids); | |
| 970 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); | |
| 971 CreateProvider(/*show_assets=*/true, /*show_offline_pages=*/false); | |
| 972 | |
| 973 for (int i = 0; i < static_cast<int>(ids.size()); ++i) { | |
| 974 provider()->DismissSuggestion( | |
| 975 GetDummySuggestionId(i, /*is_offline_page=*/false)); | |
| 976 } | |
| 977 | |
| 978 EXPECT_THAT(GetDismissedSuggestions(), SizeIs(Lt(ids.size()))); | |
|
Marc Treib
2016/12/09 16:37:26
You could expose the actual max count (e.g. via a
vitaliii
2016/12/09 17:30:36
Done.
| |
| 979 } | |
| OLD | NEW |