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

Side by Side Diff: ui/gfx/image/image_unittest.cc

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nicer diff Created 8 years, 7 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
« ui/gfx/image/image_skia.cc ('K') | « ui/gfx/image/image_skia.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "third_party/skia/include/core/SkBitmap.h" 7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/gfx/image/image.h" 8 #include "ui/gfx/image/image.h"
9 #include "ui/gfx/image/image_skia.h" 9 #include "ui/gfx/image/image_skia.h"
10 #include "ui/gfx/image/image_unittest_util.h" 10 #include "ui/gfx/image/image_unittest_util.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 TEST_F(ImageTest, Assign) { 245 TEST_F(ImageTest, Assign) {
246 gfx::Image image1(gt::CreatePlatformImage()); 246 gfx::Image image1(gt::CreatePlatformImage());
247 gfx::Image image2 = image1; 247 gfx::Image image2 = image1;
248 248
249 EXPECT_EQ(1U, image1.RepresentationCount()); 249 EXPECT_EQ(1U, image1.RepresentationCount());
250 EXPECT_EQ(1U, image2.RepresentationCount()); 250 EXPECT_EQ(1U, image2.RepresentationCount());
251 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); 251 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap());
252 } 252 }
253 253
254 TEST_F(ImageTest, MultiResolutionSkBitmap) { 254 TEST_F(ImageTest, MultiResolutionImage) {
255 const int width1 = 10; 255 const int width1x = 10;
256 const int height1 = 12; 256 const int height1x = 12;
257 const int width2 = 20; 257 const int width2x = 20;
258 const int height2 = 24; 258 const int height2x = 24;
259 259
260 std::vector<const SkBitmap*> bitmaps; 260 gfx::ImageSkia image_skia;
261 bitmaps.push_back(gt::CreateBitmap(width1, height1)); 261 image_skia.AddBitmapForScale(*gt::CreateBitmap(width1x, height1x), 1.0f);
Robert Sesek 2012/05/05 02:08:34 I think this will leak. CreateBitmap returns a poi
262 bitmaps.push_back(gt::CreateBitmap(width2, height2)); 262 image_skia.AddBitmapForScale(*gt::CreateBitmap(width2x, height2x), 2.0f);
263 gfx::Image image(bitmaps);
264 263
264 EXPECT_EQ(2u, image_skia.bitmaps().size());
265
266 float scale_factor;
267 const SkBitmap& bitmap1x = image_skia.GetBitmapForScale(1.0f, 1.0f,
268 &scale_factor);
269 EXPECT_TRUE(!bitmap1x.isNull());
270 EXPECT_EQ(1.0f, scale_factor);
271 EXPECT_EQ(width1x, bitmap1x.width());
272 EXPECT_EQ(height1x, bitmap1x.height());
273
274 const SkBitmap& bitmap2x = image_skia.GetBitmapForScale(2.0f, 2.0f,
275 &scale_factor);
276 EXPECT_TRUE(!bitmap2x.isNull());
277 EXPECT_EQ(2.0f, scale_factor);
278 EXPECT_EQ(width2x, bitmap2x.width());
279 EXPECT_EQ(height2x, bitmap2x.height());
280
281 // Check that the image has a single representation.
282 gfx::Image image(image_skia);
265 EXPECT_EQ(1u, image.RepresentationCount()); 283 EXPECT_EQ(1u, image.RepresentationCount());
266 const std::vector<const SkBitmap*>& image_bitmaps =
267 image.ToImageSkia()->bitmaps();
268 EXPECT_EQ(2u, image_bitmaps.size());
269
270 const SkBitmap* bitmap1 = image_bitmaps[0];
271 EXPECT_TRUE(bitmap1);
272 const SkBitmap* bitmap2 = image_bitmaps[1];
273 EXPECT_TRUE(bitmap2);
274
275 if (bitmap1->width() == width1) {
276 EXPECT_EQ(bitmap1->height(), height1);
277 EXPECT_EQ(bitmap2->width(), width2);
278 EXPECT_EQ(bitmap2->height(), height2);
279 } else {
280 EXPECT_EQ(bitmap1->width(), width2);
281 EXPECT_EQ(bitmap1->height(), height2);
282 EXPECT_EQ(bitmap2->width(), width1);
283 EXPECT_EQ(bitmap2->height(), height1);
284 }
285
286 // Sanity check.
287 EXPECT_EQ(1u, image.RepresentationCount());
288 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size());
289 } 284 }
290 285
291 // Integration tests with UI toolkit frameworks require linking against the 286 // Integration tests with UI toolkit frameworks require linking against the
292 // Views library and cannot be here (gfx_unittests doesn't include it). They 287 // Views library and cannot be here (gfx_unittests doesn't include it). They
293 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. 288 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc.
294 289
295 } // namespace 290 } // namespace
OLDNEW
« ui/gfx/image/image_skia.cc ('K') | « ui/gfx/image/image_skia.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698