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

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

Issue 340613004: Use ImageSkiaSource to create ImageSkia from ImagePNGReps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update comments Created 6 years, 6 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
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "third_party/skia/include/core/SkCanvas.h" 6 #include "third_party/skia/include/core/SkCanvas.h"
7 #include "third_party/skia/include/core/SkPaint.h" 7 #include "third_party/skia/include/core/SkPaint.h"
8 #include "ui/gfx/image/image.h" 8 #include "ui/gfx/image/image.h"
9 #include "ui/gfx/image/image_png_rep.h" 9 #include "ui/gfx/image/image_png_rep.h"
10 #include "ui/gfx/image/image_skia.h" 10 #include "ui/gfx/image/image_skia.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 std::vector<gfx::ImagePNGRep> image_png_reps; 237 std::vector<gfx::ImagePNGRep> image_png_reps;
238 image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f)); 238 image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
239 image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f)); 239 image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f));
240 gfx::Image image(image_png_reps); 240 gfx::Image image(image_png_reps);
241 241
242 std::vector<float> scales; 242 std::vector<float> scales;
243 scales.push_back(1.0f); 243 scales.push_back(1.0f);
244 scales.push_back(2.0f); 244 scales.push_back(2.0f);
245 gfx::ImageSkia image_skia = image.AsImageSkia(); 245 gfx::ImageSkia image_skia = image.AsImageSkia();
246 EXPECT_TRUE(gt::ImageSkiaStructureMatches(image_skia, kSize1x, kSize1x,
247 scales));
248 EXPECT_TRUE(gt::IsEqual(bytes1x, 246 EXPECT_TRUE(gt::IsEqual(bytes1x,
249 image_skia.GetRepresentation(1.0f).sk_bitmap())); 247 image_skia.GetRepresentation(1.0f).sk_bitmap()));
250 EXPECT_TRUE(gt::IsEqual(bytes2x, 248 EXPECT_TRUE(gt::IsEqual(bytes2x,
251 image_skia.GetRepresentation(2.0f).sk_bitmap())); 249 image_skia.GetRepresentation(2.0f).sk_bitmap()));
250 EXPECT_TRUE(gt::ImageSkiaStructureMatches(image_skia, kSize1x, kSize1x,
251 scales));
252
253 gfx::ImageSkiaRep rep_1_6x = image_skia.GetRepresentation(1.6f);
254 ASSERT_FALSE(rep_1_6x.is_null());
255 ASSERT_EQ(1.6f, rep_1_6x.scale());
256 EXPECT_EQ("40x40", rep_1_6x.pixel_size().ToString());
257
258 gfx::ImageSkiaRep rep_0_8x = image_skia.GetRepresentation(0.8f);
259 ASSERT_FALSE(rep_0_8x.is_null());
260 ASSERT_EQ(0.8f, rep_0_8x.scale());
261 EXPECT_EQ("20x20", rep_0_8x.pixel_size().ToString());
252 } 262 }
253 263
254 TEST_F(ImageTest, MultiResolutionPNGToPlatform) { 264 TEST_F(ImageTest, MultiResolutionPNGToPlatform) {
255 const int kSize1x = 25; 265 const int kSize1x = 25;
256 const int kSize2x = 50; 266 const int kSize2x = 50;
257 267
258 scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x); 268 scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x);
259 scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x); 269 scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x);
260 std::vector<gfx::ImagePNGRep> image_png_reps; 270 std::vector<gfx::ImagePNGRep> image_png_reps;
261 image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f)); 271 image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 gfx::ImageSkiaRep(bitmap, 1.0f))); 672 gfx::ImageSkiaRep(bitmap, 1.0f)));
663 } 673 }
664 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); 674 EXPECT_TRUE(!image.ToSkBitmap()->isNull());
665 } 675 }
666 676
667 // Integration tests with UI toolkit frameworks require linking against the 677 // Integration tests with UI toolkit frameworks require linking against the
668 // Views library and cannot be here (ui_unittests doesn't include it). They 678 // Views library and cannot be here (ui_unittests doesn't include it). They
669 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. 679 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc.
670 680
671 } // namespace 681 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698