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

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

Issue 10933129: Add RenderText::SetFont() function to simplify some call sites. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months 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/render_text.cc ('k') | ui/views/controls/textfield/native_textfield_views.cc » ('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/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 EXPECT_GT(string_size.width(), 0); 995 EXPECT_GT(string_size.width(), 0);
996 EXPECT_GT(string_size.height(), 0); 996 EXPECT_GT(string_size.height(), 0);
997 } 997 }
998 998
999 // TODO(asvitkine): This test fails because PlatformFontMac uses point font 999 // TODO(asvitkine): This test fails because PlatformFontMac uses point font
1000 // sizes instead of pixel sizes like other implementations. 1000 // sizes instead of pixel sizes like other implementations.
1001 #if !defined(OS_MACOSX) 1001 #if !defined(OS_MACOSX)
1002 TEST_F(RenderTextTest, StringSizeEmptyString) { 1002 TEST_F(RenderTextTest, StringSizeEmptyString) {
1003 const Font font; 1003 const Font font;
1004 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 1004 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1005 render_text->SetFontList(FontList(font)); 1005 render_text->SetFont(font);
1006 1006
1007 render_text->SetText(string16()); 1007 render_text->SetText(string16());
1008 EXPECT_EQ(font.GetHeight(), render_text->GetStringSize().height()); 1008 EXPECT_EQ(font.GetHeight(), render_text->GetStringSize().height());
1009 EXPECT_EQ(0, render_text->GetStringSize().width()); 1009 EXPECT_EQ(0, render_text->GetStringSize().width());
1010 1010
1011 render_text->SetText(UTF8ToUTF16(" ")); 1011 render_text->SetText(UTF8ToUTF16(" "));
1012 EXPECT_EQ(font.GetHeight(), render_text->GetStringSize().height()); 1012 EXPECT_EQ(font.GetHeight(), render_text->GetStringSize().height());
1013 } 1013 }
1014 #endif // !defined(OS_MACOSX) 1014 #endif // !defined(OS_MACOSX)
1015 1015
1016 TEST_F(RenderTextTest, SetFont) {
1017 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1018 render_text->SetFont(Font("Arial", 12));
1019 EXPECT_EQ("Arial", render_text->GetFont().GetFontName());
1020 EXPECT_EQ(12, render_text->GetFont().GetFontSize());
1021 }
1022
1016 TEST_F(RenderTextTest, StringSizeBoldWidth) { 1023 TEST_F(RenderTextTest, StringSizeBoldWidth) {
1017 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 1024 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1018 render_text->SetText(UTF8ToUTF16("Hello World")); 1025 render_text->SetText(UTF8ToUTF16("Hello World"));
1019 1026
1020 const int plain_width = render_text->GetStringSize().width(); 1027 const int plain_width = render_text->GetStringSize().width();
1021 EXPECT_GT(plain_width, 0); 1028 EXPECT_GT(plain_width, 0);
1022 1029
1023 // Apply a bold style and check that the new width is greater. 1030 // Apply a bold style and check that the new width is greater.
1024 StyleRange bold; 1031 StyleRange bold;
1025 bold.font_style |= Font::BOLD; 1032 bold.font_style |= Font::BOLD;
(...skipping 23 matching lines...) Expand all
1049 { WideToUTF16(L"\x0915\x093f") }, // Hindi 1056 { WideToUTF16(L"\x0915\x093f") }, // Hindi
1050 { WideToUTF16(L"\x05e0\x05b8") }, // Hebrew 1057 { WideToUTF16(L"\x05e0\x05b8") }, // Hebrew
1051 }; 1058 };
1052 1059
1053 Font default_font; 1060 Font default_font;
1054 Font larger_font = default_font.DeriveFont(24, default_font.GetStyle()); 1061 Font larger_font = default_font.DeriveFont(24, default_font.GetStyle());
1055 EXPECT_GT(larger_font.GetHeight(), default_font.GetHeight()); 1062 EXPECT_GT(larger_font.GetHeight(), default_font.GetHeight());
1056 1063
1057 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 1064 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
1058 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 1065 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1059 render_text->SetFontList(FontList(default_font)); 1066 render_text->SetFont(default_font);
1060 render_text->SetText(cases[i].text); 1067 render_text->SetText(cases[i].text);
1061 1068
1062 const int height1 = render_text->GetStringSize().height(); 1069 const int height1 = render_text->GetStringSize().height();
1063 EXPECT_GT(height1, 0); 1070 EXPECT_GT(height1, 0);
1064 1071
1065 // Check that setting the larger font increases the height. 1072 // Check that setting the larger font increases the height.
1066 render_text->SetFontList(FontList(larger_font)); 1073 render_text->SetFont(larger_font);
1067 const int height2 = render_text->GetStringSize().height(); 1074 const int height2 = render_text->GetStringSize().height();
1068 EXPECT_GT(height2, height1); 1075 EXPECT_GT(height2, height1);
1069 } 1076 }
1070 } 1077 }
1071 1078
1072 TEST_F(RenderTextTest, GetBaselineSanity) { 1079 TEST_F(RenderTextTest, GetBaselineSanity) {
1073 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 1080 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1074 render_text->SetText(UTF8ToUTF16("Hello World")); 1081 render_text->SetText(UTF8ToUTF16("Hello World"));
1075 const int baseline = render_text->GetBaseline(); 1082 const int baseline = render_text->GetBaseline();
1076 EXPECT_GT(baseline, 0); 1083 EXPECT_GT(baseline, 0);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1304 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1298 render_text->GetUpdatedCursorBounds().x()); 1305 render_text->GetUpdatedCursorBounds().x());
1299 1306
1300 // Reset the application default text direction to LTR. 1307 // Reset the application default text direction to LTR.
1301 SetRTL(was_rtl); 1308 SetRTL(was_rtl);
1302 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); 1309 EXPECT_EQ(was_rtl, base::i18n::IsRTL());
1303 } 1310 }
1304 #endif // !defined(OS_MACOSX) 1311 #endif // !defined(OS_MACOSX)
1305 1312
1306 } // namespace gfx 1313 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698