| 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/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #define MAYBE_LoadArial LoadArial | 51 #define MAYBE_LoadArial LoadArial |
| 52 #endif | 52 #endif |
| 53 TEST_F(FontTest, MAYBE_LoadArial) { | 53 TEST_F(FontTest, MAYBE_LoadArial) { |
| 54 Font cf("Arial", 16); | 54 Font cf("Arial", 16); |
| 55 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) | 55 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) |
| 56 EXPECT_TRUE(cf.GetNativeFont()); | 56 EXPECT_TRUE(cf.GetNativeFont()); |
| 57 #endif | 57 #endif |
| 58 EXPECT_EQ(cf.GetStyle(), Font::NORMAL); | 58 EXPECT_EQ(cf.GetStyle(), Font::NORMAL); |
| 59 EXPECT_EQ(cf.GetFontSize(), 16); | 59 EXPECT_EQ(cf.GetFontSize(), 16); |
| 60 EXPECT_EQ(cf.GetFontName(), "Arial"); | 60 EXPECT_EQ(cf.GetFontName(), "Arial"); |
| 61 EXPECT_EQ("arial", | 61 EXPECT_EQ("arial", base::ToLowerASCII(cf.GetActualFontNameForTesting())); |
| 62 base::StringToLowerASCII(cf.GetActualFontNameForTesting())); | |
| 63 } | 62 } |
| 64 | 63 |
| 65 #if defined(OS_ANDROID) | 64 #if defined(OS_ANDROID) |
| 66 #define MAYBE_LoadArialBold DISABLED_LoadArialBold | 65 #define MAYBE_LoadArialBold DISABLED_LoadArialBold |
| 67 #else | 66 #else |
| 68 #define MAYBE_LoadArialBold LoadArialBold | 67 #define MAYBE_LoadArialBold LoadArialBold |
| 69 #endif | 68 #endif |
| 70 TEST_F(FontTest, MAYBE_LoadArialBold) { | 69 TEST_F(FontTest, MAYBE_LoadArialBold) { |
| 71 Font cf("Arial", 16); | 70 Font cf("Arial", 16); |
| 72 Font bold(cf.Derive(0, Font::BOLD)); | 71 Font bold(cf.Derive(0, Font::BOLD)); |
| 73 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) | 72 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) |
| 74 EXPECT_TRUE(bold.GetNativeFont()); | 73 EXPECT_TRUE(bold.GetNativeFont()); |
| 75 #endif | 74 #endif |
| 76 EXPECT_EQ(bold.GetStyle(), Font::BOLD); | 75 EXPECT_EQ(bold.GetStyle(), Font::BOLD); |
| 77 EXPECT_EQ("arial", | 76 EXPECT_EQ("arial", base::ToLowerASCII(cf.GetActualFontNameForTesting())); |
| 78 base::StringToLowerASCII(cf.GetActualFontNameForTesting())); | |
| 79 } | 77 } |
| 80 | 78 |
| 81 #if defined(OS_ANDROID) | 79 #if defined(OS_ANDROID) |
| 82 #define MAYBE_Ascent DISABLED_Ascent | 80 #define MAYBE_Ascent DISABLED_Ascent |
| 83 #else | 81 #else |
| 84 #define MAYBE_Ascent Ascent | 82 #define MAYBE_Ascent Ascent |
| 85 #endif | 83 #endif |
| 86 TEST_F(FontTest, MAYBE_Ascent) { | 84 TEST_F(FontTest, MAYBE_Ascent) { |
| 87 Font cf("Arial", 16); | 85 Font cf("Arial", 16); |
| 88 EXPECT_GT(cf.GetBaseline(), 2); | 86 EXPECT_GT(cf.GetBaseline(), 2); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 #define MAYBE_GetActualFontNameForTesting GetActualFontNameForTesting | 130 #define MAYBE_GetActualFontNameForTesting GetActualFontNameForTesting |
| 133 #endif | 131 #endif |
| 134 // On Windows, Font::GetActualFontNameForTesting() doesn't work well for now. | 132 // On Windows, Font::GetActualFontNameForTesting() doesn't work well for now. |
| 135 // http://crbug.com/327287 | 133 // http://crbug.com/327287 |
| 136 // | 134 // |
| 137 // Check that fonts used for testing are installed and enabled. On Mac | 135 // Check that fonts used for testing are installed and enabled. On Mac |
| 138 // fonts may be installed but still need enabling in Font Book.app. | 136 // fonts may be installed but still need enabling in Font Book.app. |
| 139 // http://crbug.com/347429 | 137 // http://crbug.com/347429 |
| 140 TEST_F(FontTest, MAYBE_GetActualFontNameForTesting) { | 138 TEST_F(FontTest, MAYBE_GetActualFontNameForTesting) { |
| 141 Font arial("Arial", 16); | 139 Font arial("Arial", 16); |
| 142 EXPECT_EQ("arial", | 140 EXPECT_EQ("arial", base::ToLowerASCII(arial.GetActualFontNameForTesting())) |
| 143 base::StringToLowerASCII(arial.GetActualFontNameForTesting())) | |
| 144 << "********\n" | 141 << "********\n" |
| 145 << "Your test environment seems to be missing Arial font, which is " | 142 << "Your test environment seems to be missing Arial font, which is " |
| 146 << "needed for unittests. Check if Arial font is installed.\n" | 143 << "needed for unittests. Check if Arial font is installed.\n" |
| 147 << "********"; | 144 << "********"; |
| 148 Font symbol("Symbol", 16); | 145 Font symbol("Symbol", 16); |
| 149 EXPECT_EQ("symbol", | 146 EXPECT_EQ("symbol", base::ToLowerASCII(symbol.GetActualFontNameForTesting())) |
| 150 base::StringToLowerASCII(symbol.GetActualFontNameForTesting())) | |
| 151 << "********\n" | 147 << "********\n" |
| 152 << "Your test environment seems to be missing Symbol font, which is " | 148 << "Your test environment seems to be missing Symbol font, which is " |
| 153 << "needed for unittests. Check if Symbol font is installed.\n" | 149 << "needed for unittests. Check if Symbol font is installed.\n" |
| 154 << "********"; | 150 << "********"; |
| 155 | 151 |
| 156 const char* const invalid_font_name = "no_such_font_name"; | 152 const char* const invalid_font_name = "no_such_font_name"; |
| 157 Font fallback_font(invalid_font_name, 16); | 153 Font fallback_font(invalid_font_name, 16); |
| 158 EXPECT_NE(invalid_font_name, | 154 EXPECT_NE(invalid_font_name, |
| 159 base::StringToLowerASCII( | 155 base::ToLowerASCII(fallback_font.GetActualFontNameForTesting())); |
| 160 fallback_font.GetActualFontNameForTesting())); | |
| 161 } | 156 } |
| 162 | 157 |
| 163 #if defined(OS_WIN) | 158 #if defined(OS_WIN) |
| 164 TEST_F(FontTest, DeriveResizesIfSizeTooSmall) { | 159 TEST_F(FontTest, DeriveResizesIfSizeTooSmall) { |
| 165 Font cf("Arial", 8); | 160 Font cf("Arial", 8); |
| 166 // The minimum font size is set to 5 in browser_main.cc. | 161 // The minimum font size is set to 5 in browser_main.cc. |
| 167 ScopedMinimumFontSizeCallback minimum_size(5); | 162 ScopedMinimumFontSizeCallback minimum_size(5); |
| 168 | 163 |
| 169 Font derived_font = cf.Derive(-4, cf.GetStyle()); | 164 Font derived_font = cf.Derive(-4, cf.GetStyle()); |
| 170 EXPECT_EQ(5, derived_font.GetFontSize()); | 165 EXPECT_EQ(5, derived_font.GetFontSize()); |
| 171 } | 166 } |
| 172 | 167 |
| 173 TEST_F(FontTest, DeriveKeepsOriginalSizeIfHeightOk) { | 168 TEST_F(FontTest, DeriveKeepsOriginalSizeIfHeightOk) { |
| 174 Font cf("Arial", 8); | 169 Font cf("Arial", 8); |
| 175 // The minimum font size is set to 5 in browser_main.cc. | 170 // The minimum font size is set to 5 in browser_main.cc. |
| 176 ScopedMinimumFontSizeCallback minimum_size(5); | 171 ScopedMinimumFontSizeCallback minimum_size(5); |
| 177 | 172 |
| 178 Font derived_font = cf.Derive(-2, cf.GetStyle()); | 173 Font derived_font = cf.Derive(-2, cf.GetStyle()); |
| 179 EXPECT_EQ(6, derived_font.GetFontSize()); | 174 EXPECT_EQ(6, derived_font.GetFontSize()); |
| 180 } | 175 } |
| 181 #endif // defined(OS_WIN) | 176 #endif // defined(OS_WIN) |
| 182 | 177 |
| 183 } // namespace | 178 } // namespace |
| 184 } // namespace gfx | 179 } // namespace gfx |
| OLD | NEW |