Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_avatar_icon_util_unittest.cc
blob66f1279a2ddee9fa9e6bf24b7758d23e59ffb0c1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
7 #include "grit/theme_resources.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/image/image_skia_rep.h"
13 #include "ui/gfx/image/image_unittest_util.h"
15 namespace {
17 // Helper function to check that the image is sized properly
18 // and supports multiple pixel densities.
19 void VerifyScaling(gfx::Image& image, gfx::Size& size) {
20 gfx::Size canvas_size(100, 100);
21 gfx::Canvas canvas(canvas_size, 1.0f, false);
22 gfx::Canvas canvas2(canvas_size, 2.0f, false);
24 ASSERT_FALSE(gfx::test::IsEmpty(image));
25 EXPECT_EQ(image.Size(), size);
27 gfx::ImageSkia image_skia = *image.ToImageSkia();
28 canvas.DrawImageInt(image_skia, 15, 10);
29 EXPECT_TRUE(image.ToImageSkia()->HasRepresentation(1.0f));
31 canvas2.DrawImageInt(image_skia, 15, 10);
32 EXPECT_TRUE(image.ToImageSkia()->HasRepresentation(2.0f));
35 TEST(ProfileInfoUtilTest, SizedMenuIcon) {
36 // Test that an avatar icon isn't changed.
37 const gfx::Image& profile_image(
38 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
39 gfx::Image result =
40 profiles::GetSizedAvatarIcon(profile_image, false, 50, 50);
42 EXPECT_FALSE(gfx::test::IsEmpty(result));
43 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
45 // Test that a rectangular picture (e.g., GAIA image) is changed.
46 gfx::Image rect_picture(gfx::test::CreateImage());
48 gfx::Size size(30, 20);
49 gfx::Image result2 = profiles::GetSizedAvatarIcon(
50 rect_picture, true, size.width(), size.height());
52 VerifyScaling(result2, size);
55 TEST(ProfileInfoUtilTest, MenuIcon) {
56 // Test that an avatar icon isn't changed.
57 const gfx::Image& profile_image(
58 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
59 gfx::Image result = profiles::GetAvatarIconForMenu(profile_image, false);
60 EXPECT_FALSE(gfx::test::IsEmpty(result));
61 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
63 // Test that a rectangular picture is changed.
64 gfx::Image rect_picture(gfx::test::CreateImage());
65 gfx::Size size(profiles::kAvatarIconWidth, profiles::kAvatarIconHeight);
66 gfx::Image result2 = profiles::GetAvatarIconForMenu(rect_picture, true);
68 VerifyScaling(result2, size);
71 TEST(ProfileInfoUtilTest, WebUIIcon) {
72 // Test that an avatar icon isn't changed.
73 const gfx::Image& profile_image(
74 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
75 gfx::Image result = profiles::GetAvatarIconForWebUI(profile_image, false);
76 EXPECT_FALSE(gfx::test::IsEmpty(result));
77 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
79 // Test that a rectangular picture is changed.
80 gfx::Image rect_picture(gfx::test::CreateImage());
81 gfx::Size size(profiles::kAvatarIconWidth, profiles::kAvatarIconHeight);
82 gfx::Image result2 = profiles::GetAvatarIconForWebUI(rect_picture, true);
84 VerifyScaling(result2, size);
87 TEST(ProfileInfoUtilTest, TitleBarIcon) {
88 int width = 100;
89 int height = 40;
91 // Test that an avatar icon isn't changed.
92 const gfx::Image& profile_image(
93 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
94 gfx::Image result = profiles::GetAvatarIconForTitleBar(
95 profile_image, false, width, height);
96 EXPECT_FALSE(gfx::test::IsEmpty(result));
97 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
99 // Test that a rectangular picture is changed.
100 gfx::Image rect_picture(gfx::test::CreateImage());
102 gfx::Size size(width, height);
103 gfx::Image result2 = profiles::GetAvatarIconForTitleBar(
104 rect_picture, true, width, height);
106 VerifyScaling(result2, size);
109 } // namespace