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

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

Issue 2618243004: Add a unit test for the BookmarkSuggestionsProvider. (Closed)
Patch Set: renamed MockProvider and updated tests comments about expected behavior 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 MockContentSuggestionsProvider::MockContentSuggestionsProvider(
15 Observer* observer,
16 const std::vector<Category>& provided_categories)
17 : ContentSuggestionsProvider(observer) {
18 SetProvidedCategories(provided_categories);
19 }
20
21 MockContentSuggestionsProvider::~MockContentSuggestionsProvider() {}
22
23 void MockContentSuggestionsProvider::SetProvidedCategories(
24 const std::vector<Category>& provided_categories) {
25 statuses_.clear();
26 provided_categories_ = provided_categories;
27 for (Category category : provided_categories) {
28 statuses_[category.id()] = CategoryStatus::AVAILABLE;
29 }
30 }
31
32 CategoryStatus MockContentSuggestionsProvider::GetCategoryStatus(
33 Category category) {
34 return statuses_[category.id()];
35 }
36
37 CategoryInfo MockContentSuggestionsProvider::GetCategoryInfo(
38 Category category) {
39 return CategoryInfo(base::ASCIIToUTF16("Section title"),
40 ContentSuggestionsCardLayout::FULL_CARD, true, false,
41 true, false,
42 base::ASCIIToUTF16("No suggestions message"));
43 }
44
45 void MockContentSuggestionsProvider::FireSuggestionsChanged(
46 Category category,
47 std::vector<ContentSuggestion> suggestions) {
48 observer()->OnNewSuggestions(this, category, std::move(suggestions));
49 }
50
51 void MockContentSuggestionsProvider::FireCategoryStatusChanged(
52 Category category,
53 CategoryStatus new_status) {
54 statuses_[category.id()] = new_status;
55 observer()->OnCategoryStatusChanged(this, category, new_status);
56 }
57
58 void MockContentSuggestionsProvider::FireCategoryStatusChangedWithCurrentStatus(
59 Category category) {
60 observer()->OnCategoryStatusChanged(this, category, statuses_[category.id()]);
61 }
62
63 void MockContentSuggestionsProvider::FireSuggestionInvalidated(
64 const ContentSuggestion::ID& suggestion_id) {
65 observer()->OnSuggestionInvalidated(this, suggestion_id);
66 }
67
68 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698