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

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

Issue 2212313002: Call FetchImageCallback asynchronously when no thumbnail exists (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bookmarksprovider
Patch Set: Marc's comments Created 4 years, 4 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
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
14 #include "components/ntp_snippets/category_status.h" 16 #include "components/ntp_snippets/category_status.h"
15 #include "components/ntp_snippets/content_suggestion.h" 17 #include "components/ntp_snippets/content_suggestion.h"
16 #include "components/ntp_snippets/content_suggestions_provider.h" 18 #include "components/ntp_snippets/content_suggestions_provider.h"
17 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
20 22
23 using testing::ByRef;
24 using testing::Const;
25 using testing::ElementsAre;
21 using testing::Eq; 26 using testing::Eq;
27 using testing::InvokeWithoutArgs;
28 using testing::IsEmpty;
22 using testing::IsNull; 29 using testing::IsNull;
30 using testing::Mock;
23 using testing::NotNull; 31 using testing::NotNull;
24 using testing::IsEmpty;
25 using testing::ElementsAre;
26 using testing::Property; 32 using testing::Property;
27 using testing::Const;
28 using testing::Mock;
29 using testing::ByRef;
30 using testing::_; 33 using testing::_;
31 34
32 namespace ntp_snippets { 35 namespace ntp_snippets {
33 36
34 namespace { 37 namespace {
35 38
36 // Returns a suggestion instance for testing. 39 // Returns a suggestion instance for testing.
37 ContentSuggestion CreateSuggestion(int number) { 40 ContentSuggestion CreateSuggestion(int number) {
38 return ContentSuggestion( 41 return ContentSuggestion(
39 base::IntToString(number), 42 base::IntToString(number),
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 256
254 EXPECT_CALL(*provider1, FetchSuggestionImage(suggestion_id, _)).Times(1); 257 EXPECT_CALL(*provider1, FetchSuggestionImage(suggestion_id, _)).Times(1);
255 EXPECT_CALL(*provider2, FetchSuggestionImage(_, _)).Times(0); 258 EXPECT_CALL(*provider2, FetchSuggestionImage(_, _)).Times(0);
256 service()->FetchSuggestionImage( 259 service()->FetchSuggestionImage(
257 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched, 260 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched,
258 base::Unretained(this))); 261 base::Unretained(this)));
259 } 262 }
260 263
261 TEST_F(ContentSuggestionsServiceTest, 264 TEST_F(ContentSuggestionsServiceTest,
262 ShouldCallbackEmptyImageForUnavailableProvider) { 265 ShouldCallbackEmptyImageForUnavailableProvider) {
266 // Setup the current thread's MessageLoop.
267 base::MessageLoop message_loop;
268
269 base::RunLoop run_loop;
263 std::string suggestion_id = "TestID"; 270 std::string suggestion_id = "TestID";
264 EXPECT_CALL(*this, OnImageFetched(suggestion_id, 271 EXPECT_CALL(*this, OnImageFetched(suggestion_id,
265 Property(&gfx::Image::IsEmpty, Eq(true)))); 272 Property(&gfx::Image::IsEmpty, Eq(true))))
273 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
266 service()->FetchSuggestionImage( 274 service()->FetchSuggestionImage(
267 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched, 275 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched,
268 base::Unretained(this))); 276 base::Unretained(this)));
277 run_loop.Run();
269 } 278 }
270 279
271 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDismissSuggestion) { 280 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDismissSuggestion) {
272 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES); 281 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES);
273 Category offline_pages_category = 282 Category offline_pages_category =
274 FromKnownCategory(KnownCategories::OFFLINE_PAGES); 283 FromKnownCategory(KnownCategories::OFFLINE_PAGES);
275 MockProvider* provider1 = MakeProvider(articles_category); 284 MockProvider* provider1 = MakeProvider(articles_category);
276 MockProvider* provider2 = MakeProvider(offline_pages_category); 285 MockProvider* provider2 = MakeProvider(offline_pages_category);
277 286
278 provider2->FireSuggestionsChanged(offline_pages_category, {11}); 287 provider2->FireSuggestionsChanged(offline_pages_category, {11});
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 Mock::VerifyAndClearExpectations(&observer); 350 Mock::VerifyAndClearExpectations(&observer);
342 351
343 // Shutdown the service 352 // Shutdown the service
344 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown()); 353 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown());
345 service()->Shutdown(); 354 service()->Shutdown();
346 service()->RemoveObserver(&observer); 355 service()->RemoveObserver(&observer);
347 // The service will receive two Shutdown() calls. 356 // The service will receive two Shutdown() calls.
348 } 357 }
349 358
350 } // namespace ntp_snippets 359 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698