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

Side by Side Diff: components/ntp_tiles/most_visited_sites_unittest.cc

Issue 2897293002: Adding CrHome-specific implementation for home page tile. (Closed)
Patch Set: Handle empty home page urls Created 3 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_tiles/most_visited_sites.h" 5 #include "components/ntp_tiles/most_visited_sites.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <ostream> 10 #include <ostream>
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 }; 206 };
207 207
208 class MockMostVisitedSitesObserver : public MostVisitedSites::Observer { 208 class MockMostVisitedSitesObserver : public MostVisitedSites::Observer {
209 public: 209 public:
210 MOCK_METHOD1(OnMostVisitedURLsAvailable, void(const NTPTilesVector& tiles)); 210 MOCK_METHOD1(OnMostVisitedURLsAvailable, void(const NTPTilesVector& tiles));
211 MOCK_METHOD1(OnIconMadeAvailable, void(const GURL& site_url)); 211 MOCK_METHOD1(OnIconMadeAvailable, void(const GURL& site_url));
212 }; 212 };
213 213
214 class FakeHomePageClient : public MostVisitedSites::HomePageClient { 214 class FakeHomePageClient : public MostVisitedSites::HomePageClient {
215 public: 215 public:
216 FakeHomePageClient() : home_page_enabled_(false), ntp_is_homepage_(false) {} 216 FakeHomePageClient()
217 : home_page_enabled_(false),
218 ntp_is_homepage_(false),
219 home_page_url_(kHomePageUrl) {}
217 ~FakeHomePageClient() override {} 220 ~FakeHomePageClient() override {}
218 221
219 bool IsHomePageEnabled() const override { return home_page_enabled_; } 222 bool IsHomePageEnabled() const override { return home_page_enabled_; }
220 223
221 bool IsNewTabPageUsedAsHomePage() const override { return ntp_is_homepage_; } 224 bool IsNewTabPageUsedAsHomePage() const override { return ntp_is_homepage_; }
222 225
223 GURL GetHomepageUrl() const override { return GURL(kHomePageUrl); } 226 GURL GetHomepageUrl() const override { return home_page_url_; }
224 227
225 void SetHomePageEnabled(bool home_page_enabled) { 228 void SetHomePageEnabled(bool home_page_enabled) {
226 home_page_enabled_ = home_page_enabled; 229 home_page_enabled_ = home_page_enabled;
227 } 230 }
228 231
229 void SetNtpIsHomePage(bool ntp_is_homepage) { 232 void SetNtpIsHomePage(bool ntp_is_homepage) {
230 ntp_is_homepage_ = ntp_is_homepage; 233 ntp_is_homepage_ = ntp_is_homepage;
231 } 234 }
232 235
236 void SetHomePageUrl(GURL home_page_url) { home_page_url_ = home_page_url; }
237
233 private: 238 private:
234 bool home_page_enabled_; 239 bool home_page_enabled_;
235 bool ntp_is_homepage_; 240 bool ntp_is_homepage_;
241 GURL home_page_url_;
236 }; 242 };
237 243
238 class MockIconCacher : public IconCacher { 244 class MockIconCacher : public IconCacher {
239 public: 245 public:
240 MOCK_METHOD3(StartFetchPopularSites, 246 MOCK_METHOD3(StartFetchPopularSites,
241 void(PopularSites::Site site, 247 void(PopularSites::Site site,
242 const base::Closure& icon_available, 248 const base::Closure& icon_available,
243 const base::Closure& preliminary_icon_available)); 249 const base::Closure& preliminary_icon_available));
244 MOCK_METHOD2(StartFetchMostLikely, 250 MOCK_METHOD2(StartFetchMostLikely,
245 void(const GURL& page_url, const base::Closure& icon_available)); 251 void(const GURL& page_url, const base::Closure& icon_available));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 EXPECT_CALL(*icon_cacher, StartFetchPopularSites(_, _, _)) 372 EXPECT_CALL(*icon_cacher, StartFetchPopularSites(_, _, _))
367 .Times(AtLeast(0)); 373 .Times(AtLeast(0));
368 } 374 }
369 375
370 auto home_page_client = base::MakeUnique<FakeHomePageClient>(); 376 auto home_page_client = base::MakeUnique<FakeHomePageClient>();
371 home_page_client_ = home_page_client.get(); 377 home_page_client_ = home_page_client.get();
372 378
373 most_visited_sites_ = base::MakeUnique<MostVisitedSites>( 379 most_visited_sites_ = base::MakeUnique<MostVisitedSites>(
374 &pref_service_, mock_top_sites_, &mock_suggestions_service_, 380 &pref_service_, mock_top_sites_, &mock_suggestions_service_,
375 popular_sites_factory_.New(), std::move(icon_cacher), 381 popular_sites_factory_.New(), std::move(icon_cacher),
376 /*supervisor=*/nullptr, std::move(home_page_client)); 382 /*supervisor=*/nullptr);
383
384 most_visited_sites_->SetHomePageClient(std::move(home_page_client));
mastiz 2017/06/01 08:18:44 Can you please add at lest one test where there is
fhorschig 2017/06/01 10:12:56 Added test with feature but without client.
mastiz 2017/06/01 10:59:24 I like it much better now, thanks!
377 } 385 }
378 386
379 bool IsPopularSitesEnabledViaVariations() const { return GetParam(); } 387 bool IsPopularSitesEnabledViaVariations() const { return GetParam(); }
380 388
381 bool VerifyAndClearExpectations() { 389 bool VerifyAndClearExpectations() {
382 base::RunLoop().RunUntilIdle(); 390 base::RunLoop().RunUntilIdle();
383 const bool success = 391 const bool success =
384 Mock::VerifyAndClearExpectations(mock_top_sites_.get()) && 392 Mock::VerifyAndClearExpectations(mock_top_sites_.get()) &&
385 Mock::VerifyAndClearExpectations(&mock_suggestions_service_) && 393 Mock::VerifyAndClearExpectations(&mock_suggestions_service_) &&
386 Mock::VerifyAndClearExpectations(&mock_observer_); 394 Mock::VerifyAndClearExpectations(&mock_observer_);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 .Times(AnyNumber()) 564 .Times(AnyNumber())
557 .WillRepeatedly(Return(false)); 565 .WillRepeatedly(Return(false));
558 EXPECT_CALL(mock_observer_, 566 EXPECT_CALL(mock_observer_,
559 OnMostVisitedURLsAvailable(Not(Contains( 567 OnMostVisitedURLsAvailable(Not(Contains(
560 MatchesTile("", kHomePageUrl, TileSource::HOMEPAGE))))); 568 MatchesTile("", kHomePageUrl, TileSource::HOMEPAGE)))));
561 most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_, 569 most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_,
562 /*num_sites=*/3); 570 /*num_sites=*/3);
563 base::RunLoop().RunUntilIdle(); 571 base::RunLoop().RunUntilIdle();
564 } 572 }
565 573
574 TEST_P(MostVisitedSitesTest, ShouldNotIncludeHomePageIfEmptyUrl) {
575 const std::string kEmptyHomePageUrl;
576 base::test::ScopedFeatureList features;
577 features.InitAndEnableFeature(ntp_tiles::kPinHomePageAsTileFeature);
578 home_page_client_->SetHomePageEnabled(true);
579 home_page_client_->SetHomePageUrl(GURL(kEmptyHomePageUrl));
580 DisableRemoteSuggestions();
581 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false))
582 .WillRepeatedly(InvokeCallbackArgument<0>(MostVisitedURLList{}));
583 EXPECT_CALL(*mock_top_sites_, SyncWithHistory());
584 EXPECT_CALL(*mock_top_sites_, IsBlacklisted(Eq(kEmptyHomePageUrl)))
585 .Times(AnyNumber())
586 .WillRepeatedly(Return(false));
587 EXPECT_CALL(mock_observer_,
588 OnMostVisitedURLsAvailable(Not(
589 FirstTileIs("", kEmptyHomePageUrl, TileSource::HOMEPAGE))));
590 most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_,
591 /*num_sites=*/3);
592 base::RunLoop().RunUntilIdle();
593 }
594
566 TEST_P(MostVisitedSitesTest, ShouldNotIncludeHomePageIfBlacklisted) { 595 TEST_P(MostVisitedSitesTest, ShouldNotIncludeHomePageIfBlacklisted) {
567 base::test::ScopedFeatureList features; 596 base::test::ScopedFeatureList features;
568 features.InitAndEnableFeature(ntp_tiles::kPinHomePageAsTileFeature); 597 features.InitAndEnableFeature(ntp_tiles::kPinHomePageAsTileFeature);
569 home_page_client_->SetHomePageEnabled(true); 598 home_page_client_->SetHomePageEnabled(true);
570 DisableRemoteSuggestions(); 599 DisableRemoteSuggestions();
571 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false)) 600 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false))
572 .WillRepeatedly(InvokeCallbackArgument<0>( 601 .WillRepeatedly(InvokeCallbackArgument<0>(
573 (MostVisitedURLList{MakeMostVisitedURL("", kHomePageUrl)}))); 602 (MostVisitedURLList{MakeMostVisitedURL("", kHomePageUrl)})));
574 EXPECT_CALL(*mock_top_sites_, SyncWithHistory()); 603 EXPECT_CALL(*mock_top_sites_, SyncWithHistory());
575 EXPECT_CALL(*mock_top_sites_, IsBlacklisted(Eq(GURL(kHomePageUrl)))) 604 EXPECT_CALL(*mock_top_sites_, IsBlacklisted(Eq(GURL(kHomePageUrl))))
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 TileSource::TOP_SITES), 1198 TileSource::TOP_SITES),
1170 MatchesTile("Site 4", "https://www.site4.com/", 1199 MatchesTile("Site 4", "https://www.site4.com/",
1171 TileSource::TOP_SITES), 1200 TileSource::TOP_SITES),
1172 MatchesTile("Site 1", "https://www.site1.com/", TileSource::POPULAR), 1201 MatchesTile("Site 1", "https://www.site1.com/", TileSource::POPULAR),
1173 MatchesTile("Site 2", "https://www.site2.com/", 1202 MatchesTile("Site 2", "https://www.site2.com/",
1174 TileSource::POPULAR))); 1203 TileSource::POPULAR)));
1175 } 1204 }
1176 1205
1177 } // namespace 1206 } // namespace
1178 } // namespace ntp_tiles 1207 } // namespace ntp_tiles
OLDNEW
« components/ntp_tiles/most_visited_sites.cc ('K') | « components/ntp_tiles/most_visited_sites.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698