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

Unified Diff: components/ntp_tiles/most_visited_sites_unittest.cc

Issue 2619993002: ntp_tiles: Migrate to multi-observer model
Patch Set: Fixed build. 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_tiles/most_visited_sites_unittest.cc
diff --git a/components/ntp_tiles/most_visited_sites_unittest.cc b/components/ntp_tiles/most_visited_sites_unittest.cc
index eda087ea002db535843d5cb2cb6078d4f163ec8f..e8b63d8e1ebc07446b8357a1dce56c2f100ccdaa 100644
--- a/components/ntp_tiles/most_visited_sites_unittest.cc
+++ b/components/ntp_tiles/most_visited_sites_unittest.cc
@@ -207,13 +207,7 @@ class MostVisitedSitesTest : public ::testing::Test {
protected:
MostVisitedSitesTest()
: mock_top_sites_(new StrictMock<MockTopSites>()),
- mock_popular_sites_(new StrictMock<MockPopularSites>()),
- most_visited_sites_(&pref_service_,
- mock_top_sites_,
- &mock_suggestions_service_,
- base::WrapUnique(mock_popular_sites_),
- /*icon_cacher=*/nullptr,
- /*supervisor=*/nullptr) {
+ mock_popular_sites_(new StrictMock<MockPopularSites>()) {
MostVisitedSites::RegisterProfilePrefs(pref_service_.registry());
// TODO(mastiz): Add test coverage including Popular Sites.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
@@ -223,6 +217,20 @@ class MostVisitedSitesTest : public ::testing::Test {
EXPECT_CALL(*mock_popular_sites_, sites())
.Times(AtLeast(0))
.WillRepeatedly(ReturnRef(empty_popular_sites_vector_));
+ EXPECT_CALL(mock_suggestions_service_, AddCallback(_))
+ .WillOnce(Invoke(&suggestions_service_callbacks_,
+ &SuggestionsService::ResponseCallbackList::Add));
+
+ most_visited_sites_ =
+ base::WrapUnique<MostVisitedSites>(new MostVisitedSites(
+ &pref_service_, mock_top_sites_, &mock_suggestions_service_,
+ base::WrapUnique(mock_popular_sites_),
+ /*icon_cacher=*/nullptr,
+ /*supervisor=*/nullptr));
+ most_visited_sites_->AddObserver(&mock_observer_);
+ VerifyAndClearExpectations();
+
+ EXPECT_FALSE(suggestions_service_callbacks_.empty());
}
bool VerifyAndClearExpectations() {
@@ -245,13 +253,14 @@ class MostVisitedSitesTest : public ::testing::Test {
StrictMock<MockSuggestionsService> mock_suggestions_service_;
StrictMock<MockPopularSites>* const mock_popular_sites_;
StrictMock<MockMostVisitedSitesObserver> mock_observer_;
- MostVisitedSites most_visited_sites_;
+ std::unique_ptr<MostVisitedSites> most_visited_sites_;
const PopularSites::SitesVector empty_popular_sites_vector_;
};
-TEST_F(MostVisitedSitesTest, ShouldStartNoCallInConstructor) {
- // No call to mocks expected by the mere fact of instantiating
- // MostVisitedSites.
+TEST_F(MostVisitedSitesTest, ShouldRegisterCallbacksInConstructor) {
+ EXPECT_CALL(mock_observer_, OnMostVisitedURLsAvailable(_));
+ suggestions_service_callbacks_.Notify(
+ MakeProfile({MakeSuggestion("Site 1", "http://site1/")}));
base::RunLoop().RunUntilIdle();
}
@@ -262,9 +271,6 @@ class MostVisitedSitesWithCacheHitTest : public MostVisitedSitesTest {
MostVisitedSitesWithCacheHitTest() {
InSequence seq;
EXPECT_CALL(*mock_top_sites_, SyncWithHistory());
- EXPECT_CALL(mock_suggestions_service_, AddCallback(_))
- .WillOnce(Invoke(&suggestions_service_callbacks_,
- &SuggestionsService::ResponseCallbackList::Add));
EXPECT_CALL(mock_suggestions_service_, GetSuggestionsDataFromCache())
.WillOnce(Return(MakeProfile({
MakeSuggestion("Site 1", "http://site1/"),
@@ -279,11 +285,12 @@ class MostVisitedSitesWithCacheHitTest : public MostVisitedSitesTest {
MatchesTile("Site 2", "http://site2/",
NTPTileSource::SUGGESTIONS_SERVICE),
MatchesTile("Site 3", "http://site3/",
+ NTPTileSource::SUGGESTIONS_SERVICE),
+ MatchesTile("Site 4", "http://site4/",
NTPTileSource::SUGGESTIONS_SERVICE))));
EXPECT_CALL(mock_suggestions_service_, FetchSuggestionsData())
.WillOnce(Return(true));
- most_visited_sites_.SetMostVisitedURLsObserver(&mock_observer_,
- /*num_sites=*/3);
+ most_visited_sites_->Refresh();
VerifyAndClearExpectations();
EXPECT_FALSE(suggestions_service_callbacks_.empty());
@@ -328,20 +335,15 @@ class MostVisitedSitesWithEmptyCacheTest : public MostVisitedSitesTest {
MostVisitedSitesWithEmptyCacheTest() {
InSequence seq;
EXPECT_CALL(*mock_top_sites_, SyncWithHistory());
- EXPECT_CALL(mock_suggestions_service_, AddCallback(_))
- .WillOnce(Invoke(&suggestions_service_callbacks_,
- &SuggestionsService::ResponseCallbackList::Add));
EXPECT_CALL(mock_suggestions_service_, GetSuggestionsDataFromCache())
.WillOnce(Return(SuggestionsProfile())); // Empty cache.
EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false))
.WillOnce(Invoke(&top_sites_callbacks_, &TopSitesCallbackList::Add));
EXPECT_CALL(mock_suggestions_service_, FetchSuggestionsData())
.WillOnce(Return(true));
- most_visited_sites_.SetMostVisitedURLsObserver(&mock_observer_,
- /*num_sites=*/3);
+ most_visited_sites_->Refresh();
VerifyAndClearExpectations();
- EXPECT_FALSE(suggestions_service_callbacks_.empty());
EXPECT_FALSE(top_sites_callbacks_.empty());
}
};

Powered by Google App Engine
This is Rietveld 408576698