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

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_png.h"
7 #include "ui/gfx/image/image_skia.h" 8 #include "ui/gfx/image/image_skia.h"
8 #include "ui/gfx/image/image_unittest_util.h" 9 #include "ui/gfx/image/image_unittest_util.h"
9 10
10 #if defined(TOOLKIT_GTK) 11 #if defined(TOOLKIT_GTK)
11 #include <gtk/gtk.h> 12 #include <gtk/gtk.h>
12 #include "ui/gfx/gtk_util.h" 13 #include "ui/gfx/gtk_util.h"
13 #elif defined(OS_MACOSX) 14 #elif defined(OS_MACOSX)
14 #include "base/mac/mac_util.h" 15 #include "base/mac/mac_util.h"
15 #include "skia/ext/skia_utils_mac.h" 16 #include "skia/ext/skia_utils_mac.h"
16 #endif 17 #endif
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 87
87 const SkBitmap* bitmap1 = image.ToSkBitmap(); 88 const SkBitmap* bitmap1 = image.ToSkBitmap();
88 EXPECT_FALSE(bitmap1->isNull()); 89 EXPECT_FALSE(bitmap1->isNull());
89 EXPECT_EQ(1U, image.RepresentationCount()); 90 EXPECT_EQ(1U, image.RepresentationCount());
90 91
91 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 92 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
92 if (!kUsesSkiaNatively) 93 if (!kUsesSkiaNatively)
93 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 94 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
94 } 95 }
95 96
97 TEST_F(ImageTest, SkiaToPNGEncodeAndDecode) {
98 gfx::Image image(gt::CreateBitmap(25, 25));
99 const gfx::ImagePNG* png = image.ToImagePNG();
100 EXPECT_TRUE(png);
101 EXPECT_FALSE(png->empty());
102 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
103
104 gfx::Image from_png(*png);
105 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
106 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
107 EXPECT_TRUE(gt::IsEqual(from_png, image));
108 }
109
110 TEST_F(ImageTest, PlatformToPNGEncodeAndDecode) {
111 gfx::Image image(gt::CreatePlatformImage());
112 const gfx::ImagePNG* png = image.ToImagePNG();
113 EXPECT_TRUE(png);
114 EXPECT_FALSE(png->empty());
115 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
116
117 gfx::Image from_png(*png);
118 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
119 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
120 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image)));
121 }
122
123
96 TEST_F(ImageTest, SkiaToPlatform) { 124 TEST_F(ImageTest, SkiaToPlatform) {
97 gfx::Image image(gt::CreateBitmap(25, 25)); 125 gfx::Image image(gt::CreateBitmap(25, 25));
98 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; 126 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
99 127
100 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 128 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
101 if (!kUsesSkiaNatively) 129 if (!kUsesSkiaNatively)
102 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 130 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
103 131
104 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); 132 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image)));
105 EXPECT_EQ(kRepCount, image.RepresentationCount()); 133 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)); 343 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P));
316 } 344 }
317 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); 345 EXPECT_TRUE(!image.ToSkBitmap()->isNull());
318 } 346 }
319 347
320 // Integration tests with UI toolkit frameworks require linking against the 348 // Integration tests with UI toolkit frameworks require linking against the
321 // Views library and cannot be here (gfx_unittests doesn't include it). They 349 // 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. 350 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc.
323 351
324 } // namespace 352 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698