OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 214 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
215 } | 215 } |
216 | 216 |
217 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { | 217 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { |
218 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 218 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
219 const gfx::Size kSize(20, 10); | 219 const gfx::Size kSize(20, 10); |
220 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 220 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); |
221 // Fill all pixesl in black. | 221 // Fill all pixesl in black. |
222 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); | 222 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); |
223 | 223 |
224 SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); | 224 SkBitmap bitmap = |
| 225 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
225 // The thumbnail should deserve the highest boring score. | 226 // The thumbnail should deserve the highest boring score. |
226 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 227 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
227 } | 228 } |
228 | 229 |
229 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { | 230 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { |
230 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 231 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
231 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); | 232 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); |
232 const gfx::Size kSize(20, 10); | 233 const gfx::Size kSize(20, 10); |
233 | 234 |
234 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 235 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); |
235 // Fill all pixesl in black. | 236 // Fill all pixesl in black. |
236 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); | 237 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); |
237 // Fill the left half pixels in white. | 238 // Fill the left half pixels in white. |
238 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); | 239 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); |
239 | 240 |
240 SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); | 241 SkBitmap bitmap = |
| 242 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
241 ASSERT_EQ(kSize.width(), bitmap.width()); | 243 ASSERT_EQ(kSize.width(), bitmap.width()); |
242 ASSERT_EQ(kSize.height(), bitmap.height()); | 244 ASSERT_EQ(kSize.height(), bitmap.height()); |
243 // The thumbnail should be less boring because two colors are used. | 245 // The thumbnail should be less boring because two colors are used. |
244 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 246 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
245 } | 247 } |
246 | 248 |
247 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { | 249 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { |
248 // The input bitmap is vertically long. | 250 // The input bitmap is vertically long. |
249 gfx::CanvasSkia canvas(40, 90, true); | 251 gfx::CanvasSkia canvas(40, 90, true); |
250 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); | 252 SkBitmap bitmap = |
| 253 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
251 | 254 |
252 // The desired size is square. | 255 // The desired size is square. |
253 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 256 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
254 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 257 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
255 bitmap, 10, 10, &clip_result); | 258 bitmap, 10, 10, &clip_result); |
256 // The clipped bitmap should be square. | 259 // The clipped bitmap should be square. |
257 EXPECT_EQ(40, clipped_bitmap.width()); | 260 EXPECT_EQ(40, clipped_bitmap.width()); |
258 EXPECT_EQ(40, clipped_bitmap.height()); | 261 EXPECT_EQ(40, clipped_bitmap.height()); |
259 // The input was taller than wide. | 262 // The input was taller than wide. |
260 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); | 263 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); |
261 } | 264 } |
262 | 265 |
263 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { | 266 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { |
264 // The input bitmap is horizontally long. | 267 // The input bitmap is horizontally long. |
265 gfx::CanvasSkia canvas(90, 40, true); | 268 gfx::CanvasSkia canvas(90, 40, true); |
266 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); | 269 SkBitmap bitmap = |
| 270 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
267 | 271 |
268 // The desired size is square. | 272 // The desired size is square. |
269 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 273 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
270 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 274 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
271 bitmap, 10, 10, &clip_result); | 275 bitmap, 10, 10, &clip_result); |
272 // The clipped bitmap should be square. | 276 // The clipped bitmap should be square. |
273 EXPECT_EQ(40, clipped_bitmap.width()); | 277 EXPECT_EQ(40, clipped_bitmap.width()); |
274 EXPECT_EQ(40, clipped_bitmap.height()); | 278 EXPECT_EQ(40, clipped_bitmap.height()); |
275 // The input was wider than tall. | 279 // The input was wider than tall. |
276 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result); | 280 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result); |
277 } | 281 } |
278 | 282 |
279 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { | 283 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { |
280 // The input bitmap is square. | 284 // The input bitmap is square. |
281 gfx::CanvasSkia canvas(40, 40, true); | 285 gfx::CanvasSkia canvas(40, 40, true); |
282 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); | 286 SkBitmap bitmap = |
| 287 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
283 | 288 |
284 // The desired size is square. | 289 // The desired size is square. |
285 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 290 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
286 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 291 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
287 bitmap, 10, 10, &clip_result); | 292 bitmap, 10, 10, &clip_result); |
288 // The clipped bitmap should be square. | 293 // The clipped bitmap should be square. |
289 EXPECT_EQ(40, clipped_bitmap.width()); | 294 EXPECT_EQ(40, clipped_bitmap.width()); |
290 EXPECT_EQ(40, clipped_bitmap.height()); | 295 EXPECT_EQ(40, clipped_bitmap.height()); |
291 // There was no need to clip. | 296 // There was no need to clip. |
292 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result); | 297 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result); |
293 } | 298 } |
294 | 299 |
295 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) { | 300 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) { |
296 // The input bitmap is square. | 301 // The input bitmap is square. |
297 gfx::CanvasSkia canvas(40, 40, true); | 302 gfx::CanvasSkia canvas(40, 40, true); |
298 const SkBitmap bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); | 303 SkBitmap bitmap = |
| 304 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
299 | 305 |
300 // The desired size is horizontally long. | 306 // The desired size is horizontally long. |
301 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 307 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
302 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 308 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
303 bitmap, 20, 10, &clip_result); | 309 bitmap, 20, 10, &clip_result); |
304 // The clipped bitmap should have the same aspect ratio of the desired size. | 310 // The clipped bitmap should have the same aspect ratio of the desired size. |
305 EXPECT_EQ(40, clipped_bitmap.width()); | 311 EXPECT_EQ(40, clipped_bitmap.width()); |
306 EXPECT_EQ(20, clipped_bitmap.height()); | 312 EXPECT_EQ(20, clipped_bitmap.height()); |
307 // The input was taller than wide. | 313 // The input was taller than wide. |
308 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); | 314 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 good_score.good_clipping = true; | 404 good_score.good_clipping = true; |
399 good_score.boring_score = 0.0; | 405 good_score.boring_score = 0.0; |
400 good_score.load_completed = true; | 406 good_score.load_completed = true; |
401 top_sites->AddKnownURL(kGoodURL, good_score); | 407 top_sites->AddKnownURL(kGoodURL, good_score); |
402 | 408 |
403 // Should be false, as the existing thumbnail is good enough (i.e. don't | 409 // Should be false, as the existing thumbnail is good enough (i.e. don't |
404 // need to replace the existing thumbnail which is new and good). | 410 // need to replace the existing thumbnail which is new and good). |
405 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 411 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
406 &profile, top_sites.get(), kGoodURL)); | 412 &profile, top_sites.get(), kGoodURL)); |
407 } | 413 } |
OLD | NEW |