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" |
11 #include "content/browser/renderer_host/backing_store_manager.h" | 11 #include "content/browser/renderer_host/backing_store_manager.h" |
12 #include "content/browser/renderer_host/backing_store_skia.h" | 12 #include "content/browser/renderer_host/backing_store_skia.h" |
13 #include "content/browser/renderer_host/mock_render_process_host.h" | 13 #include "content/browser/renderer_host/mock_render_process_host.h" |
14 #include "content/browser/renderer_host/test_render_view_host.h" | 14 #include "content/browser/renderer_host/test_render_view_host.h" |
15 #include "content/browser/tab_contents/render_view_host_manager.h" | 15 #include "content/browser/tab_contents/render_view_host_manager.h" |
16 #include "content/common/view_messages.h" | |
16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
17 #include "content/common/view_messages.h" | |
18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
19 #include "skia/ext/platform_canvas.h" | 19 #include "skia/ext/platform_canvas.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/skia/include/core/SkColorPriv.h" | 21 #include "third_party/skia/include/core/SkColorPriv.h" |
22 #include "ui/gfx/canvas_skia.h" | 22 #include "ui/gfx/canvas_skia.h" |
23 #include "ui/gfx/surface/transport_dib.h" | 23 #include "ui/gfx/surface/transport_dib.h" |
24 | 24 |
25 static const int kBitmapWidth = 100; | 25 static const int kBitmapWidth = 100; |
26 static const int kBitmapHeight = 100; | 26 static const int kBitmapHeight = 100; |
27 | 27 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) { | 213 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_Empty) { |
214 SkBitmap bitmap; | 214 SkBitmap bitmap; |
215 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 215 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
216 } | 216 } |
217 | 217 |
218 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { | 218 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_SingleColor) { |
219 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 219 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
220 const gfx::Size kSize(20, 10); | 220 const gfx::Size kSize(20, 10); |
221 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 221 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); |
222 // Fill all pixesl in black. | 222 // Fill all pixesl in black. |
223 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); | 223 canvas.FillRect(kBlack, gfx::Rect(0, 0, kSize.width(), kSize.height())); |
Peter Kasting
2011/10/27 19:17:29
Nit: Shorter: gfx::Rect(gfx::Point(), kSize); (2 p
tfarina
2011/10/27 20:46:03
Done.
| |
224 | 224 |
225 SkBitmap bitmap = | 225 SkBitmap bitmap = |
226 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 226 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
227 // The thumbnail should deserve the highest boring score. | 227 // The thumbnail should deserve the highest boring score. |
228 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 228 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
229 } | 229 } |
230 | 230 |
231 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { | 231 TEST_F(ThumbnailGeneratorSimpleTest, CalculateBoringScore_TwoColors) { |
232 const SkColor kBlack = SkColorSetRGB(0, 0, 0); | 232 const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
233 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); | 233 const SkColor kWhite = SkColorSetRGB(0xFF, 0xFF, 0xFF); |
234 const gfx::Size kSize(20, 10); | 234 const gfx::Size kSize(20, 10); |
235 | 235 |
236 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); | 236 gfx::CanvasSkia canvas(kSize.width(), kSize.height(), true); |
237 // Fill all pixesl in black. | 237 // Fill all pixesl in black. |
238 canvas.FillRectInt(kBlack, 0, 0, kSize.width(), kSize.height()); | 238 canvas.FillRect(kBlack, gfx::Rect(0, 0, kSize.width(), kSize.height())); |
239 // Fill the left half pixels in white. | 239 // Fill the left half pixels in white. |
240 canvas.FillRectInt(kWhite, 0, 0, kSize.width() / 2, kSize.height()); | 240 canvas.FillRect(kWhite, gfx::Rect(0, 0, kSize.width() / 2, kSize.height())); |
241 | 241 |
242 SkBitmap bitmap = | 242 SkBitmap bitmap = |
243 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 243 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
244 ASSERT_EQ(kSize.width(), bitmap.width()); | 244 ASSERT_EQ(kSize.width(), bitmap.width()); |
245 ASSERT_EQ(kSize.height(), bitmap.height()); | 245 ASSERT_EQ(kSize.height(), bitmap.height()); |
246 // The thumbnail should be less boring because two colors are used. | 246 // The thumbnail should be less boring because two colors are used. |
247 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 247 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); |
248 } | 248 } |
249 | 249 |
250 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { | 250 TEST_F(ThumbnailGeneratorSimpleTest, GetClippedBitmap_TallerThanWide) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 good_score.good_clipping = true; | 405 good_score.good_clipping = true; |
406 good_score.boring_score = 0.0; | 406 good_score.boring_score = 0.0; |
407 good_score.load_completed = true; | 407 good_score.load_completed = true; |
408 top_sites->AddKnownURL(kGoodURL, good_score); | 408 top_sites->AddKnownURL(kGoodURL, good_score); |
409 | 409 |
410 // Should be false, as the existing thumbnail is good enough (i.e. don't | 410 // Should be false, as the existing thumbnail is good enough (i.e. don't |
411 // need to replace the existing thumbnail which is new and good). | 411 // need to replace the existing thumbnail which is new and good). |
412 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 412 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
413 &profile, top_sites.get(), kGoodURL)); | 413 &profile, top_sites.get(), kGoodURL)); |
414 } | 414 } |
OLD | NEW |