Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: ui/gfx/image_mac_unittest.mm

Issue 6849030: Add support for multi resolution icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/image_mac.mm ('k') | ui/gfx/image_unittest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include <Cocoa/Cocoa.h>
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_nsobject.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_util.h"
13
14 namespace {
15
16 class ImageMacTest : public testing::Test {
17 public:
18 size_t GetRepCount(const gfx::Image& image) {
19 return image.representations_.size();
20 }
21
22 void CreateBitmapImageRep(int width, int height, NSImageRep** image_rep) {
23 scoped_nsobject<NSImage> image([[NSImage alloc]
24 initWithSize:NSMakeSize(width, height)]);
25 [image lockFocus];
26 [[NSColor redColor] set];
27 NSRectFill(NSMakeRect(0, 0, width, height));
28 [image unlockFocus];
29 EXPECT_TRUE([[[image representations] lastObject]
30 isKindOfClass:[NSImageRep class]]);
31 *image_rep = [[image representations] lastObject];
32 }
33 };
34
35 namespace gt = gfx::test;
36
37 TEST_F(ImageMacTest, MultiResolutionNSImageToSkBitmap) {
38 const int width1 = 10;
39 const int height1 = 12;
40 const int width2 = 20;
41 const int height2 = 24;
42
43 NSImageRep* image_rep_1;
44 CreateBitmapImageRep(width1, height1, &image_rep_1);
45 NSImageRep* image_rep_2;
46 CreateBitmapImageRep(width2, height2, &image_rep_2);
47 scoped_nsobject<NSImage> ns_image([[NSImage alloc]
48 initWithSize:NSMakeSize(width1, height1)]);
49 [ns_image addRepresentation:image_rep_1];
50 [ns_image addRepresentation:image_rep_2];
51
52 gfx::Image image(ns_image.release());
53
54 EXPECT_EQ(1u, GetRepCount(image));
55 EXPECT_EQ(2u, image.GetNumberOfSkBitmaps());
56
57 const SkBitmap* bitmap1 = image.GetSkBitmapAtIndex(0);
58 EXPECT_TRUE(bitmap1);
59 const SkBitmap* bitmap2 = image.GetSkBitmapAtIndex(1);
60 EXPECT_TRUE(bitmap2);
61
62 if (bitmap1->width() == width1) {
63 EXPECT_EQ(bitmap1->height(), height1);
64 EXPECT_EQ(bitmap2->width(), width2);
65 EXPECT_EQ(bitmap2->height(), height2);
66 } else {
67 EXPECT_EQ(bitmap1->width(), width2);
68 EXPECT_EQ(bitmap1->height(), height2);
69 EXPECT_EQ(bitmap2->width(), width1);
70 EXPECT_EQ(bitmap2->height(), height1);
71 }
72
73 // GetNumberOfSkBitmaps and GetSkBitmapAtIndex should create a second
74 // representation.
75 EXPECT_EQ(2u, GetRepCount(image));
76 }
77
78 TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) {
79 const int width1 = 10;
80 const int height1 = 12;
81 const int width2 = 20;
82 const int height2 = 24;
83
84 std::vector<const SkBitmap*> bitmaps;
85 bitmaps.push_back(gt::CreateBitmap(width1, height1));
86 bitmaps.push_back(gt::CreateBitmap(width2, height2));
87 gfx::Image image(bitmaps);
88
89 EXPECT_EQ(1u, GetRepCount(image));
90 EXPECT_EQ(2u, image.GetNumberOfSkBitmaps());
91
92 NSImage* ns_image = image;
93 EXPECT_TRUE(ns_image);
94
95 EXPECT_EQ(2u, [[image representations] count]);
96 NSImageRep* image_rep_1 = [[image representations] objectAtIndex:0];
97 NSImageRep* image_rep_2 = [[image representations] objectAtIndex:1];
98
99 if ([image_rep_1 size].width == width1) {
100 EXPECT_EQ([image_rep_1 size].height, height1);
101 EXPECT_EQ([image_rep_2 size].width, width2);
102 EXPECT_EQ([image_rep_2 size].height, height2);
103 } else {
104 EXPECT_EQ([image_rep_1 size].width, width2);
105 EXPECT_EQ([image_rep_1 size].height, height2);
106 EXPECT_EQ([image_rep_2 size].width, width1);
107 EXPECT_EQ([image_rep_2 size].height, height1);
108 }
109
110 // Cast to NSImage* should create a second representation.
111 EXPECT_EQ(2u, GetRepCount(image));
112 }
113
114 } // namespace
OLDNEW
« no previous file with comments | « ui/gfx/image_mac.mm ('k') | ui/gfx/image_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698