| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <Cocoa/Cocoa.h> | 5 #include <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "ui/gfx/image/image.h" | 11 #include "ui/gfx/image/image.h" |
| 12 #include "ui/gfx/image/image_skia.h" |
| 12 #include "ui/gfx/image/image_unittest_util.h" | 13 #include "ui/gfx/image/image_unittest_util.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class ImageMacTest : public testing::Test { | 17 class ImageMacTest : public testing::Test { |
| 17 public: | 18 public: |
| 18 void CreateBitmapImageRep(int width, int height, NSImageRep** image_rep) { | 19 void CreateBitmapImageRep(int width, int height, NSImageRep** image_rep) { |
| 19 scoped_nsobject<NSImage> image( | 20 scoped_nsobject<NSImage> image( |
| 20 [[NSImage alloc] initWithSize:NSMakeSize(width, height)]); | 21 [[NSImage alloc] initWithSize:NSMakeSize(width, height)]); |
| 21 [image lockFocus]; | 22 [image lockFocus]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 NSImageRep* image_rep_2; | 42 NSImageRep* image_rep_2; |
| 42 CreateBitmapImageRep(width2, height2, &image_rep_2); | 43 CreateBitmapImageRep(width2, height2, &image_rep_2); |
| 43 scoped_nsobject<NSImage> ns_image( | 44 scoped_nsobject<NSImage> ns_image( |
| 44 [[NSImage alloc] initWithSize:NSMakeSize(width1, height1)]); | 45 [[NSImage alloc] initWithSize:NSMakeSize(width1, height1)]); |
| 45 [ns_image addRepresentation:image_rep_1]; | 46 [ns_image addRepresentation:image_rep_1]; |
| 46 [ns_image addRepresentation:image_rep_2]; | 47 [ns_image addRepresentation:image_rep_2]; |
| 47 | 48 |
| 48 gfx::Image image(ns_image.release()); | 49 gfx::Image image(ns_image.release()); |
| 49 | 50 |
| 50 EXPECT_EQ(1u, image.RepresentationCount()); | 51 EXPECT_EQ(1u, image.RepresentationCount()); |
| 51 EXPECT_EQ(2u, image.GetNumberOfSkBitmaps()); | 52 gfx::ImageSkia* image_skia = image.ToImageSkia(); |
| 53 EXPECT_EQ(2u, image_skia->GetNumberOfBitmaps()); |
| 52 | 54 |
| 53 const SkBitmap* bitmap1 = image.GetSkBitmapAtIndex(0); | 55 const SkBitmap* bitmap1 = image_skia->GetBitmapAtIndex(0); |
| 54 EXPECT_TRUE(bitmap1); | 56 EXPECT_TRUE(bitmap1); |
| 55 const SkBitmap* bitmap2 = image.GetSkBitmapAtIndex(1); | 57 const SkBitmap* bitmap2 = image_skia->GetBitmapAtIndex(1); |
| 56 EXPECT_TRUE(bitmap2); | 58 EXPECT_TRUE(bitmap2); |
| 57 | 59 |
| 58 if (bitmap1->width() == width1) { | 60 if (bitmap1->width() == width1) { |
| 59 EXPECT_EQ(bitmap1->height(), height1); | 61 EXPECT_EQ(bitmap1->height(), height1); |
| 60 EXPECT_EQ(bitmap2->width(), width2); | 62 EXPECT_EQ(bitmap2->width(), width2); |
| 61 EXPECT_EQ(bitmap2->height(), height2); | 63 EXPECT_EQ(bitmap2->height(), height2); |
| 62 } else { | 64 } else { |
| 63 EXPECT_EQ(bitmap1->width(), width2); | 65 EXPECT_EQ(bitmap1->width(), width2); |
| 64 EXPECT_EQ(bitmap1->height(), height2); | 66 EXPECT_EQ(bitmap1->height(), height2); |
| 65 EXPECT_EQ(bitmap2->width(), width1); | 67 EXPECT_EQ(bitmap2->width(), width1); |
| 66 EXPECT_EQ(bitmap2->height(), height1); | 68 EXPECT_EQ(bitmap2->height(), height1); |
| 67 } | 69 } |
| 68 | 70 |
| 69 // GetNumberOfSkBitmaps and GetSkBitmapAtIndex should create a second | 71 // GetNumberOfBitmaps and GetBitmapAtIndex should create a second |
| 70 // representation. | 72 // representation. |
| 71 EXPECT_EQ(2u, image.RepresentationCount()); | 73 EXPECT_EQ(2u, image.RepresentationCount()); |
| 72 } | 74 } |
| 73 | 75 |
| 74 TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) { | 76 TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) { |
| 75 const int width1 = 10; | 77 const int width1 = 10; |
| 76 const int height1 = 12; | 78 const int height1 = 12; |
| 77 const int width2 = 20; | 79 const int width2 = 20; |
| 78 const int height2 = 24; | 80 const int height2 = 24; |
| 79 | 81 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 101 EXPECT_EQ([image_rep_1 size].height, height2); | 103 EXPECT_EQ([image_rep_1 size].height, height2); |
| 102 EXPECT_EQ([image_rep_2 size].width, width1); | 104 EXPECT_EQ([image_rep_2 size].width, width1); |
| 103 EXPECT_EQ([image_rep_2 size].height, height1); | 105 EXPECT_EQ([image_rep_2 size].height, height1); |
| 104 } | 106 } |
| 105 | 107 |
| 106 // Cast to NSImage* should create a second representation. | 108 // Cast to NSImage* should create a second representation. |
| 107 EXPECT_EQ(2u, image.RepresentationCount()); | 109 EXPECT_EQ(2u, image.RepresentationCount()); |
| 108 } | 110 } |
| 109 | 111 |
| 110 } // namespace | 112 } // namespace |
| OLD | NEW |