| 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) |
| 11 #include <gtk/gtk.h> | 11 #include <gtk/gtk.h> |
| 12 #include "ui/gfx/gtk_util.h" | 12 #include "ui/gfx/gtk_util.h" |
| 13 #elif defined(OS_IOS) |
| 14 #include "base/mac/foundation_util.h" |
| 15 #include "skia/ext/skia_utils_ios.h" |
| 13 #elif defined(OS_MACOSX) | 16 #elif defined(OS_MACOSX) |
| 14 #include "base/mac/mac_util.h" | 17 #include "base/mac/mac_util.h" |
| 15 #include "skia/ext/skia_utils_mac.h" | 18 #include "skia/ext/skia_utils_mac.h" |
| 16 #endif | 19 #endif |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 #if defined(TOOLKIT_VIEWS) || defined(OS_ANDROID) | 23 #if defined(TOOLKIT_VIEWS) || defined(OS_ANDROID) |
| 21 const bool kUsesSkiaNatively = true; | 24 const bool kUsesSkiaNatively = true; |
| 22 #else | 25 #else |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 167 |
| 165 TEST_F(ImageTest, PNGDecodeToSkiaFailure) { | 168 TEST_F(ImageTest, PNGDecodeToSkiaFailure) { |
| 166 std::vector<unsigned char> png(100, 0); | 169 std::vector<unsigned char> png(100, 0); |
| 167 gfx::Image image(&png.front(), png.size()); | 170 gfx::Image image(&png.front(), png.size()); |
| 168 const SkBitmap* bitmap = image.ToSkBitmap(); | 171 const SkBitmap* bitmap = image.ToSkBitmap(); |
| 169 | 172 |
| 170 SkAutoLockPixels auto_lock(*bitmap); | 173 SkAutoLockPixels auto_lock(*bitmap); |
| 171 gt::CheckColor(bitmap->getColor(10, 10), true); | 174 gt::CheckColor(bitmap->getColor(10, 10), true); |
| 172 } | 175 } |
| 173 | 176 |
| 177 // TODO(rohitrao): This test needs an iOS implementation of |
| 178 // GetPlatformImageColor(). |
| 179 #if !defined(OS_IOS) |
| 174 TEST_F(ImageTest, PNGDecodeToPlatformFailure) { | 180 TEST_F(ImageTest, PNGDecodeToPlatformFailure) { |
| 175 std::vector<unsigned char> png(100, 0); | 181 std::vector<unsigned char> png(100, 0); |
| 176 gfx::Image image(&png.front(), png.size()); | 182 gfx::Image image(&png.front(), png.size()); |
| 177 gt::CheckColor(gt::GetPlatformImageColor(gt::ToPlatformType(image)), true); | 183 gt::CheckColor(gt::GetPlatformImageColor(gt::ToPlatformType(image)), true); |
| 178 } | 184 } |
| 185 #endif |
| 179 | 186 |
| 180 TEST_F(ImageTest, SkiaToPlatform) { | 187 TEST_F(ImageTest, SkiaToPlatform) { |
| 181 gfx::Image image(gt::CreateBitmap(25, 25)); | 188 gfx::Image image(gt::CreateBitmap(25, 25)); |
| 182 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 189 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
| 183 | 190 |
| 184 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 191 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
| 185 if (!kUsesSkiaNatively) | 192 if (!kUsesSkiaNatively) |
| 186 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 193 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
| 187 | 194 |
| 188 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); | 195 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 264 } |
| 258 | 265 |
| 259 TEST_F(ImageTest, SkiaToCairoCreatesGdk) { | 266 TEST_F(ImageTest, SkiaToCairoCreatesGdk) { |
| 260 gfx::Image image(gt::CreateBitmap(25, 25)); | 267 gfx::Image image(gt::CreateBitmap(25, 25)); |
| 261 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepGdk)); | 268 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepGdk)); |
| 262 EXPECT_TRUE(image.ToCairo()); | 269 EXPECT_TRUE(image.ToCairo()); |
| 263 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepGdk)); | 270 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepGdk)); |
| 264 } | 271 } |
| 265 #endif | 272 #endif |
| 266 | 273 |
| 267 #if defined(OS_MACOSX) | 274 #if defined(OS_IOS) |
| 275 TEST_F(ImageTest, SkiaToCocoaTouchCopy) { |
| 276 UIImage* ui_image; |
| 277 |
| 278 { |
| 279 gfx::Image image(gt::CreateBitmap(25, 25)); |
| 280 ui_image = image.CopyUIImage(); |
| 281 } |
| 282 |
| 283 EXPECT_TRUE(ui_image); |
| 284 base::mac::NSObjectRelease(ui_image); |
| 285 } |
| 286 #elif defined(OS_MACOSX) |
| 268 TEST_F(ImageTest, SkiaToCocoaCopy) { | 287 TEST_F(ImageTest, SkiaToCocoaCopy) { |
| 269 NSImage* ns_image; | 288 NSImage* ns_image; |
| 270 | 289 |
| 271 { | 290 { |
| 272 gfx::Image image(gt::CreateBitmap(25, 25)); | 291 gfx::Image image(gt::CreateBitmap(25, 25)); |
| 273 ns_image = image.CopyNSImage(); | 292 ns_image = image.CopyNSImage(); |
| 274 } | 293 } |
| 275 | 294 |
| 276 EXPECT_TRUE(ns_image); | 295 EXPECT_TRUE(ns_image); |
| 277 base::mac::NSObjectRelease(ns_image); | 296 base::mac::NSObjectRelease(ns_image); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); | 417 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); |
| 399 } | 418 } |
| 400 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); | 419 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); |
| 401 } | 420 } |
| 402 | 421 |
| 403 // Integration tests with UI toolkit frameworks require linking against the | 422 // Integration tests with UI toolkit frameworks require linking against the |
| 404 // Views library and cannot be here (ui_unittests doesn't include it). They | 423 // Views library and cannot be here (ui_unittests doesn't include it). They |
| 405 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 424 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
| 406 | 425 |
| 407 } // namespace | 426 } // namespace |
| OLD | NEW |