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::PlatformRepresentationIsValid(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()); |
| 128 |
129 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 129 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
130 | 130 |
131 EXPECT_TRUE(gt::ToPlatformType(image)); | 131 EXPECT_TRUE(gt::PlatformRepresentationIsValid(image)); |
132 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 132 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
133 | 133 |
134 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 134 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
135 } | 135 } |
136 | 136 |
137 TEST_F(ImageTest, PlatformToPlatform) { | 137 TEST_F(ImageTest, PlatformToPlatform) { |
138 gfx::Image image(gt::CreatePlatformImage()); | 138 gfx::Image image(gt::CreatePlatformImage()); |
139 EXPECT_TRUE(gt::ToPlatformType(image)); | 139 EXPECT_TRUE(gt::PlatformRepresentationIsValid(image)); |
140 EXPECT_EQ(1U, image.RepresentationCount()); | 140 EXPECT_EQ(1U, image.RepresentationCount()); |
141 | 141 |
142 // Make sure double conversion doesn't happen. | 142 // Make sure double conversion doesn't happen. |
143 EXPECT_TRUE(gt::ToPlatformType(image)); | 143 EXPECT_TRUE(gt::PlatformRepresentationIsValid(image)); |
144 EXPECT_EQ(1U, image.RepresentationCount()); | 144 EXPECT_EQ(1U, image.RepresentationCount()); |
145 | 145 |
146 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 146 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
147 if (!kUsesSkiaNatively) | 147 if (!kUsesSkiaNatively) |
148 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 148 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
149 } | 149 } |
150 | 150 |
151 TEST_F(ImageTest, PlatformToSkiaToCopy) { | 151 TEST_F(ImageTest, PlatformToSkiaToCopy) { |
152 const SkBitmap* bitmap; | 152 const SkBitmap* bitmap; |
153 | 153 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 EXPECT_EQ(1U, image1.RepresentationCount()); | 214 EXPECT_EQ(1U, image1.RepresentationCount()); |
215 | 215 |
216 gfx::Image image2(gt::CreatePlatformImage()); | 216 gfx::Image image2(gt::CreatePlatformImage()); |
217 const SkBitmap* bitmap2 = image2.ToSkBitmap(); | 217 const SkBitmap* bitmap2 = image2.ToSkBitmap(); |
218 gt::PlatformImage platform_image = gt::ToPlatformType(image2); | 218 gt::PlatformImage platform_image = gt::ToPlatformType(image2); |
219 EXPECT_EQ(kRepCount, image2.RepresentationCount()); | 219 EXPECT_EQ(kRepCount, image2.RepresentationCount()); |
220 | 220 |
221 image1.SwapRepresentations(&image2); | 221 image1.SwapRepresentations(&image2); |
222 | 222 |
223 EXPECT_EQ(bitmap2, image1.ToSkBitmap()); | 223 EXPECT_EQ(bitmap2, image1.ToSkBitmap()); |
224 EXPECT_EQ(platform_image, gt::ToPlatformType(image1)); | 224 EXPECT_TRUE(gt::PlatformImagesEqual(platform_image, |
| 225 gt::ToPlatformType(image1))); |
225 EXPECT_EQ(bitmap1, image2.ToSkBitmap()); | 226 EXPECT_EQ(bitmap1, image2.ToSkBitmap()); |
226 EXPECT_EQ(kRepCount, image1.RepresentationCount()); | 227 EXPECT_EQ(kRepCount, image1.RepresentationCount()); |
227 EXPECT_EQ(1U, image2.RepresentationCount()); | 228 EXPECT_EQ(1U, image2.RepresentationCount()); |
228 } | 229 } |
229 | 230 |
230 TEST_F(ImageTest, Copy) { | 231 TEST_F(ImageTest, Copy) { |
231 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 232 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
232 | 233 |
233 gfx::Image image1(gt::CreateBitmap(25, 25)); | 234 gfx::Image image1(gt::CreateBitmap(25, 25)); |
234 gfx::Image image2(image1); | 235 gfx::Image image2(image1); |
235 | 236 |
236 EXPECT_EQ(1U, image1.RepresentationCount()); | 237 EXPECT_EQ(1U, image1.RepresentationCount()); |
237 EXPECT_EQ(1U, image2.RepresentationCount()); | 238 EXPECT_EQ(1U, image2.RepresentationCount()); |
238 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); | 239 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); |
239 | 240 |
240 EXPECT_TRUE(gt::ToPlatformType(image2)); | 241 EXPECT_TRUE(gt::PlatformRepresentationIsValid(image2)); |
241 EXPECT_EQ(kRepCount, image2.RepresentationCount()); | 242 EXPECT_EQ(kRepCount, image2.RepresentationCount()); |
242 EXPECT_EQ(kRepCount, image1.RepresentationCount()); | 243 EXPECT_EQ(kRepCount, image1.RepresentationCount()); |
243 } | 244 } |
244 | 245 |
245 TEST_F(ImageTest, Assign) { | 246 TEST_F(ImageTest, Assign) { |
246 gfx::Image image1(gt::CreatePlatformImage()); | 247 gfx::Image image1(gt::CreatePlatformImage()); |
247 gfx::Image image2 = image1; | 248 gfx::Image image2 = image1; |
248 | 249 |
249 EXPECT_EQ(1U, image1.RepresentationCount()); | 250 EXPECT_EQ(1U, image1.RepresentationCount()); |
250 EXPECT_EQ(1U, image2.RepresentationCount()); | 251 EXPECT_EQ(1U, image2.RepresentationCount()); |
251 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); | 252 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); |
252 } | 253 } |
253 | 254 |
254 TEST_F(ImageTest, MultiResolutionSkBitmap) { | 255 TEST_F(ImageTest, MultiResolutionSkBitmap) { |
255 const int width1 = 10; | 256 const int width1 = 10; |
256 const int height1 = 12; | 257 const int height1 = 12; |
257 const int width2 = 20; | 258 const int width2 = 20; |
258 const int height2 = 24; | 259 const int height2 = 24; |
259 | 260 |
260 std::vector<const SkBitmap*> bitmaps; | 261 std::vector<const SkBitmap*> bitmaps; |
261 bitmaps.push_back(gt::CreateBitmap(width1, height1)); | 262 bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width1, height1))); |
262 bitmaps.push_back(gt::CreateBitmap(width2, height2)); | 263 bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width2, height2))); |
263 gfx::Image image(bitmaps); | 264 gfx::Image image(bitmaps); |
264 | 265 |
265 EXPECT_EQ(1u, image.RepresentationCount()); | 266 EXPECT_EQ(1u, image.RepresentationCount()); |
266 const std::vector<const SkBitmap*>& image_bitmaps = | 267 const std::vector<const SkBitmap*>& image_bitmaps = |
267 image.ToImageSkia()->bitmaps(); | 268 image.ToImageSkia()->bitmaps(); |
268 EXPECT_EQ(2u, image_bitmaps.size()); | 269 EXPECT_EQ(2u, image_bitmaps.size()); |
269 | 270 |
270 const SkBitmap* bitmap1 = image_bitmaps[0]; | 271 const SkBitmap* bitmap1 = image_bitmaps[0]; |
271 EXPECT_TRUE(bitmap1); | 272 EXPECT_TRUE(bitmap1); |
272 const SkBitmap* bitmap2 = image_bitmaps[1]; | 273 const SkBitmap* bitmap2 = image_bitmaps[1]; |
(...skipping 13 matching lines...) Expand all Loading... |
286 // Sanity check. | 287 // Sanity check. |
287 EXPECT_EQ(1u, image.RepresentationCount()); | 288 EXPECT_EQ(1u, image.RepresentationCount()); |
288 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size()); | 289 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size()); |
289 } | 290 } |
290 | 291 |
291 // Integration tests with UI toolkit frameworks require linking against the | 292 // Integration tests with UI toolkit frameworks require linking against the |
292 // Views library and cannot be here (gfx_unittests doesn't include it). They | 293 // 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. | 294 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
294 | 295 |
295 } // namespace | 296 } // namespace |
OLD | NEW |