Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1369)

Side by Side Diff: chrome/browser/thumbnails/simple_thumbnail_crop_unittest.cc

Issue 2758413002: cc/paint: Remove PaintCanvas::peekPixels. (Closed)
Patch Set: update Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/thumbnails/simple_thumbnail_crop.h" 5 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h"
6 6
7 #include "chrome/browser/thumbnails/thumbnailing_context.h" 7 #include "chrome/browser/thumbnails/thumbnailing_context.h"
8 #include "content/public/browser/notification_service.h" 8 #include "content/public/browser/notification_service.h"
9 #include "content/public/browser/notification_types.h" 9 #include "content/public/browser/notification_types.h"
10 #include "content/public/test/mock_render_process_host.h" 10 #include "content/public/test/mock_render_process_host.h"
11 #include "content/public/test/test_renderer_host.h" 11 #include "content/public/test/test_renderer_host.h"
12 #include "skia/ext/platform_canvas.h" 12 #include "skia/ext/platform_canvas.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/skia/include/core/SkColorPriv.h" 14 #include "third_party/skia/include/core/SkColorPriv.h"
15 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/geometry/size_conversions.h" 16 #include "ui/gfx/geometry/size_conversions.h"
17 #include "ui/surface/transport_dib.h" 17 #include "ui/surface/transport_dib.h"
18 18
19 using content::WebContents; 19 using content::WebContents;
20 using thumbnails::SimpleThumbnailCrop; 20 using thumbnails::SimpleThumbnailCrop;
21 21
22 typedef testing::Test SimpleThumbnailCropTest; 22 typedef testing::Test SimpleThumbnailCropTest;
23 23
24 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_TallerThanWide) { 24 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_TallerThanWide) {
25 // The input bitmap is vertically long. 25 // The input bitmap is vertically long.
26 gfx::Canvas canvas(gfx::Size(40, 90), 1.0f, true); 26 gfx::Canvas canvas(gfx::Size(40, 90), 1.0f, true);
27 SkBitmap bitmap = canvas.ToBitmap(); 27 SkBitmap bitmap = canvas.GetBitmap();
28 28
29 // The desired size is square. 29 // The desired size is square.
30 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED; 30 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED;
31 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap( 31 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap(
32 bitmap, 10, 10, &clip_result); 32 bitmap, 10, 10, &clip_result);
33 // The clipped bitmap should be square. 33 // The clipped bitmap should be square.
34 EXPECT_EQ(40, clipped_bitmap.width()); 34 EXPECT_EQ(40, clipped_bitmap.width());
35 EXPECT_EQ(40, clipped_bitmap.height()); 35 EXPECT_EQ(40, clipped_bitmap.height());
36 // The input was taller than wide. 36 // The input was taller than wide.
37 EXPECT_EQ(thumbnails::CLIP_RESULT_TALLER_THAN_WIDE, clip_result); 37 EXPECT_EQ(thumbnails::CLIP_RESULT_TALLER_THAN_WIDE, clip_result);
38 } 38 }
39 39
40 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_WiderThanTall) { 40 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_WiderThanTall) {
41 // The input bitmap is horizontally long. 41 // The input bitmap is horizontally long.
42 gfx::Canvas canvas(gfx::Size(70, 40), 1.0f, true); 42 gfx::Canvas canvas(gfx::Size(70, 40), 1.0f, true);
43 SkBitmap bitmap = canvas.ToBitmap(); 43 SkBitmap bitmap = canvas.GetBitmap();
44 44
45 // The desired size is square. 45 // The desired size is square.
46 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED; 46 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED;
47 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap( 47 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap(
48 bitmap, 10, 10, &clip_result); 48 bitmap, 10, 10, &clip_result);
49 // The clipped bitmap should be square. 49 // The clipped bitmap should be square.
50 EXPECT_EQ(40, clipped_bitmap.width()); 50 EXPECT_EQ(40, clipped_bitmap.width());
51 EXPECT_EQ(40, clipped_bitmap.height()); 51 EXPECT_EQ(40, clipped_bitmap.height());
52 // The input was wider than tall. 52 // The input was wider than tall.
53 EXPECT_EQ(thumbnails::CLIP_RESULT_WIDER_THAN_TALL, clip_result); 53 EXPECT_EQ(thumbnails::CLIP_RESULT_WIDER_THAN_TALL, clip_result);
54 } 54 }
55 55
56 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_TooWiderThanTall) { 56 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_TooWiderThanTall) {
57 // The input bitmap is horizontally very long. 57 // The input bitmap is horizontally very long.
58 gfx::Canvas canvas(gfx::Size(90, 40), 1.0f, true); 58 gfx::Canvas canvas(gfx::Size(90, 40), 1.0f, true);
59 SkBitmap bitmap = canvas.ToBitmap(); 59 SkBitmap bitmap = canvas.GetBitmap();
60 60
61 // The desired size is square. 61 // The desired size is square.
62 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED; 62 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED;
63 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap( 63 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap(
64 bitmap, 10, 10, &clip_result); 64 bitmap, 10, 10, &clip_result);
65 // The clipped bitmap should be square. 65 // The clipped bitmap should be square.
66 EXPECT_EQ(40, clipped_bitmap.width()); 66 EXPECT_EQ(40, clipped_bitmap.width());
67 EXPECT_EQ(40, clipped_bitmap.height()); 67 EXPECT_EQ(40, clipped_bitmap.height());
68 // The input was wider than tall. 68 // The input was wider than tall.
69 EXPECT_EQ(thumbnails::CLIP_RESULT_MUCH_WIDER_THAN_TALL, clip_result); 69 EXPECT_EQ(thumbnails::CLIP_RESULT_MUCH_WIDER_THAN_TALL, clip_result);
70 } 70 }
71 71
72 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_NotClipped) { 72 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_NotClipped) {
73 // The input bitmap is square. 73 // The input bitmap is square.
74 gfx::Canvas canvas(gfx::Size(40, 40), 1.0f, true); 74 gfx::Canvas canvas(gfx::Size(40, 40), 1.0f, true);
75 SkBitmap bitmap = canvas.ToBitmap(); 75 SkBitmap bitmap = canvas.GetBitmap();
76 76
77 // The desired size is square. 77 // The desired size is square.
78 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED; 78 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED;
79 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap( 79 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap(
80 bitmap, 10, 10, &clip_result); 80 bitmap, 10, 10, &clip_result);
81 // The clipped bitmap should be square. 81 // The clipped bitmap should be square.
82 EXPECT_EQ(40, clipped_bitmap.width()); 82 EXPECT_EQ(40, clipped_bitmap.width());
83 EXPECT_EQ(40, clipped_bitmap.height()); 83 EXPECT_EQ(40, clipped_bitmap.height());
84 // There was no need to clip. 84 // There was no need to clip.
85 EXPECT_EQ(thumbnails::CLIP_RESULT_NOT_CLIPPED, clip_result); 85 EXPECT_EQ(thumbnails::CLIP_RESULT_NOT_CLIPPED, clip_result);
86 } 86 }
87 87
88 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_NonSquareOutput) { 88 TEST_F(SimpleThumbnailCropTest, GetClippedBitmap_NonSquareOutput) {
89 // The input bitmap is square. 89 // The input bitmap is square.
90 gfx::Canvas canvas(gfx::Size(40, 40), 1.0f, true); 90 gfx::Canvas canvas(gfx::Size(40, 40), 1.0f, true);
91 SkBitmap bitmap = canvas.ToBitmap(); 91 SkBitmap bitmap = canvas.GetBitmap();
92 92
93 // The desired size is horizontally long. 93 // The desired size is horizontally long.
94 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED; 94 thumbnails::ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED;
95 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap( 95 SkBitmap clipped_bitmap = SimpleThumbnailCrop::GetClippedBitmap(
96 bitmap, 20, 10, &clip_result); 96 bitmap, 20, 10, &clip_result);
97 // The clipped bitmap should have the same aspect ratio of the desired size. 97 // The clipped bitmap should have the same aspect ratio of the desired size.
98 EXPECT_EQ(40, clipped_bitmap.width()); 98 EXPECT_EQ(40, clipped_bitmap.width());
99 EXPECT_EQ(20, clipped_bitmap.height()); 99 EXPECT_EQ(20, clipped_bitmap.height());
100 // The input was taller than wide. 100 // The input was taller than wide.
101 EXPECT_EQ(thumbnails::CLIP_RESULT_TALLER_THAN_WIDE, clip_result); 101 EXPECT_EQ(thumbnails::CLIP_RESULT_TALLER_THAN_WIDE, clip_result);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 EXPECT_LT(0, clip_rect.x()); 209 EXPECT_LT(0, clip_rect.x());
210 EXPECT_GE(2000, clip_rect.width()); 210 EXPECT_GE(2000, clip_rect.width());
211 EXPECT_EQ(800, clip_rect.height()); 211 EXPECT_EQ(800, clip_rect.height());
212 212
213 clip_rect = SimpleThumbnailCrop::GetClippingRect( 213 clip_rect = SimpleThumbnailCrop::GetClippingRect(
214 gfx::Size(900, 600), desired_size, &clip_result); 214 gfx::Size(900, 600), desired_size, &clip_result);
215 EXPECT_EQ(thumbnails::CLIP_RESULT_NOT_CLIPPED, clip_result); 215 EXPECT_EQ(thumbnails::CLIP_RESULT_NOT_CLIPPED, clip_result);
216 EXPECT_EQ(gfx::Point(0, 0).ToString(), clip_rect.origin().ToString()); 216 EXPECT_EQ(gfx::Point(0, 0).ToString(), clip_rect.origin().ToString());
217 EXPECT_EQ(gfx::Size(900, 600).ToString(), clip_rect.size().ToString()); 217 EXPECT_EQ(gfx::Size(900, 600).ToString(), clip_rect.size().ToString());
218 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698