| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 #include "skia/ext/skia_utils_mac.mm" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 namespace { |
| 9 |
| 10 class SkiaUtilsMacTest : public testing::Test { |
| 11 public: |
| 12 // If not red, is blue. |
| 13 // If not tfbit (twenty-four-bit), is 444. |
| 14 void ShapeHelper(int width, int height, bool isred, bool tfbit); |
| 15 }; |
| 16 |
| 17 void SkiaUtilsMacTest::ShapeHelper(int width, int height, |
| 18 bool isred, bool tfbit) { |
| 19 SkBitmap thing; |
| 20 |
| 21 if (tfbit) |
| 22 thing.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 23 else |
| 24 thing.setConfig(SkBitmap::kARGB_4444_Config, width, height); |
| 25 thing.allocPixels(); |
| 26 |
| 27 if (isred) |
| 28 thing.eraseRGB(0xff, 0, 0); |
| 29 else |
| 30 thing.eraseRGB(0, 0, 0xff); |
| 31 |
| 32 // Confirm size |
| 33 NSImage* image = gfx::SkBitmapToNSImage(thing); |
| 34 EXPECT_DOUBLE_EQ([image size].width, (double)width); |
| 35 EXPECT_DOUBLE_EQ([image size].height, (double)height); |
| 36 |
| 37 // Get the color of a pixel and make sure it looks fine |
| 38 [image lockFocus]; |
| 39 |
| 40 int x = width > 17 ? 17 : 0; |
| 41 int y = height > 17 ? 17 : 0; |
| 42 NSColor* color = NSReadPixel(NSMakePoint(x, y)); |
| 43 CGFloat red = 0, green = 0, blue = 0, alpha = 0; |
| 44 [image unlockFocus]; |
| 45 [color getRed:&red green:&green blue:&blue alpha:&alpha]; |
| 46 |
| 47 // Be tolerant of floating point rounding, gamma, etc. |
| 48 if (isred) { |
| 49 EXPECT_GT(red, 0.8); |
| 50 EXPECT_LT(blue, 0.2); |
| 51 } else { |
| 52 EXPECT_LT(red, 0.2); |
| 53 EXPECT_GT(blue, 0.8); |
| 54 } |
| 55 EXPECT_LT(green, 0.2); |
| 56 EXPECT_GT(alpha, 0.9); |
| 57 } |
| 58 |
| 59 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_RedSquare64x64) { |
| 60 ShapeHelper(64, 64, true, true); |
| 61 } |
| 62 |
| 63 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle199x19) { |
| 64 ShapeHelper(199, 19, false, true); |
| 65 } |
| 66 |
| 67 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle444) { |
| 68 ShapeHelper(200, 200, false, false); |
| 69 } |
| 70 |
| 71 } // namespace |
| OLD | NEW |