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/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "chrome/browser/thumbnails/thumbnailing_context.h" | 9 #include "chrome/browser/thumbnails/thumbnailing_context.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 EXPECT_NEAR(desired_aspect, clip_aspect, 0.01); | 189 EXPECT_NEAR(desired_aspect, clip_aspect, 0.01); |
190 | 190 |
191 clip_result = algorithm->GetCanvasCopyInfo( | 191 clip_result = algorithm->GetCanvasCopyInfo( |
192 gfx::Size(200, 100), | 192 gfx::Size(200, 100), |
193 ui::SCALE_FACTOR_200P, | 193 ui::SCALE_FACTOR_200P, |
194 &clipping_rect_result, | 194 &clipping_rect_result, |
195 &target_size_result); | 195 &target_size_result); |
196 EXPECT_EQ(thumbnails::CLIP_RESULT_SOURCE_IS_SMALLER, clip_result); | 196 EXPECT_EQ(thumbnails::CLIP_RESULT_SOURCE_IS_SMALLER, clip_result); |
197 EXPECT_EQ(thumbnail_size, target_size_result); | 197 EXPECT_EQ(thumbnail_size, target_size_result); |
198 } | 198 } |
| 199 |
| 200 TEST_F(SimpleThumbnailCropTest, GetClippingRect) { |
| 201 const gfx::Size desired_size(300, 200); |
| 202 thumbnails::ClipResult clip_result; |
| 203 // Try out 'microsource'. |
| 204 gfx::Rect clip_rect = SimpleThumbnailCrop::GetClippingRect( |
| 205 gfx::Size(300, 199), desired_size, &clip_result); |
| 206 EXPECT_EQ(thumbnails::CLIP_RESULT_SOURCE_IS_SMALLER, clip_result); |
| 207 EXPECT_EQ(gfx::Point(0, 0).ToString(), clip_rect.origin().ToString()); |
| 208 EXPECT_EQ(desired_size.ToString(), clip_rect.size().ToString()); |
| 209 |
| 210 // Portrait source. |
| 211 clip_rect = SimpleThumbnailCrop::GetClippingRect( |
| 212 gfx::Size(500, 1200), desired_size, &clip_result); |
| 213 EXPECT_EQ(thumbnails::CLIP_RESULT_TALLER_THAN_WIDE, clip_result); |
| 214 EXPECT_EQ(gfx::Point(0, 0).ToString(), clip_rect.origin().ToString()); |
| 215 EXPECT_EQ(500, clip_rect.width()); |
| 216 EXPECT_GE(1200, clip_rect.height()); |
| 217 |
| 218 clip_rect = SimpleThumbnailCrop::GetClippingRect( |
| 219 gfx::Size(2000, 800), desired_size, &clip_result); |
| 220 EXPECT_TRUE(clip_result == thumbnails::CLIP_RESULT_WIDER_THAN_TALL || |
| 221 clip_result == thumbnails::CLIP_RESULT_MUCH_WIDER_THAN_TALL); |
| 222 EXPECT_EQ(0, clip_rect.y()); |
| 223 EXPECT_LT(0, clip_rect.x()); |
| 224 EXPECT_GE(2000, clip_rect.width()); |
| 225 EXPECT_EQ(800, clip_rect.height()); |
| 226 |
| 227 clip_rect = SimpleThumbnailCrop::GetClippingRect( |
| 228 gfx::Size(900, 600), desired_size, &clip_result); |
| 229 EXPECT_EQ(thumbnails::CLIP_RESULT_NOT_CLIPPED, clip_result); |
| 230 EXPECT_EQ(gfx::Point(0, 0).ToString(), clip_rect.origin().ToString()); |
| 231 EXPECT_EQ(gfx::Size(900, 600).ToString(), clip_rect.size().ToString()); |
| 232 } |
OLD | NEW |