summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/image/image_unittest.cc37
-rw-r--r--ui/gfx/image/image_unittest_util_ios.mm40
-rw-r--r--ui/ui_unittests.gypi1
3 files changed, 60 insertions, 18 deletions
diff --git a/ui/gfx/image/image_unittest.cc b/ui/gfx/image/image_unittest.cc
index c0b2489..0ad95ae 100644
--- a/ui/gfx/image/image_unittest.cc
+++ b/ui/gfx/image/image_unittest.cc
@@ -176,16 +176,12 @@ TEST_F(ImageTest, PNGDecodeToSkiaFailure) {
gt::CheckColor(bitmap->getColor(10, 10), true);
}
-// TODO(rohitrao): This test needs an iOS implementation of
-// GetPlatformImageColor().
-#if !defined(OS_IOS)
TEST_F(ImageTest, PNGDecodeToPlatformFailure) {
std::vector<unsigned char> png(100, 0);
gfx::Image image(&png.front(), png.size());
gt::CheckColor(gt::GetPlatformImageColor(gt::ToPlatformType(image), 10, 10),
true);
}
-#endif
TEST_F(ImageTest, SkiaToPlatform) {
gfx::Image image(gt::CreateBitmap(25, 25));
@@ -308,9 +304,6 @@ TEST_F(ImageTest, CheckSkiaColor) {
gt::CheckColor(bitmap->getColor(10, 10), false);
}
-// TODO(rohitrao): This test needs an iOS implementation of
-// GetPlatformImageColor().
-#if !defined(OS_IOS)
TEST_F(ImageTest, SkBitmapConversionPreservesOrientation) {
const int width = 50;
const int height = 50;
@@ -324,27 +317,35 @@ TEST_F(ImageTest, SkBitmapConversionPreservesOrientation) {
SkPaint red;
red.setColor(SK_ColorRED);
canvas.drawRect(SkRect::MakeWH(width, height / 2), red);
- gt::CheckColor(bitmap.getColor(10, 10), true);
- gt::CheckColor(bitmap.getColor(10, 40), false);
+ {
+ SCOPED_TRACE("Checking color of the initial SkBitmap");
+ gt::CheckColor(bitmap.getColor(10, 10), true);
+ gt::CheckColor(bitmap.getColor(10, 40), false);
+ }
// Convert from SkBitmap to a platform representation, then check the upper
// half of the platform image to make sure it is red, not green.
gfx::Image from_skbitmap(bitmap);
- gt::CheckColor(
- gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 10),
- true);
- gt::CheckColor(
- gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 40),
- false);
+ {
+ SCOPED_TRACE("Checking color of the platform image");
+ gt::CheckColor(
+ gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 10),
+ true);
+ gt::CheckColor(
+ gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 40),
+ false);
+ }
// Force a conversion back to SkBitmap and check that the upper half is red.
gfx::Image from_platform(gt::CopyPlatformType(from_skbitmap));
const SkBitmap* bitmap2 = from_platform.ToSkBitmap();
SkAutoLockPixels auto_lock(*bitmap2);
- gt::CheckColor(bitmap2->getColor(10, 10), true);
- gt::CheckColor(bitmap2->getColor(10, 40), false);
+ {
+ SCOPED_TRACE("Checking color after conversion back to SkBitmap");
+ gt::CheckColor(bitmap2->getColor(10, 10), true);
+ gt::CheckColor(bitmap2->getColor(10, 40), false);
+ }
}
-#endif // !defined(OS_IOS)
TEST_F(ImageTest, SwapRepresentations) {
const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
diff --git a/ui/gfx/image/image_unittest_util_ios.mm b/ui/gfx/image/image_unittest_util_ios.mm
new file mode 100644
index 0000000..f2d200d
--- /dev/null
+++ b/ui/gfx/image/image_unittest_util_ios.mm
@@ -0,0 +1,40 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <CoreGraphics/CoreGraphics.h>
+#import <UIKit/UIKit.h>
+
+#include "base/mac/scoped_cftyperef.h"
+#include "skia/ext/skia_utils_ios.h"
+#include "ui/gfx/image/image_unittest_util.h"
+
+namespace gfx {
+namespace test {
+
+SkColor GetPlatformImageColor(PlatformImage image, int x, int y) {
+ // Start by extracting the target pixel into a 1x1 CGImage.
+ base::mac::ScopedCFTypeRef<CGImageRef> pixel_image(
+ CGImageCreateWithImageInRect(image.CGImage, CGRectMake(x, y, 1, 1)));
+
+ // Draw that pixel into a 1x1 bitmap context.
+ base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space(
+ CGColorSpaceCreateDeviceRGB());
+ base::mac::ScopedCFTypeRef<CGContextRef> bitmap_context(
+ CGBitmapContextCreate(/*data=*/ NULL,
+ /*width=*/ 1, /*height=*/ 1,
+ /*bitsPerComponent=*/ 8, /*bytesPerRow=*/ 4,
+ color_space,
+ kCGImageAlphaPremultipliedFirst |
+ kCGBitmapByteOrder32Host));
+ CGContextDrawImage(bitmap_context, CGRectMake(0, 0, 1, 1), pixel_image);
+
+ // The CGBitmapContext has the same memory layout as SkColor, so we can just
+ // read an SkColor straight out of the context.
+ SkColor* data =
+ reinterpret_cast<SkColor*>(CGBitmapContextGetData(bitmap_context));
+ return *data;
+}
+
+} // namespace test
+} // namespace gfx
diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi
index 6907554..c4f0b67 100644
--- a/ui/ui_unittests.gypi
+++ b/ui/ui_unittests.gypi
@@ -65,6 +65,7 @@
'gfx/image/image_unittest.cc',
'gfx/image/image_unittest_util.cc',
'gfx/image/image_unittest_util.h',
+ 'gfx/image/image_unittest_util_ios.mm',
'gfx/image/image_unittest_util_mac.mm',
'gfx/insets_unittest.cc',
],