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.h" | 5 #include "ui/gfx/font.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/string_util.h" | |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 #if defined(OS_LINUX) && !defined(USE_OZONE) | 12 #if defined(OS_LINUX) && !defined(USE_OZONE) |
12 #include <pango/pango.h> | 13 #include <pango/pango.h> |
13 #elif defined(OS_WIN) | 14 #elif defined(OS_WIN) |
14 #include "ui/gfx/platform_font_win.h" | 15 #include "ui/gfx/platform_font_win.h" |
15 #endif | 16 #endif |
16 | 17 |
17 namespace gfx { | 18 namespace gfx { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 #endif // defined(OS_WIN) | 57 #endif // defined(OS_WIN) |
57 | 58 |
58 | 59 |
59 TEST_F(FontTest, LoadArial) { | 60 TEST_F(FontTest, LoadArial) { |
60 Font cf("Arial", 16); | 61 Font cf("Arial", 16); |
61 NativeFont native = cf.GetNativeFont(); | 62 NativeFont native = cf.GetNativeFont(); |
62 EXPECT_TRUE(native); | 63 EXPECT_TRUE(native); |
63 EXPECT_EQ(cf.GetStyle(), Font::NORMAL); | 64 EXPECT_EQ(cf.GetStyle(), Font::NORMAL); |
64 EXPECT_EQ(cf.GetFontSize(), 16); | 65 EXPECT_EQ(cf.GetFontSize(), 16); |
65 EXPECT_EQ(cf.GetFontName(), "Arial"); | 66 EXPECT_EQ(cf.GetFontName(), "Arial"); |
67 EXPECT_EQ("arial", StringToLowerASCII(cf.GetActualFontName())); | |
66 FreeIfNecessary(native); | 68 FreeIfNecessary(native); |
67 } | 69 } |
68 | 70 |
69 TEST_F(FontTest, LoadArialBold) { | 71 TEST_F(FontTest, LoadArialBold) { |
70 Font cf("Arial", 16); | 72 Font cf("Arial", 16); |
71 Font bold(cf.DeriveFont(0, Font::BOLD)); | 73 Font bold(cf.DeriveFont(0, Font::BOLD)); |
72 NativeFont native = bold.GetNativeFont(); | 74 NativeFont native = bold.GetNativeFont(); |
73 EXPECT_TRUE(native); | 75 EXPECT_TRUE(native); |
74 EXPECT_EQ(bold.GetStyle(), Font::BOLD); | 76 EXPECT_EQ(bold.GetStyle(), Font::BOLD); |
77 EXPECT_EQ("arial", StringToLowerASCII(cf.GetActualFontName())); | |
75 FreeIfNecessary(native); | 78 FreeIfNecessary(native); |
76 } | 79 } |
77 | 80 |
78 TEST_F(FontTest, Ascent) { | 81 TEST_F(FontTest, Ascent) { |
79 Font cf("Arial", 16); | 82 Font cf("Arial", 16); |
80 EXPECT_GT(cf.GetBaseline(), 2); | 83 EXPECT_GT(cf.GetBaseline(), 2); |
81 EXPECT_LE(cf.GetBaseline(), 22); | 84 EXPECT_LE(cf.GetBaseline(), 22); |
82 } | 85 } |
83 | 86 |
84 TEST_F(FontTest, Height) { | 87 TEST_F(FontTest, Height) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 Font cf("Arial", 16); | 119 Font cf("Arial", 16); |
117 EXPECT_EQ(cf.GetStringWidth(base::string16()), 0); | 120 EXPECT_EQ(cf.GetStringWidth(base::string16()), 0); |
118 EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), | 121 EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), |
119 cf.GetStringWidth(base::string16())); | 122 cf.GetStringWidth(base::string16())); |
120 EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), | 123 EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), |
121 cf.GetStringWidth(ASCIIToUTF16("a"))); | 124 cf.GetStringWidth(ASCIIToUTF16("a"))); |
122 EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), | 125 EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), |
123 cf.GetStringWidth(ASCIIToUTF16("ab"))); | 126 cf.GetStringWidth(ASCIIToUTF16("ab"))); |
124 } | 127 } |
125 | 128 |
129 #if !defined(OS_WIN) | |
130 // On Windows, Font::GetActualFontName() doesn't work well for now. | |
msw
2013/12/09 19:27:15
nit: file an issue to follow up.
Yuki
2013/12/10 09:58:59
Done.
| |
131 TEST_F(FontTest, GetActualFontName) { | |
132 Font arial("Arial", 16); | |
133 EXPECT_EQ("arial", StringToLowerASCII(arial.GetActualFontName())); | |
134 Font symbol("Symbol", 16); | |
135 EXPECT_EQ("symbol", StringToLowerASCII(symbol.GetActualFontName())); | |
136 | |
137 const char* const invalid_font_name = "no_such_a_font_name"; | |
msw
2013/12/09 19:27:15
nit: consider "invalid_font_name" or "no_such_font
Yuki
2013/12/10 09:58:59
Done.
| |
138 Font fallback_font(invalid_font_name, 16); | |
139 EXPECT_NE(invalid_font_name, | |
140 StringToLowerASCII(fallback_font.GetActualFontName())); | |
141 } | |
142 #endif | |
143 | |
126 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
127 TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { | 145 TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { |
128 Font cf("Arial", 8); | 146 Font cf("Arial", 8); |
129 // The minimum font size is set to 5 in browser_main.cc. | 147 // The minimum font size is set to 5 in browser_main.cc. |
130 ScopedMinimumFontSizeCallback minimum_size(5); | 148 ScopedMinimumFontSizeCallback minimum_size(5); |
131 | 149 |
132 Font derived_font = cf.DeriveFont(-4); | 150 Font derived_font = cf.DeriveFont(-4); |
133 EXPECT_EQ(5, derived_font.GetFontSize()); | 151 EXPECT_EQ(5, derived_font.GetFontSize()); |
134 } | 152 } |
135 | 153 |
136 TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { | 154 TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { |
137 Font cf("Arial", 8); | 155 Font cf("Arial", 8); |
138 // The minimum font size is set to 5 in browser_main.cc. | 156 // The minimum font size is set to 5 in browser_main.cc. |
139 ScopedMinimumFontSizeCallback minimum_size(5); | 157 ScopedMinimumFontSizeCallback minimum_size(5); |
140 | 158 |
141 Font derived_font = cf.DeriveFont(-2); | 159 Font derived_font = cf.DeriveFont(-2); |
142 EXPECT_EQ(6, derived_font.GetFontSize()); | 160 EXPECT_EQ(6, derived_font.GetFontSize()); |
143 } | 161 } |
144 #endif // defined(OS_WIN) | 162 #endif // defined(OS_WIN) |
145 | 163 |
146 } // namespace | 164 } // namespace |
147 } // namespace gfx | 165 } // namespace gfx |
OLD | NEW |