OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 kSmallIconHeight)); | 193 kSmallIconHeight)); |
194 icon = IconUtil::CreateHICONFromSkBitmap(*bitmap); | 194 icon = IconUtil::CreateHICONFromSkBitmap(*bitmap); |
195 EXPECT_FALSE(icon.is_valid()); | 195 EXPECT_FALSE(icon.is_valid()); |
196 } | 196 } |
197 | 197 |
198 // The following test case makes sure IconUtil::CreateIconFileFromImageFamily | 198 // The following test case makes sure IconUtil::CreateIconFileFromImageFamily |
199 // fails gracefully when called with invalid input parameters. | 199 // fails gracefully when called with invalid input parameters. |
200 TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) { | 200 TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) { |
201 std::unique_ptr<SkBitmap> bitmap; | 201 std::unique_ptr<SkBitmap> bitmap; |
202 gfx::ImageFamily image_family; | 202 gfx::ImageFamily image_family; |
203 base::FilePath valid_icon_filename = temp_directory_.path().AppendASCII( | 203 base::FilePath valid_icon_filename = |
204 kTempIconFilename); | 204 temp_directory_.GetPath().AppendASCII(kTempIconFilename); |
205 base::FilePath invalid_icon_filename = temp_directory_.path().AppendASCII( | 205 base::FilePath invalid_icon_filename = |
206 "<>?.ico"); | 206 temp_directory_.GetPath().AppendASCII("<>?.ico"); |
207 | 207 |
208 // Wrong bitmap format. | 208 // Wrong bitmap format. |
209 bitmap.reset(new SkBitmap); | 209 bitmap.reset(new SkBitmap); |
210 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); | 210 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); |
211 // Must allocate pixels or else ImageSkia will ignore the bitmap and just | 211 // Must allocate pixels or else ImageSkia will ignore the bitmap and just |
212 // return an empty image. | 212 // return an empty image. |
213 bitmap->allocPixels(SkImageInfo::MakeA8(kSmallIconWidth, kSmallIconHeight)); | 213 bitmap->allocPixels(SkImageInfo::MakeA8(kSmallIconWidth, kSmallIconHeight)); |
214 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height()); | 214 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height()); |
215 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); | 215 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); |
216 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, | 216 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, |
(...skipping 28 matching lines...) Expand all Loading... |
245 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height() * 4); | 245 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height() * 4); |
246 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); | 246 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); |
247 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, | 247 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, |
248 invalid_icon_filename)); | 248 invalid_icon_filename)); |
249 EXPECT_FALSE(base::PathExists(invalid_icon_filename)); | 249 EXPECT_FALSE(base::PathExists(invalid_icon_filename)); |
250 } | 250 } |
251 | 251 |
252 // This test case makes sure IconUtil::CreateIconFileFromImageFamily fails if | 252 // This test case makes sure IconUtil::CreateIconFileFromImageFamily fails if |
253 // the image family is empty or invalid. | 253 // the image family is empty or invalid. |
254 TEST_F(IconUtilTest, TestCreateIconFileEmptyImageFamily) { | 254 TEST_F(IconUtilTest, TestCreateIconFileEmptyImageFamily) { |
255 base::FilePath icon_filename = temp_directory_.path().AppendASCII( | 255 base::FilePath icon_filename = |
256 kTempIconFilename); | 256 temp_directory_.GetPath().AppendASCII(kTempIconFilename); |
257 | 257 |
258 // Empty image family. | 258 // Empty image family. |
259 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(gfx::ImageFamily(), | 259 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(gfx::ImageFamily(), |
260 icon_filename)); | 260 icon_filename)); |
261 EXPECT_FALSE(base::PathExists(icon_filename)); | 261 EXPECT_FALSE(base::PathExists(icon_filename)); |
262 | 262 |
263 // Image family with only an empty image. | 263 // Image family with only an empty image. |
264 gfx::ImageFamily image_family; | 264 gfx::ImageFamily image_family; |
265 image_family.Add(gfx::Image()); | 265 image_family.Add(gfx::Image()); |
266 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, | 266 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 EXPECT_EQ(bitmap_info.bmiHeader.biBitCount, 32); | 335 EXPECT_EQ(bitmap_info.bmiHeader.biBitCount, 32); |
336 ::ReleaseDC(NULL, hdc); | 336 ::ReleaseDC(NULL, hdc); |
337 } | 337 } |
338 | 338 |
339 // This test case makes sure that CreateIconFileFromImageFamily creates a | 339 // This test case makes sure that CreateIconFileFromImageFamily creates a |
340 // valid .ico file given an ImageFamily, and appropriately creates all icon | 340 // valid .ico file given an ImageFamily, and appropriately creates all icon |
341 // sizes from the given input. | 341 // sizes from the given input. |
342 TEST_F(IconUtilTest, TestCreateIconFileFromImageFamily) { | 342 TEST_F(IconUtilTest, TestCreateIconFileFromImageFamily) { |
343 gfx::ImageFamily image_family; | 343 gfx::ImageFamily image_family; |
344 base::FilePath icon_filename = | 344 base::FilePath icon_filename = |
345 temp_directory_.path().AppendASCII(kTempIconFilename); | 345 temp_directory_.GetPath().AppendASCII(kTempIconFilename); |
346 | 346 |
347 // Test with only a 16x16 icon. Should only scale up to 48x48. | 347 // Test with only a 16x16 icon. Should only scale up to 48x48. |
348 image_family.Add(gfx::Image::CreateFrom1xBitmap( | 348 image_family.Add(gfx::Image::CreateFrom1xBitmap( |
349 CreateBlackSkBitmap(kSmallIconWidth, kSmallIconHeight))); | 349 CreateBlackSkBitmap(kSmallIconWidth, kSmallIconHeight))); |
350 ASSERT_TRUE(IconUtil::CreateIconFileFromImageFamily(image_family, | 350 ASSERT_TRUE(IconUtil::CreateIconFileFromImageFamily(image_family, |
351 icon_filename)); | 351 icon_filename)); |
352 CheckAllIconSizes(icon_filename, 48); | 352 CheckAllIconSizes(icon_filename, 48); |
353 | 353 |
354 // Test with a 48x48 icon. Should only scale down. | 354 // Test with a 48x48 icon. Should only scale down. |
355 image_family.Add(gfx::Image::CreateFrom1xBitmap(CreateBlackSkBitmap(48, 48))); | 355 image_family.Add(gfx::Image::CreateFrom1xBitmap(CreateBlackSkBitmap(48, 48))); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 } | 423 } |
424 | 424 |
425 // This tests that kNumIconDimensionsUpToMediumSize has the correct value. | 425 // This tests that kNumIconDimensionsUpToMediumSize has the correct value. |
426 TEST_F(IconUtilTest, TestNumIconDimensionsUpToMediumSize) { | 426 TEST_F(IconUtilTest, TestNumIconDimensionsUpToMediumSize) { |
427 ASSERT_LE(IconUtil::kNumIconDimensionsUpToMediumSize, | 427 ASSERT_LE(IconUtil::kNumIconDimensionsUpToMediumSize, |
428 IconUtil::kNumIconDimensions); | 428 IconUtil::kNumIconDimensions); |
429 EXPECT_EQ(IconUtil::kMediumIconSize, | 429 EXPECT_EQ(IconUtil::kMediumIconSize, |
430 IconUtil::kIconDimensions[ | 430 IconUtil::kIconDimensions[ |
431 IconUtil::kNumIconDimensionsUpToMediumSize - 1]); | 431 IconUtil::kNumIconDimensionsUpToMediumSize - 1]); |
432 } | 432 } |
OLD | NEW |