| 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 "components/ntp_snippets/offline_pages/offline_page_suggestions_provide
r.h" | 5 #include "components/ntp_snippets/offline_pages/offline_page_suggestions_provide
r.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 OfflinePageItem CreateDummyRecentTab(int id, base::Time time) { | 68 OfflinePageItem CreateDummyRecentTab(int id, base::Time time) { |
| 69 OfflinePageItem item = CreateDummyRecentTab(id); | 69 OfflinePageItem item = CreateDummyRecentTab(id); |
| 70 item.last_access_time = time; | 70 item.last_access_time = time; |
| 71 return item; | 71 return item; |
| 72 } | 72 } |
| 73 | 73 |
| 74 OfflinePageItem CreateDummyDownload(int id) { | 74 OfflinePageItem CreateDummyDownload(int id) { |
| 75 return CreateDummyItem(offline_pages::kAsyncNamespace, id); | 75 return CreateDummyItem(offline_pages::kAsyncNamespace, id); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void CaptureDismissedSuggestions( |
| 79 std::vector<ContentSuggestion>* captured_suggestions, |
| 80 std::vector<ContentSuggestion> dismissed_suggestions) { |
| 81 std::move(dismissed_suggestions.begin(), dismissed_suggestions.end(), |
| 82 std::back_inserter(*captured_suggestions)); |
| 83 } |
| 84 |
| 78 } // namespace | 85 } // namespace |
| 79 | 86 |
| 80 class MockOfflinePageModel : public StubOfflinePageModel { | 87 class FakeOfflinePageModel : public StubOfflinePageModel { |
| 81 public: | 88 public: |
| 82 MockOfflinePageModel() {} | 89 FakeOfflinePageModel() {} |
| 83 | 90 |
| 84 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override { | 91 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override { |
| 85 callback.Run(items_); | 92 callback.Run(items_); |
| 86 } | 93 } |
| 87 | 94 |
| 88 std::vector<OfflinePageItem>* items() { return &items_; } | 95 const std::vector<OfflinePageItem>& items() { return items_; } |
| 96 std::vector<OfflinePageItem>* mutable_items() { return &items_; } |
| 89 | 97 |
| 90 private: | 98 private: |
| 91 std::vector<OfflinePageItem> items_; | 99 std::vector<OfflinePageItem> items_; |
| 92 }; | 100 }; |
| 93 | 101 |
| 94 class OfflinePageSuggestionsProviderTest : public testing::Test { | 102 class OfflinePageSuggestionsProviderTest : public testing::Test { |
| 95 public: | 103 public: |
| 96 OfflinePageSuggestionsProviderTest() | 104 OfflinePageSuggestionsProviderTest() |
| 97 : pref_service_(new TestingPrefServiceSimple()) { | 105 : pref_service_(new TestingPrefServiceSimple()) { |
| 98 OfflinePageSuggestionsProvider::RegisterProfilePrefs( | 106 OfflinePageSuggestionsProvider::RegisterProfilePrefs( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 119 } | 127 } |
| 120 | 128 |
| 121 Category recent_tabs_category() { | 129 Category recent_tabs_category() { |
| 122 return category_factory_.FromKnownCategory(KnownCategories::RECENT_TABS); | 130 return category_factory_.FromKnownCategory(KnownCategories::RECENT_TABS); |
| 123 } | 131 } |
| 124 | 132 |
| 125 Category downloads_category() { | 133 Category downloads_category() { |
| 126 return category_factory_.FromKnownCategory(KnownCategories::DOWNLOADS); | 134 return category_factory_.FromKnownCategory(KnownCategories::DOWNLOADS); |
| 127 } | 135 } |
| 128 | 136 |
| 129 void AddItem(OfflinePageItem item) { model()->items()->push_back(item); } | |
| 130 | |
| 131 std::string GetDummySuggestionId(Category category, int id) { | 137 std::string GetDummySuggestionId(Category category, int id) { |
| 132 return provider_->MakeUniqueID(category, base::IntToString(id)); | 138 return provider_->MakeUniqueID(category, base::IntToString(id)); |
| 133 } | 139 } |
| 134 | 140 |
| 135 ContentSuggestion CreateDummySuggestion(Category category, int id) { | 141 ContentSuggestion CreateDummySuggestion(Category category, int id) { |
| 136 std::string strid = base::IntToString(id); | 142 std::string strid = base::IntToString(id); |
| 137 ContentSuggestion result( | 143 ContentSuggestion result( |
| 138 GetDummySuggestionId(category, id), | 144 GetDummySuggestionId(category, id), |
| 139 GURL("file:///some/folder/test" + strid + ".mhtml")); | 145 GURL("file:///some/folder/test" + strid + ".mhtml")); |
| 140 result.set_title(base::UTF8ToUTF16("http://dummy.com/" + strid)); | 146 result.set_title(base::UTF8ToUTF16("http://dummy.com/" + strid)); |
| 141 return result; | 147 return result; |
| 142 } | 148 } |
| 143 | 149 |
| 144 void FireOfflinePageModelChanged() { | 150 void FireOfflinePageModelChanged() { |
| 145 provider_->OfflinePageModelChanged(model()); | 151 provider_->OfflinePageModelChanged(model()); |
| 146 } | 152 } |
| 147 | 153 |
| 148 void FireOfflinePageDeleted(const OfflinePageItem& item) { | 154 void FireOfflinePageDeleted(const OfflinePageItem& item) { |
| 149 provider_->OfflinePageDeleted(item.offline_id, item.client_id); | 155 provider_->OfflinePageDeleted(item.offline_id, item.client_id); |
| 150 } | 156 } |
| 151 | 157 |
| 152 std::set<std::string> ReadDismissedIDsFromPrefs(Category category) { | 158 std::set<std::string> ReadDismissedIDsFromPrefs(Category category) { |
| 153 return provider_->ReadDismissedIDsFromPrefs(category); | 159 return provider_->ReadDismissedIDsFromPrefs(category); |
| 154 } | 160 } |
| 155 | 161 |
| 156 // Workaround to realize a DismissedSuggestionsCallback. Because gMock can't | |
| 157 // handle non-movable parameters, a helper method is needed to forward the | |
| 158 // call to the actual MOCK_METHOD. | |
| 159 void DismissedSuggestionsHelper( | |
| 160 std::vector<ContentSuggestion> dismissed_suggestions) { | |
| 161 ReceivedDismissedSuggestions(dismissed_suggestions); | |
| 162 } | |
| 163 MOCK_METHOD1( | |
| 164 ReceivedDismissedSuggestions, | |
| 165 void(const std::vector<ContentSuggestion>& dismissed_suggestions)); | |
| 166 | |
| 167 ContentSuggestionsProvider* provider() { return provider_.get(); } | 162 ContentSuggestionsProvider* provider() { return provider_.get(); } |
| 168 MockOfflinePageModel* model() { return &model_; } | 163 FakeOfflinePageModel* model() { return &model_; } |
| 169 MockContentSuggestionsProviderObserver* observer() { return &observer_; } | 164 MockContentSuggestionsProviderObserver* observer() { return &observer_; } |
| 170 TestingPrefServiceSimple* pref_service() { return pref_service_.get(); } | 165 TestingPrefServiceSimple* pref_service() { return pref_service_.get(); } |
| 171 | 166 |
| 172 private: | 167 private: |
| 173 MockOfflinePageModel model_; | 168 FakeOfflinePageModel model_; |
| 174 MockContentSuggestionsProviderObserver observer_; | 169 MockContentSuggestionsProviderObserver observer_; |
| 175 CategoryFactory category_factory_; | 170 CategoryFactory category_factory_; |
| 176 std::unique_ptr<TestingPrefServiceSimple> pref_service_; | 171 std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
| 177 // Last so that the dependencies are deleted after the provider. | 172 // Last so that the dependencies are deleted after the provider. |
| 178 std::unique_ptr<OfflinePageSuggestionsProvider> provider_; | 173 std::unique_ptr<OfflinePageSuggestionsProvider> provider_; |
| 179 | 174 |
| 180 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProviderTest); | 175 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProviderTest); |
| 181 }; | 176 }; |
| 182 | 177 |
| 183 TEST_F(OfflinePageSuggestionsProviderTest, ShouldSplitAndConvertToSuggestions) { | 178 TEST_F(OfflinePageSuggestionsProviderTest, ShouldSplitAndConvertToSuggestions) { |
| 184 AddItem(CreateDummyRecentTab(1)); | 179 model()->mutable_items()->push_back(CreateDummyRecentTab(1)); |
| 185 AddItem(CreateDummyRecentTab(2)); | 180 model()->mutable_items()->push_back(CreateDummyRecentTab(2)); |
| 186 AddItem(CreateDummyRecentTab(3)); | 181 model()->mutable_items()->push_back(CreateDummyRecentTab(3)); |
| 187 AddItem(CreateDummyDownload(101)); | 182 model()->mutable_items()->push_back(CreateDummyDownload(101)); |
| 188 | 183 |
| 189 EXPECT_CALL( | 184 EXPECT_CALL( |
| 190 *observer(), | 185 *observer(), |
| 191 OnNewSuggestions(_, recent_tabs_category(), | 186 OnNewSuggestions(_, recent_tabs_category(), |
| 192 UnorderedElementsAre( | 187 UnorderedElementsAre( |
| 193 Property(&ContentSuggestion::url, | 188 Property(&ContentSuggestion::url, |
| 194 GURL("file:///some/folder/test1.mhtml")), | 189 GURL("file:///some/folder/test1.mhtml")), |
| 195 Property(&ContentSuggestion::url, | 190 Property(&ContentSuggestion::url, |
| 196 GURL("file:///some/folder/test2.mhtml")), | 191 GURL("file:///some/folder/test2.mhtml")), |
| 197 Property(&ContentSuggestion::url, | 192 Property(&ContentSuggestion::url, |
| 198 GURL("file:///some/folder/test3.mhtml"))))); | 193 GURL("file:///some/folder/test3.mhtml"))))); |
| 199 | 194 |
| 200 EXPECT_CALL(*observer(), | 195 EXPECT_CALL(*observer(), |
| 201 OnNewSuggestions( | 196 OnNewSuggestions( |
| 202 _, downloads_category(), | 197 _, downloads_category(), |
| 203 UnorderedElementsAre(AllOf( | 198 UnorderedElementsAre(AllOf( |
| 204 Property(&ContentSuggestion::url, | 199 Property(&ContentSuggestion::url, |
| 205 GURL("file:///some/folder/test101.mhtml")), | 200 GURL("file:///some/folder/test101.mhtml")), |
| 206 Property(&ContentSuggestion::title, | 201 Property(&ContentSuggestion::title, |
| 207 base::UTF8ToUTF16("http://dummy.com/101")))))); | 202 base::UTF8ToUTF16("http://dummy.com/101")))))); |
| 208 | 203 |
| 209 FireOfflinePageModelChanged(); | 204 FireOfflinePageModelChanged(); |
| 210 } | 205 } |
| 211 | 206 |
| 212 TEST_F(OfflinePageSuggestionsProviderTest, ShouldIgnoreDisabledCategories) { | 207 TEST_F(OfflinePageSuggestionsProviderTest, ShouldIgnoreDisabledCategories) { |
| 213 AddItem(CreateDummyRecentTab(1)); | 208 model()->mutable_items()->push_back(CreateDummyRecentTab(1)); |
| 214 AddItem(CreateDummyRecentTab(2)); | 209 model()->mutable_items()->push_back(CreateDummyRecentTab(2)); |
| 215 AddItem(CreateDummyRecentTab(3)); | 210 model()->mutable_items()->push_back(CreateDummyRecentTab(3)); |
| 216 AddItem(CreateDummyDownload(101)); | 211 model()->mutable_items()->push_back(CreateDummyDownload(101)); |
| 217 | 212 |
| 218 // Disable recent tabs, enable downloads. | 213 // Disable recent tabs, enable downloads. |
| 219 EXPECT_CALL(*observer(), OnNewSuggestions(_, recent_tabs_category(), _)) | 214 EXPECT_CALL(*observer(), OnNewSuggestions(_, recent_tabs_category(), _)) |
| 220 .Times(0); | 215 .Times(0); |
| 221 EXPECT_CALL( | 216 EXPECT_CALL( |
| 222 *observer(), | 217 *observer(), |
| 223 OnNewSuggestions(_, downloads_category(), | 218 OnNewSuggestions(_, downloads_category(), |
| 224 UnorderedElementsAre(Property( | 219 UnorderedElementsAre(Property( |
| 225 &ContentSuggestion::url, | 220 &ContentSuggestion::url, |
| 226 GURL("file:///some/folder/test101.mhtml"))))); | 221 GURL("file:///some/folder/test101.mhtml"))))); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 241 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)) | 236 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)) |
| 242 .Times(0); | 237 .Times(0); |
| 243 RecreateProvider(true, false, true); | 238 RecreateProvider(true, false, true); |
| 244 Mock::VerifyAndClearExpectations(observer()); | 239 Mock::VerifyAndClearExpectations(observer()); |
| 245 } | 240 } |
| 246 | 241 |
| 247 TEST_F(OfflinePageSuggestionsProviderTest, ShouldSortByMostRecentlyVisited) { | 242 TEST_F(OfflinePageSuggestionsProviderTest, ShouldSortByMostRecentlyVisited) { |
| 248 base::Time now = base::Time::Now(); | 243 base::Time now = base::Time::Now(); |
| 249 base::Time yesterday = now - base::TimeDelta::FromDays(1); | 244 base::Time yesterday = now - base::TimeDelta::FromDays(1); |
| 250 base::Time tomorrow = now + base::TimeDelta::FromDays(1); | 245 base::Time tomorrow = now + base::TimeDelta::FromDays(1); |
| 251 AddItem(CreateDummyRecentTab(1, now)); | 246 model()->mutable_items()->push_back(CreateDummyRecentTab(1, now)); |
| 252 AddItem(CreateDummyRecentTab(2, yesterday)); | 247 model()->mutable_items()->push_back(CreateDummyRecentTab(2, yesterday)); |
| 253 AddItem(CreateDummyRecentTab(3, tomorrow)); | 248 model()->mutable_items()->push_back(CreateDummyRecentTab(3, tomorrow)); |
| 254 | 249 |
| 255 EXPECT_CALL( | 250 EXPECT_CALL( |
| 256 *observer(), | 251 *observer(), |
| 257 OnNewSuggestions( | 252 OnNewSuggestions( |
| 258 _, recent_tabs_category(), | 253 _, recent_tabs_category(), |
| 259 ElementsAre(Property(&ContentSuggestion::url, | 254 ElementsAre(Property(&ContentSuggestion::url, |
| 260 GURL("file:///some/folder/test3.mhtml")), | 255 GURL("file:///some/folder/test3.mhtml")), |
| 261 Property(&ContentSuggestion::url, | 256 Property(&ContentSuggestion::url, |
| 262 GURL("file:///some/folder/test1.mhtml")), | 257 GURL("file:///some/folder/test1.mhtml")), |
| 263 Property(&ContentSuggestion::url, | 258 Property(&ContentSuggestion::url, |
| 264 GURL("file:///some/folder/test2.mhtml"))))); | 259 GURL("file:///some/folder/test2.mhtml"))))); |
| 265 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); | 260 EXPECT_CALL(*observer(), OnNewSuggestions(_, downloads_category(), _)); |
| 266 FireOfflinePageModelChanged(); | 261 FireOfflinePageModelChanged(); |
| 267 } | 262 } |
| 268 | 263 |
| 269 TEST_F(OfflinePageSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) { | 264 TEST_F(OfflinePageSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) { |
| 270 EXPECT_FALSE( | 265 EXPECT_FALSE( |
| 271 provider()->GetCategoryInfo(recent_tabs_category()).has_more_button()); | 266 provider()->GetCategoryInfo(recent_tabs_category()).has_more_button()); |
| 272 EXPECT_TRUE( | 267 EXPECT_TRUE( |
| 273 provider()->GetCategoryInfo(downloads_category()).has_more_button()); | 268 provider()->GetCategoryInfo(downloads_category()).has_more_button()); |
| 274 RecreateProvider(true, true, false); | 269 RecreateProvider(true, true, false); |
| 275 EXPECT_FALSE( | 270 EXPECT_FALSE( |
| 276 provider()->GetCategoryInfo(recent_tabs_category()).has_more_button()); | 271 provider()->GetCategoryInfo(recent_tabs_category()).has_more_button()); |
| 277 EXPECT_FALSE( | 272 EXPECT_FALSE( |
| 278 provider()->GetCategoryInfo(downloads_category()).has_more_button()); | 273 provider()->GetCategoryInfo(downloads_category()).has_more_button()); |
| 279 } | 274 } |
| 280 | 275 |
| 281 TEST_F(OfflinePageSuggestionsProviderTest, ShouldDismiss) { | 276 TEST_F(OfflinePageSuggestionsProviderTest, ShouldDismiss) { |
| 282 AddItem(CreateDummyRecentTab(1)); | 277 model()->mutable_items()->push_back(CreateDummyRecentTab(1)); |
| 283 AddItem(CreateDummyRecentTab(2)); | 278 model()->mutable_items()->push_back(CreateDummyRecentTab(2)); |
| 284 AddItem(CreateDummyRecentTab(3)); | 279 model()->mutable_items()->push_back(CreateDummyRecentTab(3)); |
| 285 AddItem(CreateDummyRecentTab(4)); | 280 model()->mutable_items()->push_back(CreateDummyRecentTab(4)); |
| 286 FireOfflinePageModelChanged(); | 281 FireOfflinePageModelChanged(); |
| 287 | 282 |
| 288 // Dismiss 2 and 3. | 283 // Dismiss 2 and 3. |
| 289 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); | 284 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); |
| 290 provider()->DismissSuggestion( | 285 provider()->DismissSuggestion( |
| 291 GetDummySuggestionId(recent_tabs_category(), 2)); | 286 GetDummySuggestionId(recent_tabs_category(), 2)); |
| 292 provider()->DismissSuggestion( | 287 provider()->DismissSuggestion( |
| 293 GetDummySuggestionId(recent_tabs_category(), 3)); | 288 GetDummySuggestionId(recent_tabs_category(), 3)); |
| 294 Mock::VerifyAndClearExpectations(observer()); | 289 Mock::VerifyAndClearExpectations(observer()); |
| 295 | 290 |
| 296 // They should disappear from the reported suggestions. | 291 // They should disappear from the reported suggestions. |
| 297 EXPECT_CALL( | 292 EXPECT_CALL( |
| 298 *observer(), | 293 *observer(), |
| 299 OnNewSuggestions(_, recent_tabs_category(), | 294 OnNewSuggestions(_, recent_tabs_category(), |
| 300 UnorderedElementsAre( | 295 UnorderedElementsAre( |
| 301 Property(&ContentSuggestion::url, | 296 Property(&ContentSuggestion::url, |
| 302 GURL("file:///some/folder/test1.mhtml")), | 297 GURL("file:///some/folder/test1.mhtml")), |
| 303 Property(&ContentSuggestion::url, | 298 Property(&ContentSuggestion::url, |
| 304 GURL("file:///some/folder/test4.mhtml"))))); | 299 GURL("file:///some/folder/test4.mhtml"))))); |
| 305 EXPECT_CALL(*observer(), | 300 EXPECT_CALL(*observer(), |
| 306 OnNewSuggestions(_, downloads_category(), IsEmpty())); | 301 OnNewSuggestions(_, downloads_category(), IsEmpty())); |
| 307 FireOfflinePageModelChanged(); | 302 FireOfflinePageModelChanged(); |
| 308 Mock::VerifyAndClearExpectations(observer()); | 303 Mock::VerifyAndClearExpectations(observer()); |
| 309 | 304 |
| 310 // And appear in the dismissed suggestions for the right category. | 305 // And appear in the dismissed suggestions for the right category. |
| 311 EXPECT_CALL(*this, ReceivedDismissedSuggestions(UnorderedElementsAre( | 306 std::vector<ContentSuggestion> dismissed_suggestions; |
| 312 Property(&ContentSuggestion::url, | |
| 313 GURL("file:///some/folder/test2.mhtml")), | |
| 314 Property(&ContentSuggestion::url, | |
| 315 GURL("file:///some/folder/test3.mhtml"))))); | |
| 316 provider()->GetDismissedSuggestionsForDebugging( | 307 provider()->GetDismissedSuggestionsForDebugging( |
| 317 recent_tabs_category(), | 308 recent_tabs_category(), |
| 318 base::Bind( | 309 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); |
| 319 &OfflinePageSuggestionsProviderTest::DismissedSuggestionsHelper, | 310 EXPECT_THAT( |
| 320 base::Unretained(this))); | 311 dismissed_suggestions, |
| 321 Mock::VerifyAndClearExpectations(this); | 312 UnorderedElementsAre(Property(&ContentSuggestion::url, |
| 313 GURL("file:///some/folder/test2.mhtml")), |
| 314 Property(&ContentSuggestion::url, |
| 315 GURL("file:///some/folder/test3.mhtml")))); |
| 322 | 316 |
| 323 // The other category should have no dismissed suggestions. | 317 // The other category should have no dismissed suggestions. |
| 324 EXPECT_CALL(*this, ReceivedDismissedSuggestions(IsEmpty())); | 318 dismissed_suggestions.clear(); |
| 325 provider()->GetDismissedSuggestionsForDebugging( | 319 provider()->GetDismissedSuggestionsForDebugging( |
| 326 downloads_category(), | 320 downloads_category(), |
| 327 base::Bind( | 321 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); |
| 328 &OfflinePageSuggestionsProviderTest::DismissedSuggestionsHelper, | 322 EXPECT_THAT(dismissed_suggestions, IsEmpty()); |
| 329 base::Unretained(this))); | |
| 330 Mock::VerifyAndClearExpectations(this); | |
| 331 | 323 |
| 332 // Clear dismissed suggestions. | 324 // Clear dismissed suggestions. |
| 333 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); | 325 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); |
| 334 | 326 |
| 335 // They should be gone from the dismissed suggestions. | 327 // They should be gone from the dismissed suggestions. |
| 336 EXPECT_CALL(*this, ReceivedDismissedSuggestions(IsEmpty())); | 328 dismissed_suggestions.clear(); |
| 337 provider()->GetDismissedSuggestionsForDebugging( | 329 provider()->GetDismissedSuggestionsForDebugging( |
| 338 recent_tabs_category(), | 330 recent_tabs_category(), |
| 339 base::Bind( | 331 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); |
| 340 &OfflinePageSuggestionsProviderTest::DismissedSuggestionsHelper, | 332 EXPECT_THAT(dismissed_suggestions, IsEmpty()); |
| 341 base::Unretained(this))); | |
| 342 Mock::VerifyAndClearExpectations(this); | |
| 343 | 333 |
| 344 // And appear in the reported suggestions for the category again. | 334 // And appear in the reported suggestions for the category again. |
| 345 EXPECT_CALL(*observer(), | 335 EXPECT_CALL(*observer(), |
| 346 OnNewSuggestions(_, recent_tabs_category(), SizeIs(4))); | 336 OnNewSuggestions(_, recent_tabs_category(), SizeIs(4))); |
| 347 EXPECT_CALL(*observer(), | 337 EXPECT_CALL(*observer(), |
| 348 OnNewSuggestions(_, downloads_category(), IsEmpty())); | 338 OnNewSuggestions(_, downloads_category(), IsEmpty())); |
| 349 FireOfflinePageModelChanged(); | 339 FireOfflinePageModelChanged(); |
| 350 Mock::VerifyAndClearExpectations(observer()); | 340 Mock::VerifyAndClearExpectations(observer()); |
| 351 } | 341 } |
| 352 | 342 |
| 353 TEST_F(OfflinePageSuggestionsProviderTest, | 343 TEST_F(OfflinePageSuggestionsProviderTest, |
| 354 ShouldInvalidateWhenOfflinePageDeleted) { | 344 ShouldInvalidateWhenOfflinePageDeleted) { |
| 355 AddItem(CreateDummyRecentTab(1)); | 345 model()->mutable_items()->push_back(CreateDummyRecentTab(1)); |
| 356 AddItem(CreateDummyRecentTab(2)); | 346 model()->mutable_items()->push_back(CreateDummyRecentTab(2)); |
| 357 AddItem(CreateDummyRecentTab(3)); | 347 model()->mutable_items()->push_back(CreateDummyRecentTab(3)); |
| 358 FireOfflinePageModelChanged(); | 348 FireOfflinePageModelChanged(); |
| 359 | 349 |
| 360 // Invalidation of suggestion 2 should be forwarded. | 350 // Invalidation of suggestion 2 should be forwarded. |
| 361 EXPECT_CALL( | 351 EXPECT_CALL( |
| 362 *observer(), | 352 *observer(), |
| 363 OnSuggestionInvalidated(_, recent_tabs_category(), | 353 OnSuggestionInvalidated(_, recent_tabs_category(), |
| 364 GetDummySuggestionId(recent_tabs_category(), 2))); | 354 GetDummySuggestionId(recent_tabs_category(), 2))); |
| 365 FireOfflinePageDeleted(model()->items()->at(1)); | 355 FireOfflinePageDeleted(model()->items().at(1)); |
| 366 } | 356 } |
| 367 | 357 |
| 368 TEST_F(OfflinePageSuggestionsProviderTest, ShouldClearDismissedOnInvalidate) { | 358 TEST_F(OfflinePageSuggestionsProviderTest, ShouldClearDismissedOnInvalidate) { |
| 369 AddItem(CreateDummyRecentTab(1)); | 359 model()->mutable_items()->push_back(CreateDummyRecentTab(1)); |
| 370 AddItem(CreateDummyRecentTab(2)); | 360 model()->mutable_items()->push_back(CreateDummyRecentTab(2)); |
| 371 AddItem(CreateDummyRecentTab(3)); | 361 model()->mutable_items()->push_back(CreateDummyRecentTab(3)); |
| 372 FireOfflinePageModelChanged(); | 362 FireOfflinePageModelChanged(); |
| 373 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); | 363 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); |
| 374 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); | 364 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); |
| 375 | 365 |
| 376 provider()->DismissSuggestion( | 366 provider()->DismissSuggestion( |
| 377 GetDummySuggestionId(recent_tabs_category(), 2)); | 367 GetDummySuggestionId(recent_tabs_category(), 2)); |
| 378 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), SizeIs(1)); | 368 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), SizeIs(1)); |
| 379 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); | 369 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); |
| 380 | 370 |
| 381 FireOfflinePageDeleted(model()->items()->at(1)); | 371 FireOfflinePageDeleted(model()->items().at(1)); |
| 382 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); | 372 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); |
| 383 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); | 373 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); |
| 384 } | 374 } |
| 385 | 375 |
| 386 TEST_F(OfflinePageSuggestionsProviderTest, ShouldClearDismissedOnFetch) { | 376 TEST_F(OfflinePageSuggestionsProviderTest, ShouldClearDismissedOnFetch) { |
| 387 AddItem(CreateDummyDownload(1)); | 377 model()->mutable_items()->push_back(CreateDummyDownload(1)); |
| 388 AddItem(CreateDummyDownload(2)); | 378 model()->mutable_items()->push_back(CreateDummyDownload(2)); |
| 389 AddItem(CreateDummyDownload(3)); | 379 model()->mutable_items()->push_back(CreateDummyDownload(3)); |
| 390 FireOfflinePageModelChanged(); | 380 FireOfflinePageModelChanged(); |
| 391 | 381 |
| 392 provider()->DismissSuggestion(GetDummySuggestionId(downloads_category(), 2)); | 382 provider()->DismissSuggestion(GetDummySuggestionId(downloads_category(), 2)); |
| 393 provider()->DismissSuggestion(GetDummySuggestionId(downloads_category(), 3)); | 383 provider()->DismissSuggestion(GetDummySuggestionId(downloads_category(), 3)); |
| 394 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); | 384 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); |
| 395 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), SizeIs(2)); | 385 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), SizeIs(2)); |
| 396 | 386 |
| 397 model()->items()->clear(); | 387 model()->mutable_items()->clear(); |
| 398 AddItem(CreateDummyDownload(2)); | 388 model()->mutable_items()->push_back(CreateDummyDownload(2)); |
| 399 FireOfflinePageModelChanged(); | 389 FireOfflinePageModelChanged(); |
| 400 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); | 390 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); |
| 401 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), SizeIs(1)); | 391 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), SizeIs(1)); |
| 402 | 392 |
| 403 model()->items()->clear(); | 393 model()->mutable_items()->clear(); |
| 404 FireOfflinePageModelChanged(); | 394 FireOfflinePageModelChanged(); |
| 405 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); | 395 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); |
| 406 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); | 396 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); |
| 407 } | 397 } |
| 408 | 398 |
| 409 } // namespace ntp_snippets | 399 } // namespace ntp_snippets |
| OLD | NEW |