| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 MockProvider* RegisterProvider( | 185 MockProvider* RegisterProvider( |
| 186 const std::vector<Category>& provided_categories) { | 186 const std::vector<Category>& provided_categories) { |
| 187 std::unique_ptr<MockProvider> provider = base::MakeUnique<MockProvider>( | 187 std::unique_ptr<MockProvider> provider = base::MakeUnique<MockProvider>( |
| 188 service(), category_factory(), provided_categories); | 188 service(), category_factory(), provided_categories); |
| 189 MockProvider* result = provider.get(); | 189 MockProvider* result = provider.get(); |
| 190 service()->RegisterProvider(std::move(provider)); | 190 service()->RegisterProvider(std::move(provider)); |
| 191 return result; | 191 return result; |
| 192 } | 192 } |
| 193 | 193 |
| 194 MOCK_METHOD2(OnImageFetched, | 194 MOCK_METHOD1(OnImageFetched, void(const gfx::Image&)); |
| 195 void(const std::string& suggestion_id, const gfx::Image&)); | |
| 196 | 195 |
| 197 protected: | 196 protected: |
| 198 void CreateContentSuggestionsService( | 197 void CreateContentSuggestionsService( |
| 199 ContentSuggestionsService::State enabled) { | 198 ContentSuggestionsService::State enabled) { |
| 200 ASSERT_FALSE(service_); | 199 ASSERT_FALSE(service_); |
| 201 service_.reset(new ContentSuggestionsService(enabled)); | 200 service_.reset(new ContentSuggestionsService(enabled)); |
| 202 } | 201 } |
| 203 | 202 |
| 204 ContentSuggestionsService* service() { return service_.get(); } | 203 ContentSuggestionsService* service() { return service_.get(); } |
| 205 | 204 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 base::Unretained(this))); | 289 base::Unretained(this))); |
| 291 } | 290 } |
| 292 | 291 |
| 293 TEST_F(ContentSuggestionsServiceTest, | 292 TEST_F(ContentSuggestionsServiceTest, |
| 294 ShouldCallbackEmptyImageForUnavailableProvider) { | 293 ShouldCallbackEmptyImageForUnavailableProvider) { |
| 295 // Setup the current thread's MessageLoop. | 294 // Setup the current thread's MessageLoop. |
| 296 base::MessageLoop message_loop; | 295 base::MessageLoop message_loop; |
| 297 | 296 |
| 298 base::RunLoop run_loop; | 297 base::RunLoop run_loop; |
| 299 std::string suggestion_id = "TestID"; | 298 std::string suggestion_id = "TestID"; |
| 300 EXPECT_CALL(*this, OnImageFetched(suggestion_id, | 299 EXPECT_CALL(*this, OnImageFetched(Property(&gfx::Image::IsEmpty, Eq(true)))) |
| 301 Property(&gfx::Image::IsEmpty, Eq(true)))) | |
| 302 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 300 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 303 service()->FetchSuggestionImage( | 301 service()->FetchSuggestionImage( |
| 304 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched, | 302 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched, |
| 305 base::Unretained(this))); | 303 base::Unretained(this))); |
| 306 run_loop.Run(); | 304 run_loop.Run(); |
| 307 } | 305 } |
| 308 | 306 |
| 309 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDismissSuggestion) { | 307 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDismissSuggestion) { |
| 310 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES); | 308 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES); |
| 311 Category offline_pages_category = | 309 Category offline_pages_category = |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 512 |
| 515 EXPECT_THAT(service()->GetCategoryStatus(category), | 513 EXPECT_THAT(service()->GetCategoryStatus(category), |
| 516 Eq(CategoryStatus::NOT_PROVIDED)); | 514 Eq(CategoryStatus::NOT_PROVIDED)); |
| 517 EXPECT_TRUE(service()->GetCategories().empty()); | 515 EXPECT_TRUE(service()->GetCategories().empty()); |
| 518 ExpectThatSuggestionsAre(category, std::vector<int>()); | 516 ExpectThatSuggestionsAre(category, std::vector<int>()); |
| 519 | 517 |
| 520 service()->RemoveObserver(&observer); | 518 service()->RemoveObserver(&observer); |
| 521 } | 519 } |
| 522 | 520 |
| 523 } // namespace ntp_snippets | 521 } // namespace ntp_snippets |
| OLD | NEW |