Chromium Code Reviews

Side by Side Diff: components/ntp_snippets/content_suggestions_service_unittest.cc

Issue 2167063003: Rename discard to dismiss for NTP snippets and content suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bridgeumbiegen
Patch Set: Fix unit test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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/content_suggestions_service.h" 5 #include "components/ntp_snippets/content_suggestions_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 68 matching lines...)
79 statuses_[category] = new_status; 79 statuses_[category] = new_status;
80 observer_->OnCategoryStatusChanged(category, new_status); 80 observer_->OnCategoryStatusChanged(category, new_status);
81 } 81 }
82 82
83 void FireShutdown() { 83 void FireShutdown() {
84 observer_->OnProviderShutdown(this); 84 observer_->OnProviderShutdown(this);
85 observer_ = nullptr; 85 observer_ = nullptr;
86 } 86 }
87 87
88 MOCK_METHOD0(ClearCachedSuggestionsForDebugging, void()); 88 MOCK_METHOD0(ClearCachedSuggestionsForDebugging, void());
89 MOCK_METHOD0(ClearDiscardedSuggestionsForDebugging, void()); 89 MOCK_METHOD0(ClearDismissedSuggestionsForDebugging, void());
90 MOCK_METHOD1(DiscardSuggestion, void(const std::string& suggestion_id)); 90 MOCK_METHOD1(DismissSuggestion, void(const std::string& suggestion_id));
91 MOCK_METHOD2(FetchSuggestionImage, 91 MOCK_METHOD2(FetchSuggestionImage,
92 void(const std::string& suggestion_id, 92 void(const std::string& suggestion_id,
93 const ImageFetchedCallback& callback)); 93 const ImageFetchedCallback& callback));
94 94
95 private: 95 private:
96 Observer* observer_; 96 Observer* observer_;
97 std::map<ContentSuggestionsCategory, ContentSuggestionsCategoryStatus> 97 std::map<ContentSuggestionsCategory, ContentSuggestionsCategoryStatus>
98 statuses_; 98 statuses_;
99 }; 99 };
100 100
(...skipping 197 matching lines...)
298 TEST_F(ContentSuggestionsServiceTest, 298 TEST_F(ContentSuggestionsServiceTest,
299 ShouldCallbackEmptyImageForUnavailableProvider) { 299 ShouldCallbackEmptyImageForUnavailableProvider) {
300 std::string suggestion_id = "TestID"; 300 std::string suggestion_id = "TestID";
301 EXPECT_CALL(*this, OnImageFetched(suggestion_id, 301 EXPECT_CALL(*this, OnImageFetched(suggestion_id,
302 Property(&gfx::Image::IsEmpty, Eq(true)))); 302 Property(&gfx::Image::IsEmpty, Eq(true))));
303 service()->FetchSuggestionImage( 303 service()->FetchSuggestionImage(
304 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched, 304 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched,
305 base::Unretained(this))); 305 base::Unretained(this)));
306 } 306 }
307 307
308 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDiscardSuggestion) { 308 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDismissSuggestion) {
309 MockProvider provider1(ContentSuggestionsCategory::ARTICLES); 309 MockProvider provider1(ContentSuggestionsCategory::ARTICLES);
310 MockProvider provider2(ContentSuggestionsCategory::OFFLINE_PAGES); 310 MockProvider provider2(ContentSuggestionsCategory::OFFLINE_PAGES);
311 service()->RegisterProvider(&provider1); 311 service()->RegisterProvider(&provider1);
312 service()->RegisterProvider(&provider2); 312 service()->RegisterProvider(&provider2);
313 313
314 provider2.FireSuggestionsChanged(ContentSuggestionsCategory::OFFLINE_PAGES, 314 provider2.FireSuggestionsChanged(ContentSuggestionsCategory::OFFLINE_PAGES,
315 {11}); 315 {11});
316 std::string suggestion_id = CreateSuggestion(11).id(); 316 std::string suggestion_id = CreateSuggestion(11).id();
317 317
318 EXPECT_CALL(provider1, DiscardSuggestion(_)).Times(0); 318 EXPECT_CALL(provider1, DismissSuggestion(_)).Times(0);
319 EXPECT_CALL(provider2, DiscardSuggestion(suggestion_id)).Times(1); 319 EXPECT_CALL(provider2, DismissSuggestion(suggestion_id)).Times(1);
320 service()->DiscardSuggestion(suggestion_id); 320 service()->DismissSuggestion(suggestion_id);
321 provider1.FireShutdown(); 321 provider1.FireShutdown();
322 provider2.FireShutdown(); 322 provider2.FireShutdown();
323 } 323 }
324 324
325 TEST_F(ContentSuggestionsServiceTest, ShouldForwardSuggestions) { 325 TEST_F(ContentSuggestionsServiceTest, ShouldForwardSuggestions) {
326 // Create and register providers 326 // Create and register providers
327 MockProvider provider1(ContentSuggestionsCategory::ARTICLES); 327 MockProvider provider1(ContentSuggestionsCategory::ARTICLES);
328 MockProvider provider2(ContentSuggestionsCategory::OFFLINE_PAGES); 328 MockProvider provider2(ContentSuggestionsCategory::OFFLINE_PAGES);
329 service()->RegisterProvider(&provider1); 329 service()->RegisterProvider(&provider1);
330 service()->RegisterProvider(&provider2); 330 service()->RegisterProvider(&provider2);
(...skipping 87 matching lines...)
418 Eq(ContentSuggestionsCategoryStatus::NOT_PROVIDED)); 418 Eq(ContentSuggestionsCategoryStatus::NOT_PROVIDED));
419 419
420 // Shutdown the service 420 // Shutdown the service
421 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown()); 421 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown());
422 service()->Shutdown(); 422 service()->Shutdown();
423 service()->RemoveObserver(&observer); 423 service()->RemoveObserver(&observer);
424 // The service will receive two Shutdown() calls. 424 // The service will receive two Shutdown() calls.
425 } 425 }
426 426
427 } // namespace ntp_snippets 427 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/content_suggestions_service.cc ('k') | components/ntp_snippets/ntp_snippet.h » ('j') | no next file with comments »

Powered by Google App Engine