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" | |
6 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "third_party/skia/include/core/SkBitmap.h" | 6 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "ui/gfx/image/image.h" | 7 #include "ui/gfx/image/image.h" |
9 #include "ui/gfx/image/image_skia.h" | 8 #include "ui/gfx/image/image_skia.h" |
10 #include "ui/gfx/image/image_unittest_util.h" | 9 #include "ui/gfx/image/image_unittest_util.h" |
11 | 10 |
12 #if defined(TOOLKIT_GTK) | 11 #if defined(TOOLKIT_GTK) |
13 #include <gtk/gtk.h> | 12 #include <gtk/gtk.h> |
14 #include "ui/gfx/gtk_util.h" | 13 #include "ui/gfx/gtk_util.h" |
15 #elif defined(OS_MACOSX) | 14 #elif defined(OS_MACOSX) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 EXPECT_TRUE(bitmap); | 60 EXPECT_TRUE(bitmap); |
62 EXPECT_FALSE(bitmap->isNull()); | 61 EXPECT_FALSE(bitmap->isNull()); |
63 EXPECT_EQ(1U, image.RepresentationCount()); | 62 EXPECT_EQ(1U, image.RepresentationCount()); |
64 | 63 |
65 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 64 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
66 if (!kUsesSkiaNatively) | 65 if (!kUsesSkiaNatively) |
67 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 66 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
68 } | 67 } |
69 | 68 |
70 TEST_F(ImageTest, SkiaRefToSkia) { | 69 TEST_F(ImageTest, SkiaRefToSkia) { |
71 scoped_ptr<SkBitmap> originalBitmap(gt::CreateBitmap(25, 25)); | 70 SkBitmap originalBitmap(gt::CreateBitmap(25, 25)); |
72 gfx::Image image(*originalBitmap.get()); | 71 gfx::Image image(originalBitmap); |
73 const SkBitmap* bitmap = image.ToSkBitmap(); | 72 const SkBitmap* bitmap = image.ToSkBitmap(); |
74 EXPECT_TRUE(bitmap); | 73 EXPECT_TRUE(bitmap); |
75 EXPECT_FALSE(bitmap->isNull()); | 74 EXPECT_FALSE(bitmap->isNull()); |
76 EXPECT_EQ(1U, image.RepresentationCount()); | 75 EXPECT_EQ(1U, image.RepresentationCount()); |
77 | 76 |
78 EXPECT_EQ(bitmap, image.ToSkBitmap()); | 77 EXPECT_EQ(bitmap, image.ToSkBitmap()); |
79 if (!kUsesSkiaNatively) | 78 if (!kUsesSkiaNatively) |
80 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 79 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
81 } | 80 } |
82 | 81 |
(...skipping 14 matching lines...) Expand all Loading... |
97 } | 96 } |
98 | 97 |
99 TEST_F(ImageTest, SkiaToPlatform) { | 98 TEST_F(ImageTest, SkiaToPlatform) { |
100 gfx::Image image(gt::CreateBitmap(25, 25)); | 99 gfx::Image image(gt::CreateBitmap(25, 25)); |
101 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 100 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
102 | 101 |
103 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 102 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
104 if (!kUsesSkiaNatively) | 103 if (!kUsesSkiaNatively) |
105 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 104 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
106 | 105 |
107 EXPECT_TRUE(gt::ToPlatformType(image)); | 106 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); |
108 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 107 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
109 | 108 |
110 const SkBitmap* bitmap = image.ToSkBitmap(); | 109 const SkBitmap* bitmap = image.ToSkBitmap(); |
111 EXPECT_FALSE(bitmap->isNull()); | 110 EXPECT_FALSE(bitmap->isNull()); |
112 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 111 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
113 | 112 |
114 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 113 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
115 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 114 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
116 } | 115 } |
117 | 116 |
118 TEST_F(ImageTest, PlatformToSkia) { | 117 TEST_F(ImageTest, PlatformToSkia) { |
119 gfx::Image image(gt::CreatePlatformImage()); | 118 gfx::Image image(gt::CreatePlatformImage()); |
120 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 119 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
121 | 120 |
122 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 121 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
123 if (!kUsesSkiaNatively) | 122 if (!kUsesSkiaNatively) |
124 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 123 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
125 | 124 |
126 const SkBitmap* bitmap = image.ToSkBitmap(); | 125 const SkBitmap* bitmap = image.ToSkBitmap(); |
127 EXPECT_TRUE(bitmap); | 126 EXPECT_TRUE(bitmap); |
128 EXPECT_FALSE(bitmap->isNull()); | 127 EXPECT_FALSE(bitmap->isNull()); |
129 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 128 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
130 | 129 |
131 EXPECT_TRUE(gt::ToPlatformType(image)); | 130 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); |
132 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 131 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
133 | 132 |
134 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 133 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
135 } | 134 } |
136 | 135 |
137 TEST_F(ImageTest, PlatformToPlatform) { | 136 TEST_F(ImageTest, PlatformToPlatform) { |
138 gfx::Image image(gt::CreatePlatformImage()); | 137 gfx::Image image(gt::CreatePlatformImage()); |
139 EXPECT_TRUE(gt::ToPlatformType(image)); | 138 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); |
140 EXPECT_EQ(1U, image.RepresentationCount()); | 139 EXPECT_EQ(1U, image.RepresentationCount()); |
141 | 140 |
142 // Make sure double conversion doesn't happen. | 141 // Make sure double conversion doesn't happen. |
143 EXPECT_TRUE(gt::ToPlatformType(image)); | 142 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); |
144 EXPECT_EQ(1U, image.RepresentationCount()); | 143 EXPECT_EQ(1U, image.RepresentationCount()); |
145 | 144 |
146 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 145 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
147 if (!kUsesSkiaNatively) | 146 if (!kUsesSkiaNatively) |
148 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 147 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
149 } | 148 } |
150 | 149 |
151 TEST_F(ImageTest, PlatformToSkiaToCopy) { | 150 TEST_F(ImageTest, PlatformToSkiaToCopy) { |
152 const SkBitmap* bitmap; | 151 const SkBitmap* bitmap; |
153 | 152 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 EXPECT_EQ(1U, image1.RepresentationCount()); | 213 EXPECT_EQ(1U, image1.RepresentationCount()); |
215 | 214 |
216 gfx::Image image2(gt::CreatePlatformImage()); | 215 gfx::Image image2(gt::CreatePlatformImage()); |
217 const SkBitmap* bitmap2 = image2.ToSkBitmap(); | 216 const SkBitmap* bitmap2 = image2.ToSkBitmap(); |
218 gt::PlatformImage platform_image = gt::ToPlatformType(image2); | 217 gt::PlatformImage platform_image = gt::ToPlatformType(image2); |
219 EXPECT_EQ(kRepCount, image2.RepresentationCount()); | 218 EXPECT_EQ(kRepCount, image2.RepresentationCount()); |
220 | 219 |
221 image1.SwapRepresentations(&image2); | 220 image1.SwapRepresentations(&image2); |
222 | 221 |
223 EXPECT_EQ(bitmap2, image1.ToSkBitmap()); | 222 EXPECT_EQ(bitmap2, image1.ToSkBitmap()); |
224 EXPECT_EQ(platform_image, gt::ToPlatformType(image1)); | 223 EXPECT_TRUE(gt::PlatformImagesEqual(platform_image, |
| 224 gt::ToPlatformType(image1))); |
225 EXPECT_EQ(bitmap1, image2.ToSkBitmap()); | 225 EXPECT_EQ(bitmap1, image2.ToSkBitmap()); |
226 EXPECT_EQ(kRepCount, image1.RepresentationCount()); | 226 EXPECT_EQ(kRepCount, image1.RepresentationCount()); |
227 EXPECT_EQ(1U, image2.RepresentationCount()); | 227 EXPECT_EQ(1U, image2.RepresentationCount()); |
228 } | 228 } |
229 | 229 |
230 TEST_F(ImageTest, Copy) { | 230 TEST_F(ImageTest, Copy) { |
231 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 231 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
232 | 232 |
233 gfx::Image image1(gt::CreateBitmap(25, 25)); | 233 gfx::Image image1(gt::CreateBitmap(25, 25)); |
234 gfx::Image image2(image1); | 234 gfx::Image image2(image1); |
235 | 235 |
236 EXPECT_EQ(1U, image1.RepresentationCount()); | 236 EXPECT_EQ(1U, image1.RepresentationCount()); |
237 EXPECT_EQ(1U, image2.RepresentationCount()); | 237 EXPECT_EQ(1U, image2.RepresentationCount()); |
238 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); | 238 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); |
239 | 239 |
240 EXPECT_TRUE(gt::ToPlatformType(image2)); | 240 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image2))); |
241 EXPECT_EQ(kRepCount, image2.RepresentationCount()); | 241 EXPECT_EQ(kRepCount, image2.RepresentationCount()); |
242 EXPECT_EQ(kRepCount, image1.RepresentationCount()); | 242 EXPECT_EQ(kRepCount, image1.RepresentationCount()); |
243 } | 243 } |
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, MultiResolutionSkBitmap) { |
255 const int width1 = 10; | 255 const int width1 = 10; |
256 const int height1 = 12; | 256 const int height1 = 12; |
257 const int width2 = 20; | 257 const int width2 = 20; |
258 const int height2 = 24; | 258 const int height2 = 24; |
259 | 259 |
260 std::vector<const SkBitmap*> bitmaps; | 260 std::vector<const SkBitmap*> bitmaps; |
261 bitmaps.push_back(gt::CreateBitmap(width1, height1)); | 261 bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width1, height1))); |
262 bitmaps.push_back(gt::CreateBitmap(width2, height2)); | 262 bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width2, height2))); |
263 gfx::Image image(bitmaps); | 263 gfx::Image image(bitmaps); |
264 | 264 |
265 EXPECT_EQ(1u, image.RepresentationCount()); | 265 EXPECT_EQ(1u, image.RepresentationCount()); |
266 const std::vector<const SkBitmap*>& image_bitmaps = | 266 const std::vector<const SkBitmap*>& image_bitmaps = |
267 image.ToImageSkia()->bitmaps(); | 267 image.ToImageSkia()->bitmaps(); |
268 EXPECT_EQ(2u, image_bitmaps.size()); | 268 EXPECT_EQ(2u, image_bitmaps.size()); |
269 | 269 |
270 const SkBitmap* bitmap1 = image_bitmaps[0]; | 270 const SkBitmap* bitmap1 = image_bitmaps[0]; |
271 EXPECT_TRUE(bitmap1); | 271 EXPECT_TRUE(bitmap1); |
272 const SkBitmap* bitmap2 = image_bitmaps[1]; | 272 const SkBitmap* bitmap2 = image_bitmaps[1]; |
(...skipping 13 matching lines...) Expand all Loading... |
286 // Sanity check. | 286 // Sanity check. |
287 EXPECT_EQ(1u, image.RepresentationCount()); | 287 EXPECT_EQ(1u, image.RepresentationCount()); |
288 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size()); | 288 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size()); |
289 } | 289 } |
290 | 290 |
291 // Integration tests with UI toolkit frameworks require linking against the | 291 // Integration tests with UI toolkit frameworks require linking against the |
292 // Views library and cannot be here (gfx_unittests doesn't include it). They | 292 // 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. | 293 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
294 | 294 |
295 } // namespace | 295 } // namespace |
OLD | NEW |