Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_info_util_unittest.cc
blob786e5b7bd08088f39e322749d62aefed020d8511
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
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/profile_info_util.h"
7 #include "grit/generated_resources.h"
8 #include "grit/theme_resources.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/image/image_skia.h"
13 #include "ui/gfx/image/image_skia_rep.h"
14 #include "ui/gfx/image/image_unittest_util.h"
16 namespace {
18 // Helper function to check that the image is sized properly
19 // and supports multiple pixel densities.
20 void VerifyScaling(gfx::Image& image, gfx::Size& size) {
21 gfx::Size canvas_size(100, 100);
22 gfx::Canvas canvas(canvas_size, 1.0f, false);
23 gfx::Canvas canvas2(canvas_size, 2.0f, false);
25 ASSERT_FALSE(gfx::test::IsEmpty(image));
26 EXPECT_EQ(image.Size(), size);
28 gfx::ImageSkia image_skia = *image.ToImageSkia();
29 canvas.DrawImageInt(image_skia, 15, 10);
30 EXPECT_TRUE(image.ToImageSkia()->HasRepresentation(1.0f));
32 canvas2.DrawImageInt(image_skia, 15, 10);
33 EXPECT_TRUE(image.ToImageSkia()->HasRepresentation(2.0f));
36 TEST(ProfileInfoUtilTest, SizedMenuIcon) {
37 // Test that an avatar icon isn't changed.
38 const gfx::Image& profile_image(
39 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
40 gfx::Image result =
41 profiles::GetSizedAvatarIconWithBorder(profile_image, false, 50, 50);
43 EXPECT_FALSE(gfx::test::IsEmpty(result));
44 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
46 // Test that a rectangular picture (e.g., GAIA image) is changed.
47 gfx::Image rect_picture(gfx::test::CreateImage());
49 gfx::Size size(30, 20);
50 gfx::Image result2 =
51 profiles::GetSizedAvatarIconWithBorder(
52 rect_picture, true, size.width(), size.height());
54 VerifyScaling(result2, size);
57 TEST(ProfileInfoUtilTest, MenuIcon) {
58 // Test that an avatar icon isn't changed.
59 const gfx::Image& profile_image(
60 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
61 gfx::Image result = profiles::GetAvatarIconForMenu(profile_image, false);
62 EXPECT_FALSE(gfx::test::IsEmpty(result));
63 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
65 // Test that a rectangular picture is changed.
66 gfx::Image rect_picture(gfx::test::CreateImage());
67 gfx::Size size(profiles::kAvatarIconWidth, profiles::kAvatarIconHeight);
68 gfx::Image result2 = profiles::GetAvatarIconForMenu(rect_picture, true);
70 VerifyScaling(result2, size);
73 TEST(ProfileInfoUtilTest, WebUIIcon) {
74 // Test that an avatar icon isn't changed.
75 const gfx::Image& profile_image(
76 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
77 gfx::Image result = profiles::GetAvatarIconForWebUI(profile_image, false);
78 EXPECT_FALSE(gfx::test::IsEmpty(result));
79 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
81 // Test that a rectangular picture is changed.
82 gfx::Image rect_picture(gfx::test::CreateImage());
83 gfx::Size size(profiles::kAvatarIconWidth, profiles::kAvatarIconHeight);
84 gfx::Image result2 = profiles::GetAvatarIconForWebUI(rect_picture, true);
86 VerifyScaling(result2, size);
89 TEST(ProfileInfoUtilTest, TitleBarIcon) {
90 int width = 100;
91 int height = 40;
93 // Test that an avatar icon isn't changed.
94 const gfx::Image& profile_image(
95 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
96 gfx::Image result = profiles::GetAvatarIconForTitleBar(
97 profile_image, false, width, height);
98 EXPECT_FALSE(gfx::test::IsEmpty(result));
99 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
101 // Test that a rectangular picture is changed.
102 gfx::Image rect_picture(gfx::test::CreateImage());
104 gfx::Size size(width, height);
105 gfx::Image result2 = profiles::GetAvatarIconForTitleBar(
106 rect_picture, true, width, height);
108 VerifyScaling(result2, size);
111 } // namespace