| 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 <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 "ui/gfx/image/image.h" | 10 #include "ui/gfx/image/image.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 image_skia.AddRepresentation(gfx::ImageSkiaRep( | 153 image_skia.AddRepresentation(gfx::ImageSkiaRep( |
| 154 gt::CreateBitmap(kWidth1x, kHeight1x), ui::SCALE_FACTOR_100P)); | 154 gt::CreateBitmap(kWidth1x, kHeight1x), ui::SCALE_FACTOR_100P)); |
| 155 image_skia.AddRepresentation(gfx::ImageSkiaRep( | 155 image_skia.AddRepresentation(gfx::ImageSkiaRep( |
| 156 gt::CreateBitmap(kWidth2x, kHeight2x), ui::SCALE_FACTOR_200P)); | 156 gt::CreateBitmap(kWidth2x, kHeight2x), ui::SCALE_FACTOR_200P)); |
| 157 | 157 |
| 158 gfx::Image image(image_skia); | 158 gfx::Image image(image_skia); |
| 159 | 159 |
| 160 EXPECT_EQ(1u, image.RepresentationCount()); | 160 EXPECT_EQ(1u, image.RepresentationCount()); |
| 161 EXPECT_EQ(2u, image.ToImageSkia()->image_reps().size()); | 161 EXPECT_EQ(2u, image.ToImageSkia()->image_reps().size()); |
| 162 | 162 |
| 163 NSImage* ns_image = image; | 163 NSImage* ns_image = image.ToNSImage(); |
| 164 EXPECT_TRUE(ns_image); | 164 EXPECT_TRUE(ns_image); |
| 165 | 165 |
| 166 // Image size should be the same as the 1x bitmap. | 166 // Image size should be the same as the 1x bitmap. |
| 167 EXPECT_EQ([ns_image size].width, kWidth1x); | 167 EXPECT_EQ([ns_image size].width, kWidth1x); |
| 168 EXPECT_EQ([ns_image size].height, kHeight1x); | 168 EXPECT_EQ([ns_image size].height, kHeight1x); |
| 169 | 169 |
| 170 EXPECT_EQ(2u, [[image representations] count]); | 170 EXPECT_EQ(2u, [[ns_image representations] count]); |
| 171 NSImageRep* ns_image_rep1 = [[image representations] objectAtIndex:0]; | 171 NSImageRep* ns_image_rep1 = [[ns_image representations] objectAtIndex:0]; |
| 172 NSImageRep* ns_image_rep2 = [[image representations] objectAtIndex:1]; | 172 NSImageRep* ns_image_rep2 = [[ns_image representations] objectAtIndex:1]; |
| 173 | 173 |
| 174 if ([ns_image_rep1 size].width == kWidth1x) { | 174 if ([ns_image_rep1 size].width == kWidth1x) { |
| 175 EXPECT_EQ([ns_image_rep1 size].width, kWidth1x); | 175 EXPECT_EQ([ns_image_rep1 size].width, kWidth1x); |
| 176 EXPECT_EQ([ns_image_rep1 size].height, kHeight1x); | 176 EXPECT_EQ([ns_image_rep1 size].height, kHeight1x); |
| 177 EXPECT_EQ([ns_image_rep2 size].width, kWidth2x); | 177 EXPECT_EQ([ns_image_rep2 size].width, kWidth2x); |
| 178 EXPECT_EQ([ns_image_rep2 size].height, kHeight2x); | 178 EXPECT_EQ([ns_image_rep2 size].height, kHeight2x); |
| 179 } else { | 179 } else { |
| 180 EXPECT_EQ([ns_image_rep1 size].width, kWidth2x); | 180 EXPECT_EQ([ns_image_rep1 size].width, kWidth2x); |
| 181 EXPECT_EQ([ns_image_rep1 size].height, kHeight2x); | 181 EXPECT_EQ([ns_image_rep1 size].height, kHeight2x); |
| 182 EXPECT_EQ([ns_image_rep2 size].width, kWidth1x); | 182 EXPECT_EQ([ns_image_rep2 size].width, kWidth1x); |
| 183 EXPECT_EQ([ns_image_rep2 size].height, kHeight1x); | 183 EXPECT_EQ([ns_image_rep2 size].height, kHeight1x); |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Cast to NSImage* should create a second representation. | 186 // Cast to NSImage* should create a second representation. |
| 187 EXPECT_EQ(2u, image.RepresentationCount()); | 187 EXPECT_EQ(2u, image.RepresentationCount()); |
| 188 } | 188 } |
| 189 | 189 |
| 190 } // namespace | 190 } // namespace |
| OLD | NEW |