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.
4
5 #include "chrome/browser/themes/theme_properties.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace {
10
11 typedef testing::Test ThemePropertiesTest;
12
TEST_F(ThemePropertiesTest,AlignmentConversion)13 TEST_F(ThemePropertiesTest, AlignmentConversion) {
14 // Verify that we get out what we put in.
15 std::string top_left = "left top";
16 int alignment = ThemeProperties::StringToAlignment(top_left);
17 EXPECT_EQ(ThemeProperties::ALIGN_TOP | ThemeProperties::ALIGN_LEFT,
18 alignment);
19 EXPECT_EQ(top_left, ThemeProperties::AlignmentToString(alignment));
20
21 // We get back a normalized version of what we put in.
22 alignment = ThemeProperties::StringToAlignment("top");
23 EXPECT_EQ(ThemeProperties::ALIGN_TOP, alignment);
24 EXPECT_EQ("center top", ThemeProperties::AlignmentToString(alignment));
25
26 alignment = ThemeProperties::StringToAlignment("left");
27 EXPECT_EQ(ThemeProperties::ALIGN_LEFT, alignment);
28 EXPECT_EQ("left center", ThemeProperties::AlignmentToString(alignment));
29
30 alignment = ThemeProperties::StringToAlignment("right");
31 EXPECT_EQ(ThemeProperties::ALIGN_RIGHT, alignment);
32 EXPECT_EQ("right center", ThemeProperties::AlignmentToString(alignment));
33
34 alignment = ThemeProperties::StringToAlignment("righttopbottom");
35 EXPECT_EQ(ThemeProperties::ALIGN_CENTER, alignment);
36 EXPECT_EQ("center center", ThemeProperties::AlignmentToString(alignment));
37 }
38
TEST_F(ThemePropertiesTest,AlignmentConversionInput)39 TEST_F(ThemePropertiesTest, AlignmentConversionInput) {
40 // Verify that we output in an expected format.
41 int alignment = ThemeProperties::StringToAlignment("bottom right");
42 EXPECT_EQ("right bottom", ThemeProperties::AlignmentToString(alignment));
43
44 // Verify that bad strings don't cause explosions.
45 alignment = ThemeProperties::StringToAlignment("new zealand");
46 EXPECT_EQ("center center", ThemeProperties::AlignmentToString(alignment));
47
48 // Verify that bad strings don't cause explosions.
49 alignment = ThemeProperties::StringToAlignment("new zealand top");
50 EXPECT_EQ("center top", ThemeProperties::AlignmentToString(alignment));
51
52 // Verify that bad strings don't cause explosions.
53 alignment = ThemeProperties::StringToAlignment("new zealandtop");
54 EXPECT_EQ("center center", ThemeProperties::AlignmentToString(alignment));
55 }
56
57 }; // namespace
58