Chromium Code Reviews| Index: ui/gfx/platform_font_win_unittest.cc |
| diff --git a/ui/gfx/platform_font_win_unittest.cc b/ui/gfx/platform_font_win_unittest.cc |
| index dc4ac5eb54bf92896c92c339f6f22da41b265202..57136406df9a833d2dd298a22f8cdf4ba54b6536 100644 |
| --- a/ui/gfx/platform_font_win_unittest.cc |
| +++ b/ui/gfx/platform_font_win_unittest.cc |
| @@ -17,72 +17,41 @@ |
| namespace gfx { |
| -namespace { |
| - |
| -// Returns a font based on |base_font| with height at most |target_height| and |
| -// font size maximized. Returns |base_font| if height is already equal. |
| -gfx::Font AdjustFontSizeForHeight(const gfx::Font& base_font, |
| - int target_height) { |
| - Font expected_font = base_font; |
| - if (base_font.GetHeight() < target_height) { |
| - // Increase size while height is <= |target_height|. |
| - Font larger_font = base_font.Derive(1, 0); |
| - while (larger_font.GetHeight() <= target_height) { |
| - expected_font = larger_font; |
| - larger_font = larger_font.Derive(1, 0); |
| - } |
| - } else if (expected_font.GetHeight() > target_height) { |
| - // Decrease size until height is <= |target_height|. |
| - do { |
| - expected_font = expected_font.Derive(-1, 0); |
| - } while (expected_font.GetHeight() > target_height); |
| - } |
| - return expected_font; |
| -} |
| - |
| -} // namespace |
| - |
| TEST(PlatformFontWinTest, DeriveFontWithHeight) { |
| - // TODO(ananta): Fix this test for DirectWrite. http://crbug.com/442010 |
| - if (gfx::win::IsDirectWriteEnabled()) |
| - return; |
| - |
| const Font base_font; |
| PlatformFontWin* platform_font = |
| static_cast<PlatformFontWin*>(base_font.platform_font()); |
| for (int i = -10; i < 10; i++) { |
| - const int target_height = base_font.GetHeight() + i; |
| - Font expected_font = AdjustFontSizeForHeight(base_font, target_height); |
| - ASSERT_LE(expected_font.GetHeight(), target_height); |
| - |
| - Font derived_font = platform_font->DeriveFontWithHeight(target_height, 0); |
| - EXPECT_EQ(expected_font.GetFontName(), derived_font.GetFontName()); |
| - EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); |
| - EXPECT_LE(expected_font.GetHeight(), target_height); |
| + const int target_height = base_font.GetHeight() + i; |
| + Font derived_font = platform_font->DeriveFontWithHeight(target_height, 0); |
| + // Ideally a derived font should have its height less or equal to the |
|
msw
2015/01/10 01:50:15
I'm confused about how either of these behaviors a
ananta
2015/01/10 02:05:49
Yes. They both retrieve the DW metrics. However wi
msw
2015/01/10 02:28:32
Okay, this must only occur when PlatformFontWin::D
ananta
2015/01/12 20:10:31
I changed the logic in the DeriveFontWithHeight fu
|
| + // target height. However for font heights like 17 with DirectWrite we |
| + // end up getting a font with height 18. We just check that the derived |
| + // font height is at most 1 px off. |
| + EXPECT_LE(abs(derived_font.GetHeight() - target_height), 1); |
| + // A derived Font one size larger should ideally exceed the target height. |
| + // However with DirectWrite with bigger heights like 24+, the derived font |
| + // ends up being the same height as the target height. |
| + EXPECT_GE(derived_font.Derive(1, 0).GetHeight(), target_height); |
| + EXPECT_EQ(platform_font->GetActualFontNameForTesting(), |
| + derived_font.GetActualFontNameForTesting()); |
| EXPECT_EQ(0, derived_font.GetStyle()); |
| - |
| derived_font = platform_font->DeriveFontWithHeight(target_height, |
| Font::BOLD); |
| - EXPECT_EQ(expected_font.GetFontName(), derived_font.GetFontName()); |
| - EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); |
| - EXPECT_LE(expected_font.GetHeight(), target_height); |
| + // Please refer above as to why we validate that the difference between |
| + // the derived font height and desired font height is at most 1. |
| + EXPECT_LE(abs(derived_font.GetHeight() - target_height), 1); |
| + // Please refer above as to why we use EXPECT_GE to check the derived font |
| + // height. |
| + EXPECT_GE(derived_font.Derive(1, 0).GetHeight(), target_height); |
| + EXPECT_EQ(platform_font->GetActualFontNameForTesting(), |
| + derived_font.GetActualFontNameForTesting()); |
| EXPECT_EQ(Font::BOLD, derived_font.GetStyle()); |
| - |
| - // Test that deriving from the new font has the expected result. |
| - Font rederived_font = derived_font.Derive(1, 0); |
| - expected_font = Font(derived_font.GetFontName(), |
| - derived_font.GetFontSize() + 1); |
| - EXPECT_EQ(expected_font.GetFontName(), rederived_font.GetFontName()); |
| - EXPECT_EQ(expected_font.GetFontSize(), rederived_font.GetFontSize()); |
| - EXPECT_EQ(expected_font.GetHeight(), rederived_font.GetHeight()); |
| } |
| } |
| TEST(PlatformFontWinTest, DeriveFontWithHeight_Consistency) { |
| - // TODO(ananta): Fix this test for DirectWrite. http://crbug.com/442010 |
| - if (gfx::win::IsDirectWriteEnabled()) |
| - return; |
| gfx::Font arial_12("Arial", 12); |
| ASSERT_GT(16, arial_12.GetHeight()); |
| gfx::Font derived_1 = static_cast<PlatformFontWin*>( |
| @@ -197,5 +166,4 @@ TEST(PlatformFontWinTest, Metrics_SkiaVersusGDI) { |
| } |
| } |
| - |
| } // namespace gfx |