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

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

Issue 10799014: Add support for PNG representation in gfx::Image (Closed) Base URL: http://git.chromium.org/chromium/src.git@bookmark-sync
Patch Set: Created 8 years, 5 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
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 "ui/gfx/image/image.h" 6 #include "ui/gfx/image/image.h"
7 #include "ui/gfx/image/image_skia.h" 7 #include "ui/gfx/image/image_skia.h"
8 #include "ui/gfx/image/image_unittest_util.h" 8 #include "ui/gfx/image/image_unittest_util.h"
9 9
10 #if defined(TOOLKIT_GTK) 10 #if defined(TOOLKIT_GTK)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 const SkBitmap* bitmap1 = image.ToSkBitmap(); 87 const SkBitmap* bitmap1 = image.ToSkBitmap();
88 EXPECT_FALSE(bitmap1->isNull()); 88 EXPECT_FALSE(bitmap1->isNull());
89 EXPECT_EQ(1U, image.RepresentationCount()); 89 EXPECT_EQ(1U, image.RepresentationCount());
90 90
91 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 91 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
92 if (!kUsesSkiaNatively) 92 if (!kUsesSkiaNatively)
93 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 93 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
94 } 94 }
95 95
96 TEST_F(ImageTest, SkiaToPNGEncodeAndDecode) {
97 gfx::Image image(gt::CreateBitmap(25, 25));
98 const std::vector<unsigned char>* png = image.ToImagePNG();
99 EXPECT_TRUE(png);
100 EXPECT_FALSE(png->empty());
101 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
102
103 gfx::Image from_png(*png);
104 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
105 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
106 EXPECT_TRUE(gt::IsEqual(from_png, image));
107 }
108
109 TEST_F(ImageTest, PlatformToPNGEncodeAndDecode) {
110 gfx::Image image(gt::CreatePlatformImage());
111 const std::vector<unsigned char>* png = image.ToImagePNG();
112 EXPECT_TRUE(png);
113 EXPECT_FALSE(png->empty());
114 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
115
116 gfx::Image from_png(*png);
117 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
118 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
119 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image)));
120 }
121
122
96 TEST_F(ImageTest, SkiaToPlatform) { 123 TEST_F(ImageTest, SkiaToPlatform) {
97 gfx::Image image(gt::CreateBitmap(25, 25)); 124 gfx::Image image(gt::CreateBitmap(25, 25));
98 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; 125 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
99 126
100 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 127 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
101 if (!kUsesSkiaNatively) 128 if (!kUsesSkiaNatively)
102 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 129 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
103 130
104 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); 131 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image)));
105 EXPECT_EQ(kRepCount, image.RepresentationCount()); 132 EXPECT_EQ(kRepCount, image.RepresentationCount());
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); 342 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P));
316 } 343 }
317 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); 344 EXPECT_TRUE(!image.ToSkBitmap()->isNull());
318 } 345 }
319 346
320 // Integration tests with UI toolkit frameworks require linking against the 347 // Integration tests with UI toolkit frameworks require linking against the
321 // Views library and cannot be here (gfx_unittests doesn't include it). They 348 // Views library and cannot be here (gfx_unittests doesn't include it). They
322 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. 349 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc.
323 350
324 } // namespace 351 } // namespace
OLDNEW
« ui/gfx/image/image.cc ('K') | « ui/gfx/image/image.cc ('k') | ui/gfx/image/image_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698