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

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

Issue 2618243004: Add a unit test for the BookmarkSuggestionsProvider. (Closed)
Patch Set: fixed BUILD dependencies Created 3 years, 11 months 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/ntp_snippets/mock_content_suggestions_provider.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/strings/utf_string_conversions.h"
11
12 namespace ntp_snippets {
13
14 MockProvider::MockProvider(Observer* observer,
15 const std::vector<Category>& provided_categories)
16 : ContentSuggestionsProvider(observer) {
17 SetProvidedCategories(provided_categories);
18 }
19
20 MockProvider::~MockProvider() {}
21
22 void MockProvider::SetProvidedCategories(
23 const std::vector<Category>& provided_categories) {
24 statuses_.clear();
25 provided_categories_ = provided_categories;
26 for (Category category : provided_categories) {
27 statuses_[category.id()] = CategoryStatus::AVAILABLE;
28 }
29 }
30
31 CategoryStatus MockProvider::GetCategoryStatus(Category category) {
32 return statuses_[category.id()];
33 }
34
35 CategoryInfo MockProvider::GetCategoryInfo(Category category) {
36 return CategoryInfo(base::ASCIIToUTF16("Section title"),
37 ContentSuggestionsCardLayout::FULL_CARD, true, false,
38 true, false,
39 base::ASCIIToUTF16("No suggestions message"));
40 }
41
42 void MockProvider::FireSuggestionsChanged(
43 Category category,
44 std::vector<ContentSuggestion> suggestions) {
45 observer()->OnNewSuggestions(this, category, std::move(suggestions));
46 }
47
48 void MockProvider::FireCategoryStatusChanged(Category category,
49 CategoryStatus new_status) {
50 statuses_[category.id()] = new_status;
51 observer()->OnCategoryStatusChanged(this, category, new_status);
52 }
53
54 void MockProvider::FireCategoryStatusChangedWithCurrentStatus(
55 Category category) {
56 observer()->OnCategoryStatusChanged(this, category, statuses_[category.id()]);
57 }
58
59 void MockProvider::FireSuggestionInvalidated(
60 const ContentSuggestion::ID& suggestion_id) {
61 observer()->OnSuggestionInvalidated(this, suggestion_id);
62 }
63
64 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698