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

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

Issue 2230473002: Refactor and extend SnippetsBridge for multi-section support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@categoryinfo
Patch Set: Michael'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"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 void(const std::string& suggestion_id, 96 void(const std::string& suggestion_id,
97 const ImageFetchedCallback& callback)); 97 const ImageFetchedCallback& callback));
98 98
99 private: 99 private:
100 std::vector<Category> provided_categories_; 100 std::vector<Category> provided_categories_;
101 std::map<int, CategoryStatus> statuses_; 101 std::map<int, CategoryStatus> statuses_;
102 }; 102 };
103 103
104 class MockServiceObserver : public ContentSuggestionsService::Observer { 104 class MockServiceObserver : public ContentSuggestionsService::Observer {
105 public: 105 public:
106 MOCK_METHOD0(OnNewSuggestions, void()); 106 MOCK_METHOD1(OnNewSuggestions, void(Category category));
107 MOCK_METHOD2(OnCategoryStatusChanged, 107 MOCK_METHOD2(OnCategoryStatusChanged,
108 void(Category changed_category, CategoryStatus new_status)); 108 void(Category changed_category, CategoryStatus new_status));
109 MOCK_METHOD0(ContentSuggestionsServiceShutdown, void()); 109 MOCK_METHOD0(ContentSuggestionsServiceShutdown, void());
110 ~MockServiceObserver() override {} 110 ~MockServiceObserver() override {}
111 }; 111 };
112 112
113 } // namespace 113 } // namespace
114 114
115 class ContentSuggestionsServiceTest : public testing::Test { 115 class ContentSuggestionsServiceTest : public testing::Test {
116 public: 116 public:
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 MockProvider* provider1 = MakeProvider(articles_category); 310 MockProvider* provider1 = MakeProvider(articles_category);
311 MockProvider* provider2 = MakeProvider(offline_pages_category); 311 MockProvider* provider2 = MakeProvider(offline_pages_category);
312 EXPECT_THAT(providers().at(articles_category), Eq(provider1)); 312 EXPECT_THAT(providers().at(articles_category), Eq(provider1));
313 EXPECT_THAT(providers().at(offline_pages_category), Eq(provider2)); 313 EXPECT_THAT(providers().at(offline_pages_category), Eq(provider2));
314 314
315 // Create and register observer 315 // Create and register observer
316 MockServiceObserver observer; 316 MockServiceObserver observer;
317 service()->AddObserver(&observer); 317 service()->AddObserver(&observer);
318 318
319 // Send suggestions 1 and 2 319 // Send suggestions 1 and 2
320 EXPECT_CALL(observer, OnNewSuggestions()).Times(1); 320 EXPECT_CALL(observer, OnNewSuggestions(articles_category)).Times(1);
321 provider1->FireSuggestionsChanged(articles_category, {1, 2}); 321 provider1->FireSuggestionsChanged(articles_category, {1, 2});
322 ExpectThatSuggestionsAre(articles_category, {1, 2}); 322 ExpectThatSuggestionsAre(articles_category, {1, 2});
323 Mock::VerifyAndClearExpectations(&observer); 323 Mock::VerifyAndClearExpectations(&observer);
324 324
325 // Send them again, make sure they're not reported twice 325 // Send them again, make sure they're not reported twice
326 EXPECT_CALL(observer, OnNewSuggestions()).Times(1); 326 EXPECT_CALL(observer, OnNewSuggestions(articles_category)).Times(1);
327 provider1->FireSuggestionsChanged(articles_category, {1, 2}); 327 provider1->FireSuggestionsChanged(articles_category, {1, 2});
328 ExpectThatSuggestionsAre(articles_category, {1, 2}); 328 ExpectThatSuggestionsAre(articles_category, {1, 2});
329 ExpectThatSuggestionsAre(offline_pages_category, std::vector<int>()); 329 ExpectThatSuggestionsAre(offline_pages_category, std::vector<int>());
330 Mock::VerifyAndClearExpectations(&observer); 330 Mock::VerifyAndClearExpectations(&observer);
331 331
332 // Send suggestions 13 and 14 332 // Send suggestions 13 and 14
333 EXPECT_CALL(observer, OnNewSuggestions()).Times(1); 333 EXPECT_CALL(observer, OnNewSuggestions(offline_pages_category)).Times(1);
334 provider2->FireSuggestionsChanged(offline_pages_category, {13, 14}); 334 provider2->FireSuggestionsChanged(offline_pages_category, {13, 14});
335 ExpectThatSuggestionsAre(articles_category, {1, 2}); 335 ExpectThatSuggestionsAre(articles_category, {1, 2});
336 ExpectThatSuggestionsAre(offline_pages_category, {13, 14}); 336 ExpectThatSuggestionsAre(offline_pages_category, {13, 14});
337 Mock::VerifyAndClearExpectations(&observer); 337 Mock::VerifyAndClearExpectations(&observer);
338 338
339 // Send suggestion 1 only 339 // Send suggestion 1 only
340 EXPECT_CALL(observer, OnNewSuggestions()).Times(1); 340 EXPECT_CALL(observer, OnNewSuggestions(articles_category)).Times(1);
341 provider1->FireSuggestionsChanged(articles_category, {1}); 341 provider1->FireSuggestionsChanged(articles_category, {1});
342 ExpectThatSuggestionsAre(articles_category, {1}); 342 ExpectThatSuggestionsAre(articles_category, {1});
343 ExpectThatSuggestionsAre(offline_pages_category, {13, 14}); 343 ExpectThatSuggestionsAre(offline_pages_category, {13, 14});
344 Mock::VerifyAndClearExpectations(&observer); 344 Mock::VerifyAndClearExpectations(&observer);
345 345
346 // provider2 reports OFFLINE_PAGES as unavailable 346 // provider2 reports OFFLINE_PAGES as unavailable
347 EXPECT_CALL(observer, OnCategoryStatusChanged( 347 EXPECT_CALL(observer, OnCategoryStatusChanged(
348 offline_pages_category, 348 offline_pages_category,
349 CategoryStatus::CATEGORY_EXPLICITLY_DISABLED)) 349 CategoryStatus::CATEGORY_EXPLICITLY_DISABLED))
350 .Times(1); 350 .Times(1);
351 provider2->FireCategoryStatusChanged( 351 provider2->FireCategoryStatusChanged(
352 offline_pages_category, CategoryStatus::CATEGORY_EXPLICITLY_DISABLED); 352 offline_pages_category, CategoryStatus::CATEGORY_EXPLICITLY_DISABLED);
353 EXPECT_THAT(service()->GetCategoryStatus(articles_category), 353 EXPECT_THAT(service()->GetCategoryStatus(articles_category),
354 Eq(CategoryStatus::AVAILABLE)); 354 Eq(CategoryStatus::AVAILABLE));
355 EXPECT_THAT(service()->GetCategoryStatus(offline_pages_category), 355 EXPECT_THAT(service()->GetCategoryStatus(offline_pages_category),
356 Eq(CategoryStatus::CATEGORY_EXPLICITLY_DISABLED)); 356 Eq(CategoryStatus::CATEGORY_EXPLICITLY_DISABLED));
357 ExpectThatSuggestionsAre(articles_category, {1}); 357 ExpectThatSuggestionsAre(articles_category, {1});
358 ExpectThatSuggestionsAre(offline_pages_category, std::vector<int>()); 358 ExpectThatSuggestionsAre(offline_pages_category, std::vector<int>());
359 Mock::VerifyAndClearExpectations(&observer); 359 Mock::VerifyAndClearExpectations(&observer);
360 360
361 // Shutdown the service 361 // Shutdown the service
362 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown()); 362 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown());
363 service()->Shutdown(); 363 service()->Shutdown();
364 service()->RemoveObserver(&observer); 364 service()->RemoveObserver(&observer);
365 // The service will receive two Shutdown() calls. 365 // The service will receive two Shutdown() calls.
366 } 366 }
367 367
368 } // namespace ntp_snippets 368 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698