OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 10 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 static int minimum_size_; | 50 static int minimum_size_; |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(ScopedMinimumFontSizeCallback); | 52 DISALLOW_COPY_AND_ASSIGN(ScopedMinimumFontSizeCallback); |
53 }; | 53 }; |
54 | 54 |
55 int ScopedMinimumFontSizeCallback::minimum_size_ = 0; | 55 int ScopedMinimumFontSizeCallback::minimum_size_ = 0; |
56 #endif // defined(OS_WIN) | 56 #endif // defined(OS_WIN) |
57 | 57 |
58 | 58 |
59 TEST_F(FontTest, LoadArial) { | 59 TEST_F(FontTest, LoadArial) { |
60 Font cf(ASCIIToUTF16("Arial"), 16); | 60 Font cf("Arial", 16); |
61 gfx::NativeFont native = cf.GetNativeFont(); | 61 gfx::NativeFont native = cf.GetNativeFont(); |
62 ASSERT_TRUE(native); | 62 ASSERT_TRUE(native); |
63 ASSERT_EQ(cf.GetStyle(), Font::NORMAL); | 63 ASSERT_EQ(cf.GetStyle(), Font::NORMAL); |
64 ASSERT_EQ(cf.GetFontSize(), 16); | 64 ASSERT_EQ(cf.GetFontSize(), 16); |
65 ASSERT_EQ(cf.GetFontName(), ASCIIToUTF16("Arial")); | 65 ASSERT_EQ(cf.GetFontName(), "Arial"); |
66 FreeIfNecessary(native); | 66 FreeIfNecessary(native); |
67 } | 67 } |
68 | 68 |
69 TEST_F(FontTest, LoadArialBold) { | 69 TEST_F(FontTest, LoadArialBold) { |
70 Font cf(ASCIIToUTF16("Arial"), 16); | 70 Font cf("Arial", 16); |
71 Font bold(cf.DeriveFont(0, Font::BOLD)); | 71 Font bold(cf.DeriveFont(0, Font::BOLD)); |
72 gfx::NativeFont native = bold.GetNativeFont(); | 72 gfx::NativeFont native = bold.GetNativeFont(); |
73 ASSERT_TRUE(native); | 73 ASSERT_TRUE(native); |
74 ASSERT_EQ(bold.GetStyle(), Font::BOLD); | 74 ASSERT_EQ(bold.GetStyle(), Font::BOLD); |
75 FreeIfNecessary(native); | 75 FreeIfNecessary(native); |
76 } | 76 } |
77 | 77 |
78 TEST_F(FontTest, Ascent) { | 78 TEST_F(FontTest, Ascent) { |
79 Font cf(ASCIIToUTF16("Arial"), 16); | 79 Font cf("Arial", 16); |
80 ASSERT_GT(cf.GetBaseline(), 2); | 80 ASSERT_GT(cf.GetBaseline(), 2); |
81 ASSERT_LE(cf.GetBaseline(), 22); | 81 ASSERT_LE(cf.GetBaseline(), 22); |
82 } | 82 } |
83 | 83 |
84 TEST_F(FontTest, Height) { | 84 TEST_F(FontTest, Height) { |
85 Font cf(ASCIIToUTF16("Arial"), 16); | 85 Font cf("Arial", 16); |
86 ASSERT_GE(cf.GetHeight(), 16); | 86 ASSERT_GE(cf.GetHeight(), 16); |
87 // TODO(akalin): Figure out why height is so large on Linux. | 87 // TODO(akalin): Figure out why height is so large on Linux. |
88 ASSERT_LE(cf.GetHeight(), 26); | 88 ASSERT_LE(cf.GetHeight(), 26); |
89 } | 89 } |
90 | 90 |
91 TEST_F(FontTest, AvgWidths) { | 91 TEST_F(FontTest, AvgWidths) { |
92 Font cf(ASCIIToUTF16("Arial"), 16); | 92 Font cf("Arial", 16); |
93 ASSERT_EQ(cf.GetExpectedTextWidth(0), 0); | 93 ASSERT_EQ(cf.GetExpectedTextWidth(0), 0); |
94 ASSERT_GT(cf.GetExpectedTextWidth(1), cf.GetExpectedTextWidth(0)); | 94 ASSERT_GT(cf.GetExpectedTextWidth(1), cf.GetExpectedTextWidth(0)); |
95 ASSERT_GT(cf.GetExpectedTextWidth(2), cf.GetExpectedTextWidth(1)); | 95 ASSERT_GT(cf.GetExpectedTextWidth(2), cf.GetExpectedTextWidth(1)); |
96 ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2)); | 96 ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2)); |
97 } | 97 } |
98 | 98 |
99 TEST_F(FontTest, AvgCharWidth) { | 99 TEST_F(FontTest, AvgCharWidth) { |
100 Font cf(ASCIIToUTF16("Arial"), 16); | 100 Font cf("Arial", 16); |
101 ASSERT_GT(cf.GetAverageCharacterWidth(), 0); | 101 ASSERT_GT(cf.GetAverageCharacterWidth(), 0); |
102 } | 102 } |
103 | 103 |
104 TEST_F(FontTest, Widths) { | 104 TEST_F(FontTest, Widths) { |
105 Font cf(ASCIIToUTF16("Arial"), 16); | 105 Font cf("Arial", 16); |
106 ASSERT_EQ(cf.GetStringWidth(ASCIIToUTF16("")), 0); | 106 ASSERT_EQ(cf.GetStringWidth(ASCIIToUTF16("")), 0); |
107 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), | 107 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), |
108 cf.GetStringWidth(ASCIIToUTF16(""))); | 108 cf.GetStringWidth(ASCIIToUTF16(""))); |
109 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), | 109 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), |
110 cf.GetStringWidth(ASCIIToUTF16("a"))); | 110 cf.GetStringWidth(ASCIIToUTF16("a"))); |
111 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), | 111 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), |
112 cf.GetStringWidth(ASCIIToUTF16("ab"))); | 112 cf.GetStringWidth(ASCIIToUTF16("ab"))); |
113 } | 113 } |
114 | 114 |
115 #if defined(OS_WIN) | 115 #if defined(OS_WIN) |
116 TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { | 116 TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { |
117 Font cf(L"Arial", 8); | 117 Font cf("Arial", 8); |
118 // The minimum font size is set to 5 in browser_main.cc. | 118 // The minimum font size is set to 5 in browser_main.cc. |
119 ScopedMinimumFontSizeCallback minimum_size(5); | 119 ScopedMinimumFontSizeCallback minimum_size(5); |
120 | 120 |
121 Font derived_font = cf.DeriveFont(-4); | 121 Font derived_font = cf.DeriveFont(-4); |
122 EXPECT_EQ(5, derived_font.GetFontSize()); | 122 EXPECT_EQ(5, derived_font.GetFontSize()); |
123 } | 123 } |
124 | 124 |
125 TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { | 125 TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { |
126 Font cf(L"Arial", 8); | 126 Font cf("Arial", 8); |
127 // The minimum font size is set to 5 in browser_main.cc. | 127 // The minimum font size is set to 5 in browser_main.cc. |
128 ScopedMinimumFontSizeCallback minimum_size(5); | 128 ScopedMinimumFontSizeCallback minimum_size(5); |
129 | 129 |
130 Font derived_font = cf.DeriveFont(-2); | 130 Font derived_font = cf.DeriveFont(-2); |
131 EXPECT_EQ(6, derived_font.GetFontSize()); | 131 EXPECT_EQ(6, derived_font.GetFontSize()); |
132 } | 132 } |
133 #endif // defined(OS_WIN) | 133 #endif // defined(OS_WIN) |
134 | 134 |
135 } // namespace | 135 } // namespace |
OLD | NEW |