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)); | |
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 #if !defined(OS_IOS) |
| 253 // IOS does not support arbitrary scale factors. |
| 254 gfx::ImageSkiaRep rep_1_6x = image_skia.GetRepresentation(1.6f); |
| 255 ASSERT_FALSE(rep_1_6x.is_null()); |
| 256 ASSERT_EQ(1.6f, rep_1_6x.scale()); |
| 257 EXPECT_EQ("40x40", rep_1_6x.pixel_size().ToString()); |
| 258 |
| 259 gfx::ImageSkiaRep rep_0_8x = image_skia.GetRepresentation(0.8f); |
| 260 ASSERT_FALSE(rep_0_8x.is_null()); |
| 261 ASSERT_EQ(0.8f, rep_0_8x.scale()); |
| 262 EXPECT_EQ("20x20", rep_0_8x.pixel_size().ToString()); |
| 263 #endif |
252 } | 264 } |
253 | 265 |
254 TEST_F(ImageTest, MultiResolutionPNGToPlatform) { | 266 TEST_F(ImageTest, MultiResolutionPNGToPlatform) { |
255 const int kSize1x = 25; | 267 const int kSize1x = 25; |
256 const int kSize2x = 50; | 268 const int kSize2x = 50; |
257 | 269 |
258 scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x); | 270 scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x); |
259 scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x); | 271 scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x); |
260 std::vector<gfx::ImagePNGRep> image_png_reps; | 272 std::vector<gfx::ImagePNGRep> image_png_reps; |
261 image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f)); | 273 image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f)); |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 gfx::ImageSkiaRep(bitmap, 1.0f))); | 674 gfx::ImageSkiaRep(bitmap, 1.0f))); |
663 } | 675 } |
664 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); | 676 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); |
665 } | 677 } |
666 | 678 |
667 // Integration tests with UI toolkit frameworks require linking against the | 679 // Integration tests with UI toolkit frameworks require linking against the |
668 // Views library and cannot be here (ui_unittests doesn't include it). They | 680 // 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. | 681 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
670 | 682 |
671 } // namespace | 683 } // namespace |
OLD | NEW |