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