| 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/testing_profile.h" | 10 #include "chrome/test/testing_profile.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ViewHostMsg_UpdateRect_Params params; | 96 ViewHostMsg_UpdateRect_Params params; |
| 97 params.bitmap_rect = gfx::Rect(0, 0, kBitmapWidth, kBitmapHeight); | 97 params.bitmap_rect = gfx::Rect(0, 0, kBitmapWidth, kBitmapHeight); |
| 98 params.view_size = params.bitmap_rect.size(); | 98 params.view_size = params.bitmap_rect.size(); |
| 99 params.copy_rects.push_back(params.bitmap_rect); | 99 params.copy_rects.push_back(params.bitmap_rect); |
| 100 params.flags = 0; | 100 params.flags = 0; |
| 101 | 101 |
| 102 scoped_ptr<skia::PlatformCanvas> canvas( | 102 scoped_ptr<skia::PlatformCanvas> canvas( |
| 103 transport_dib_->GetPlatformCanvas(kBitmapWidth, kBitmapHeight)); | 103 transport_dib_->GetPlatformCanvas(kBitmapWidth, kBitmapHeight)); |
| 104 switch (type) { | 104 switch (type) { |
| 105 case TRANSPORT_BLACK: | 105 case TRANSPORT_BLACK: |
| 106 canvas->getTopPlatformDevice().accessBitmap(true).eraseARGB( | 106 skia::GetTopDevice(canvas.get())->accessBitmap(true).eraseARGB( |
| 107 0xFF, 0, 0, 0); | 107 0xFF, 0, 0, 0); |
| 108 break; | 108 break; |
| 109 case TRANSPORT_WHITE: | 109 case TRANSPORT_WHITE: |
| 110 canvas->getTopPlatformDevice().accessBitmap(true).eraseARGB( | 110 skia::GetTopDevice(canvas.get())->accessBitmap(true).eraseARGB( |
| 111 0xFF, 0xFF, 0xFF, 0xFF); | 111 0xFF, 0xFF, 0xFF, 0xFF); |
| 112 break; | 112 break; |
| 113 case TRANSPORT_OTHER: | 113 case TRANSPORT_OTHER: |
| 114 default: | 114 default: |
| 115 NOTREACHED(); | 115 NOTREACHED(); |
| 116 break; | 116 break; |
| 117 } | 117 } |
| 118 | 118 |
| 119 params.bitmap = transport_dib_->id(); | 119 params.bitmap = transport_dib_->id(); |
| 120 | 120 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 204 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { | 207 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { |
| 208 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 208 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
| 209 const gfx::Size kSize(20, 10); | 209 const gfx::Size kSize(20, 10); |
| 210 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 210 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); |
| 211 // Fill all pixesl in black. | 211 // Fill all pixesl in black. |
| 212 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); | 212 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); |
| 213 | 213 |
| 214 SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 214 SkBitmap bitmap = skia::GetTopDevice(&canvas)->accessBitmap(false); |
| 215 // The thumbnail should deserve the highest boring score. | 215 // The thumbnail should deserve the highest boring score. |
| 216 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 216 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { | 219 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { |
| 220 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 220 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
| 221 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); | 221 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); |
| 222 const gfx::Size kSize(20, 10); | 222 const gfx::Size kSize(20, 10); |
| 223 | 223 |
| 224 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 224 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); |
| 225 // Fill all pixesl in black. | 225 // Fill all pixesl in black. |
| 226 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); | 226 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); |
| 227 // Fill the left half pixels in white. | 227 // Fill the left half pixels in white. |
| 228 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); | 228 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); |
| 229 | 229 |
| 230 SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 230 SkBitmap bitmap = skia::GetTopDevice(&canvas)->accessBitmap(false); |
| 231 ASSERT_EQ(kSize.width(), bitmap.width()); | 231 ASSERT_EQ(kSize.width(), bitmap.width()); |
| 232 ASSERT_EQ(kSize.height(), bitmap.height()); | 232 ASSERT_EQ(kSize.height(), bitmap.height()); |
| 233 // The thumbnail should be less boring because two colors are used. | 233 // The thumbnail should be less boring because two colors are used. |
| 234 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 234 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
| 235 } | 235 } |
| 236 | 236 |
| 237 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { | 237 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { |
| 238 // The input bitmap is vertically long. | 238 // The input bitmap is vertically long. |
| 239 gfx::CanvasSkia canvas(40, 90, true); | 239 gfx::CanvasSkia canvas(40, 90, true); |
| 240 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 240 const SkBitmap bitmap = skia::GetTopDevice(&canvas)->accessBitmap(false); |
| 241 | 241 |
| 242 // The desired size is square. | 242 // The desired size is square. |
| 243 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 243 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
| 244 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 244 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
| 245 bitmap, 10, 10, &clip_result); | 245 bitmap, 10, 10, &clip_result); |
| 246 // The clipped bitmap should be square. | 246 // The clipped bitmap should be square. |
| 247 EXPECT_EQ(40, clipped_bitmap.width()); | 247 EXPECT_EQ(40, clipped_bitmap.width()); |
| 248 EXPECT_EQ(40, clipped_bitmap.height()); | 248 EXPECT_EQ(40, clipped_bitmap.height()); |
| 249 // The input was taller than wide. | 249 // The input was taller than wide. |
| 250 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); | 250 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); |
| 251 } | 251 } |
| 252 | 252 |
| 253 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { | 253 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { |
| 254 // The input bitmap is horizontally long. | 254 // The input bitmap is horizontally long. |
| 255 gfx::CanvasSkia canvas(90, 40, true); | 255 gfx::CanvasSkia canvas(90, 40, true); |
| 256 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 256 const SkBitmap bitmap = skia::GetTopDevice(&canvas)->accessBitmap(false); |
| 257 | 257 |
| 258 // The desired size is square. | 258 // The desired size is square. |
| 259 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 259 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
| 260 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 260 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
| 261 bitmap, 10, 10, &clip_result); | 261 bitmap, 10, 10, &clip_result); |
| 262 // The clipped bitmap should be square. | 262 // The clipped bitmap should be square. |
| 263 EXPECT_EQ(40, clipped_bitmap.width()); | 263 EXPECT_EQ(40, clipped_bitmap.width()); |
| 264 EXPECT_EQ(40, clipped_bitmap.height()); | 264 EXPECT_EQ(40, clipped_bitmap.height()); |
| 265 // The input was wider than tall. | 265 // The input was wider than tall. |
| 266 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result); | 266 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result); |
| 267 } | 267 } |
| 268 | 268 |
| 269 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { | 269 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { |
| 270 // The input bitmap is square. | 270 // The input bitmap is square. |
| 271 gfx::CanvasSkia canvas(40, 40, true); | 271 gfx::CanvasSkia canvas(40, 40, true); |
| 272 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 272 const SkBitmap bitmap = skia::GetTopDevice(&canvas)->accessBitmap(false); |
| 273 | 273 |
| 274 // The desired size is square. | 274 // The desired size is square. |
| 275 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 275 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
| 276 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 276 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
| 277 bitmap, 10, 10, &clip_result); | 277 bitmap, 10, 10, &clip_result); |
| 278 // The clipped bitmap should be square. | 278 // The clipped bitmap should be square. |
| 279 EXPECT_EQ(40, clipped_bitmap.width()); | 279 EXPECT_EQ(40, clipped_bitmap.width()); |
| 280 EXPECT_EQ(40, clipped_bitmap.height()); | 280 EXPECT_EQ(40, clipped_bitmap.height()); |
| 281 // There was no need to clip. | 281 // There was no need to clip. |
| 282 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result); | 282 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result); |
| 283 } | 283 } |
| 284 | 284 |
| 285 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) { | 285 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) { |
| 286 // The input bitmap is square. | 286 // The input bitmap is square. |
| 287 gfx::CanvasSkia canvas(40, 40, true); | 287 gfx::CanvasSkia canvas(40, 40, true); |
| 288 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 288 const SkBitmap bitmap = skia::GetTopDevice(&canvas)->accessBitmap(false); |
| 289 | 289 |
| 290 // The desired size is horizontally long. | 290 // The desired size is horizontally long. |
| 291 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 291 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
| 292 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 292 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
| 293 bitmap, 20, 10, &clip_result); | 293 bitmap, 20, 10, &clip_result); |
| 294 // The clipped bitmap should have the same aspect ratio of the desired size. | 294 // The clipped bitmap should have the same aspect ratio of the desired size. |
| 295 EXPECT_EQ(40, clipped_bitmap.width()); | 295 EXPECT_EQ(40, clipped_bitmap.width()); |
| 296 EXPECT_EQ(20, clipped_bitmap.height()); | 296 EXPECT_EQ(20, clipped_bitmap.height()); |
| 297 // The input was taller than wide. | 297 // The input was taller than wide. |
| 298 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); | 298 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 good_score.at_top = true; | 387 good_score.at_top = true; |
| 388 good_score.good_clipping = true; | 388 good_score.good_clipping = true; |
| 389 good_score.boring_score = 0.0; | 389 good_score.boring_score = 0.0; |
| 390 top_sites->AddKnownURL(kGoodURL, good_score); | 390 top_sites->AddKnownURL(kGoodURL, good_score); |
| 391 | 391 |
| 392 // Should be false, as the existing thumbnail is good enough (i.e. don't | 392 // Should be false, as the existing thumbnail is good enough (i.e. don't |
| 393 // need to replace the existing thumbnail which is new and good). | 393 // need to replace the existing thumbnail which is new and good). |
| 394 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 394 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
| 395 &profile, top_sites.get(), kGoodURL)); | 395 &profile, top_sites.get(), kGoodURL)); |
| 396 } | 396 } |
| OLD | NEW |