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

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

Issue 10332163: Revert 137075 - Get rid of Image::Image(SkBitmap*) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
« no previous file with comments | « ui/gfx/image/image.cc ('k') | ui/gfx/image/image_unittest_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/memory/scoped_ptr.h"
5 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
6 #include "third_party/skia/include/core/SkBitmap.h" 7 #include "third_party/skia/include/core/SkBitmap.h"
7 #include "ui/gfx/image/image.h" 8 #include "ui/gfx/image/image.h"
8 #include "ui/gfx/image/image_skia.h" 9 #include "ui/gfx/image/image_skia.h"
9 #include "ui/gfx/image/image_unittest_util.h" 10 #include "ui/gfx/image/image_unittest_util.h"
10 11
11 #if defined(TOOLKIT_GTK) 12 #if defined(TOOLKIT_GTK)
12 #include <gtk/gtk.h> 13 #include <gtk/gtk.h>
13 #include "ui/gfx/gtk_util.h" 14 #include "ui/gfx/gtk_util.h"
14 #elif defined(OS_MACOSX) 15 #elif defined(OS_MACOSX)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 EXPECT_TRUE(bitmap); 61 EXPECT_TRUE(bitmap);
61 EXPECT_FALSE(bitmap->isNull()); 62 EXPECT_FALSE(bitmap->isNull());
62 EXPECT_EQ(1U, image.RepresentationCount()); 63 EXPECT_EQ(1U, image.RepresentationCount());
63 64
64 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 65 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
65 if (!kUsesSkiaNatively) 66 if (!kUsesSkiaNatively)
66 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 67 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
67 } 68 }
68 69
69 TEST_F(ImageTest, SkiaRefToSkia) { 70 TEST_F(ImageTest, SkiaRefToSkia) {
70 SkBitmap originalBitmap(gt::CreateBitmap(25, 25)); 71 scoped_ptr<SkBitmap> originalBitmap(gt::CreateBitmap(25, 25));
71 gfx::Image image(originalBitmap); 72 gfx::Image image(*originalBitmap.get());
72 const SkBitmap* bitmap = image.ToSkBitmap(); 73 const SkBitmap* bitmap = image.ToSkBitmap();
73 EXPECT_TRUE(bitmap); 74 EXPECT_TRUE(bitmap);
74 EXPECT_FALSE(bitmap->isNull()); 75 EXPECT_FALSE(bitmap->isNull());
75 EXPECT_EQ(1U, image.RepresentationCount()); 76 EXPECT_EQ(1U, image.RepresentationCount());
76 77
77 EXPECT_EQ(bitmap, image.ToSkBitmap()); 78 EXPECT_EQ(bitmap, image.ToSkBitmap());
78 if (!kUsesSkiaNatively) 79 if (!kUsesSkiaNatively)
79 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 80 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
80 } 81 }
81 82
(...skipping 14 matching lines...) Expand all
96 } 97 }
97 98
98 TEST_F(ImageTest, SkiaToPlatform) { 99 TEST_F(ImageTest, SkiaToPlatform) {
99 gfx::Image image(gt::CreateBitmap(25, 25)); 100 gfx::Image image(gt::CreateBitmap(25, 25));
100 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; 101 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
101 102
102 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 103 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
103 if (!kUsesSkiaNatively) 104 if (!kUsesSkiaNatively)
104 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 105 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
105 106
106 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); 107 EXPECT_TRUE(gt::ToPlatformType(image));
107 EXPECT_EQ(kRepCount, image.RepresentationCount()); 108 EXPECT_EQ(kRepCount, image.RepresentationCount());
108 109
109 const SkBitmap* bitmap = image.ToSkBitmap(); 110 const SkBitmap* bitmap = image.ToSkBitmap();
110 EXPECT_FALSE(bitmap->isNull()); 111 EXPECT_FALSE(bitmap->isNull());
111 EXPECT_EQ(kRepCount, image.RepresentationCount()); 112 EXPECT_EQ(kRepCount, image.RepresentationCount());
112 113
113 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 114 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
114 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 115 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
115 } 116 }
116 117
117 TEST_F(ImageTest, PlatformToSkia) { 118 TEST_F(ImageTest, PlatformToSkia) {
118 gfx::Image image(gt::CreatePlatformImage()); 119 gfx::Image image(gt::CreatePlatformImage());
119 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; 120 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
120 121
121 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 122 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
122 if (!kUsesSkiaNatively) 123 if (!kUsesSkiaNatively)
123 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 124 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia));
124 125
125 const SkBitmap* bitmap = image.ToSkBitmap(); 126 const SkBitmap* bitmap = image.ToSkBitmap();
126 EXPECT_TRUE(bitmap); 127 EXPECT_TRUE(bitmap);
127 EXPECT_FALSE(bitmap->isNull()); 128 EXPECT_FALSE(bitmap->isNull());
128 EXPECT_EQ(kRepCount, image.RepresentationCount()); 129 EXPECT_EQ(kRepCount, image.RepresentationCount());
129 130
130 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); 131 EXPECT_TRUE(gt::ToPlatformType(image));
131 EXPECT_EQ(kRepCount, image.RepresentationCount()); 132 EXPECT_EQ(kRepCount, image.RepresentationCount());
132 133
133 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 134 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
134 } 135 }
135 136
136 TEST_F(ImageTest, PlatformToPlatform) { 137 TEST_F(ImageTest, PlatformToPlatform) {
137 gfx::Image image(gt::CreatePlatformImage()); 138 gfx::Image image(gt::CreatePlatformImage());
138 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); 139 EXPECT_TRUE(gt::ToPlatformType(image));
139 EXPECT_EQ(1U, image.RepresentationCount()); 140 EXPECT_EQ(1U, image.RepresentationCount());
140 141
141 // Make sure double conversion doesn't happen. 142 // Make sure double conversion doesn't happen.
142 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); 143 EXPECT_TRUE(gt::ToPlatformType(image));
143 EXPECT_EQ(1U, image.RepresentationCount()); 144 EXPECT_EQ(1U, image.RepresentationCount());
144 145
145 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 146 EXPECT_TRUE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
146 if (!kUsesSkiaNatively) 147 if (!kUsesSkiaNatively)
147 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 148 EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia));
148 } 149 }
149 150
150 TEST_F(ImageTest, PlatformToSkiaToCopy) { 151 TEST_F(ImageTest, PlatformToSkiaToCopy) {
151 const SkBitmap* bitmap; 152 const SkBitmap* bitmap;
152 153
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 EXPECT_EQ(1U, image1.RepresentationCount()); 214 EXPECT_EQ(1U, image1.RepresentationCount());
214 215
215 gfx::Image image2(gt::CreatePlatformImage()); 216 gfx::Image image2(gt::CreatePlatformImage());
216 const SkBitmap* bitmap2 = image2.ToSkBitmap(); 217 const SkBitmap* bitmap2 = image2.ToSkBitmap();
217 gt::PlatformImage platform_image = gt::ToPlatformType(image2); 218 gt::PlatformImage platform_image = gt::ToPlatformType(image2);
218 EXPECT_EQ(kRepCount, image2.RepresentationCount()); 219 EXPECT_EQ(kRepCount, image2.RepresentationCount());
219 220
220 image1.SwapRepresentations(&image2); 221 image1.SwapRepresentations(&image2);
221 222
222 EXPECT_EQ(bitmap2, image1.ToSkBitmap()); 223 EXPECT_EQ(bitmap2, image1.ToSkBitmap());
223 EXPECT_TRUE(gt::PlatformImagesEqual(platform_image, 224 EXPECT_EQ(platform_image, gt::ToPlatformType(image1));
224 gt::ToPlatformType(image1)));
225 EXPECT_EQ(bitmap1, image2.ToSkBitmap()); 225 EXPECT_EQ(bitmap1, image2.ToSkBitmap());
226 EXPECT_EQ(kRepCount, image1.RepresentationCount()); 226 EXPECT_EQ(kRepCount, image1.RepresentationCount());
227 EXPECT_EQ(1U, image2.RepresentationCount()); 227 EXPECT_EQ(1U, image2.RepresentationCount());
228 } 228 }
229 229
230 TEST_F(ImageTest, Copy) { 230 TEST_F(ImageTest, Copy) {
231 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; 231 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
232 232
233 gfx::Image image1(gt::CreateBitmap(25, 25)); 233 gfx::Image image1(gt::CreateBitmap(25, 25));
234 gfx::Image image2(image1); 234 gfx::Image image2(image1);
235 235
236 EXPECT_EQ(1U, image1.RepresentationCount()); 236 EXPECT_EQ(1U, image1.RepresentationCount());
237 EXPECT_EQ(1U, image2.RepresentationCount()); 237 EXPECT_EQ(1U, image2.RepresentationCount());
238 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); 238 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap());
239 239
240 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image2))); 240 EXPECT_TRUE(gt::ToPlatformType(image2));
241 EXPECT_EQ(kRepCount, image2.RepresentationCount()); 241 EXPECT_EQ(kRepCount, image2.RepresentationCount());
242 EXPECT_EQ(kRepCount, image1.RepresentationCount()); 242 EXPECT_EQ(kRepCount, image1.RepresentationCount());
243 } 243 }
244 244
245 TEST_F(ImageTest, Assign) { 245 TEST_F(ImageTest, Assign) {
246 gfx::Image image1(gt::CreatePlatformImage()); 246 gfx::Image image1(gt::CreatePlatformImage());
247 gfx::Image image2 = image1; 247 gfx::Image image2 = image1;
248 248
249 EXPECT_EQ(1U, image1.RepresentationCount()); 249 EXPECT_EQ(1U, image1.RepresentationCount());
250 EXPECT_EQ(1U, image2.RepresentationCount()); 250 EXPECT_EQ(1U, image2.RepresentationCount());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // Sanity check. 286 // Sanity check.
287 EXPECT_EQ(1u, image.RepresentationCount()); 287 EXPECT_EQ(1u, image.RepresentationCount());
288 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size()); 288 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size());
289 } 289 }
290 290
291 // Integration tests with UI toolkit frameworks require linking against the 291 // Integration tests with UI toolkit frameworks require linking against the
292 // Views library and cannot be here (gfx_unittests doesn't include it). They 292 // Views library and cannot be here (gfx_unittests doesn't include it). They
293 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. 293 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc.
294 294
295 } // namespace 295 } // namespace
OLDNEW
« no previous file with comments | « ui/gfx/image/image.cc ('k') | ui/gfx/image/image_unittest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698