Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "skia/ext/skia_utils_mac.h" | 5 #include "skia/ext/skia_utils_mac.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | |
| 9 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 13 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class SkiaUtilsMacTest : public testing::Test { | 17 class SkiaUtilsMacTest : public testing::Test { |
| 17 public: | 18 public: |
| 18 // Creates a red or blue bitmap. | 19 // Creates a red or blue bitmap. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 SkBitmap thing(CreateSkBitmap(width, height, isred, tfbit)); | 183 SkBitmap thing(CreateSkBitmap(width, height, isred, tfbit)); |
| 183 | 184 |
| 184 // Confirm size | 185 // Confirm size |
| 185 NSImage* image = gfx::SkBitmapToNSImage(thing); | 186 NSImage* image = gfx::SkBitmapToNSImage(thing); |
| 186 EXPECT_DOUBLE_EQ([image size].width, (double)width); | 187 EXPECT_DOUBLE_EQ([image size].width, (double)width); |
| 187 EXPECT_DOUBLE_EQ([image size].height, (double)height); | 188 EXPECT_DOUBLE_EQ([image size].height, (double)height); |
| 188 | 189 |
| 189 EXPECT_TRUE([[image representations] count] == 1); | 190 EXPECT_TRUE([[image representations] count] == 1); |
| 190 EXPECT_TRUE([[[image representations] lastObject] | 191 EXPECT_TRUE([[[image representations] lastObject] |
| 191 isKindOfClass:[NSBitmapImageRep class]]); | 192 isKindOfClass:[NSBitmapImageRep class]]); |
| 192 TestImageRep([[image representations] lastObject], isred); | 193 TestImageRep(base::mac::ObjCCastStrict<NSBitmapImageRep>( |
|
Nico
2015/10/09 17:42:04
here the compiler now realizes that the last repre
| |
| 194 [[image representations] lastObject]), | |
| 195 isred); | |
| 193 } | 196 } |
| 194 | 197 |
| 195 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_RedSquare64x64) { | 198 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_RedSquare64x64) { |
| 196 ShapeHelper(64, 64, true, true); | 199 ShapeHelper(64, 64, true, true); |
| 197 } | 200 } |
| 198 | 201 |
| 199 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle199x19) { | 202 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle199x19) { |
| 200 ShapeHelper(199, 19, false, true); | 203 ShapeHelper(199, 19, false, true); |
| 201 } | 204 } |
| 202 | 205 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 215 EXPECT_DOUBLE_EQ(height, [imageRep size].height); | 218 EXPECT_DOUBLE_EQ(height, [imageRep size].height); |
| 216 TestImageRep(imageRep, false); | 219 TestImageRep(imageRep, false); |
| 217 } | 220 } |
| 218 | 221 |
| 219 TEST_F(SkiaUtilsMacTest, NSImageRepToSkBitmap) { | 222 TEST_F(SkiaUtilsMacTest, NSImageRepToSkBitmap) { |
| 220 int width = 10; | 223 int width = 10; |
| 221 int height = 15; | 224 int height = 15; |
| 222 | 225 |
| 223 NSImage* image = CreateNSImage(width, height); | 226 NSImage* image = CreateNSImage(width, height); |
| 224 EXPECT_EQ(1u, [[image representations] count]); | 227 EXPECT_EQ(1u, [[image representations] count]); |
| 225 NSBitmapImageRep* imageRep = [[image representations] lastObject]; | 228 NSBitmapImageRep* imageRep = base::mac::ObjCCastStrict<NSBitmapImageRep>( |
| 229 [[image representations] lastObject]); | |
| 226 NSColorSpace* colorSpace = [NSColorSpace genericRGBColorSpace]; | 230 NSColorSpace* colorSpace = [NSColorSpace genericRGBColorSpace]; |
| 227 SkBitmap bitmap(gfx::NSImageRepToSkBitmapWithColorSpace( | 231 SkBitmap bitmap(gfx::NSImageRepToSkBitmapWithColorSpace( |
| 228 imageRep, [image size], false, [colorSpace CGColorSpace])); | 232 imageRep, [image size], false, [colorSpace CGColorSpace])); |
| 229 TestSkBitmap(bitmap); | 233 TestSkBitmap(bitmap); |
| 230 } | 234 } |
| 231 | 235 |
| 232 TEST_F(SkiaUtilsMacTest, BitLocker_Identity) { | 236 TEST_F(SkiaUtilsMacTest, BitLocker_Identity) { |
| 233 RunBitLockerTest(SkiaUtilsMacTest::TestIdentity); | 237 RunBitLockerTest(SkiaUtilsMacTest::TestIdentity); |
| 234 } | 238 } |
| 235 | 239 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 256 TEST_F(SkiaUtilsMacTest, BitLocker_ClipNoBits) { | 260 TEST_F(SkiaUtilsMacTest, BitLocker_ClipNoBits) { |
| 257 RunBitLockerTest(SkiaUtilsMacTest::TestClipNoBits); | 261 RunBitLockerTest(SkiaUtilsMacTest::TestClipNoBits); |
| 258 } | 262 } |
| 259 | 263 |
| 260 TEST_F(SkiaUtilsMacTest, BitLocker_XClipNoBits) { | 264 TEST_F(SkiaUtilsMacTest, BitLocker_XClipNoBits) { |
| 261 RunBitLockerTest(SkiaUtilsMacTest::TestXClipNoBits); | 265 RunBitLockerTest(SkiaUtilsMacTest::TestXClipNoBits); |
| 262 } | 266 } |
| 263 | 267 |
| 264 } // namespace | 268 } // namespace |
| 265 | 269 |
| OLD | NEW |