Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_avatar_icon_util_unittest.cc
blob1cb97ab4f00789e24fea8e30120825bd8db3ee98
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/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::GetSizedAvatarIcon(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 = profiles::GetSizedAvatarIcon(
51 rect_picture, true, size.width(), size.height());
53 VerifyScaling(result2, size);
56 TEST(ProfileInfoUtilTest, MenuIcon) {
57 // Test that an avatar icon isn't changed.
58 const gfx::Image& profile_image(
59 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
60 gfx::Image result = profiles::GetAvatarIconForMenu(profile_image, false);
61 EXPECT_FALSE(gfx::test::IsEmpty(result));
62 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
64 // Test that a rectangular picture is changed.
65 gfx::Image rect_picture(gfx::test::CreateImage());
66 gfx::Size size(profiles::kAvatarIconWidth, profiles::kAvatarIconHeight);
67 gfx::Image result2 = profiles::GetAvatarIconForMenu(rect_picture, true);
69 VerifyScaling(result2, size);
72 TEST(ProfileInfoUtilTest, WebUIIcon) {
73 // Test that an avatar icon isn't changed.
74 const gfx::Image& profile_image(
75 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
76 gfx::Image result = profiles::GetAvatarIconForWebUI(profile_image, false);
77 EXPECT_FALSE(gfx::test::IsEmpty(result));
78 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
80 // Test that a rectangular picture is changed.
81 gfx::Image rect_picture(gfx::test::CreateImage());
82 gfx::Size size(profiles::kAvatarIconWidth, profiles::kAvatarIconHeight);
83 gfx::Image result2 = profiles::GetAvatarIconForWebUI(rect_picture, true);
85 VerifyScaling(result2, size);
88 TEST(ProfileInfoUtilTest, TitleBarIcon) {
89 int width = 100;
90 int height = 40;
92 // Test that an avatar icon isn't changed.
93 const gfx::Image& profile_image(
94 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_PROFILE_AVATAR_0));
95 gfx::Image result = profiles::GetAvatarIconForTitleBar(
96 profile_image, false, width, height);
97 EXPECT_FALSE(gfx::test::IsEmpty(result));
98 EXPECT_TRUE(gfx::test::IsEqual(profile_image, result));
100 // Test that a rectangular picture is changed.
101 gfx::Image rect_picture(gfx::test::CreateImage());
103 gfx::Size size(width, height);
104 gfx::Image result2 = profiles::GetAvatarIconForTitleBar(
105 rect_picture, true, width, height);
107 VerifyScaling(result2, size);
110 } // namespace