Chromium Code Reviews| Index: chrome/browser/thumbnails/thumbnail_service_unittest.cc |
| diff --git a/chrome/browser/thumbnails/thumbnail_service_unittest.cc b/chrome/browser/thumbnails/thumbnail_service_unittest.cc |
| index 32f564c37a3a8b9050ace37b824873a55f2f528f..3f0516fd44fa28bdcbea4be912c82411a5513a03 100644 |
| --- a/chrome/browser/thumbnails/thumbnail_service_unittest.cc |
| +++ b/chrome/browser/thumbnails/thumbnail_service_unittest.cc |
| @@ -5,20 +5,29 @@ |
| #include "chrome/browser/thumbnails/thumbnail_service_impl.h" |
| #include "base/memory/ref_counted.h" |
| +#include "chrome/browser/history/top_sites_factory.h" |
| #include "chrome/browser/history/top_sites_impl.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| typedef testing::Test ThumbnailServiceTest; |
| +namespace { |
| + |
| +scoped_refptr<RefcountedKeyedService> BuildMockTopSites( |
|
sdefresne
2015/01/21 17:57:23
This function won't compile as "MockTopSites" is n
|
| + content::BrowserContext* profile) { |
| + return scoped_refptr<RefcountedKeyedService>( |
| + new MockTopSites(static_cast<Profile*>(profile))); |
| +} |
| + |
| +} // namespace |
|
sdefresne
2015/01/21 17:57:23
nit: you can also put "MockTopSites" and "MockProf
|
| + |
| // A mock version of TopSitesImpl, used for testing |
| // ShouldAcquirePageThumbnail(). |
| class MockTopSites : public history::TopSitesImpl { |
| public: |
| explicit MockTopSites(Profile* profile) |
| - : history::TopSitesImpl(profile), |
| - capacity_(1) { |
| - } |
| + : history::TopSitesImpl(profile), capacity_(1) {} |
| // history::TopSitesImpl overrides. |
| bool IsNonForcedFull() override { return known_url_map_.size() >= capacity_; } |
| @@ -54,17 +63,17 @@ class MockTopSites : public history::TopSitesImpl { |
| // A mock version of TestingProfile holds MockTopSites. |
| class MockProfile : public TestingProfile { |
| public: |
| - MockProfile() : mock_top_sites_(new MockTopSites(this)) { |
| + MockProfile() { |
| + TopSitesFactory::GetInstance()::SetTestingFactory(this, BuildMockTopSites); |
|
sdefresne
2015/01/21 17:57:23
This won't compile, it should be:
TopSitesFactory
|
| } |
| - history::TopSites* GetTopSites() override { return mock_top_sites_.get(); } |
| - |
| void AddKnownURL(const GURL& url, const ThumbnailScore& score) { |
| - mock_top_sites_->AddKnownURL(url, score); |
| + scoped_refptr<history::TopSites> top_sites = |
| + TopSitesFactory::GetForProfile(this); |
| + static_cast<MockTopSites*>(top_sites.get())->AddKnownURL(url, score); |
| } |
| private: |
| - scoped_refptr<MockTopSites> mock_top_sites_; |
| DISALLOW_COPY_AND_ASSIGN(MockProfile); |
| }; |
| @@ -94,7 +103,9 @@ TEST_F(ThumbnailServiceTest, ShouldUpdateThumbnail) { |
| ThumbnailScore bad_score; |
| bad_score.time_at_snapshot = base::Time::UnixEpoch(); // Ancient time stamp. |
| profile.AddKnownURL(kGoodURL, bad_score); |
| - ASSERT_TRUE(profile.GetTopSites()->IsNonForcedFull()); |
| + scoped_refptr<history::TopSites> top_sites = |
| + TopSitesFactory::GetForProfile(profile); |
|
sdefresne
2015/01/21 17:57:23
You need to use "&profile" here and below since "p
|
| + ASSERT_TRUE(top_sites->IsNonForcedFull()); |
| // Should be false, as the top sites data is full, and the new URL is |
| // not known. |