summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/tests/ui_gfx_image_unittest.mm
blob: 4e45cf20aa886ae12fae13821110e4f72bb59b38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 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 <AppKit/AppKit.h>

#import "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_unittest_util.h"

namespace {

class UiGfxImageTest : public CocoaTest {
};

// http://crbug.com/247379
TEST_F(UiGfxImageTest, DISABLED_CheckColor) {
  // TODO(kbr): re-enable: http://crbug.com/222296
  if (base::mac::IsOSMountainLionOrLater())
    return;

  gfx::Image image = gfx::Image::CreateFrom1xBitmap(
      gfx::test::CreateBitmap(25, 25));
  NSImage* ns_image = image.ToNSImage();
  [ns_image lockFocus];
  NSColor* color = NSReadPixel(NSMakePoint(10, 10));
  [ns_image unlockFocus];

  // SkBitmapToNSImage returns a bitmap in the calibrated color space (sRGB),
  // while NSReadPixel returns a color in the device color space. Convert back
  // to the calibrated color space before testing.
  color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];

  CGFloat components[4] = { 0 };
  [color getComponents:components];

  EXPECT_LT(components[0], 0.05);
  EXPECT_GT(components[1], 0.95);
  EXPECT_LT(components[2], 0.05);
  EXPECT_GT(components[3], 0.95);
}

TEST_F(UiGfxImageTest, ImageView) {
  base::scoped_nsobject<NSImageView> image_view(
      [[NSImageView alloc] initWithFrame:NSMakeRect(10, 10, 25, 25)]);
  [[test_window() contentView] addSubview:image_view];
  [test_window() orderFront:nil];

  gfx::Image image = gfx::Image::CreateFrom1xBitmap(
      gfx::test::CreateBitmap(25, 25));
  [image_view setImage:image.ToNSImage()];
}

}  // namespace