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 IsFull() 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 { |
| 28 return false; |
| 29 } |
27 virtual bool IsKnownURL(const GURL& url) OVERRIDE { | 30 virtual bool IsKnownURL(const GURL& url) OVERRIDE { |
28 return known_url_map_.find(url.spec()) != known_url_map_.end(); | 31 return known_url_map_.find(url.spec()) != known_url_map_.end(); |
29 } | 32 } |
30 virtual bool GetPageThumbnailScore(const GURL& url, | 33 virtual bool GetPageThumbnailScore(const GURL& url, |
31 ThumbnailScore* score) OVERRIDE { | 34 ThumbnailScore* score) OVERRIDE { |
32 std::map<std::string, ThumbnailScore>::const_iterator iter = | 35 std::map<std::string, ThumbnailScore>::const_iterator iter = |
33 known_url_map_.find(url.spec()); | 36 known_url_map_.find(url.spec()); |
34 if (iter == known_url_map_.end()) { | 37 if (iter == known_url_map_.end()) { |
35 return false; | 38 return false; |
36 } else { | 39 } else { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Should be true, as it's a good URL. | 94 // Should be true, as it's a good URL. |
92 EXPECT_TRUE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); | 95 EXPECT_TRUE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); |
93 | 96 |
94 // Not checking incognito mode since the service wouldn't have been created | 97 // Not checking incognito mode since the service wouldn't have been created |
95 // in that case anyway. | 98 // in that case anyway. |
96 | 99 |
97 // Add a known URL. This makes the top sites data full. | 100 // Add a known URL. This makes the top sites data full. |
98 ThumbnailScore bad_score; | 101 ThumbnailScore bad_score; |
99 bad_score.time_at_snapshot = base::Time::UnixEpoch(); // Ancient time stamp. | 102 bad_score.time_at_snapshot = base::Time::UnixEpoch(); // Ancient time stamp. |
100 profile.AddKnownURL(kGoodURL, bad_score); | 103 profile.AddKnownURL(kGoodURL, bad_score); |
101 ASSERT_TRUE(profile.GetTopSites()->IsFull()); | 104 ASSERT_TRUE(profile.GetTopSites()->IsNonForcedFull()); |
102 | 105 |
103 // Should be false, as the top sites data is full, and the new URL is | 106 // Should be false, as the top sites data is full, and the new URL is |
104 // not known. | 107 // not known. |
105 const GURL kAnotherGoodURL("http://www.youtube.com/"); | 108 const GURL kAnotherGoodURL("http://www.youtube.com/"); |
106 EXPECT_FALSE(thumbnail_service->ShouldAcquirePageThumbnail(kAnotherGoodURL)); | 109 EXPECT_FALSE(thumbnail_service->ShouldAcquirePageThumbnail(kAnotherGoodURL)); |
107 | 110 |
108 // Should be true, as the existing thumbnail is bad (i.e. need a better one). | 111 // Should be true, as the existing thumbnail is bad (i.e. need a better one). |
109 EXPECT_TRUE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); | 112 EXPECT_TRUE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); |
110 | 113 |
111 // Replace the thumbnail score with a really good one. | 114 // Replace the thumbnail score with a really good one. |
112 ThumbnailScore good_score; | 115 ThumbnailScore good_score; |
113 good_score.time_at_snapshot = base::Time::Now(); // Very new. | 116 good_score.time_at_snapshot = base::Time::Now(); // Very new. |
114 good_score.at_top = true; | 117 good_score.at_top = true; |
115 good_score.good_clipping = true; | 118 good_score.good_clipping = true; |
116 good_score.boring_score = 0.0; | 119 good_score.boring_score = 0.0; |
117 good_score.load_completed = true; | 120 good_score.load_completed = true; |
118 profile.AddKnownURL(kGoodURL, good_score); | 121 profile.AddKnownURL(kGoodURL, good_score); |
119 | 122 |
120 // 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 |
121 // need to replace the existing thumbnail which is new and good). | 124 // need to replace the existing thumbnail which is new and good). |
122 EXPECT_FALSE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); | 125 EXPECT_FALSE(thumbnail_service->ShouldAcquirePageThumbnail(kGoodURL)); |
123 } | 126 } |
OLD | NEW |