| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/image.h" | 5 #include "ui/gfx/image.h" |
| 6 | 6 |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
| 10 #include "ui/gfx/image_unittest.h" | 10 #include "ui/gfx/image_unittest.h" |
| 11 | 11 |
| 12 #if defined(OS_LINUX) | 12 #if defined(OS_LINUX) |
| 13 #include <gtk/gtk.h> | 13 #include <gtk/gtk.h> |
| 14 #include "ui/gfx/gtk_util.h" | 14 #include "ui/gfx/gtk_util.h" |
| 15 #elif defined(OS_MACOSX) | 15 #elif defined(OS_MACOSX) |
| 16 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
| 17 #include "skia/ext/skia_utils_mac.h" | 17 #include "skia/ext/skia_utils_mac.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 using namespace ui::gfx::test; | 22 using namespace gfx::test; |
| 23 | 23 |
| 24 #if defined(TOOLKIT_VIEWS) | 24 #if defined(TOOLKIT_VIEWS) |
| 25 const bool kUsesSkiaNatively = true; | 25 const bool kUsesSkiaNatively = true; |
| 26 #else | 26 #else |
| 27 const bool kUsesSkiaNatively = false; | 27 const bool kUsesSkiaNatively = false; |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 class ImageTest : public testing::Test { | 30 class ImageTest : public testing::Test { |
| 31 public: | 31 public: |
| 32 size_t GetRepCount(const ui::gfx::Image& image) { | 32 size_t GetRepCount(const gfx::Image& image) { |
| 33 return image.representations_.size(); | 33 return image.representations_.size(); |
| 34 } | 34 } |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 TEST_F(ImageTest, SkiaToSkia) { | 37 TEST_F(ImageTest, SkiaToSkia) { |
| 38 ui::gfx::Image image(CreateBitmap()); | 38 gfx::Image image(CreateBitmap()); |
| 39 const SkBitmap* bitmap = static_cast<const SkBitmap*>(image); | 39 const SkBitmap* bitmap = static_cast<const SkBitmap*>(image); |
| 40 EXPECT_TRUE(bitmap); | 40 EXPECT_TRUE(bitmap); |
| 41 EXPECT_FALSE(bitmap->isNull()); | 41 EXPECT_FALSE(bitmap->isNull()); |
| 42 EXPECT_EQ(1U, GetRepCount(image)); | 42 EXPECT_EQ(1U, GetRepCount(image)); |
| 43 | 43 |
| 44 // Make sure double conversion doesn't happen. | 44 // Make sure double conversion doesn't happen. |
| 45 bitmap = static_cast<const SkBitmap*>(image); | 45 bitmap = static_cast<const SkBitmap*>(image); |
| 46 EXPECT_TRUE(bitmap); | 46 EXPECT_TRUE(bitmap); |
| 47 EXPECT_FALSE(bitmap->isNull()); | 47 EXPECT_FALSE(bitmap->isNull()); |
| 48 EXPECT_EQ(1U, GetRepCount(image)); | 48 EXPECT_EQ(1U, GetRepCount(image)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST_F(ImageTest, SkiaToSkiaRef) { | 51 TEST_F(ImageTest, SkiaToSkiaRef) { |
| 52 ui::gfx::Image image(CreateBitmap()); | 52 gfx::Image image(CreateBitmap()); |
| 53 | 53 |
| 54 const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); | 54 const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); |
| 55 EXPECT_FALSE(bitmap.isNull()); | 55 EXPECT_FALSE(bitmap.isNull()); |
| 56 EXPECT_EQ(1U, GetRepCount(image)); | 56 EXPECT_EQ(1U, GetRepCount(image)); |
| 57 | 57 |
| 58 const SkBitmap* bitmap1 = static_cast<const SkBitmap*>(image); | 58 const SkBitmap* bitmap1 = static_cast<const SkBitmap*>(image); |
| 59 EXPECT_FALSE(bitmap1->isNull()); | 59 EXPECT_FALSE(bitmap1->isNull()); |
| 60 EXPECT_EQ(1U, GetRepCount(image)); | 60 EXPECT_EQ(1U, GetRepCount(image)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(ImageTest, SkiaToPlatform) { | 63 TEST_F(ImageTest, SkiaToPlatform) { |
| 64 ui::gfx::Image image(CreateBitmap()); | 64 gfx::Image image(CreateBitmap()); |
| 65 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 65 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
| 66 | 66 |
| 67 EXPECT_TRUE(static_cast<PlatformImage>(image)); | 67 EXPECT_TRUE(static_cast<PlatformImage>(image)); |
| 68 EXPECT_EQ(kRepCount, GetRepCount(image)); | 68 EXPECT_EQ(kRepCount, GetRepCount(image)); |
| 69 | 69 |
| 70 const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); | 70 const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); |
| 71 EXPECT_FALSE(bitmap.isNull()); | 71 EXPECT_FALSE(bitmap.isNull()); |
| 72 EXPECT_EQ(kRepCount, GetRepCount(image)); | 72 EXPECT_EQ(kRepCount, GetRepCount(image)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST_F(ImageTest, PlatformToSkia) { | 75 TEST_F(ImageTest, PlatformToSkia) { |
| 76 ui::gfx::Image image(CreatePlatformImage()); | 76 gfx::Image image(CreatePlatformImage()); |
| 77 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 77 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
| 78 | 78 |
| 79 const SkBitmap* bitmap = static_cast<const SkBitmap*>(image); | 79 const SkBitmap* bitmap = static_cast<const SkBitmap*>(image); |
| 80 EXPECT_TRUE(bitmap); | 80 EXPECT_TRUE(bitmap); |
| 81 EXPECT_FALSE(bitmap->isNull()); | 81 EXPECT_FALSE(bitmap->isNull()); |
| 82 EXPECT_EQ(kRepCount, GetRepCount(image)); | 82 EXPECT_EQ(kRepCount, GetRepCount(image)); |
| 83 | 83 |
| 84 EXPECT_TRUE(static_cast<PlatformImage>(image)); | 84 EXPECT_TRUE(static_cast<PlatformImage>(image)); |
| 85 EXPECT_EQ(kRepCount, GetRepCount(image)); | 85 EXPECT_EQ(kRepCount, GetRepCount(image)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 TEST_F(ImageTest, PlatformToPlatform) { | 88 TEST_F(ImageTest, PlatformToPlatform) { |
| 89 ui::gfx::Image image(CreatePlatformImage()); | 89 gfx::Image image(CreatePlatformImage()); |
| 90 EXPECT_TRUE(static_cast<PlatformImage>(image)); | 90 EXPECT_TRUE(static_cast<PlatformImage>(image)); |
| 91 EXPECT_EQ(1U, GetRepCount(image)); | 91 EXPECT_EQ(1U, GetRepCount(image)); |
| 92 | 92 |
| 93 // Make sure double conversion doesn't happen. | 93 // Make sure double conversion doesn't happen. |
| 94 EXPECT_TRUE(static_cast<PlatformImage>(image)); | 94 EXPECT_TRUE(static_cast<PlatformImage>(image)); |
| 95 EXPECT_EQ(1U, GetRepCount(image)); | 95 EXPECT_EQ(1U, GetRepCount(image)); |
| 96 } | 96 } |
| 97 | 97 |
| 98 TEST_F(ImageTest, CheckSkiaColor) { | 98 TEST_F(ImageTest, CheckSkiaColor) { |
| 99 ui::gfx::Image image(CreatePlatformImage()); | 99 gfx::Image image(CreatePlatformImage()); |
| 100 const SkBitmap& bitmap(image); | 100 const SkBitmap& bitmap(image); |
| 101 | 101 |
| 102 SkAutoLockPixels auto_lock(bitmap); | 102 SkAutoLockPixels auto_lock(bitmap); |
| 103 uint32_t* pixel = bitmap.getAddr32(10, 10); | 103 uint32_t* pixel = bitmap.getAddr32(10, 10); |
| 104 EXPECT_EQ(SK_ColorRED, *pixel); | 104 EXPECT_EQ(SK_ColorRED, *pixel); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Integration tests with UI toolkit frameworks require linking against the | 107 // Integration tests with UI toolkit frameworks require linking against the |
| 108 // Views library and cannot be here (gfx_unittests doesn't include it). They | 108 // Views library and cannot be here (gfx_unittests doesn't include it). They |
| 109 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 109 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
| 110 | 110 |
| 111 } // namespace | 111 } // namespace |
| OLD | NEW |