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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "ui/gfx/image/image.h" | 8 #include "ui/gfx/image/image.h" |
9 #include "ui/gfx/image/image_skia.h" | 9 #include "ui/gfx/image/image_skia.h" |
10 #include "ui/gfx/image/image_unittest_util.h" | 10 #include "ui/gfx/image/image_unittest_util.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 TEST_F(ImageTest, Assign) { | 245 TEST_F(ImageTest, Assign) { |
246 gfx::Image image1(gt::CreatePlatformImage()); | 246 gfx::Image image1(gt::CreatePlatformImage()); |
247 gfx::Image image2 = image1; | 247 gfx::Image image2 = image1; |
248 | 248 |
249 EXPECT_EQ(1U, image1.RepresentationCount()); | 249 EXPECT_EQ(1U, image1.RepresentationCount()); |
250 EXPECT_EQ(1U, image2.RepresentationCount()); | 250 EXPECT_EQ(1U, image2.RepresentationCount()); |
251 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); | 251 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); |
252 } | 252 } |
253 | 253 |
254 TEST_F(ImageTest, MultiResolutionSkBitmap) { | 254 TEST_F(ImageTest, MultiResolutionImage) { |
255 const int width1 = 10; | 255 const int width1x = 10; |
256 const int height1 = 12; | 256 const int height1x = 12; |
257 const int width2 = 20; | 257 const int width2x = 20; |
258 const int height2 = 24; | 258 const int height2x = 24; |
259 | 259 |
260 std::vector<const SkBitmap*> bitmaps; | 260 gfx::ImageSkia image_skia; |
261 bitmaps.push_back(gt::CreateBitmap(width1, height1)); | 261 image_skia.AddBitmapForScale(*gt::CreateBitmap(width1x, height1x), 1.0f); |
262 bitmaps.push_back(gt::CreateBitmap(width2, height2)); | 262 image_skia.AddBitmapForScale(*gt::CreateBitmap(width2x, height2x), 2.0f); |
263 gfx::Image image(bitmaps); | |
264 | 263 |
| 264 EXPECT_EQ(2u, image_skia.bitmaps().size()); |
| 265 |
| 266 const SkBitmap* bitmap; |
| 267 float scale_factor; |
| 268 EXPECT_TRUE(image_skia.GetBitmapForScale(1.0f, 1.0f, &bitmap, &scale_factor)); |
| 269 EXPECT_EQ(1.0f, scale_factor); |
| 270 EXPECT_EQ(width1x, bitmap->width()); |
| 271 EXPECT_EQ(height1x, bitmap->height()); |
| 272 |
| 273 EXPECT_TRUE(image_skia.GetBitmapForScale(2.0f, 2.0f, &bitmap, &scale_factor)); |
| 274 EXPECT_EQ(2.0f, scale_factor); |
| 275 EXPECT_EQ(width2x, bitmap->width()); |
| 276 EXPECT_EQ(height2x, bitmap->height()); |
| 277 |
| 278 // Check that the image has a single representation. |
| 279 gfx::Image image(image_skia); |
265 EXPECT_EQ(1u, image.RepresentationCount()); | 280 EXPECT_EQ(1u, image.RepresentationCount()); |
266 const std::vector<const SkBitmap*>& image_bitmaps = | |
267 image.ToImageSkia()->bitmaps(); | |
268 EXPECT_EQ(2u, image_bitmaps.size()); | |
269 | |
270 const SkBitmap* bitmap1 = image_bitmaps[0]; | |
271 EXPECT_TRUE(bitmap1); | |
272 const SkBitmap* bitmap2 = image_bitmaps[1]; | |
273 EXPECT_TRUE(bitmap2); | |
274 | |
275 if (bitmap1->width() == width1) { | |
276 EXPECT_EQ(bitmap1->height(), height1); | |
277 EXPECT_EQ(bitmap2->width(), width2); | |
278 EXPECT_EQ(bitmap2->height(), height2); | |
279 } else { | |
280 EXPECT_EQ(bitmap1->width(), width2); | |
281 EXPECT_EQ(bitmap1->height(), height2); | |
282 EXPECT_EQ(bitmap2->width(), width1); | |
283 EXPECT_EQ(bitmap2->height(), height1); | |
284 } | |
285 | |
286 // Sanity check. | |
287 EXPECT_EQ(1u, image.RepresentationCount()); | |
288 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size()); | |
289 } | 281 } |
290 | 282 |
291 // Integration tests with UI toolkit frameworks require linking against the | 283 // Integration tests with UI toolkit frameworks require linking against the |
292 // Views library and cannot be here (gfx_unittests doesn't include it). They | 284 // Views library and cannot be here (gfx_unittests doesn't include it). They |
293 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 285 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
294 | 286 |
295 } // namespace | 287 } // namespace |
OLD | NEW |