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..f5f4edfc348736b2ec388d1664ba1ca86382c4e3 100644 |
| --- a/chrome/browser/thumbnails/thumbnail_service_unittest.cc |
| +++ b/chrome/browser/thumbnails/thumbnail_service_unittest.cc |
| @@ -6,19 +6,28 @@ |
| #include "base/memory/ref_counted.h" |
| #include "chrome/browser/history/top_sites_impl.h" |
| +#include "chrome/browser/history/top_sites_factory.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| typedef testing::Test ThumbnailServiceTest; |
| +namespace { |
| + |
| +scoped_refptr<RefcountedKeyedService> BuildMockTopSites( |
| + content::BrowserContext* profile) { |
| + return scoped_refptr<RefcountedKeyedService>( |
| + new MockTopSites(static_cast<Profile*>(profile))); |
| +} |
| + |
| +} // namespace |
| + |
| // 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,18 @@ 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, |
|
Bernhard Bauer
2015/01/06 11:10:30
Looks like the indentation got messed up here?
|
| + BuildMockTopSites); |
| } |
| - 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); |
| + top_sites->AddKnownURL(url, score); |
| } |
| private: |
| - scoped_refptr<MockTopSites> mock_top_sites_; |
| DISALLOW_COPY_AND_ASSIGN(MockProfile); |
| }; |
| @@ -94,7 +104,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); |
| + ASSERT_TRUE(top_sites->IsNonForcedFull()); |
| // Should be false, as the top sites data is full, and the new URL is |
| // not known. |