Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ui/gfx/font_list_unittest.cc

Issue 119993002: Makes gfx::FontList carry UNDERLINE flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« ui/gfx/font_list.cc ('K') | « ui/gfx/font_list.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Helper function for comparing fonts for equality. 17 // Helper function for comparing fonts for equality.
18 std::string FontToString(const gfx::Font& font) { 18 std::string FontToString(const gfx::Font& font) {
19 std::string font_string = font.GetFontName(); 19 std::string font_string = font.GetFontName();
20 font_string += "|"; 20 font_string += "|";
21 font_string += base::IntToString(font.GetFontSize()); 21 font_string += base::IntToString(font.GetFontSize());
22 int style = font.GetStyle(); 22 int style = font.GetStyle();
23 if (style & gfx::Font::BOLD) 23 if (style & gfx::Font::BOLD)
24 font_string += "|bold"; 24 font_string += "|bold";
25 if (style & gfx::Font::ITALIC) 25 if (style & gfx::Font::ITALIC)
26 font_string += "|italic"; 26 font_string += "|italic";
27 if (style & gfx::Font::UNDERLINE)
28 font_string += "|underline";
27 return font_string; 29 return font_string;
28 } 30 }
29 31
30 } // namespace 32 } // namespace
31 33
32 namespace gfx { 34 namespace gfx {
33 35
34 TEST(FontListTest, FontDescString_FromDescString) { 36 TEST(FontListTest, FontDescString_FromDescString) {
35 // Test init from font name style size string. 37 // Test init from font name style size string.
36 FontList font_list = FontList("Droid Sans serif, Sans serif, 10px"); 38 FontList font_list = FontList("Droid Sans serif, Sans serif, 10px");
37 EXPECT_EQ("Droid Sans serif, Sans serif, 10px", 39 EXPECT_EQ("Droid Sans serif, Sans serif, 10px",
38 font_list.GetFontDescriptionString()); 40 font_list.GetFontDescriptionString());
39 } 41 }
40 42
41 TEST(FontListTest, FontDescString_FromFontNamesStyleAndSize) { 43 TEST(FontListTest, FontDescString_FromFontNamesStyleAndSize) {
42 // Test init from font names, style and size. 44 // Test init from font names, style and size.
43 std::vector<std::string> font_names; 45 std::vector<std::string> font_names;
44 font_names.push_back("Arial"); 46 font_names.push_back("Arial");
45 font_names.push_back("Droid Sans serif"); 47 font_names.push_back("Droid Sans serif");
46 int font_style = Font::BOLD | Font::ITALIC; 48 int font_style = Font::BOLD | Font::ITALIC | Font::UNDERLINE;
47 int font_size = 11; 49 int font_size = 11;
48 FontList font_list = FontList(font_names, font_style, font_size); 50 FontList font_list = FontList(font_names, font_style, font_size);
49 EXPECT_EQ("Arial,Droid Sans serif,Bold Italic 11px", 51 EXPECT_EQ("Arial,Droid Sans serif,Bold Italic Underline 11px",
50 font_list.GetFontDescriptionString()); 52 font_list.GetFontDescriptionString());
51 } 53 }
52 54
53 TEST(FontListTest, FontDescString_FromFont) { 55 TEST(FontListTest, FontDescString_FromFont) {
54 // Test init from Font. 56 // Test init from Font.
55 Font font("Arial", 8); 57 Font font("Arial", 8);
56 FontList font_list = FontList(font); 58 FontList font_list = FontList(font);
57 EXPECT_EQ("Arial,8px", font_list.GetFontDescriptionString()); 59 EXPECT_EQ("Arial,8px", font_list.GetFontDescriptionString());
58 } 60 }
59 61
60 TEST(FontListTest, FontDescString_FromFontWithNonNormalStyle) { 62 TEST(FontListTest, FontDescString_FromFontWithNonNormalStyle) {
61 // Test init from Font with non-normal style. 63 // Test init from Font with non-normal style.
62 Font font("Arial", 8); 64 Font font("Arial", 8);
63 FontList font_list = FontList(font.DeriveFont(2, Font::BOLD)); 65 FontList font_list = FontList(font.DeriveFont(2, Font::BOLD));
64 EXPECT_EQ("Arial,Bold 10px", font_list.GetFontDescriptionString()); 66 EXPECT_EQ("Arial,Bold 10px", font_list.GetFontDescriptionString());
65 67
66 font_list = FontList(font.DeriveFont(-2, Font::ITALIC)); 68 font_list = FontList(font.DeriveFont(-2, Font::ITALIC));
67 EXPECT_EQ("Arial,Italic 6px", font_list.GetFontDescriptionString()); 69 EXPECT_EQ("Arial,Italic 6px", font_list.GetFontDescriptionString());
70
71 font_list = FontList(font.DeriveFont(-4, Font::UNDERLINE));
72 EXPECT_EQ("Arial,Underline 4px", font_list.GetFontDescriptionString());
68 } 73 }
69 74
70 TEST(FontListTest, FontDescString_FromFontVector) { 75 TEST(FontListTest, FontDescString_FromFontVector) {
71 // Test init from Font vector. 76 // Test init from Font vector.
72 Font font("Arial", 8); 77 Font font("Arial", 8);
73 Font font_1("Sans serif", 10); 78 Font font_1("Sans serif", 10);
74 std::vector<Font> fonts; 79 std::vector<Font> fonts;
75 fonts.push_back(font.DeriveFont(0, Font::BOLD)); 80 fonts.push_back(font.DeriveFont(0, Font::BOLD));
76 fonts.push_back(font_1.DeriveFont(-2, Font::BOLD)); 81 fonts.push_back(font_1.DeriveFont(-2, Font::BOLD));
77 FontList font_list = FontList(fonts); 82 FontList font_list = FontList(fonts);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 const std::vector<Font>& derived_fonts = derived.GetFonts(); 267 const std::vector<Font>& derived_fonts = derived.GetFonts();
263 268
264 EXPECT_EQ(2U, derived_fonts.size()); 269 EXPECT_EQ(2U, derived_fonts.size());
265 EXPECT_EQ("Arial|13|italic", FontToString(derived_fonts[0])); 270 EXPECT_EQ("Arial|13|italic", FontToString(derived_fonts[0]));
266 EXPECT_EQ("Sans serif|13|italic", FontToString(derived_fonts[1])); 271 EXPECT_EQ("Sans serif|13|italic", FontToString(derived_fonts[1]));
267 } 272 }
268 273
269 TEST(FontListTest, FontDescString_DeriveFontListWithSizeDeltaAndStyle) { 274 TEST(FontListTest, FontDescString_DeriveFontListWithSizeDeltaAndStyle) {
270 FontList font_list = FontList("Arial,Sans serif,Bold Italic 8px"); 275 FontList font_list = FontList("Arial,Sans serif,Bold Italic 8px");
271 276
272 FontList derived = 277 FontList derived = font_list.DeriveFontListWithSizeDeltaAndStyle(
273 font_list.DeriveFontListWithSizeDeltaAndStyle(10, Font::ITALIC); 278 10, Font::ITALIC | Font::UNDERLINE);
274 EXPECT_EQ("Arial,Sans serif,Italic 18px", 279 EXPECT_EQ("Arial,Sans serif,Italic Underline 18px",
275 derived.GetFontDescriptionString()); 280 derived.GetFontDescriptionString());
276 } 281 }
277 282
278 TEST(FontListTest, Fonts_DeriveFontListWithSizeDeltaAndStyle) { 283 TEST(FontListTest, Fonts_DeriveFontListWithSizeDeltaAndStyle) {
279 std::vector<Font> fonts; 284 std::vector<Font> fonts;
280 fonts.push_back(gfx::Font("Arial", 8)); 285 fonts.push_back(gfx::Font("Arial", 8));
281 fonts.push_back(gfx::Font("Sans serif", 8)); 286 fonts.push_back(gfx::Font("Sans serif", 8));
282 FontList font_list = FontList(fonts); 287 FontList font_list = FontList(fonts);
283 288
284 FontList derived = 289 FontList derived = font_list.DeriveFontListWithSizeDeltaAndStyle(
285 font_list.DeriveFontListWithSizeDeltaAndStyle(5, Font::BOLD); 290 5, Font::BOLD | Font::UNDERLINE);
286 const std::vector<Font>& derived_fonts = derived.GetFonts(); 291 const std::vector<Font>& derived_fonts = derived.GetFonts();
287 292
288 EXPECT_EQ(2U, derived_fonts.size()); 293 EXPECT_EQ(2U, derived_fonts.size());
289 EXPECT_EQ("Arial|13|bold", FontToString(derived_fonts[0])); 294 EXPECT_EQ("Arial|13|bold|underline", FontToString(derived_fonts[0]));
290 EXPECT_EQ("Sans serif|13|bold", FontToString(derived_fonts[1])); 295 EXPECT_EQ("Sans serif|13|bold|underline", FontToString(derived_fonts[1]));
291 } 296 }
292 297
293 TEST(FontListTest, Fonts_GetHeight_GetBaseline) { 298 TEST(FontListTest, Fonts_GetHeight_GetBaseline) {
294 // If a font list has only one font, the height and baseline must be the same. 299 // If a font list has only one font, the height and baseline must be the same.
295 Font font1("Arial", 16); 300 Font font1("Arial", 16);
296 ASSERT_EQ("arial", StringToLowerASCII(font1.GetActualFontNameForTesting())); 301 ASSERT_EQ("arial", StringToLowerASCII(font1.GetActualFontNameForTesting()));
297 FontList font_list1("Arial, 16px"); 302 FontList font_list1("Arial, 16px");
298 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight()); 303 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight());
299 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline()); 304 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline());
300 305
(...skipping 11 matching lines...) Expand all
312 // ascent of FontList == max(ascent of Fonts) 317 // ascent of FontList == max(ascent of Fonts)
313 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(), 318 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(),
314 font2.GetHeight() - font2.GetBaseline()), 319 font2.GetHeight() - font2.GetBaseline()),
315 font_list_mix.GetHeight() - font_list_mix.GetBaseline()); 320 font_list_mix.GetHeight() - font_list_mix.GetBaseline());
316 // descent of FontList == max(descent of Fonts) 321 // descent of FontList == max(descent of Fonts)
317 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()), 322 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()),
318 font_list_mix.GetBaseline()); 323 font_list_mix.GetBaseline());
319 } 324 }
320 325
321 } // namespace gfx 326 } // namespace gfx
OLDNEW
« ui/gfx/font_list.cc ('K') | « ui/gfx/font_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698