- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / tests / ui_gfx_image_unittest.mm
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
3 // found in the LICENSE file.
4
5 #import <AppKit/AppKit.h>
6
7 #import "base/mac/mac_util.h"
8 #include "base/mac/scoped_nsobject.h"
9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/gfx/image/image.h"
13 #include "ui/gfx/image/image_unittest_util.h"
14
15 namespace {
16
17 class UiGfxImageTest : public CocoaTest {
18 };
19
20 // http://crbug.com/247379
21 TEST_F(UiGfxImageTest, DISABLED_CheckColor) {
22   // TODO(kbr): re-enable: http://crbug.com/222296
23   if (base::mac::IsOSMountainLionOrLater())
24     return;
25
26   gfx::Image image = gfx::Image::CreateFrom1xBitmap(
27       gfx::test::CreateBitmap(25, 25));
28   NSImage* ns_image = image.ToNSImage();
29   [ns_image lockFocus];
30   NSColor* color = NSReadPixel(NSMakePoint(10, 10));
31   [ns_image unlockFocus];
32
33   // SkBitmapToNSImage returns a bitmap in the calibrated color space (sRGB),
34   // while NSReadPixel returns a color in the device color space. Convert back
35   // to the calibrated color space before testing.
36   color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
37
38   CGFloat components[4] = { 0 };
39   [color getComponents:components];
40
41   EXPECT_LT(components[0], 0.05);
42   EXPECT_GT(components[1], 0.95);
43   EXPECT_LT(components[2], 0.05);
44   EXPECT_GT(components[3], 0.95);
45 }
46
47 TEST_F(UiGfxImageTest, ImageView) {
48   base::scoped_nsobject<NSImageView> image_view(
49       [[NSImageView alloc] initWithFrame:NSMakeRect(10, 10, 25, 25)]);
50   [[test_window() contentView] addSubview:image_view];
51   [test_window() orderFront:nil];
52
53   gfx::Image image = gfx::Image::CreateFrom1xBitmap(
54       gfx::test::CreateBitmap(25, 25));
55   [image_view setImage:image.ToNSImage()];
56 }
57
58 }  // namespace