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

Side by Side Diff: ui/gfx/icon_util_unittest.cc

Issue 326583002: use setInfo instead of (deprecated) setConfig (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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
« no previous file with comments | « no previous file | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/gfx/icon_util.h" 5 #include "ui/gfx/icon_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 // The following test case makes sure IconUtil::CreateHICONFromSkBitmap fails 166 // The following test case makes sure IconUtil::CreateHICONFromSkBitmap fails
167 // gracefully when called with invalid input parameters. 167 // gracefully when called with invalid input parameters.
168 TEST_F(IconUtilTest, TestBitmapToIconInvalidParameters) { 168 TEST_F(IconUtilTest, TestBitmapToIconInvalidParameters) {
169 HICON icon = NULL; 169 HICON icon = NULL;
170 scoped_ptr<SkBitmap> bitmap; 170 scoped_ptr<SkBitmap> bitmap;
171 171
172 // Wrong bitmap format. 172 // Wrong bitmap format.
173 bitmap.reset(new SkBitmap); 173 bitmap.reset(new SkBitmap);
174 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 174 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
175 bitmap->setConfig(SkImageInfo::MakeA8(kSmallIconWidth, kSmallIconHeight)); 175 bitmap->setInfo(SkImageInfo::MakeA8(kSmallIconWidth, kSmallIconHeight));
176 icon = IconUtil::CreateHICONFromSkBitmap(*bitmap); 176 icon = IconUtil::CreateHICONFromSkBitmap(*bitmap);
177 EXPECT_EQ(icon, static_cast<HICON>(NULL)); 177 EXPECT_EQ(icon, static_cast<HICON>(NULL));
178 178
179 // Invalid bitmap size. 179 // Invalid bitmap size.
180 bitmap.reset(new SkBitmap); 180 bitmap.reset(new SkBitmap);
181 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 181 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
182 bitmap->setConfig(SkImageInfo::MakeN32Premul(0, 0)); 182 bitmap->setInfo(SkImageInfo::MakeN32Premul(0, 0));
183 icon = IconUtil::CreateHICONFromSkBitmap(*bitmap); 183 icon = IconUtil::CreateHICONFromSkBitmap(*bitmap);
184 EXPECT_EQ(icon, static_cast<HICON>(NULL)); 184 EXPECT_EQ(icon, static_cast<HICON>(NULL));
185 185
186 // Valid bitmap configuration but no pixels allocated. 186 // Valid bitmap configuration but no pixels allocated.
187 bitmap.reset(new SkBitmap); 187 bitmap.reset(new SkBitmap);
188 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 188 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
189 bitmap->setConfig(SkImageInfo::MakeN32Premul(kSmallIconWidth, 189 bitmap->setInfo(SkImageInfo::MakeN32Premul(kSmallIconWidth,
190 kSmallIconHeight)); 190 kSmallIconHeight));
191 icon = IconUtil::CreateHICONFromSkBitmap(*bitmap); 191 icon = IconUtil::CreateHICONFromSkBitmap(*bitmap);
192 EXPECT_TRUE(icon == NULL); 192 EXPECT_TRUE(icon == NULL);
193 } 193 }
194 194
195 // The following test case makes sure IconUtil::CreateIconFileFromImageFamily 195 // The following test case makes sure IconUtil::CreateIconFileFromImageFamily
196 // fails gracefully when called with invalid input parameters. 196 // fails gracefully when called with invalid input parameters.
197 TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) { 197 TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) {
198 scoped_ptr<SkBitmap> bitmap; 198 scoped_ptr<SkBitmap> bitmap;
199 gfx::ImageFamily image_family; 199 gfx::ImageFamily image_family;
200 base::FilePath valid_icon_filename = temp_directory_.path().AppendASCII( 200 base::FilePath valid_icon_filename = temp_directory_.path().AppendASCII(
201 kTempIconFilename); 201 kTempIconFilename);
202 base::FilePath invalid_icon_filename = temp_directory_.path().AppendASCII( 202 base::FilePath invalid_icon_filename = temp_directory_.path().AppendASCII(
203 "<>?.ico"); 203 "<>?.ico");
204 204
205 // Wrong bitmap format. 205 // Wrong bitmap format.
206 bitmap.reset(new SkBitmap); 206 bitmap.reset(new SkBitmap);
207 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 207 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
208 bitmap->setConfig(SkImageInfo::MakeA8(kSmallIconWidth, kSmallIconHeight));
209 // Must allocate pixels or else ImageSkia will ignore the bitmap and just 208 // Must allocate pixels or else ImageSkia will ignore the bitmap and just
210 // return an empty image. 209 // return an empty image.
211 bitmap->allocPixels(); 210 bitmap->allocPixels(SkImageInfo::MakeA8(kSmallIconWidth, kSmallIconHeight));
212 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height()); 211 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height());
213 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); 212 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
214 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, 213 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
215 valid_icon_filename)); 214 valid_icon_filename));
216 EXPECT_FALSE(base::PathExists(valid_icon_filename)); 215 EXPECT_FALSE(base::PathExists(valid_icon_filename));
217 216
218 // Invalid bitmap size. 217 // Invalid bitmap size.
219 image_family.clear(); 218 image_family.clear();
220 bitmap.reset(new SkBitmap); 219 bitmap.reset(new SkBitmap);
221 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 220 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
222 bitmap->setConfig(SkImageInfo::MakeN32Premul(0, 0)); 221 bitmap->allocPixels(SkImageInfo::MakeN32Premul(0, 0));
223 bitmap->allocPixels();
224 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); 222 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
225 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, 223 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
226 valid_icon_filename)); 224 valid_icon_filename));
227 EXPECT_FALSE(base::PathExists(valid_icon_filename)); 225 EXPECT_FALSE(base::PathExists(valid_icon_filename));
228 226
229 // Bitmap with no allocated pixels. 227 // Bitmap with no allocated pixels.
230 image_family.clear(); 228 image_family.clear();
231 bitmap.reset(new SkBitmap); 229 bitmap.reset(new SkBitmap);
232 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 230 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
233 bitmap->setConfig(SkImageInfo::MakeN32Premul(kSmallIconWidth, 231 bitmap->setInfo(SkImageInfo::MakeN32Premul(kSmallIconWidth,
234 kSmallIconHeight)); 232 kSmallIconHeight));
235 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); 233 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
236 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, 234 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
237 valid_icon_filename)); 235 valid_icon_filename));
238 EXPECT_FALSE(base::PathExists(valid_icon_filename)); 236 EXPECT_FALSE(base::PathExists(valid_icon_filename));
239 237
240 // Invalid file name. 238 // Invalid file name.
241 image_family.clear(); 239 image_family.clear();
242 bitmap->allocPixels(); 240 bitmap->allocPixels();
243 // Setting the pixels to black. 241 // Setting the pixels to black.
244 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height() * 4); 242 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height() * 4);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 422 }
425 423
426 // This tests that kNumIconDimensionsUpToMediumSize has the correct value. 424 // This tests that kNumIconDimensionsUpToMediumSize has the correct value.
427 TEST_F(IconUtilTest, TestNumIconDimensionsUpToMediumSize) { 425 TEST_F(IconUtilTest, TestNumIconDimensionsUpToMediumSize) {
428 ASSERT_LE(IconUtil::kNumIconDimensionsUpToMediumSize, 426 ASSERT_LE(IconUtil::kNumIconDimensionsUpToMediumSize,
429 IconUtil::kNumIconDimensions); 427 IconUtil::kNumIconDimensions);
430 EXPECT_EQ(IconUtil::kMediumIconSize, 428 EXPECT_EQ(IconUtil::kMediumIconSize,
431 IconUtil::kIconDimensions[ 429 IconUtil::kIconDimensions[
432 IconUtil::kNumIconDimensionsUpToMediumSize - 1]); 430 IconUtil::kNumIconDimensionsUpToMediumSize - 1]);
433 } 431 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698