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..6de7f7c415038e0aebcfbfed2111bbd9aec079f3 100644 |
--- a/chrome/browser/thumbnails/thumbnail_service_unittest.cc |
+++ b/chrome/browser/thumbnails/thumbnail_service_unittest.cc |
@@ -5,20 +5,21 @@ |
#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 { |
+ |
// 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_; } |
@@ -51,23 +52,14 @@ class MockTopSites : public history::TopSitesImpl { |
DISALLOW_COPY_AND_ASSIGN(MockTopSites); |
}; |
-// A mock version of TestingProfile holds MockTopSites. |
-class MockProfile : public TestingProfile { |
- public: |
- MockProfile() : mock_top_sites_(new MockTopSites(this)) { |
- } |
- |
- history::TopSites* GetTopSites() override { return mock_top_sites_.get(); } |
- |
- void AddKnownURL(const GURL& url, const ThumbnailScore& score) { |
- mock_top_sites_->AddKnownURL(url, score); |
- } |
- |
- private: |
- scoped_refptr<MockTopSites> mock_top_sites_; |
+// Testing factory that build a |MockTopSites| instance. |
+scoped_refptr<RefcountedKeyedService> BuildMockTopSites( |
+ content::BrowserContext* profile) { |
+ return scoped_refptr<RefcountedKeyedService>( |
+ new MockTopSites(static_cast<Profile*>(profile))); |
+} |
- DISALLOW_COPY_AND_ASSIGN(MockProfile); |
-}; |
+} // namespace |
TEST_F(ThumbnailServiceTest, ShouldUpdateThumbnail) { |
const GURL kGoodURL("http://www.google.com/"); |
@@ -76,7 +68,11 @@ TEST_F(ThumbnailServiceTest, ShouldUpdateThumbnail) { |
// Set up the mock profile along with mock top sites. |
base::ScopedTempDir temp_dir; |
ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
- MockProfile profile; |
+ TestingProfile profile; |
+ scoped_refptr<MockTopSites> mock_top_sites = static_cast<MockTopSites*>( |
+ TopSitesFactory::GetInstance() |
+ ->SetTestingFactoryAndUse(&profile, BuildMockTopSites) |
+ .get()); |
scoped_refptr<thumbnails::ThumbnailService> thumbnail_service( |
new thumbnails::ThumbnailServiceImpl(&profile)); |
@@ -93,8 +89,10 @@ TEST_F(ThumbnailServiceTest, ShouldUpdateThumbnail) { |
// Add a known URL. This makes the top sites data full. |
ThumbnailScore bad_score; |
bad_score.time_at_snapshot = base::Time::UnixEpoch(); // Ancient time stamp. |
- profile.AddKnownURL(kGoodURL, bad_score); |
- ASSERT_TRUE(profile.GetTopSites()->IsNonForcedFull()); |
+ mock_top_sites->AddKnownURL(kGoodURL, bad_score); |
+ 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. |
@@ -111,7 +109,7 @@ TEST_F(ThumbnailServiceTest, ShouldUpdateThumbnail) { |
good_score.good_clipping = true; |
good_score.boring_score = 0.0; |
good_score.load_completed = true; |
- profile.AddKnownURL(kGoodURL, good_score); |
+ mock_top_sites->AddKnownURL(kGoodURL, good_score); |
// Should be false, as the existing thumbnail is good enough (i.e. don't |
// need to replace the existing thumbnail which is new and good). |