| 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/string16.h" |
| 7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 11 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 11 #include <pango/pango.h> | 12 #include <pango/pango.h> |
| 12 #elif defined(OS_WIN) | 13 #elif defined(OS_WIN) |
| 13 #include "ui/gfx/platform_font_win.h" | 14 #include "ui/gfx/platform_font_win.h" |
| 14 #endif | 15 #endif |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2)); | 97 ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 TEST_F(FontTest, AvgCharWidth) { | 100 TEST_F(FontTest, AvgCharWidth) { |
| 100 Font cf("Arial", 16); | 101 Font cf("Arial", 16); |
| 101 ASSERT_GT(cf.GetAverageCharacterWidth(), 0); | 102 ASSERT_GT(cf.GetAverageCharacterWidth(), 0); |
| 102 } | 103 } |
| 103 | 104 |
| 104 TEST_F(FontTest, Widths) { | 105 TEST_F(FontTest, Widths) { |
| 105 Font cf("Arial", 16); | 106 Font cf("Arial", 16); |
| 106 ASSERT_EQ(cf.GetStringWidth(ASCIIToUTF16("")), 0); | 107 ASSERT_EQ(cf.GetStringWidth(string16()), 0); |
| 107 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), | 108 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), |
| 108 cf.GetStringWidth(ASCIIToUTF16(""))); | 109 cf.GetStringWidth(string16())); |
| 109 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), | 110 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), |
| 110 cf.GetStringWidth(ASCIIToUTF16("a"))); | 111 cf.GetStringWidth(ASCIIToUTF16("a"))); |
| 111 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), | 112 ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), |
| 112 cf.GetStringWidth(ASCIIToUTF16("ab"))); | 113 cf.GetStringWidth(ASCIIToUTF16("ab"))); |
| 113 } | 114 } |
| 114 | 115 |
| 115 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
| 116 TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { | 117 TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { |
| 117 Font cf("Arial", 8); | 118 Font cf("Arial", 8); |
| 118 // The minimum font size is set to 5 in browser_main.cc. | 119 // The minimum font size is set to 5 in browser_main.cc. |
| 119 ScopedMinimumFontSizeCallback minimum_size(5); | 120 ScopedMinimumFontSizeCallback minimum_size(5); |
| 120 | 121 |
| 121 Font derived_font = cf.DeriveFont(-4); | 122 Font derived_font = cf.DeriveFont(-4); |
| 122 EXPECT_EQ(5, derived_font.GetFontSize()); | 123 EXPECT_EQ(5, derived_font.GetFontSize()); |
| 123 } | 124 } |
| 124 | 125 |
| 125 TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { | 126 TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { |
| 126 Font cf("Arial", 8); | 127 Font cf("Arial", 8); |
| 127 // The minimum font size is set to 5 in browser_main.cc. | 128 // The minimum font size is set to 5 in browser_main.cc. |
| 128 ScopedMinimumFontSizeCallback minimum_size(5); | 129 ScopedMinimumFontSizeCallback minimum_size(5); |
| 129 | 130 |
| 130 Font derived_font = cf.DeriveFont(-2); | 131 Font derived_font = cf.DeriveFont(-2); |
| 131 EXPECT_EQ(6, derived_font.GetFontSize()); | 132 EXPECT_EQ(6, derived_font.GetFontSize()); |
| 132 } | 133 } |
| 133 #endif // defined(OS_WIN) | 134 #endif // defined(OS_WIN) |
| 134 | 135 |
| 135 } // namespace | 136 } // namespace |
| OLD | NEW |