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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "ui/gfx/image/image.h" | 6 #include "ui/gfx/image/image.h" |
7 #include "ui/gfx/image/image_skia.h" | 7 #include "ui/gfx/image/image_skia.h" |
8 #include "ui/gfx/image/image_unittest_util.h" | 8 #include "ui/gfx/image/image_unittest_util.h" |
9 | 9 |
10 #if defined(TOOLKIT_GTK) | 10 #if defined(TOOLKIT_GTK) |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // Test calling SwapRepresentations() with an empty image. | 41 // Test calling SwapRepresentations() with an empty image. |
42 gfx::Image image2(gt::CreateBitmap(25, 25)); | 42 gfx::Image image2(gt::CreateBitmap(25, 25)); |
43 EXPECT_FALSE(image2.IsEmpty()); | 43 EXPECT_FALSE(image2.IsEmpty()); |
44 | 44 |
45 image.SwapRepresentations(&image2); | 45 image.SwapRepresentations(&image2); |
46 EXPECT_FALSE(image.IsEmpty()); | 46 EXPECT_FALSE(image.IsEmpty()); |
47 EXPECT_TRUE(image2.IsEmpty()); | 47 EXPECT_TRUE(image2.IsEmpty()); |
48 } | 48 } |
49 | 49 |
| 50 // Test constructing a gfx::Image from an empty PlatformImage. |
| 51 TEST_F(ImageTest, EmptyImageFromEmptyPlatformImage) { |
| 52 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) |
| 53 gfx::Image image1(NULL); |
| 54 EXPECT_TRUE(image1.IsEmpty()); |
| 55 EXPECT_EQ(0U, image1.RepresentationCount()); |
| 56 #endif |
| 57 |
| 58 // SkBitmap and gfx::ImageSkia are available on all platforms. |
| 59 SkBitmap bitmap; |
| 60 EXPECT_TRUE(bitmap.empty()); |
| 61 gfx::Image image2(bitmap); |
| 62 EXPECT_TRUE(image2.IsEmpty()); |
| 63 EXPECT_EQ(0U, image2.RepresentationCount()); |
| 64 |
| 65 gfx::ImageSkia image_skia; |
| 66 EXPECT_TRUE(image_skia.isNull()); |
| 67 gfx::Image image3(image_skia); |
| 68 EXPECT_TRUE(image3.IsEmpty()); |
| 69 EXPECT_EQ(0U, image3.RepresentationCount()); |
| 70 } |
| 71 |
50 TEST_F(ImageTest, SkiaToSkia) { | 72 TEST_F(ImageTest, SkiaToSkia) { |
51 gfx::Image image(gt::CreateBitmap(25, 25)); | 73 gfx::Image image(gt::CreateBitmap(25, 25)); |
52 const SkBitmap* bitmap = image.ToSkBitmap(); | 74 const SkBitmap* bitmap = image.ToSkBitmap(); |
53 EXPECT_TRUE(bitmap); | 75 EXPECT_TRUE(bitmap); |
54 EXPECT_FALSE(bitmap->isNull()); | 76 EXPECT_FALSE(bitmap->isNull()); |
55 EXPECT_EQ(1U, image.RepresentationCount()); | 77 EXPECT_EQ(1U, image.RepresentationCount()); |
56 | 78 |
57 // Make sure double conversion doesn't happen. | 79 // Make sure double conversion doesn't happen. |
58 bitmap = image.ToSkBitmap(); | 80 bitmap = image.ToSkBitmap(); |
59 EXPECT_TRUE(bitmap); | 81 EXPECT_TRUE(bitmap); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); | 398 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); |
377 } | 399 } |
378 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); | 400 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); |
379 } | 401 } |
380 | 402 |
381 // Integration tests with UI toolkit frameworks require linking against the | 403 // Integration tests with UI toolkit frameworks require linking against the |
382 // Views library and cannot be here (ui_unittests doesn't include it). They | 404 // Views library and cannot be here (ui_unittests doesn't include it). They |
383 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 405 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
384 | 406 |
385 } // namespace | 407 } // namespace |
OLD | NEW |