OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/font_list.h" | 5 #include "ui/gfx/font_list.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 #if !defined(OS_ANDROID) | |
17 // Helper function for comparing fonts for equality. | 18 // Helper function for comparing fonts for equality. |
18 std::string FontToString(const gfx::Font& font) { | 19 std::string FontToString(const gfx::Font& font) { |
19 std::string font_string = font.GetFontName(); | 20 std::string font_string = font.GetFontName(); |
20 font_string += "|"; | 21 font_string += "|"; |
21 font_string += base::IntToString(font.GetFontSize()); | 22 font_string += base::IntToString(font.GetFontSize()); |
22 int style = font.GetStyle(); | 23 int style = font.GetStyle(); |
23 if (style & gfx::Font::BOLD) | 24 if (style & gfx::Font::BOLD) |
24 font_string += "|bold"; | 25 font_string += "|bold"; |
25 if (style & gfx::Font::ITALIC) | 26 if (style & gfx::Font::ITALIC) |
26 font_string += "|italic"; | 27 font_string += "|italic"; |
27 if (style & gfx::Font::UNDERLINE) | 28 if (style & gfx::Font::UNDERLINE) |
28 font_string += "|underline"; | 29 font_string += "|underline"; |
29 return font_string; | 30 return font_string; |
30 } | 31 } |
32 #endif | |
31 | 33 |
32 } // namespace | 34 } // namespace |
33 | 35 |
34 namespace gfx { | 36 namespace gfx { |
35 | 37 |
36 TEST(FontListTest, ParseDescription) { | 38 TEST(FontListTest, ParseDescription) { |
37 std::vector<std::string> families; | 39 std::vector<std::string> families; |
38 int style = gfx::Font::NORMAL; | 40 int style = gfx::Font::NORMAL; |
39 int size_pixels = 0; | 41 int size_pixels = 0; |
40 | 42 |
(...skipping 25 matching lines...) Expand all Loading... | |
66 EXPECT_FALSE(FontList::ParseDescription("Arial,12px,", &families, &style, | 68 EXPECT_FALSE(FontList::ParseDescription("Arial,12px,", &families, &style, |
67 &size_pixels)); | 69 &size_pixels)); |
68 EXPECT_FALSE(FontList::ParseDescription("Arial,0px", &families, &style, | 70 EXPECT_FALSE(FontList::ParseDescription("Arial,0px", &families, &style, |
69 &size_pixels)); | 71 &size_pixels)); |
70 EXPECT_FALSE(FontList::ParseDescription("Arial,-1px", &families, &style, | 72 EXPECT_FALSE(FontList::ParseDescription("Arial,-1px", &families, &style, |
71 &size_pixels)); | 73 &size_pixels)); |
72 EXPECT_FALSE(FontList::ParseDescription("Arial,foo 12px", &families, &style, | 74 EXPECT_FALSE(FontList::ParseDescription("Arial,foo 12px", &families, &style, |
73 &size_pixels)); | 75 &size_pixels)); |
74 } | 76 } |
75 | 77 |
78 TEST(FontListTest, FontDescString_GetStyle) { | |
79 FontList font_list = FontList("Arial,Sans serif, 8px"); | |
80 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); | |
81 | |
82 font_list = FontList("Arial,Sans serif,Bold 8px"); | |
83 EXPECT_EQ(Font::BOLD, font_list.GetFontStyle()); | |
84 | |
85 font_list = FontList("Arial,Sans serif,Italic 8px"); | |
86 EXPECT_EQ(Font::ITALIC, font_list.GetFontStyle()); | |
87 | |
88 font_list = FontList("Arial,Italic Bold 8px"); | |
89 EXPECT_EQ(Font::BOLD | Font::ITALIC, font_list.GetFontStyle()); | |
90 } | |
91 | |
92 // TODO(489354): Enable tests on Android | |
93 #if !defined(OS_ANDROID) | |
jbudorick
2015/05/18 19:17:56
I think this should be done via the MAYBE_FooTest
pkotwicz
2015/05/18 20:59:05
Done.
| |
76 TEST(FontListTest, Fonts_FromDescString) { | 94 TEST(FontListTest, Fonts_FromDescString) { |
77 // Test init from font name size string. | 95 // Test init from font name size string. |
78 FontList font_list = FontList("arial, Courier New, 13px"); | 96 FontList font_list = FontList("arial, Courier New, 13px"); |
79 const std::vector<Font>& fonts = font_list.GetFonts(); | 97 const std::vector<Font>& fonts = font_list.GetFonts(); |
80 ASSERT_EQ(2U, fonts.size()); | 98 ASSERT_EQ(2U, fonts.size()); |
81 EXPECT_EQ("arial|13", FontToString(fonts[0])); | 99 EXPECT_EQ("arial|13", FontToString(fonts[0])); |
82 EXPECT_EQ("Courier New|13", FontToString(fonts[1])); | 100 EXPECT_EQ("Courier New|13", FontToString(fonts[1])); |
83 } | 101 } |
84 | 102 |
85 TEST(FontListTest, Fonts_FromDescStringInFlexibleFormat) { | 103 TEST(FontListTest, Fonts_FromDescStringInFlexibleFormat) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 std::vector<Font> input_fonts; | 149 std::vector<Font> input_fonts; |
132 input_fonts.push_back(font.Derive(0, Font::BOLD)); | 150 input_fonts.push_back(font.Derive(0, Font::BOLD)); |
133 input_fonts.push_back(font_1.Derive(-2, Font::BOLD)); | 151 input_fonts.push_back(font_1.Derive(-2, Font::BOLD)); |
134 FontList font_list = FontList(input_fonts); | 152 FontList font_list = FontList(input_fonts); |
135 const std::vector<Font>& fonts = font_list.GetFonts(); | 153 const std::vector<Font>& fonts = font_list.GetFonts(); |
136 ASSERT_EQ(2U, fonts.size()); | 154 ASSERT_EQ(2U, fonts.size()); |
137 EXPECT_EQ("Arial|8|bold", FontToString(fonts[0])); | 155 EXPECT_EQ("Arial|8|bold", FontToString(fonts[0])); |
138 EXPECT_EQ("Courier New|8|bold", FontToString(fonts[1])); | 156 EXPECT_EQ("Courier New|8|bold", FontToString(fonts[1])); |
139 } | 157 } |
140 | 158 |
141 TEST(FontListTest, FontDescString_GetStyle) { | |
142 FontList font_list = FontList("Arial,Sans serif, 8px"); | |
143 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); | |
144 | |
145 font_list = FontList("Arial,Sans serif,Bold 8px"); | |
146 EXPECT_EQ(Font::BOLD, font_list.GetFontStyle()); | |
147 | |
148 font_list = FontList("Arial,Sans serif,Italic 8px"); | |
149 EXPECT_EQ(Font::ITALIC, font_list.GetFontStyle()); | |
150 | |
151 font_list = FontList("Arial,Italic Bold 8px"); | |
152 EXPECT_EQ(Font::BOLD | Font::ITALIC, font_list.GetFontStyle()); | |
153 } | |
154 | |
155 TEST(FontListTest, Fonts_GetStyle) { | 159 TEST(FontListTest, Fonts_GetStyle) { |
156 std::vector<Font> fonts; | 160 std::vector<Font> fonts; |
157 fonts.push_back(gfx::Font("Arial", 8)); | 161 fonts.push_back(gfx::Font("Arial", 8)); |
158 fonts.push_back(gfx::Font("Sans serif", 8)); | 162 fonts.push_back(gfx::Font("Sans serif", 8)); |
159 FontList font_list = FontList(fonts); | 163 FontList font_list = FontList(fonts); |
160 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); | 164 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); |
161 fonts[0] = fonts[0].Derive(0, Font::ITALIC | Font::BOLD); | 165 fonts[0] = fonts[0].Derive(0, Font::ITALIC | Font::BOLD); |
162 fonts[1] = fonts[1].Derive(0, Font::ITALIC | Font::BOLD); | 166 fonts[1] = fonts[1].Derive(0, Font::ITALIC | Font::BOLD); |
163 font_list = FontList(fonts); | 167 font_list = FontList(fonts); |
164 EXPECT_EQ(Font::ITALIC | Font::BOLD, font_list.GetFontStyle()); | 168 EXPECT_EQ(Font::ITALIC | Font::BOLD, font_list.GetFontStyle()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 EXPECT_LT(derived_1.GetFontSize(), font_list.GetFontSize()); | 242 EXPECT_LT(derived_1.GetFontSize(), font_list.GetFontSize()); |
239 | 243 |
240 // A larger upper bound should not change the height of the font list. | 244 // A larger upper bound should not change the height of the font list. |
241 const int height_2 = font_list.GetHeight() + 5; | 245 const int height_2 = font_list.GetHeight() + 5; |
242 FontList derived_2 = font_list.DeriveWithHeightUpperBound(height_2); | 246 FontList derived_2 = font_list.DeriveWithHeightUpperBound(height_2); |
243 EXPECT_LE(derived_2.GetHeight(), height_2); | 247 EXPECT_LE(derived_2.GetHeight(), height_2); |
244 EXPECT_EQ(font_list.GetHeight(), derived_2.GetHeight()); | 248 EXPECT_EQ(font_list.GetHeight(), derived_2.GetHeight()); |
245 EXPECT_EQ(font_list.GetFontSize(), derived_2.GetFontSize()); | 249 EXPECT_EQ(font_list.GetFontSize(), derived_2.GetFontSize()); |
246 } | 250 } |
247 | 251 |
252 #endif // !defined(OS_ANDROID) | |
253 | |
248 } // namespace gfx | 254 } // namespace gfx |
OLD | NEW |