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 "chrome/browser/thumbnails/simple_thumbnail_crop.h" | 5 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/thumbnails/thumbnailing_context.h" | 9 #include "chrome/browser/thumbnails/thumbnailing_context.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 bitmap, 20, 10, &clip_result); | 103 bitmap, 20, 10, &clip_result); |
104 // The clipped bitmap should have the same aspect ratio of the desired size. | 104 // The clipped bitmap should have the same aspect ratio of the desired size. |
105 EXPECT_EQ(40, clipped_bitmap.width()); | 105 EXPECT_EQ(40, clipped_bitmap.width()); |
106 EXPECT_EQ(20, clipped_bitmap.height()); | 106 EXPECT_EQ(20, clipped_bitmap.height()); |
107 // The input was taller than wide. | 107 // The input was taller than wide. |
108 EXPECT_EQ(thumbnails::CLIP_RESULT_TALLER_THAN_WIDE, clip_result); | 108 EXPECT_EQ(thumbnails::CLIP_RESULT_TALLER_THAN_WIDE, clip_result); |
109 } | 109 } |
110 | 110 |
111 TEST_F(SimpleThumbnailCropTest, GetCanvasCopyInfo) { | 111 TEST_F(SimpleThumbnailCropTest, GetCanvasCopyInfo) { |
112 gfx::Size thumbnail_size(200, 120); | 112 gfx::Size thumbnail_size(200, 120); |
113 gfx::Size expected_2x_size = | 113 gfx::Size expected_2x_size = gfx::ScaleToFlooredSize(thumbnail_size, 2.0); |
114 gfx::ToFlooredSize(gfx::ScaleSize(thumbnail_size, 2.0)); | |
115 float desired_aspect = | 114 float desired_aspect = |
116 static_cast<float>(thumbnail_size.width()) / thumbnail_size.height(); | 115 static_cast<float>(thumbnail_size.width()) / thumbnail_size.height(); |
117 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( | 116 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( |
118 new SimpleThumbnailCrop(thumbnail_size)); | 117 new SimpleThumbnailCrop(thumbnail_size)); |
119 gfx::Rect clipping_rect_result; | 118 gfx::Rect clipping_rect_result; |
120 gfx::Size target_size_result; | 119 gfx::Size target_size_result; |
121 | 120 |
122 thumbnails::ClipResult clip_result = algorithm->GetCanvasCopyInfo( | 121 thumbnails::ClipResult clip_result = algorithm->GetCanvasCopyInfo( |
123 gfx::Size(400, 210), | 122 gfx::Size(400, 210), |
124 ui::SCALE_FACTOR_200P, | 123 ui::SCALE_FACTOR_200P, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 164 } |
166 | 165 |
167 TEST_F(SimpleThumbnailCropTest, GetCanvasCopyInfoDifferentScales) { | 166 TEST_F(SimpleThumbnailCropTest, GetCanvasCopyInfoDifferentScales) { |
168 gfx::Size thumbnail_size(200, 120); | 167 gfx::Size thumbnail_size(200, 120); |
169 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( | 168 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( |
170 new SimpleThumbnailCrop(thumbnail_size)); | 169 new SimpleThumbnailCrop(thumbnail_size)); |
171 | 170 |
172 gfx::Rect clipping_rect_result; | 171 gfx::Rect clipping_rect_result; |
173 gfx::Size target_size_result; | 172 gfx::Size target_size_result; |
174 | 173 |
175 gfx::Size expected_2x_size = | 174 gfx::Size expected_2x_size = gfx::ScaleToFlooredSize(thumbnail_size, 2.0); |
176 gfx::ToFlooredSize(gfx::ScaleSize(thumbnail_size, 2.0)); | |
177 | 175 |
178 // Test at 1x scale. Expect a 2x thumbnail (we do this for quality). | 176 // Test at 1x scale. Expect a 2x thumbnail (we do this for quality). |
179 algorithm->GetCanvasCopyInfo(gfx::Size(400, 210), ui::SCALE_FACTOR_100P, | 177 algorithm->GetCanvasCopyInfo(gfx::Size(400, 210), ui::SCALE_FACTOR_100P, |
180 &clipping_rect_result, &target_size_result); | 178 &clipping_rect_result, &target_size_result); |
181 EXPECT_EQ(expected_2x_size, target_size_result); | 179 EXPECT_EQ(expected_2x_size, target_size_result); |
182 | 180 |
183 // Test at 2x scale. | 181 // Test at 2x scale. |
184 algorithm->GetCanvasCopyInfo(gfx::Size(400, 210), ui::SCALE_FACTOR_200P, | 182 algorithm->GetCanvasCopyInfo(gfx::Size(400, 210), ui::SCALE_FACTOR_200P, |
185 &clipping_rect_result, &target_size_result); | 183 &clipping_rect_result, &target_size_result); |
186 EXPECT_EQ(expected_2x_size, target_size_result); | 184 EXPECT_EQ(expected_2x_size, target_size_result); |
187 | 185 |
188 // Test at 3x scale. | 186 // Test at 3x scale. |
189 gfx::Size expected_3x_size = | 187 gfx::Size expected_3x_size = gfx::ScaleToFlooredSize(thumbnail_size, 3.0); |
190 gfx::ToFlooredSize(gfx::ScaleSize(thumbnail_size, 3.0)); | |
191 algorithm->GetCanvasCopyInfo(gfx::Size(400, 210), ui::SCALE_FACTOR_300P, | 188 algorithm->GetCanvasCopyInfo(gfx::Size(400, 210), ui::SCALE_FACTOR_300P, |
192 &clipping_rect_result, &target_size_result); | 189 &clipping_rect_result, &target_size_result); |
193 EXPECT_EQ(expected_3x_size, target_size_result); | 190 EXPECT_EQ(expected_3x_size, target_size_result); |
194 } | 191 } |
195 | 192 |
196 TEST_F(SimpleThumbnailCropTest, GetClippingRect) { | 193 TEST_F(SimpleThumbnailCropTest, GetClippingRect) { |
197 const gfx::Size desired_size(300, 200); | 194 const gfx::Size desired_size(300, 200); |
198 thumbnails::ClipResult clip_result; | 195 thumbnails::ClipResult clip_result; |
199 // Try out 'microsource'. | 196 // Try out 'microsource'. |
200 gfx::Rect clip_rect = SimpleThumbnailCrop::GetClippingRect( | 197 gfx::Rect clip_rect = SimpleThumbnailCrop::GetClippingRect( |
(...skipping 18 matching lines...) Expand all Loading... |
219 EXPECT_LT(0, clip_rect.x()); | 216 EXPECT_LT(0, clip_rect.x()); |
220 EXPECT_GE(2000, clip_rect.width()); | 217 EXPECT_GE(2000, clip_rect.width()); |
221 EXPECT_EQ(800, clip_rect.height()); | 218 EXPECT_EQ(800, clip_rect.height()); |
222 | 219 |
223 clip_rect = SimpleThumbnailCrop::GetClippingRect( | 220 clip_rect = SimpleThumbnailCrop::GetClippingRect( |
224 gfx::Size(900, 600), desired_size, &clip_result); | 221 gfx::Size(900, 600), desired_size, &clip_result); |
225 EXPECT_EQ(thumbnails::CLIP_RESULT_NOT_CLIPPED, clip_result); | 222 EXPECT_EQ(thumbnails::CLIP_RESULT_NOT_CLIPPED, clip_result); |
226 EXPECT_EQ(gfx::Point(0, 0).ToString(), clip_rect.origin().ToString()); | 223 EXPECT_EQ(gfx::Point(0, 0).ToString(), clip_rect.origin().ToString()); |
227 EXPECT_EQ(gfx::Size(900, 600).ToString(), clip_rect.size().ToString()); | 224 EXPECT_EQ(gfx::Size(900, 600).ToString(), clip_rect.size().ToString()); |
228 } | 225 } |
OLD | NEW |