| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/thumbnails/thumbnail_service_impl.h" | 5 #include "chrome/browser/thumbnails/thumbnail_service_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "chrome/browser/history/top_sites_impl.h" | 8 #include "chrome/browser/history/top_sites_service.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 typedef testing::Test ThumbnailServiceTest; | 12 typedef testing::Test ThumbnailServiceTest; |
| 13 | 13 |
| 14 // A mock version of TopSitesImpl, used for testing | 14 // A mock version of TopSitesImpl, used for testing |
| 15 // ShouldAcquirePageThumbnail(). | 15 // ShouldAcquirePageThumbnail(). |
| 16 class MockTopSites : public history::TopSitesImpl { | 16 class MockTopSites : public history::TopSitesService { |
| 17 public: | 17 public: |
| 18 explicit MockTopSites(Profile* profile) | 18 explicit MockTopSites(Profile* profile) |
| 19 : history::TopSitesImpl(profile), | 19 : history::TopSitesService(profile), capacity_(1) {} |
| 20 capacity_(1) { | |
| 21 } | |
| 22 | 20 |
| 23 // history::TopSitesImpl overrides. | 21 // history::TopSitesImpl overrides. |
| 24 bool IsNonForcedFull() override { return known_url_map_.size() >= capacity_; } | 22 bool IsNonForcedFull() override { return known_url_map_.size() >= capacity_; } |
| 25 bool IsForcedFull() override { return false; } | 23 bool IsForcedFull() override { return false; } |
| 26 bool IsKnownURL(const GURL& url) override { | 24 bool IsKnownURL(const GURL& url) override { |
| 27 return known_url_map_.find(url.spec()) != known_url_map_.end(); | 25 return known_url_map_.find(url.spec()) != known_url_map_.end(); |
| 28 } | 26 } |
| 29 bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score) override { | 27 bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score) override { |
| 30 std::map<std::string, ThumbnailScore>::const_iterator iter = | 28 std::map<std::string, ThumbnailScore>::const_iterator iter = |
| 31 known_url_map_.find(url.spec()); | 29 known_url_map_.find(url.spec()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 | 48 |
| 51 DISALLOW_COPY_AND_ASSIGN(MockTopSites); | 49 DISALLOW_COPY_AND_ASSIGN(MockTopSites); |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 // A mock version of TestingProfile holds MockTopSites. | 52 // A mock version of TestingProfile holds MockTopSites. |
| 55 class MockProfile : public TestingProfile { | 53 class MockProfile : public TestingProfile { |
| 56 public: | 54 public: |
| 57 MockProfile() : mock_top_sites_(new MockTopSites(this)) { | 55 MockProfile() : mock_top_sites_(new MockTopSites(this)) { |
| 58 } | 56 } |
| 59 | 57 |
| 60 history::TopSites* GetTopSites() override { return mock_top_sites_.get(); } | 58 history::TopSitesProvider* GetTopSites() { return mock_top_sites_.get(); } |
| 61 | 59 |
| 62 void AddKnownURL(const GURL& url, const ThumbnailScore& score) { | 60 void AddKnownURL(const GURL& url, const ThumbnailScore& score) { |
| 63 mock_top_sites_->AddKnownURL(url, score); | 61 mock_top_sites_->AddKnownURL(url, score); |
| 64 } | 62 } |
| 65 | 63 |
| 66 private: | 64 private: |
| 67 scoped_refptr<MockTopSites> mock_top_sites_; | 65 scoped_refptr<MockTopSites> mock_top_sites_; |
| 68 | 66 |
| 69 DISALLOW_COPY_AND_ASSIGN(MockProfile); | 67 DISALLOW_COPY_AND_ASSIGN(MockProfile); |
| 70 }; | 68 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 good_score.at_top = true; | 108 good_score.at_top = true; |
| 111 good_score.good_clipping = true; | 109 good_score.good_clipping = true; |
| 112 good_score.boring_score = 0.0; | 110 good_score.boring_score = 0.0; |
| 113 good_score.load_completed = true; | 111 good_score.load_completed = true; |
| 114 profile.AddKnownURL(kGoodURL, good_score); | 112 profile.AddKnownURL(kGoodURL, good_score); |
| 115 | 113 |
| 116 // Should be false, as the existing thumbnail is good enough (i.e. don't | 114 // Should be false, as the existing thumbnail is good enough (i.e. don't |
| 117 // need to replace the existing thumbnail which is new and good). | 115 // need to replace the existing thumbnail which is new and good). |
| 118 EXPECT_FALSE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); | 116 EXPECT_FALSE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); |
| 119 } | 117 } |
| OLD | NEW |