Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

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

Issue 2466863003: Finalize backend for fetching more NTPSnippets. (Closed)
Patch Set: Known suggestion are now a parameter for Fetch. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 void FireSuggestionInvalidated(const ContentSuggestion::ID& suggestion_id) { 83 void FireSuggestionInvalidated(const ContentSuggestion::ID& suggestion_id) {
84 observer()->OnSuggestionInvalidated(this, suggestion_id); 84 observer()->OnSuggestionInvalidated(this, suggestion_id);
85 } 85 }
86 86
87 MOCK_METHOD3(ClearHistory, 87 MOCK_METHOD3(ClearHistory,
88 void(base::Time begin, 88 void(base::Time begin,
89 base::Time end, 89 base::Time end,
90 const base::Callback<bool(const GURL& url)>& filter)); 90 const base::Callback<bool(const GURL& url)>& filter));
91 MOCK_METHOD2(FetchMore, void(const Category&, FetchedMoreCallback)); 91 MOCK_METHOD3(Fetch,
92 void(const Category&, std::set<std::string>, FetchingCallback));
92 MOCK_METHOD1(ClearCachedSuggestions, void(Category category)); 93 MOCK_METHOD1(ClearCachedSuggestions, void(Category category));
93 MOCK_METHOD2(GetDismissedSuggestionsForDebugging, 94 MOCK_METHOD2(GetDismissedSuggestionsForDebugging,
94 void(Category category, 95 void(Category category,
95 const DismissedSuggestionsCallback& callback)); 96 const DismissedSuggestionsCallback& callback));
96 MOCK_METHOD1(ClearDismissedSuggestionsForDebugging, void(Category category)); 97 MOCK_METHOD1(ClearDismissedSuggestionsForDebugging, void(Category category));
97 MOCK_METHOD1(DismissSuggestion, 98 MOCK_METHOD1(DismissSuggestion,
98 void(const ContentSuggestion::ID& suggestion_id)); 99 void(const ContentSuggestion::ID& suggestion_id));
99 MOCK_METHOD2(FetchSuggestionImage, 100 MOCK_METHOD2(FetchSuggestionImage,
100 void(const ContentSuggestion::ID& suggestion_id, 101 void(const ContentSuggestion::ID& suggestion_id,
101 const ImageFetchedCallback& callback)); 102 const ImageFetchedCallback& callback));
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 TEST_F(ContentSuggestionsServiceTest, ShouldForwardClearHistory) { 570 TEST_F(ContentSuggestionsServiceTest, ShouldForwardClearHistory) {
570 Category category = FromKnownCategory(KnownCategories::DOWNLOADS); 571 Category category = FromKnownCategory(KnownCategories::DOWNLOADS);
571 MockProvider* provider = RegisterProvider(category); 572 MockProvider* provider = RegisterProvider(category);
572 base::Time begin = base::Time::FromTimeT(123), 573 base::Time begin = base::Time::FromTimeT(123),
573 end = base::Time::FromTimeT(456); 574 end = base::Time::FromTimeT(456);
574 EXPECT_CALL(*provider, ClearHistory(begin, end, _)); 575 EXPECT_CALL(*provider, ClearHistory(begin, end, _));
575 base::Callback<bool(const GURL& url)> filter; 576 base::Callback<bool(const GURL& url)> filter;
576 service()->ClearHistory(begin, end, filter); 577 service()->ClearHistory(begin, end, filter);
577 } 578 }
578 579
579 TEST_F(ContentSuggestionsServiceTest, ShouldForwardFetchMore) { 580 TEST_F(ContentSuggestionsServiceTest, ShouldForwardFetch) {
580 Category category = FromKnownCategory(KnownCategories::ARTICLES); 581 Category category = FromKnownCategory(KnownCategories::ARTICLES);
582 std::set<std::string> known_suggestions;
581 MockProvider* provider = RegisterProvider(category); 583 MockProvider* provider = RegisterProvider(category);
582 provider->FireCategoryStatusChangedWithCurrentStatus(category); 584 provider->FireCategoryStatusChangedWithCurrentStatus(category);
583 EXPECT_CALL(*provider, FetchMore(category, _)); 585 EXPECT_CALL(*provider, Fetch(category, known_suggestions, _));
584 service()->FetchMore(category, 586 service()->Fetch(category, known_suggestions,
585 ContentSuggestionsService::FetchedMoreCallback()); 587 ContentSuggestionsService::FetchingCallback());
586 } 588 }
587 589
588 TEST_F(ContentSuggestionsServiceTest, DismissAndRestoreCategory) { 590 TEST_F(ContentSuggestionsServiceTest, DismissAndRestoreCategory) {
589 // Register a category with one suggestion. 591 // Register a category with one suggestion.
590 Category category = FromKnownCategory(KnownCategories::ARTICLES); 592 Category category = FromKnownCategory(KnownCategories::ARTICLES);
591 MockProvider* provider = RegisterProvider(category); 593 MockProvider* provider = RegisterProvider(category);
592 provider->FireCategoryStatusChangedWithCurrentStatus(category); 594 provider->FireCategoryStatusChangedWithCurrentStatus(category);
593 provider->FireSuggestionsChanged(category, CreateSuggestions(category, {42})); 595 provider->FireSuggestionsChanged(category, CreateSuggestions(category, {42}));
594 596
595 EXPECT_THAT(service()->GetCategories(), ElementsAre(category)); 597 EXPECT_THAT(service()->GetCategories(), ElementsAre(category));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 provider = RegisterProvider(category); 695 provider = RegisterProvider(category);
694 provider->FireCategoryStatusChangedWithCurrentStatus(category); 696 provider->FireCategoryStatusChangedWithCurrentStatus(category);
695 EXPECT_TRUE(service()->IsCategoryDismissed(category)); 697 EXPECT_TRUE(service()->IsCategoryDismissed(category));
696 698
697 service()->RestoreDismissedCategories(); 699 service()->RestoreDismissedCategories();
698 EXPECT_FALSE(service()->IsCategoryDismissed(category)); 700 EXPECT_FALSE(service()->IsCategoryDismissed(category));
699 EXPECT_THAT(providers().find(category)->second, Eq(provider)); 701 EXPECT_THAT(providers().find(category)->second, Eq(provider));
700 } 702 }
701 703
702 } // namespace ntp_snippets 704 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698