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_impl.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::TopSitesImpl { |
17 public: | 17 public: |
18 explicit MockTopSites(Profile* profile) | 18 explicit MockTopSites(Profile* profile) |
19 : history::TopSitesImpl(profile), | 19 : history::TopSitesImpl(profile), |
20 capacity_(1) { | 20 capacity_(1) { |
21 } | 21 } |
22 | 22 |
23 // history::TopSitesImpl overrides. | 23 // history::TopSitesImpl overrides. |
24 virtual bool IsNonForcedFull() OVERRIDE { | 24 virtual bool IsNonForcedFull() override { |
25 return known_url_map_.size() >= capacity_; | 25 return known_url_map_.size() >= capacity_; |
26 } | 26 } |
27 virtual bool IsForcedFull() OVERRIDE { | 27 virtual bool IsForcedFull() override { |
28 return false; | 28 return false; |
29 } | 29 } |
30 virtual bool IsKnownURL(const GURL& url) OVERRIDE { | 30 virtual bool IsKnownURL(const GURL& url) override { |
31 return known_url_map_.find(url.spec()) != known_url_map_.end(); | 31 return known_url_map_.find(url.spec()) != known_url_map_.end(); |
32 } | 32 } |
33 virtual bool GetPageThumbnailScore(const GURL& url, | 33 virtual bool GetPageThumbnailScore(const GURL& url, |
34 ThumbnailScore* score) OVERRIDE { | 34 ThumbnailScore* score) override { |
35 std::map<std::string, ThumbnailScore>::const_iterator iter = | 35 std::map<std::string, ThumbnailScore>::const_iterator iter = |
36 known_url_map_.find(url.spec()); | 36 known_url_map_.find(url.spec()); |
37 if (iter == known_url_map_.end()) { | 37 if (iter == known_url_map_.end()) { |
38 return false; | 38 return false; |
39 } else { | 39 } else { |
40 *score = iter->second; | 40 *score = iter->second; |
41 return true; | 41 return true; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
(...skipping 10 matching lines...) Expand all Loading... |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(MockTopSites); | 56 DISALLOW_COPY_AND_ASSIGN(MockTopSites); |
57 }; | 57 }; |
58 | 58 |
59 // A mock version of TestingProfile holds MockTopSites. | 59 // A mock version of TestingProfile holds MockTopSites. |
60 class MockProfile : public TestingProfile { | 60 class MockProfile : public TestingProfile { |
61 public: | 61 public: |
62 MockProfile() : mock_top_sites_(new MockTopSites(this)) { | 62 MockProfile() : mock_top_sites_(new MockTopSites(this)) { |
63 } | 63 } |
64 | 64 |
65 virtual history::TopSites* GetTopSites() OVERRIDE { | 65 virtual history::TopSites* GetTopSites() override { |
66 return mock_top_sites_.get(); | 66 return mock_top_sites_.get(); |
67 } | 67 } |
68 | 68 |
69 void AddKnownURL(const GURL& url, const ThumbnailScore& score) { | 69 void AddKnownURL(const GURL& url, const ThumbnailScore& score) { |
70 mock_top_sites_->AddKnownURL(url, score); | 70 mock_top_sites_->AddKnownURL(url, score); |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 scoped_refptr<MockTopSites> mock_top_sites_; | 74 scoped_refptr<MockTopSites> mock_top_sites_; |
75 | 75 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 good_score.at_top = true; | 117 good_score.at_top = true; |
118 good_score.good_clipping = true; | 118 good_score.good_clipping = true; |
119 good_score.boring_score = 0.0; | 119 good_score.boring_score = 0.0; |
120 good_score.load_completed = true; | 120 good_score.load_completed = true; |
121 profile.AddKnownURL(kGoodURL, good_score); | 121 profile.AddKnownURL(kGoodURL, good_score); |
122 | 122 |
123 // Should be false, as the existing thumbnail is good enough (i.e. don't | 123 // Should be false, as the existing thumbnail is good enough (i.e. don't |
124 // need to replace the existing thumbnail which is new and good). | 124 // need to replace the existing thumbnail which is new and good). |
125 EXPECT_FALSE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); | 125 EXPECT_FALSE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); |
126 } | 126 } |
OLD | NEW |