| 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 "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 Loading... |
| 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)); |
| 246 EXPECT_TRUE(gt::IsEqual(bytes1x, | 248 EXPECT_TRUE(gt::IsEqual(bytes1x, |
| 247 image_skia.GetRepresentation(1.0f).sk_bitmap())); | 249 image_skia.GetRepresentation(1.0f).sk_bitmap())); |
| 248 EXPECT_TRUE(gt::IsEqual(bytes2x, | 250 EXPECT_TRUE(gt::IsEqual(bytes2x, |
| 249 image_skia.GetRepresentation(2.0f).sk_bitmap())); | 251 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()); | |
| 262 } | 252 } |
| 263 | 253 |
| 264 TEST_F(ImageTest, MultiResolutionPNGToPlatform) { | 254 TEST_F(ImageTest, MultiResolutionPNGToPlatform) { |
| 265 const int kSize1x = 25; | 255 const int kSize1x = 25; |
| 266 const int kSize2x = 50; | 256 const int kSize2x = 50; |
| 267 | 257 |
| 268 scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x); | 258 scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x); |
| 269 scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x); | 259 scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x); |
| 270 std::vector<gfx::ImagePNGRep> image_png_reps; | 260 std::vector<gfx::ImagePNGRep> image_png_reps; |
| 271 image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f)); | 261 image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f)); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 gfx::ImageSkiaRep(bitmap, 1.0f))); | 662 gfx::ImageSkiaRep(bitmap, 1.0f))); |
| 673 } | 663 } |
| 674 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); | 664 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); |
| 675 } | 665 } |
| 676 | 666 |
| 677 // Integration tests with UI toolkit frameworks require linking against the | 667 // Integration tests with UI toolkit frameworks require linking against the |
| 678 // Views library and cannot be here (ui_unittests doesn't include it). They | 668 // Views library and cannot be here (ui_unittests doesn't include it). They |
| 679 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 669 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
| 680 | 670 |
| 681 } // namespace | 671 } // namespace |
| OLD | NEW |