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" |
11 #include "content/browser/renderer_host/mock_render_process_host.h" | 11 #include "content/browser/renderer_host/mock_render_process_host.h" |
12 #include "content/browser/renderer_host/test_render_view_host.h" | 12 #include "content/browser/renderer_host/test_render_view_host.h" |
13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
15 #include "skia/ext/platform_canvas.h" | 15 #include "skia/ext/platform_canvas.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/skia/include/core/SkColorPriv.h" | 17 #include "third_party/skia/include/core/SkColorPriv.h" |
18 #include "ui/gfx/canvas_skia.h" | 18 #include "ui/gfx/canvas_skia.h" |
19 #include "ui/gfx/surface/transport_dib.h" | 19 #include "ui/gfx/surface/transport_dib.h" |
20 | 20 |
21 using content::WebContents; | 21 using content::WebContents; |
22 | 22 |
23 typedef testing::Test ThumbnailGeneratorTest; | 23 typedef testing::Test ThumbnailGeneratorTest; |
24 | 24 |
25 TEST_F(ThumbnailGeneratorTest, CalculateBoringScore_Empty) { | 25 TEST_F(ThumbnailGeneratorTest, CalculateBoringScore_Empty) { |
26 SkBitmap bitmap; | 26 SkBitmap bitmap; |
27 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 27 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(bitmap)); |
28 } | 28 } |
29 | 29 |
30 TEST_F(ThumbnailGeneratorTest, CalculateBoringScore_SingleColor) { | 30 TEST_F(ThumbnailGeneratorTest, CalculateBoringScore_SingleColor) { |
31 const gfx::Size kSize(20, 10); | 31 const gfx::Size kSize(20, 10); |
32 gfx::CanvasSkia canvas(kSize, true); | 32 gfx::CanvasSkia canvas(kSize, true); |
33 // Fill all pixesl in black. | 33 // Fill all pixesl in black. |
34 canvas.FillRect(gfx::Rect(kSize), SK_ColorBLACK); | 34 canvas.FillRect(gfx::Rect(kSize), SK_ColorBLACK); |
35 | 35 |
36 SkBitmap bitmap = | 36 SkBitmap bitmap = |
37 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 37 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
38 // The thumbnail should deserve the highest boring score. | 38 // The thumbnail should deserve the highest boring score. |
39 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 39 EXPECT_DOUBLE_EQ(1.0, ThumbnailGenerator::CalculateBoringScore(bitmap)); |
40 } | 40 } |
41 | 41 |
42 TEST_F(ThumbnailGeneratorTest, CalculateBoringScore_TwoColors) { | 42 TEST_F(ThumbnailGeneratorTest, CalculateBoringScore_TwoColors) { |
43 const gfx::Size kSize(20, 10); | 43 const gfx::Size kSize(20, 10); |
44 | 44 |
45 gfx::CanvasSkia canvas(kSize, true); | 45 gfx::CanvasSkia canvas(kSize, true); |
46 // Fill all pixesl in black. | 46 // Fill all pixesl in black. |
47 canvas.FillRect(gfx::Rect(kSize), SK_ColorBLACK); | 47 canvas.FillRect(gfx::Rect(kSize), SK_ColorBLACK); |
48 // Fill the left half pixels in white. | 48 // Fill the left half pixels in white. |
49 canvas.FillRect(gfx::Rect(0, 0, kSize.width() / 2, kSize.height()), | 49 canvas.FillRect(gfx::Rect(0, 0, kSize.width() / 2, kSize.height()), |
50 SK_ColorWHITE); | 50 SK_ColorWHITE); |
51 | 51 |
52 SkBitmap bitmap = | 52 SkBitmap bitmap = |
53 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 53 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
54 ASSERT_EQ(kSize.width(), bitmap.width()); | 54 ASSERT_EQ(kSize.width(), bitmap.width()); |
55 ASSERT_EQ(kSize.height(), bitmap.height()); | 55 ASSERT_EQ(kSize.height(), bitmap.height()); |
56 // The thumbnail should be less boring because two colors are used. | 56 // The thumbnail should be less boring because two colors are used. |
57 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(&bitmap)); | 57 EXPECT_DOUBLE_EQ(0.5, ThumbnailGenerator::CalculateBoringScore(bitmap)); |
58 } | 58 } |
59 | 59 |
60 TEST_F(ThumbnailGeneratorTest, GetClippedBitmap_TallerThanWide) { | 60 TEST_F(ThumbnailGeneratorTest, GetClippedBitmap_TallerThanWide) { |
61 // The input bitmap is vertically long. | 61 // The input bitmap is vertically long. |
62 gfx::CanvasSkia canvas(gfx::Size(40, 90), true); | 62 gfx::CanvasSkia canvas(gfx::Size(40, 90), true); |
63 SkBitmap bitmap = | 63 SkBitmap bitmap = |
64 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); | 64 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); |
65 | 65 |
66 // The desired size is square. | 66 // The desired size is square. |
67 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; | 67 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 good_score.good_clipping = true; | 215 good_score.good_clipping = true; |
216 good_score.boring_score = 0.0; | 216 good_score.boring_score = 0.0; |
217 good_score.load_completed = true; | 217 good_score.load_completed = true; |
218 top_sites->AddKnownURL(kGoodURL, good_score); | 218 top_sites->AddKnownURL(kGoodURL, good_score); |
219 | 219 |
220 // Should be false, as the existing thumbnail is good enough (i.e. don't | 220 // Should be false, as the existing thumbnail is good enough (i.e. don't |
221 // need to replace the existing thumbnail which is new and good). | 221 // need to replace the existing thumbnail which is new and good). |
222 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 222 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
223 &profile, top_sites.get(), kGoodURL)); | 223 &profile, top_sites.get(), kGoodURL)); |
224 } | 224 } |
OLD | NEW |