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 const std::vector<const SkBitmap*>& bitmaps = image.ToImageSkia()->bitmaps(); |
| 53 EXPECT_EQ(2u, bitmaps.size()); |
52 | 54 |
53 const SkBitmap* bitmap1 = image.GetSkBitmapAtIndex(0); | 55 const SkBitmap* bitmap1 = bitmaps[0]; |
54 EXPECT_TRUE(bitmap1); | 56 EXPECT_TRUE(bitmap1); |
55 const SkBitmap* bitmap2 = image.GetSkBitmapAtIndex(1); | 57 const SkBitmap* bitmap2 = bitmaps[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 // ToImageSkia should create a second representation. |
70 // representation. | |
71 EXPECT_EQ(2u, image.RepresentationCount()); | 72 EXPECT_EQ(2u, image.RepresentationCount()); |
72 } | 73 } |
73 | 74 |
74 TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) { | 75 TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) { |
75 const int width1 = 10; | 76 const int width1 = 10; |
76 const int height1 = 12; | 77 const int height1 = 12; |
77 const int width2 = 20; | 78 const int width2 = 20; |
78 const int height2 = 24; | 79 const int height2 = 24; |
79 | 80 |
80 std::vector<const SkBitmap*> bitmaps; | 81 std::vector<const SkBitmap*> bitmaps; |
81 bitmaps.push_back(gt::CreateBitmap(width1, height1)); | 82 bitmaps.push_back(gt::CreateBitmap(width1, height1)); |
82 bitmaps.push_back(gt::CreateBitmap(width2, height2)); | 83 bitmaps.push_back(gt::CreateBitmap(width2, height2)); |
83 gfx::Image image(bitmaps); | 84 gfx::Image image(bitmaps); |
84 | 85 |
85 EXPECT_EQ(1u, image.RepresentationCount()); | 86 EXPECT_EQ(1u, image.RepresentationCount()); |
86 EXPECT_EQ(2u, image.GetNumberOfSkBitmaps()); | 87 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size()); |
87 | 88 |
88 NSImage* ns_image = image; | 89 NSImage* ns_image = image; |
89 EXPECT_TRUE(ns_image); | 90 EXPECT_TRUE(ns_image); |
90 | 91 |
91 EXPECT_EQ(2u, [[image representations] count]); | 92 EXPECT_EQ(2u, [[image representations] count]); |
92 NSImageRep* image_rep_1 = [[image representations] objectAtIndex:0]; | 93 NSImageRep* image_rep_1 = [[image representations] objectAtIndex:0]; |
93 NSImageRep* image_rep_2 = [[image representations] objectAtIndex:1]; | 94 NSImageRep* image_rep_2 = [[image representations] objectAtIndex:1]; |
94 | 95 |
95 if ([image_rep_1 size].width == width1) { | 96 if ([image_rep_1 size].width == width1) { |
96 EXPECT_EQ([image_rep_1 size].height, height1); | 97 EXPECT_EQ([image_rep_1 size].height, height1); |
97 EXPECT_EQ([image_rep_2 size].width, width2); | 98 EXPECT_EQ([image_rep_2 size].width, width2); |
98 EXPECT_EQ([image_rep_2 size].height, height2); | 99 EXPECT_EQ([image_rep_2 size].height, height2); |
99 } else { | 100 } else { |
100 EXPECT_EQ([image_rep_1 size].width, width2); | 101 EXPECT_EQ([image_rep_1 size].width, width2); |
101 EXPECT_EQ([image_rep_1 size].height, height2); | 102 EXPECT_EQ([image_rep_1 size].height, height2); |
102 EXPECT_EQ([image_rep_2 size].width, width1); | 103 EXPECT_EQ([image_rep_2 size].width, width1); |
103 EXPECT_EQ([image_rep_2 size].height, height1); | 104 EXPECT_EQ([image_rep_2 size].height, height1); |
104 } | 105 } |
105 | 106 |
106 // Cast to NSImage* should create a second representation. | 107 // Cast to NSImage* should create a second representation. |
107 EXPECT_EQ(2u, image.RepresentationCount()); | 108 EXPECT_EQ(2u, image.RepresentationCount()); |
108 } | 109 } |
109 | 110 |
110 } // namespace | 111 } // namespace |
OLD | NEW |