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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "chrome/browser/history/top_sites.h" | 7 #include "chrome/browser/history/top_sites.h" |
8 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 8 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 const GURL kBadURL("chrome://newtab"); | 184 const GURL kBadURL("chrome://newtab"); |
185 | 185 |
186 // Set up the profile. | 186 // Set up the profile. |
187 TestingProfile profile; | 187 TestingProfile profile; |
188 | 188 |
189 // Set up the top sites service. | 189 // Set up the top sites service. |
190 ScopedTempDir temp_dir; | 190 ScopedTempDir temp_dir; |
191 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 191 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
192 scoped_refptr<MockTopSites> top_sites(new MockTopSites(&profile)); | 192 scoped_refptr<MockTopSites> top_sites(new MockTopSites(&profile)); |
193 | 193 |
| 194 // Should be false when we don't have a surface |
| 195 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
| 196 &profile, top_sites.get(), kBadURL, false)); |
| 197 |
194 // Should be false because it's a bad URL. | 198 // Should be false because it's a bad URL. |
195 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 199 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
196 &profile, top_sites.get(), kBadURL)); | 200 &profile, top_sites.get(), kBadURL, true)); |
197 | 201 |
198 // Should be true, as it's a good URL. | 202 // Should be true, as it's a good URL. |
199 EXPECT_TRUE(ThumbnailGenerator::ShouldUpdateThumbnail( | 203 EXPECT_TRUE(ThumbnailGenerator::ShouldUpdateThumbnail( |
200 &profile, top_sites.get(), kGoodURL)); | 204 &profile, top_sites.get(), kGoodURL, true)); |
201 | 205 |
202 // Should be false, if it's in the incognito mode. | 206 // Should be false, if it's in the incognito mode. |
203 profile.set_incognito(true); | 207 profile.set_incognito(true); |
204 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 208 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
205 &profile, top_sites.get(), kGoodURL)); | 209 &profile, top_sites.get(), kGoodURL, true)); |
206 | 210 |
207 // Should be true again, once turning off the incognito mode. | 211 // Should be true again, once turning off the incognito mode. |
208 profile.set_incognito(false); | 212 profile.set_incognito(false); |
209 EXPECT_TRUE(ThumbnailGenerator::ShouldUpdateThumbnail( | 213 EXPECT_TRUE(ThumbnailGenerator::ShouldUpdateThumbnail( |
210 &profile, top_sites.get(), kGoodURL)); | 214 &profile, top_sites.get(), kGoodURL, true)); |
211 | 215 |
212 // Add a known URL. This makes the top sites data full. | 216 // Add a known URL. This makes the top sites data full. |
213 ThumbnailScore bad_score; | 217 ThumbnailScore bad_score; |
214 bad_score.time_at_snapshot = base::Time::UnixEpoch(); // Ancient time stamp. | 218 bad_score.time_at_snapshot = base::Time::UnixEpoch(); // Ancient time stamp. |
215 top_sites->AddKnownURL(kGoodURL, bad_score); | 219 top_sites->AddKnownURL(kGoodURL, bad_score); |
216 ASSERT_TRUE(top_sites->IsFull()); | 220 ASSERT_TRUE(top_sites->IsFull()); |
217 | 221 |
218 // Should be false, as the top sites data is full, and the new URL is | 222 // Should be false, as the top sites data is full, and the new URL is |
219 // not known. | 223 // not known. |
220 const GURL kAnotherGoodURL("http://www.youtube.com/"); | 224 const GURL kAnotherGoodURL("http://www.youtube.com/"); |
221 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 225 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
222 &profile, top_sites.get(), kAnotherGoodURL)); | 226 &profile, top_sites.get(), kAnotherGoodURL, true)); |
223 | 227 |
224 // Should be true, as the existing thumbnail is bad (i.e need a better one). | 228 // Should be true, as the existing thumbnail is bad (i.e need a better one). |
225 EXPECT_TRUE(ThumbnailGenerator::ShouldUpdateThumbnail( | 229 EXPECT_TRUE(ThumbnailGenerator::ShouldUpdateThumbnail( |
226 &profile, top_sites.get(), kGoodURL)); | 230 &profile, top_sites.get(), kGoodURL, true)); |
227 | 231 |
228 // Replace the thumbnail score with a really good one. | 232 // Replace the thumbnail score with a really good one. |
229 ThumbnailScore good_score; | 233 ThumbnailScore good_score; |
230 good_score.time_at_snapshot = base::Time::Now(); // Very new. | 234 good_score.time_at_snapshot = base::Time::Now(); // Very new. |
231 good_score.at_top = true; | 235 good_score.at_top = true; |
232 good_score.good_clipping = true; | 236 good_score.good_clipping = true; |
233 good_score.boring_score = 0.0; | 237 good_score.boring_score = 0.0; |
234 good_score.load_completed = true; | 238 good_score.load_completed = true; |
235 top_sites->AddKnownURL(kGoodURL, good_score); | 239 top_sites->AddKnownURL(kGoodURL, good_score); |
236 | 240 |
237 // Should be false, as the existing thumbnail is good enough (i.e. don't | 241 // Should be false, as the existing thumbnail is good enough (i.e. don't |
238 // need to replace the existing thumbnail which is new and good). | 242 // need to replace the existing thumbnail which is new and good). |
239 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 243 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
240 &profile, top_sites.get(), kGoodURL)); | 244 &profile, top_sites.get(), kGoodURL, true)); |
241 } | 245 } |
OLD | NEW |