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

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

Issue 79263004: Enables font-related unittests again. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. 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
« no previous file with comments | « ui/gfx/font_list_unittest.cc ('k') | ui/gfx/platform_font.h » ('j') | 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.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
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.GetActualFontNameForTesting()));
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.GetActualFontNameForTesting()));
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
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::GetActualFontNameForTesting() doesn't work well for now.
131 // http://crbug.com/327287
132 TEST_F(FontTest, GetActualFontNameForTesting) {
133 Font arial("Arial", 16);
134 EXPECT_EQ("arial", StringToLowerASCII(arial.GetActualFontNameForTesting()));
135 Font symbol("Symbol", 16);
136 EXPECT_EQ("symbol", StringToLowerASCII(symbol.GetActualFontNameForTesting()));
137
138 const char* const invalid_font_name = "no_such_font_name";
139 Font fallback_font(invalid_font_name, 16);
140 EXPECT_NE(invalid_font_name,
141 StringToLowerASCII(fallback_font.GetActualFontNameForTesting()));
142 }
143 #endif
144
126 #if defined(OS_WIN) 145 #if defined(OS_WIN)
127 TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { 146 TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) {
128 Font cf("Arial", 8); 147 Font cf("Arial", 8);
129 // The minimum font size is set to 5 in browser_main.cc. 148 // The minimum font size is set to 5 in browser_main.cc.
130 ScopedMinimumFontSizeCallback minimum_size(5); 149 ScopedMinimumFontSizeCallback minimum_size(5);
131 150
132 Font derived_font = cf.DeriveFont(-4); 151 Font derived_font = cf.DeriveFont(-4);
133 EXPECT_EQ(5, derived_font.GetFontSize()); 152 EXPECT_EQ(5, derived_font.GetFontSize());
134 } 153 }
135 154
136 TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { 155 TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) {
137 Font cf("Arial", 8); 156 Font cf("Arial", 8);
138 // The minimum font size is set to 5 in browser_main.cc. 157 // The minimum font size is set to 5 in browser_main.cc.
139 ScopedMinimumFontSizeCallback minimum_size(5); 158 ScopedMinimumFontSizeCallback minimum_size(5);
140 159
141 Font derived_font = cf.DeriveFont(-2); 160 Font derived_font = cf.DeriveFont(-2);
142 EXPECT_EQ(6, derived_font.GetFontSize()); 161 EXPECT_EQ(6, derived_font.GetFontSize());
143 } 162 }
144 #endif // defined(OS_WIN) 163 #endif // defined(OS_WIN)
145 164
146 } // namespace 165 } // namespace
147 } // namespace gfx 166 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_list_unittest.cc ('k') | ui/gfx/platform_font.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698