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 "third_party/skia/include/core/SkCanvas.h" | 6 #include "third_party/skia/include/core/SkCanvas.h" |
7 #include "third_party/skia/include/core/SkPaint.h" | 7 #include "third_party/skia/include/core/SkPaint.h" |
8 #include "ui/gfx/image/image.h" | 8 #include "ui/gfx/image/image.h" |
9 #include "ui/gfx/image/image_png_rep.h" | 9 #include "ui/gfx/image/image_png_rep.h" |
10 #include "ui/gfx/image/image_skia.h" | 10 #include "ui/gfx/image/image_skia.h" |
11 #include "ui/gfx/image/image_unittest_util.h" | 11 #include "ui/gfx/image/image_unittest_util.h" |
12 | 12 |
13 #if defined(TOOLKIT_GTK) | 13 #if defined(OS_IOS) |
14 #include <gtk/gtk.h> | |
15 #include "ui/gfx/gtk_util.h" | |
16 #elif defined(OS_IOS) | |
17 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
18 #include "skia/ext/skia_utils_ios.h" | 15 #include "skia/ext/skia_utils_ios.h" |
19 #elif defined(OS_MACOSX) | 16 #elif defined(OS_MACOSX) |
20 #include "base/mac/mac_util.h" | 17 #include "base/mac/mac_util.h" |
21 #include "skia/ext/skia_utils_mac.h" | 18 #include "skia/ext/skia_utils_mac.h" |
22 #endif | 19 #endif |
23 | 20 |
24 namespace { | 21 namespace { |
25 | 22 |
26 #if defined(TOOLKIT_VIEWS) || defined(OS_ANDROID) || \ | 23 #if defined(TOOLKIT_VIEWS) || defined(OS_ANDROID) || \ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 EXPECT_FALSE(image.IsEmpty()); | 65 EXPECT_FALSE(image.IsEmpty()); |
69 EXPECT_EQ(25, image.Width()); | 66 EXPECT_EQ(25, image.Width()); |
70 EXPECT_EQ(25, image.Height()); | 67 EXPECT_EQ(25, image.Height()); |
71 EXPECT_TRUE(image2.IsEmpty()); | 68 EXPECT_TRUE(image2.IsEmpty()); |
72 EXPECT_EQ(0, image2.Width()); | 69 EXPECT_EQ(0, image2.Width()); |
73 EXPECT_EQ(0, image2.Height()); | 70 EXPECT_EQ(0, image2.Height()); |
74 } | 71 } |
75 | 72 |
76 // Test constructing a gfx::Image from an empty PlatformImage. | 73 // Test constructing a gfx::Image from an empty PlatformImage. |
77 TEST_F(ImageTest, EmptyImageFromEmptyPlatformImage) { | 74 TEST_F(ImageTest, EmptyImageFromEmptyPlatformImage) { |
78 #if defined(OS_IOS) || defined(OS_MACOSX) || defined(TOOLKIT_GTK) | 75 #if defined(OS_IOS) || defined(OS_MACOSX) |
79 gfx::Image image1(NULL); | 76 gfx::Image image1(NULL); |
80 EXPECT_TRUE(image1.IsEmpty()); | 77 EXPECT_TRUE(image1.IsEmpty()); |
81 EXPECT_EQ(0, image1.Width()); | 78 EXPECT_EQ(0, image1.Width()); |
82 EXPECT_EQ(0, image1.Height()); | 79 EXPECT_EQ(0, image1.Height()); |
83 EXPECT_EQ(0U, image1.RepresentationCount()); | 80 EXPECT_EQ(0U, image1.RepresentationCount()); |
84 #endif | 81 #endif |
85 | 82 |
86 // gfx::ImageSkia and gfx::ImagePNGRep are available on all platforms. | 83 // gfx::ImageSkia and gfx::ImagePNGRep are available on all platforms. |
87 gfx::ImageSkia image_skia; | 84 gfx::ImageSkia image_skia; |
88 EXPECT_TRUE(image_skia.isNull()); | 85 EXPECT_TRUE(image_skia.isNull()); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 { | 426 { |
430 gfx::Image image(gt::CreatePlatformImage()); | 427 gfx::Image image(gt::CreatePlatformImage()); |
431 bitmap = image.CopySkBitmap(); | 428 bitmap = image.CopySkBitmap(); |
432 } | 429 } |
433 | 430 |
434 EXPECT_TRUE(bitmap); | 431 EXPECT_TRUE(bitmap); |
435 EXPECT_FALSE(bitmap->isNull()); | 432 EXPECT_FALSE(bitmap->isNull()); |
436 delete bitmap; | 433 delete bitmap; |
437 } | 434 } |
438 | 435 |
439 #if defined(TOOLKIT_GTK) | |
440 TEST_F(ImageTest, SkiaToGdkCopy) { | |
441 GdkPixbuf* pixbuf; | |
442 | |
443 { | |
444 gfx::Image image(gt::CreateImageSkia(25, 25)); | |
445 pixbuf = image.CopyGdkPixbuf(); | |
446 } | |
447 | |
448 EXPECT_TRUE(pixbuf); | |
449 g_object_unref(pixbuf); | |
450 } | |
451 | |
452 TEST_F(ImageTest, SkiaToCairoCreatesGdk) { | |
453 gfx::Image image(gt::CreateImageSkia(25, 25)); | |
454 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepGdk)); | |
455 EXPECT_TRUE(image.ToCairo()); | |
456 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepGdk)); | |
457 } | |
458 #endif | |
459 | |
460 #if defined(OS_IOS) | 436 #if defined(OS_IOS) |
461 TEST_F(ImageTest, SkiaToCocoaTouchCopy) { | 437 TEST_F(ImageTest, SkiaToCocoaTouchCopy) { |
462 UIImage* ui_image; | 438 UIImage* ui_image; |
463 | 439 |
464 { | 440 { |
465 gfx::Image image(gt::CreateImageSkia(25, 25)); | 441 gfx::Image image(gt::CreateImageSkia(25, 25)); |
466 ui_image = image.CopyUIImage(); | 442 ui_image = image.CopyUIImage(); |
467 } | 443 } |
468 | 444 |
469 EXPECT_TRUE(ui_image); | 445 EXPECT_TRUE(ui_image); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 gfx::ImageSkiaRep(bitmap, 1.0f))); | 662 gfx::ImageSkiaRep(bitmap, 1.0f))); |
687 } | 663 } |
688 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); | 664 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); |
689 } | 665 } |
690 | 666 |
691 // Integration tests with UI toolkit frameworks require linking against the | 667 // Integration tests with UI toolkit frameworks require linking against the |
692 // Views library and cannot be here (ui_unittests doesn't include it). They | 668 // Views library and cannot be here (ui_unittests doesn't include it). They |
693 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 669 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
694 | 670 |
695 } // namespace | 671 } // namespace |
OLD | NEW |