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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 #endif | 183 #endif |
184 | 184 |
185 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) { | 185 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) { |
186 SkBitmap bitmap; | 186 SkBitmap bitmap; |
187 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 187 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
188 } | 188 } |
189 | 189 |
190 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { | 190 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { |
191 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 191 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
192 const gfx::Size kSize(20, 10); | 192 const gfx::Size kSize(20, 10); |
193 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 193 gfx::CanvasSkia canvas; |
| 194 ASSERT_TRUE(canvas.Init(kSize.width(), kSize.height(), true)); |
194 // Fill all pixesl in black. | 195 // Fill all pixesl in black. |
195 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); | 196 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); |
196 | 197 |
197 SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 198 SkBitmap bitmap = canvas.skia_canvas()->getTopDevice()->accessBitmap(false); |
198 // The thumbnail should deserve the highest boring score. | 199 // The thumbnail should deserve the highest boring score. |
199 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 200 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
200 } | 201 } |
201 | 202 |
202 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { | 203 TEST(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { |
203 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 204 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
204 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); | 205 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); |
205 const gfx::Size kSize(20, 10); | 206 const gfx::Size kSize(20, 10); |
206 | 207 |
207 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 208 gfx::CanvasSkia canvas; |
| 209 ASSERT_TRUE(canvas.Init(kSize.width(), kSize.height(), true)); |
208 // Fill all pixesl in black. | 210 // Fill all pixesl in black. |
209 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); | 211 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); |
210 // Fill the left half pixels in white. | 212 // Fill the left half pixels in white. |
211 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); | 213 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); |
212 | 214 |
213 SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 215 SkBitmap bitmap = canvas.skia_canvas()->getTopDevice()->accessBitmap(false); |
214 ASSERT_EQ(kSize.width(), bitmap.width()); | 216 ASSERT_EQ(kSize.width(), bitmap.width()); |
215 ASSERT_EQ(kSize.height(), bitmap.height()); | 217 ASSERT_EQ(kSize.height(), bitmap.height()); |
216 // The thumbnail should be less boring because two colors are used. | 218 // The thumbnail should be less boring because two colors are used. |
217 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 219 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
218 } | 220 } |
219 | 221 |
220 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { | 222 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { |
221 // The input bitmap is vertically long. | 223 // The input bitmap is vertically long. |
222 gfx::CanvasSkia canvas(40, 90, true); | 224 gfx::CanvasSkia canvas; |
223 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 225 ASSERT_TRUE(canvas.Init(40, 90, true)); |
| 226 const SkBitmap& bitmap = |
| 227 canvas.skia_canvas()->getTopDevice()->accessBitmap(false); |
224 | 228 |
225 // The desired size is square. | 229 // The desired size is square. |
226 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 230 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
227 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 231 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
228 bitmap, 10, 10, &clip_result); | 232 bitmap, 10, 10, &clip_result); |
229 // The clipped bitmap should be square. | 233 // The clipped bitmap should be square. |
230 EXPECT_EQ(40, clipped_bitmap.width()); | 234 EXPECT_EQ(40, clipped_bitmap.width()); |
231 EXPECT_EQ(40, clipped_bitmap.height()); | 235 EXPECT_EQ(40, clipped_bitmap.height()); |
232 // The input was taller than wide. | 236 // The input was taller than wide. |
233 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); | 237 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); |
234 } | 238 } |
235 | 239 |
236 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { | 240 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_WiderThanTall) { |
237 // The input bitmap is horizontally long. | 241 // The input bitmap is horizontally long. |
238 gfx::CanvasSkia canvas(90, 40, true); | 242 gfx::CanvasSkia canvas; |
239 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 243 ASSERT_TRUE(canvas.Init(90, 40, true)); |
| 244 const SkBitmap& bitmap = |
| 245 canvas.skia_canvas()->getTopDevice()->accessBitmap(false); |
240 | 246 |
241 // The desired size is square. | 247 // The desired size is square. |
242 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 248 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
243 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 249 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
244 bitmap, 10, 10, &clip_result); | 250 bitmap, 10, 10, &clip_result); |
245 // The clipped bitmap should be square. | 251 // The clipped bitmap should be square. |
246 EXPECT_EQ(40, clipped_bitmap.width()); | 252 EXPECT_EQ(40, clipped_bitmap.width()); |
247 EXPECT_EQ(40, clipped_bitmap.height()); | 253 EXPECT_EQ(40, clipped_bitmap.height()); |
248 // The input was wider than tall. | 254 // The input was wider than tall. |
249 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result); | 255 EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result); |
250 } | 256 } |
251 | 257 |
252 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { | 258 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NotClipped) { |
253 // The input bitmap is square. | 259 // The input bitmap is square. |
254 gfx::CanvasSkia canvas(40, 40, true); | 260 gfx::CanvasSkia canvas; |
255 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 261 ASSERT_TRUE(canvas.Init(40, 40, true)); |
| 262 const SkBitmap& bitmap = |
| 263 canvas.skia_canvas()->getTopDevice()->accessBitmap(false); |
256 | 264 |
257 // The desired size is square. | 265 // The desired size is square. |
258 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 266 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
259 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 267 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
260 bitmap, 10, 10, &clip_result); | 268 bitmap, 10, 10, &clip_result); |
261 // The clipped bitmap should be square. | 269 // The clipped bitmap should be square. |
262 EXPECT_EQ(40, clipped_bitmap.width()); | 270 EXPECT_EQ(40, clipped_bitmap.width()); |
263 EXPECT_EQ(40, clipped_bitmap.height()); | 271 EXPECT_EQ(40, clipped_bitmap.height()); |
264 // There was no need to clip. | 272 // There was no need to clip. |
265 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result); | 273 EXPECT_EQ(ThumbnailGenerator::kNotClipped, clip_result); |
266 } | 274 } |
267 | 275 |
268 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) { | 276 TEST(ThumbnailGeneratorSimpleTest, GetClippedBitmap_NonSquareOutput) { |
269 // The input bitmap is square. | 277 // The input bitmap is square. |
270 gfx::CanvasSkia canvas(40, 40, true); | 278 gfx::CanvasSkia canvas; |
271 const SkBitmap bitmap = canvas.getTopPlatformDevice().accessBitmap(false); | 279 ASSERT_TRUE(canvas.Init(40, 40, true)); |
| 280 const SkBitmap& bitmap = |
| 281 canvas.skia_canvas()->getTopDevice()->accessBitmap(false); |
272 | 282 |
273 // The desired size is horizontally long. | 283 // The desired size is horizontally long. |
274 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 284 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
275 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 285 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
276 bitmap, 20, 10, &clip_result); | 286 bitmap, 20, 10, &clip_result); |
277 // The clipped bitmap should have the same aspect ratio of the desired size. | 287 // The clipped bitmap should have the same aspect ratio of the desired size. |
278 EXPECT_EQ(40, clipped_bitmap.width()); | 288 EXPECT_EQ(40, clipped_bitmap.width()); |
279 EXPECT_EQ(20, clipped_bitmap.height()); | 289 EXPECT_EQ(20, clipped_bitmap.height()); |
280 // The input was taller than wide. | 290 // The input was taller than wide. |
281 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); | 291 EXPECT_EQ(ThumbnailGenerator::kTallerThanWide, clip_result); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 good_score.at_top = true; | 380 good_score.at_top = true; |
371 good_score.good_clipping = true; | 381 good_score.good_clipping = true; |
372 good_score.boring_score = 0.0; | 382 good_score.boring_score = 0.0; |
373 top_sites->AddKnownURL(kGoodURL, good_score); | 383 top_sites->AddKnownURL(kGoodURL, good_score); |
374 | 384 |
375 // Should be false, as the existing thumbnail is good enough (i.e. don't | 385 // Should be false, as the existing thumbnail is good enough (i.e. don't |
376 // need to replace the existing thumbnail which is new and good). | 386 // need to replace the existing thumbnail which is new and good). |
377 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 387 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
378 &profile, top_sites.get(), kGoodURL)); | 388 &profile, top_sites.get(), kGoodURL)); |
379 } | 389 } |
OLD | NEW |