| 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 "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.h" | 8 #include "ui/gfx/image.h" |
| 9 #include "ui/gfx/image_unittest_util.h" | 9 #include "ui/gfx/image_unittest_util.h" |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 EXPECT_TRUE(bitmap); | 35 EXPECT_TRUE(bitmap); |
| 36 EXPECT_FALSE(bitmap->isNull()); | 36 EXPECT_FALSE(bitmap->isNull()); |
| 37 EXPECT_EQ(1U, image.RepresentationCount()); | 37 EXPECT_EQ(1U, image.RepresentationCount()); |
| 38 | 38 |
| 39 // Make sure double conversion doesn't happen. | 39 // Make sure double conversion doesn't happen. |
| 40 bitmap = static_cast<const SkBitmap*>(image); | 40 bitmap = static_cast<const SkBitmap*>(image); |
| 41 EXPECT_TRUE(bitmap); | 41 EXPECT_TRUE(bitmap); |
| 42 EXPECT_FALSE(bitmap->isNull()); | 42 EXPECT_FALSE(bitmap->isNull()); |
| 43 EXPECT_EQ(1U, image.RepresentationCount()); | 43 EXPECT_EQ(1U, image.RepresentationCount()); |
| 44 | 44 |
| 45 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kSkBitmapRep)); | 45 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
| 46 if (!kUsesSkiaNatively) | 46 if (!kUsesSkiaNatively) |
| 47 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 47 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
| 48 } | 48 } |
| 49 | 49 |
| 50 TEST_F(ImageTest, SkiaToSkiaRef) { | 50 TEST_F(ImageTest, SkiaToSkiaRef) { |
| 51 gfx::Image image(gt::CreateBitmap(25, 25)); | 51 gfx::Image image(gt::CreateBitmap(25, 25)); |
| 52 | 52 |
| 53 const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); | 53 const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); |
| 54 EXPECT_FALSE(bitmap.isNull()); | 54 EXPECT_FALSE(bitmap.isNull()); |
| 55 EXPECT_EQ(1U, image.RepresentationCount()); | 55 EXPECT_EQ(1U, image.RepresentationCount()); |
| 56 | 56 |
| 57 const SkBitmap* bitmap1 = static_cast<const SkBitmap*>(image); | 57 const SkBitmap* bitmap1 = static_cast<const SkBitmap*>(image); |
| 58 EXPECT_FALSE(bitmap1->isNull()); | 58 EXPECT_FALSE(bitmap1->isNull()); |
| 59 EXPECT_EQ(1U, image.RepresentationCount()); | 59 EXPECT_EQ(1U, image.RepresentationCount()); |
| 60 | 60 |
| 61 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kSkBitmapRep)); | 61 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
| 62 if (!kUsesSkiaNatively) | 62 if (!kUsesSkiaNatively) |
| 63 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 63 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST_F(ImageTest, SkiaToPlatform) { | 66 TEST_F(ImageTest, SkiaToPlatform) { |
| 67 gfx::Image image(gt::CreateBitmap(25, 25)); | 67 gfx::Image image(gt::CreateBitmap(25, 25)); |
| 68 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 68 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
| 69 | 69 |
| 70 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kSkBitmapRep)); | 70 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
| 71 if (!kUsesSkiaNatively) | 71 if (!kUsesSkiaNatively) |
| 72 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 72 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
| 73 | 73 |
| 74 EXPECT_TRUE(static_cast<gt::PlatformImage>(image)); | 74 EXPECT_TRUE(static_cast<gt::PlatformImage>(image)); |
| 75 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 75 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
| 76 | 76 |
| 77 const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); | 77 const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); |
| 78 EXPECT_FALSE(bitmap.isNull()); | 78 EXPECT_FALSE(bitmap.isNull()); |
| 79 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 79 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
| 80 | 80 |
| 81 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kSkBitmapRep)); | 81 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
| 82 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 82 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
| 83 } | 83 } |
| 84 | 84 |
| 85 TEST_F(ImageTest, PlatformToSkia) { | 85 TEST_F(ImageTest, PlatformToSkia) { |
| 86 gfx::Image image(gt::CreatePlatformImage()); | 86 gfx::Image image(gt::CreatePlatformImage()); |
| 87 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 87 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
| 88 | 88 |
| 89 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 89 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
| 90 if (!kUsesSkiaNatively) | 90 if (!kUsesSkiaNatively) |
| 91 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kSkBitmapRep)); | 91 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
| 92 | 92 |
| 93 const SkBitmap* bitmap = static_cast<const SkBitmap*>(image); | 93 const SkBitmap* bitmap = static_cast<const SkBitmap*>(image); |
| 94 EXPECT_TRUE(bitmap); | 94 EXPECT_TRUE(bitmap); |
| 95 EXPECT_FALSE(bitmap->isNull()); | 95 EXPECT_FALSE(bitmap->isNull()); |
| 96 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 96 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
| 97 | 97 |
| 98 EXPECT_TRUE(static_cast<gt::PlatformImage>(image)); | 98 EXPECT_TRUE(static_cast<gt::PlatformImage>(image)); |
| 99 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 99 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
| 100 | 100 |
| 101 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kSkBitmapRep)); | 101 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 TEST_F(ImageTest, PlatformToPlatform) { | 104 TEST_F(ImageTest, PlatformToPlatform) { |
| 105 gfx::Image image(gt::CreatePlatformImage()); | 105 gfx::Image image(gt::CreatePlatformImage()); |
| 106 EXPECT_TRUE(static_cast<gt::PlatformImage>(image)); | 106 EXPECT_TRUE(static_cast<gt::PlatformImage>(image)); |
| 107 EXPECT_EQ(1U, image.RepresentationCount()); | 107 EXPECT_EQ(1U, image.RepresentationCount()); |
| 108 | 108 |
| 109 // Make sure double conversion doesn't happen. | 109 // Make sure double conversion doesn't happen. |
| 110 EXPECT_TRUE(static_cast<gt::PlatformImage>(image)); | 110 EXPECT_TRUE(static_cast<gt::PlatformImage>(image)); |
| 111 EXPECT_EQ(1U, image.RepresentationCount()); | 111 EXPECT_EQ(1U, image.RepresentationCount()); |
| 112 | 112 |
| 113 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 113 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
| 114 if (!kUsesSkiaNatively) | 114 if (!kUsesSkiaNatively) |
| 115 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kSkBitmapRep)); | 115 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST_F(ImageTest, CheckSkiaColor) { | 118 TEST_F(ImageTest, CheckSkiaColor) { |
| 119 gfx::Image image(gt::CreatePlatformImage()); | 119 gfx::Image image(gt::CreatePlatformImage()); |
| 120 const SkBitmap& bitmap(image); | 120 const SkBitmap& bitmap(image); |
| 121 | 121 |
| 122 SkAutoLockPixels auto_lock(bitmap); | 122 SkAutoLockPixels auto_lock(bitmap); |
| 123 uint32_t* pixel = bitmap.getAddr32(10, 10); | 123 uint32_t* pixel = bitmap.getAddr32(10, 10); |
| 124 EXPECT_EQ(SK_ColorRED, *pixel); | 124 EXPECT_EQ(SK_ColorRED, *pixel); |
| 125 } | 125 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // Sanity check. | 204 // Sanity check. |
| 205 EXPECT_EQ(1u, image.RepresentationCount()); | 205 EXPECT_EQ(1u, image.RepresentationCount()); |
| 206 EXPECT_EQ(2u, image.GetNumberOfSkBitmaps()); | 206 EXPECT_EQ(2u, image.GetNumberOfSkBitmaps()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Integration tests with UI toolkit frameworks require linking against the | 209 // Integration tests with UI toolkit frameworks require linking against the |
| 210 // Views library and cannot be here (gfx_unittests doesn't include it). They | 210 // Views library and cannot be here (gfx_unittests doesn't include it). They |
| 211 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 211 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
| 212 | 212 |
| 213 } // namespace | 213 } // namespace |
| OLD | NEW |