| 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/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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 std::vector<Category> GetProvidedCategories() override { | 68 std::vector<Category> GetProvidedCategories() override { |
| 69 return provided_categories_; | 69 return provided_categories_; |
| 70 } | 70 } |
| 71 | 71 |
| 72 CategoryStatus GetCategoryStatus(Category category) { | 72 CategoryStatus GetCategoryStatus(Category category) { |
| 73 return statuses_[category.id()]; | 73 return statuses_[category.id()]; |
| 74 } | 74 } |
| 75 | 75 |
| 76 CategoryInfo GetCategoryInfo(Category category) { | 76 CategoryInfo GetCategoryInfo(Category category) { |
| 77 return CategoryInfo(base::ASCIIToUTF16("Section title"), | 77 return CategoryInfo(base::ASCIIToUTF16("Section title"), |
| 78 ContentSuggestionsCardLayout::FULL_CARD); | 78 ContentSuggestionsCardLayout::FULL_CARD, true); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void FireSuggestionsChanged(Category category, std::vector<int> numbers) { | 81 void FireSuggestionsChanged(Category category, std::vector<int> numbers) { |
| 82 observer()->OnNewSuggestions(this, category, CreateSuggestions(numbers)); | 82 observer()->OnNewSuggestions(this, category, CreateSuggestions(numbers)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void FireCategoryStatusChanged(Category category, CategoryStatus new_status) { | 85 void FireCategoryStatusChanged(Category category, CategoryStatus new_status) { |
| 86 statuses_[category.id()] = new_status; | 86 statuses_[category.id()] = new_status; |
| 87 observer()->OnCategoryStatusChanged(this, category, new_status); | 87 observer()->OnCategoryStatusChanged(this, category, new_status); |
| 88 } | 88 } |
| 89 | 89 |
| 90 MOCK_METHOD1(FetchMoreSuggestions, void(Category category)); |
| 91 MOCK_METHOD1(DismissSuggestion, void(const std::string& suggestion_id)); |
| 92 MOCK_METHOD2(FetchSuggestionImage, |
| 93 void(const std::string& suggestion_id, |
| 94 const ImageFetchedCallback& callback)); |
| 90 MOCK_METHOD1(ClearCachedSuggestionsForDebugging, void(Category category)); | 95 MOCK_METHOD1(ClearCachedSuggestionsForDebugging, void(Category category)); |
| 91 MOCK_METHOD1(GetDismissedSuggestionsForDebugging, | 96 MOCK_METHOD1(GetDismissedSuggestionsForDebugging, |
| 92 std::vector<ContentSuggestion>(Category category)); | 97 std::vector<ContentSuggestion>(Category category)); |
| 93 MOCK_METHOD1(ClearDismissedSuggestionsForDebugging, void(Category category)); | 98 MOCK_METHOD1(ClearDismissedSuggestionsForDebugging, void(Category category)); |
| 94 MOCK_METHOD1(DismissSuggestion, void(const std::string& suggestion_id)); | |
| 95 MOCK_METHOD2(FetchSuggestionImage, | |
| 96 void(const std::string& suggestion_id, | |
| 97 const ImageFetchedCallback& callback)); | |
| 98 | 99 |
| 99 private: | 100 private: |
| 100 std::vector<Category> provided_categories_; | 101 std::vector<Category> provided_categories_; |
| 101 std::map<int, CategoryStatus> statuses_; | 102 std::map<int, CategoryStatus> statuses_; |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 class MockServiceObserver : public ContentSuggestionsService::Observer { | 105 class MockServiceObserver : public ContentSuggestionsService::Observer { |
| 105 public: | 106 public: |
| 106 MOCK_METHOD1(OnNewSuggestions, void(Category category)); | 107 MOCK_METHOD1(OnNewSuggestions, void(Category category)); |
| 107 MOCK_METHOD2(OnCategoryStatusChanged, | 108 MOCK_METHOD2(OnCategoryStatusChanged, |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 Mock::VerifyAndClearExpectations(&observer); | 360 Mock::VerifyAndClearExpectations(&observer); |
| 360 | 361 |
| 361 // Shutdown the service | 362 // Shutdown the service |
| 362 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown()); | 363 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown()); |
| 363 service()->Shutdown(); | 364 service()->Shutdown(); |
| 364 service()->RemoveObserver(&observer); | 365 service()->RemoveObserver(&observer); |
| 365 // The service will receive two Shutdown() calls. | 366 // The service will receive two Shutdown() calls. |
| 366 } | 367 } |
| 367 | 368 |
| 368 } // namespace ntp_snippets | 369 } // namespace ntp_snippets |
| OLD | NEW |