| 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 <vector> |
| 8 |
| 7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/gfx/gfx_paths.h" | 16 #include "ui/gfx/gfx_paths.h" |
| 15 #include "ui/gfx/icon_util_unittests_resource.h" | 17 #include "ui/gfx/icon_util_unittests_resource.h" |
| 16 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // Test with an empty and non-empty image. | 399 // Test with an empty and non-empty image. |
| 398 // The empty image should be ignored. | 400 // The empty image should be ignored. |
| 399 image_family.clear(); | 401 image_family.clear(); |
| 400 image_family.Add(gfx::Image()); | 402 image_family.Add(gfx::Image()); |
| 401 image_family.Add(gfx::Image::CreateFrom1xBitmap(CreateBlackSkBitmap(16, 16))); | 403 image_family.Add(gfx::Image::CreateFrom1xBitmap(CreateBlackSkBitmap(16, 16))); |
| 402 ASSERT_TRUE(IconUtil::CreateIconFileFromImageFamily(image_family, | 404 ASSERT_TRUE(IconUtil::CreateIconFileFromImageFamily(image_family, |
| 403 icon_filename)); | 405 icon_filename)); |
| 404 CheckAllIconSizes(icon_filename, 48); | 406 CheckAllIconSizes(icon_filename, 48); |
| 405 } | 407 } |
| 406 | 408 |
| 407 TEST_F(IconUtilTest, TestCreateSkBitmapFromIconResource48x48) { | 409 TEST_F(IconUtilTest, TestCreateImageFamilyFromIconResource) { |
| 408 HMODULE module = GetModuleHandle(NULL); | 410 HMODULE module = GetModuleHandle(NULL); |
| 409 scoped_ptr<SkBitmap> bitmap( | 411 scoped_ptr<gfx::ImageFamily> family( |
| 410 IconUtil::CreateSkBitmapFromIconResource(module, IDR_MAINFRAME, 48)); | 412 IconUtil::CreateImageFamilyFromIconResource(module, IDR_MAINFRAME)); |
| 411 ASSERT_TRUE(bitmap.get()); | 413 ASSERT_TRUE(family.get()); |
| 412 EXPECT_EQ(48, bitmap->width()); | 414 EXPECT_FALSE(family->empty()); |
| 413 EXPECT_EQ(48, bitmap->height()); | 415 std::vector<gfx::Image> images; |
| 414 } | 416 for (const auto& image : *family) |
| 417 images.push_back(image); |
| 415 | 418 |
| 416 TEST_F(IconUtilTest, TestCreateSkBitmapFromIconResource256x256) { | 419 // Assert that the family contains all of the images from the icon resource. |
| 417 HMODULE module = GetModuleHandle(NULL); | 420 EXPECT_EQ(5, images.size()); |
| 418 scoped_ptr<SkBitmap> bitmap( | 421 EXPECT_EQ(16, images[0].Width()); |
| 419 IconUtil::CreateSkBitmapFromIconResource(module, IDR_MAINFRAME, 256)); | 422 EXPECT_EQ(24, images[1].Width()); |
| 420 ASSERT_TRUE(bitmap.get()); | 423 EXPECT_EQ(32, images[2].Width()); |
| 421 EXPECT_EQ(256, bitmap->width()); | 424 EXPECT_EQ(48, images[3].Width()); |
| 422 EXPECT_EQ(256, bitmap->height()); | 425 EXPECT_EQ(256, images[4].Width()); |
| 423 } | 426 } |
| 424 | 427 |
| 425 // This tests that kNumIconDimensionsUpToMediumSize has the correct value. | 428 // This tests that kNumIconDimensionsUpToMediumSize has the correct value. |
| 426 TEST_F(IconUtilTest, TestNumIconDimensionsUpToMediumSize) { | 429 TEST_F(IconUtilTest, TestNumIconDimensionsUpToMediumSize) { |
| 427 ASSERT_LE(IconUtil::kNumIconDimensionsUpToMediumSize, | 430 ASSERT_LE(IconUtil::kNumIconDimensionsUpToMediumSize, |
| 428 IconUtil::kNumIconDimensions); | 431 IconUtil::kNumIconDimensions); |
| 429 EXPECT_EQ(IconUtil::kMediumIconSize, | 432 EXPECT_EQ(IconUtil::kMediumIconSize, |
| 430 IconUtil::kIconDimensions[ | 433 IconUtil::kIconDimensions[ |
| 431 IconUtil::kNumIconDimensionsUpToMediumSize - 1]); | 434 IconUtil::kNumIconDimensionsUpToMediumSize - 1]); |
| 432 } | 435 } |
| OLD | NEW |