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

Unified Diff: ui/gfx/image/image_mac_unittest.mm

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/image/image_mac_unittest.mm
diff --git a/ui/gfx/image/image_mac_unittest.mm b/ui/gfx/image/image_mac_unittest.mm
index f0ed004e4095f5422f62d20952731d438b551ac8..6d77b8b238fe741577a6f692ab6c8b21018b8302 100644
--- a/ui/gfx/image/image_mac_unittest.mm
+++ b/ui/gfx/image/image_mac_unittest.mm
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/memory/scoped_nsobject.h"
+#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
@@ -31,57 +32,60 @@ class ImageMacTest : public testing::Test {
namespace gt = gfx::test;
-TEST_F(ImageMacTest, MultiResolutionNSImageToSkBitmap) {
- const int width1 = 10;
- const int height1 = 12;
- const int width2 = 20;
- const int height2 = 24;
+TEST_F(ImageMacTest, MultiResolutionNSImageToImageSkia) {
+ const int width1x = 10;
+ const int height1x = 12;
+ const int width2x = 20;
+ const int height2x = 24;
NSImageRep* image_rep_1;
- CreateBitmapImageRep(width1, height1, &image_rep_1);
+ CreateBitmapImageRep(width1x, height1x, &image_rep_1);
NSImageRep* image_rep_2;
- CreateBitmapImageRep(width2, height2, &image_rep_2);
+ CreateBitmapImageRep(width2x, height2x, &image_rep_2);
scoped_nsobject<NSImage> ns_image(
- [[NSImage alloc] initWithSize:NSMakeSize(width1, height1)]);
+ [[NSImage alloc] initWithSize:NSMakeSize(width1x, height1x)]);
[ns_image addRepresentation:image_rep_1];
[ns_image addRepresentation:image_rep_2];
gfx::Image image(ns_image.release());
EXPECT_EQ(1u, image.RepresentationCount());
- const std::vector<const SkBitmap*>& bitmaps = image.ToImageSkia()->bitmaps();
- EXPECT_EQ(2u, bitmaps.size());
-
- const SkBitmap* bitmap1 = bitmaps[0];
- EXPECT_TRUE(bitmap1);
- const SkBitmap* bitmap2 = bitmaps[1];
- EXPECT_TRUE(bitmap2);
-
- if (bitmap1->width() == width1) {
- EXPECT_EQ(bitmap1->height(), height1);
- EXPECT_EQ(bitmap2->width(), width2);
- EXPECT_EQ(bitmap2->height(), height2);
- } else {
- EXPECT_EQ(bitmap1->width(), width2);
- EXPECT_EQ(bitmap1->height(), height2);
- EXPECT_EQ(bitmap2->width(), width1);
- EXPECT_EQ(bitmap2->height(), height1);
- }
+
+ const gfx::ImageSkia* image_skia = image.ToImageSkia();
+ EXPECT_EQ(2u, image_skia->bitmaps().size());
+
+ const SkBitmap* bitmap;
+ float scale_factor;
+ EXPECT_TRUE(image_skia->GetBitmapForScale(1.0f, 1.0f, &bitmap,
+ &scale_factor));
+ EXPECT_EQ(width1x, bitmap->width());
+ EXPECT_EQ(height1x, bitmap->height());
+ EXPECT_EQ(scale_factor, 1.0f);
+
+ EXPECT_TRUE(image_skia->GetBitmapForScale(2.0f, 2.0f, &bitmap,
+ &scale_factor));
+ EXPECT_EQ(width2x, bitmap->width());
+ EXPECT_EQ(height2x, bitmap->height());
+ EXPECT_EQ(scale_factor, 2.0f);
// ToImageSkia should create a second representation.
EXPECT_EQ(2u, image.RepresentationCount());
}
-TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) {
- const int width1 = 10;
- const int height1 = 12;
- const int width2 = 20;
- const int height2 = 24;
+TEST_F(ImageMacTest, MultiResolutionImageSkiaToNSImage) {
+ const int width1x = 10;
+ const int height1x= 12;
+ const int width2x = 20;
+ const int height2x = 24;
+
+ scoped_ptr<SkBitmap> bitmap1x(gt::CreateBitmap(width1x, height1x));
+ scoped_ptr<SkBitmap> bitmap2x(gt::CreateBitmap(width2x, height2x));
- std::vector<const SkBitmap*> bitmaps;
- bitmaps.push_back(gt::CreateBitmap(width1, height1));
- bitmaps.push_back(gt::CreateBitmap(width2, height2));
- gfx::Image image(bitmaps);
+ gfx::ImageSkia image_skia;
+ image_skia.AddBitmapForScale(*bitmap1x, 1.0f);
+ image_skia.AddBitmapForScale(*bitmap2x, 2.0f);
+
+ gfx::Image image(image_skia);
EXPECT_EQ(1u, image.RepresentationCount());
EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size());
@@ -89,19 +93,24 @@ TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) {
NSImage* ns_image = image;
EXPECT_TRUE(ns_image);
+ // Image size should be the same as the 1x bitmap.
+ EXPECT_EQ([ns_image size].width, width1x);
+ EXPECT_EQ([ns_image size].height, height1x);
+
EXPECT_EQ(2u, [[image representations] count]);
NSImageRep* image_rep_1 = [[image representations] objectAtIndex:0];
NSImageRep* image_rep_2 = [[image representations] objectAtIndex:1];
- if ([image_rep_1 size].width == width1) {
- EXPECT_EQ([image_rep_1 size].height, height1);
- EXPECT_EQ([image_rep_2 size].width, width2);
- EXPECT_EQ([image_rep_2 size].height, height2);
+ if ([image_rep_1 size].width == width1x) {
+ EXPECT_EQ([image_rep_1 size].width, width1x);
+ EXPECT_EQ([image_rep_1 size].height, height1x);
+ EXPECT_EQ([image_rep_2 size].width, width2x);
+ EXPECT_EQ([image_rep_2 size].height, height2x);
} else {
- EXPECT_EQ([image_rep_1 size].width, width2);
- EXPECT_EQ([image_rep_1 size].height, height2);
- EXPECT_EQ([image_rep_2 size].width, width1);
- EXPECT_EQ([image_rep_2 size].height, height1);
+ EXPECT_EQ([image_rep_1 size].width, width2x);
+ EXPECT_EQ([image_rep_1 size].height, height2x);
+ EXPECT_EQ([image_rep_2 size].width, width1x);
+ EXPECT_EQ([image_rep_2 size].height, height1x);
}
// Cast to NSImage* should create a second representation.
« no previous file with comments | « ui/gfx/image/image_mac.mm ('k') | ui/gfx/image/image_skia.h » ('j') | ui/gfx/image/image_skia.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698