| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> | 
| 6 | 6 | 
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" | 
| 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" | 
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" | 
| 11 #include "ui/gfx/image.h" | 11 #include "ui/gfx/image.h" | 
| 12 #include "ui/gfx/image_unittest.h" | 12 #include "ui/gfx/image_unittest_util.h" | 
| 13 | 13 | 
| 14 namespace { | 14 namespace { | 
| 15 | 15 | 
| 16 class UiGfxImageTest : public CocoaTest { | 16 class UiGfxImageTest : public CocoaTest { | 
| 17 }; | 17 }; | 
| 18 | 18 | 
| 19 TEST_F(UiGfxImageTest, CheckColor) { | 19 TEST_F(UiGfxImageTest, CheckColor) { | 
| 20   gfx::Image image(gfx::test::CreateBitmap()); | 20   gfx::Image image(gfx::test::CreateBitmap(25, 25)); | 
| 21   [image lockFocus]; | 21   [image lockFocus]; | 
| 22   NSColor* color = NSReadPixel(NSMakePoint(10, 10)); | 22   NSColor* color = NSReadPixel(NSMakePoint(10, 10)); | 
| 23   [image unlockFocus]; | 23   [image unlockFocus]; | 
| 24 | 24 | 
| 25   // SkBitmapToNSImage returns a bitmap in the calibrated color space (sRGB), | 25   // SkBitmapToNSImage returns a bitmap in the calibrated color space (sRGB), | 
| 26   // while NSReadPixel returns a color in the device color space. Convert back | 26   // while NSReadPixel returns a color in the device color space. Convert back | 
| 27   // to the calibrated color space before testing. | 27   // to the calibrated color space before testing. | 
| 28   color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; | 28   color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; | 
| 29 | 29 | 
| 30   CGFloat components[4] = { 0 }; | 30   CGFloat components[4] = { 0 }; | 
| 31   [color getComponents:components]; | 31   [color getComponents:components]; | 
| 32 | 32 | 
| 33   EXPECT_GT(components[0], 0.95); | 33   EXPECT_GT(components[0], 0.95); | 
| 34   EXPECT_LT(components[1], 0.05); | 34   EXPECT_LT(components[1], 0.05); | 
| 35   EXPECT_LT(components[2], 0.05); | 35   EXPECT_LT(components[2], 0.05); | 
| 36   EXPECT_GT(components[3], 0.95); | 36   EXPECT_GT(components[3], 0.95); | 
| 37 } | 37 } | 
| 38 | 38 | 
| 39 TEST_F(UiGfxImageTest, ImageView) { | 39 TEST_F(UiGfxImageTest, ImageView) { | 
| 40   scoped_nsobject<NSImageView> image_view( | 40   scoped_nsobject<NSImageView> image_view( | 
| 41       [[NSImageView alloc] initWithFrame:NSMakeRect(10, 10, 25, 25)]); | 41       [[NSImageView alloc] initWithFrame:NSMakeRect(10, 10, 25, 25)]); | 
| 42   [[test_window() contentView] addSubview:image_view]; | 42   [[test_window() contentView] addSubview:image_view]; | 
| 43   [test_window() orderFront:nil]; | 43   [test_window() orderFront:nil]; | 
| 44 | 44 | 
| 45   gfx::Image image(gfx::test::CreateBitmap()); | 45   gfx::Image image(gfx::test::CreateBitmap(25, 25)); | 
| 46   [image_view setImage:image]; | 46   [image_view setImage:image]; | 
| 47 } | 47 } | 
| 48 | 48 | 
| 49 }  // namespace | 49 }  // namespace | 
| OLD | NEW | 
|---|