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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 146 } |
147 | 147 |
148 void FireOfflinePageDeleted(const OfflinePageItem& item) { | 148 void FireOfflinePageDeleted(const OfflinePageItem& item) { |
149 provider_->OfflinePageDeleted(item.offline_id, item.client_id); | 149 provider_->OfflinePageDeleted(item.offline_id, item.client_id); |
150 } | 150 } |
151 | 151 |
152 std::set<std::string> ReadDismissedIDsFromPrefs(Category category) { | 152 std::set<std::string> ReadDismissedIDsFromPrefs(Category category) { |
153 return provider_->ReadDismissedIDsFromPrefs(category); | 153 return provider_->ReadDismissedIDsFromPrefs(category); |
154 } | 154 } |
155 | 155 |
156 // Workaround to realize a DismissedSuggestionsCallback. Because gMock can't | 156 void CaptureDismissedSuggestions( |
Marc Treib
2016/08/29 14:54:29
This could be a global function, or at least a sta
tschumann
2016/08/29 15:19:11
Let's make this a function in an unnamed namespace
Philipp Keck
2016/08/29 15:27:05
Done.
| |
157 // handle non-movable parameters, a helper method is needed to forward the | 157 std::vector<ContentSuggestion>* captured_suggestions, |
158 // call to the actual MOCK_METHOD. | |
159 void DismissedSuggestionsHelper( | |
160 std::vector<ContentSuggestion> dismissed_suggestions) { | 158 std::vector<ContentSuggestion> dismissed_suggestions) { |
161 ReceivedDismissedSuggestions(dismissed_suggestions); | 159 std::move(dismissed_suggestions.begin(), dismissed_suggestions.end(), |
160 std::back_inserter(*captured_suggestions)); | |
162 } | 161 } |
163 MOCK_METHOD1( | |
164 ReceivedDismissedSuggestions, | |
165 void(const std::vector<ContentSuggestion>& dismissed_suggestions)); | |
166 | 162 |
167 ContentSuggestionsProvider* provider() { return provider_.get(); } | 163 ContentSuggestionsProvider* provider() { return provider_.get(); } |
168 MockOfflinePageModel* model() { return &model_; } | 164 MockOfflinePageModel* model() { return &model_; } |
169 MockContentSuggestionsProviderObserver* observer() { return &observer_; } | 165 MockContentSuggestionsProviderObserver* observer() { return &observer_; } |
170 TestingPrefServiceSimple* pref_service() { return pref_service_.get(); } | 166 TestingPrefServiceSimple* pref_service() { return pref_service_.get(); } |
171 | 167 |
172 private: | 168 private: |
173 MockOfflinePageModel model_; | 169 MockOfflinePageModel model_; |
174 MockContentSuggestionsProviderObserver observer_; | 170 MockContentSuggestionsProviderObserver observer_; |
175 CategoryFactory category_factory_; | 171 CategoryFactory category_factory_; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 Property(&ContentSuggestion::url, | 297 Property(&ContentSuggestion::url, |
302 GURL("file:///some/folder/test1.mhtml")), | 298 GURL("file:///some/folder/test1.mhtml")), |
303 Property(&ContentSuggestion::url, | 299 Property(&ContentSuggestion::url, |
304 GURL("file:///some/folder/test4.mhtml"))))); | 300 GURL("file:///some/folder/test4.mhtml"))))); |
305 EXPECT_CALL(*observer(), | 301 EXPECT_CALL(*observer(), |
306 OnNewSuggestions(_, downloads_category(), IsEmpty())); | 302 OnNewSuggestions(_, downloads_category(), IsEmpty())); |
307 FireOfflinePageModelChanged(); | 303 FireOfflinePageModelChanged(); |
308 Mock::VerifyAndClearExpectations(observer()); | 304 Mock::VerifyAndClearExpectations(observer()); |
309 | 305 |
310 // And appear in the dismissed suggestions for the right category. | 306 // And appear in the dismissed suggestions for the right category. |
311 EXPECT_CALL(*this, ReceivedDismissedSuggestions(UnorderedElementsAre( | 307 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( | 308 provider()->GetDismissedSuggestionsForDebugging( |
317 recent_tabs_category(), | 309 recent_tabs_category(), |
318 base::Bind( | 310 base::Bind( |
319 &OfflinePageSuggestionsProviderTest::DismissedSuggestionsHelper, | 311 &OfflinePageSuggestionsProviderTest::CaptureDismissedSuggestions, |
320 base::Unretained(this))); | 312 base::Unretained(this), &dismissed_suggestions)); |
313 EXPECT_THAT( | |
314 dismissed_suggestions, | |
315 UnorderedElementsAre(Property(&ContentSuggestion::url, | |
316 GURL("file:///some/folder/test2.mhtml")), | |
317 Property(&ContentSuggestion::url, | |
318 GURL("file:///some/folder/test3.mhtml")))); | |
321 Mock::VerifyAndClearExpectations(this); | 319 Mock::VerifyAndClearExpectations(this); |
tschumann
2016/08/29 15:19:11
you can drop this line here and in other places no
Philipp Keck
2016/08/29 15:27:05
Done.
| |
322 | 320 |
323 // The other category should have no dismissed suggestions. | 321 // The other category should have no dismissed suggestions. |
324 EXPECT_CALL(*this, ReceivedDismissedSuggestions(IsEmpty())); | 322 dismissed_suggestions.clear(); |
325 provider()->GetDismissedSuggestionsForDebugging( | 323 provider()->GetDismissedSuggestionsForDebugging( |
326 downloads_category(), | 324 downloads_category(), |
327 base::Bind( | 325 base::Bind( |
328 &OfflinePageSuggestionsProviderTest::DismissedSuggestionsHelper, | 326 &OfflinePageSuggestionsProviderTest::CaptureDismissedSuggestions, |
329 base::Unretained(this))); | 327 base::Unretained(this), &dismissed_suggestions)); |
328 EXPECT_THAT(dismissed_suggestions, IsEmpty()); | |
330 Mock::VerifyAndClearExpectations(this); | 329 Mock::VerifyAndClearExpectations(this); |
331 | 330 |
332 // Clear dismissed suggestions. | 331 // Clear dismissed suggestions. |
333 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); | 332 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); |
334 | 333 |
335 // They should be gone from the dismissed suggestions. | 334 // They should be gone from the dismissed suggestions. |
336 EXPECT_CALL(*this, ReceivedDismissedSuggestions(IsEmpty())); | 335 dismissed_suggestions.clear(); |
337 provider()->GetDismissedSuggestionsForDebugging( | 336 provider()->GetDismissedSuggestionsForDebugging( |
338 recent_tabs_category(), | 337 recent_tabs_category(), |
339 base::Bind( | 338 base::Bind( |
340 &OfflinePageSuggestionsProviderTest::DismissedSuggestionsHelper, | 339 &OfflinePageSuggestionsProviderTest::CaptureDismissedSuggestions, |
341 base::Unretained(this))); | 340 base::Unretained(this), &dismissed_suggestions)); |
341 EXPECT_THAT(dismissed_suggestions, IsEmpty()); | |
342 Mock::VerifyAndClearExpectations(this); | 342 Mock::VerifyAndClearExpectations(this); |
343 | 343 |
344 // And appear in the reported suggestions for the category again. | 344 // And appear in the reported suggestions for the category again. |
345 EXPECT_CALL(*observer(), | 345 EXPECT_CALL(*observer(), |
346 OnNewSuggestions(_, recent_tabs_category(), SizeIs(4))); | 346 OnNewSuggestions(_, recent_tabs_category(), SizeIs(4))); |
347 EXPECT_CALL(*observer(), | 347 EXPECT_CALL(*observer(), |
348 OnNewSuggestions(_, downloads_category(), IsEmpty())); | 348 OnNewSuggestions(_, downloads_category(), IsEmpty())); |
349 FireOfflinePageModelChanged(); | 349 FireOfflinePageModelChanged(); |
350 Mock::VerifyAndClearExpectations(observer()); | 350 Mock::VerifyAndClearExpectations(observer()); |
351 } | 351 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); | 400 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); |
401 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), SizeIs(1)); | 401 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), SizeIs(1)); |
402 | 402 |
403 model()->items()->clear(); | 403 model()->items()->clear(); |
404 FireOfflinePageModelChanged(); | 404 FireOfflinePageModelChanged(); |
405 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); | 405 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); |
406 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); | 406 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); |
407 } | 407 } |
408 | 408 |
409 } // namespace ntp_snippets | 409 } // namespace ntp_snippets |
OLD | NEW |