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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 2302313002: Configure font font names in GFX unittests (Closed)
Patch Set: Reintroduce height based assertions now that CJK font is used in StringSizeRespectsFontListMetrics Created 4 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 side-by-side diff with in-line comments
Download patch
« ui/gfx/font_names_testing.cc ('K') | « ui/gfx/font_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index d5eb931a6cf72b2fd806d89745e512b084c8e7da..a9b1eb83256e9db10f4acebdd8fb98e0c862d2fd 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -29,6 +29,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/font.h"
+#include "ui/gfx/font_names_testing.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/range/range.h"
@@ -1966,7 +1967,8 @@ TEST_P(RenderTextTest, StringSizeLongStrings) {
TEST_P(RenderTextTest, StringSizeEmptyString) {
// Ascent and descent of Arial and Symbol are different on most platforms.
- const FontList font_list("Arial,Symbol, 16px");
+ const FontList font_list(
+ base::StringPrintf("Arial,%s, 16px", kSymbolFontName));
RenderText* render_text = GetRenderText();
render_text->SetFontList(font_list);
render_text->SetDisplayRect(Rect(0, 0, 0, font_list.GetHeight()));
@@ -1988,23 +1990,23 @@ TEST_P(RenderTextTest, StringSizeRespectsFontListMetrics) {
Font arial_font("Arial", 16);
ASSERT_EQ("arial",
base::ToLowerASCII(arial_font.GetActualFontNameForTesting()));
- Font symbol_font("Symbol", 16);
- ASSERT_EQ("symbol",
- base::ToLowerASCII(symbol_font.GetActualFontNameForTesting()));
- EXPECT_NE(arial_font.GetHeight(), symbol_font.GetHeight());
- EXPECT_NE(arial_font.GetBaseline(), symbol_font.GetBaseline());
- // "a" should be rendered with Arial, not with Symbol.
+ Font cjk_font(kCJKFontName, 16);
+ ASSERT_EQ(base::ToLowerASCII(kCJKFontName),
+ base::ToLowerASCII(cjk_font.GetActualFontNameForTesting()));
+ EXPECT_NE(arial_font.GetHeight(), cjk_font.GetHeight());
+ EXPECT_NE(arial_font.GetBaseline(), cjk_font.GetBaseline());
+ // "a" should be rendered with Arial, not with the CJK font.
const char* arial_font_text = "a";
- // "®" (registered trademark symbol) should be rendered with Symbol,
- // not with Arial.
- const char* symbol_font_text = "\xC2\xAE";
+ // "円" CJK UNIFIED IDEOGRAPH-5186, aka the Yen sign should be rendered with
+ // the CJK font, not with Arial.
+ const char* cjk_font_text = u8"円";
msw 2016/09/06 20:06:06 nit: use the escape codes instead?
Font smaller_font = arial_font;
- Font larger_font = symbol_font;
+ Font larger_font = cjk_font;
const char* smaller_font_text = arial_font_text;
- const char* larger_font_text = symbol_font_text;
- if (symbol_font.GetHeight() < arial_font.GetHeight() &&
- symbol_font.GetBaseline() < arial_font.GetBaseline()) {
+ const char* larger_font_text = cjk_font_text;
+ if (cjk_font.GetHeight() < arial_font.GetHeight() &&
+ cjk_font.GetBaseline() < arial_font.GetBaseline()) {
std::swap(smaller_font, larger_font);
std::swap(smaller_font_text, larger_font_text);
}
@@ -2019,6 +2021,9 @@ TEST_P(RenderTextTest, StringSizeRespectsFontListMetrics) {
render_text->font_list().GetHeight()));
EXPECT_EQ(smaller_font.GetHeight(), render_text->GetStringSize().height());
EXPECT_EQ(smaller_font.GetBaseline(), render_text->GetBaseline());
+ EXPECT_STRCASEEQ(
+ render_text->GetFontSpansForTesting()[0].first.GetFontName().c_str(),
+ smaller_font.GetFontName().c_str());
// Layout the same text with mixed fonts. The text should be rendered with
// the smaller font, but the height and baseline are determined with the
@@ -2030,6 +2035,9 @@ TEST_P(RenderTextTest, StringSizeRespectsFontListMetrics) {
render_text->SetFontList(font_list);
render_text->SetDisplayRect(Rect(0, 0, 0,
render_text->font_list().GetHeight()));
+ EXPECT_STRCASEEQ(
+ render_text->GetFontSpansForTesting()[0].first.GetFontName().c_str(),
+ smaller_font.GetFontName().c_str());
EXPECT_LT(smaller_font.GetHeight(), render_text->GetStringSize().height());
EXPECT_LT(smaller_font.GetBaseline(), render_text->GetBaseline());
EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height());
@@ -2054,11 +2062,12 @@ TEST_P(RenderTextTest, MinLineHeight) {
TEST_P(RenderTextTest, SetFontList) {
RenderText* render_text = GetRenderText();
- render_text->SetFontList(FontList("Arial,Symbol, 13px"));
+ render_text->SetFontList(
+ FontList(base::StringPrintf("Arial,%s, 13px", kSymbolFontName)));
const std::vector<Font>& fonts = render_text->font_list().GetFonts();
ASSERT_EQ(2U, fonts.size());
EXPECT_EQ("Arial", fonts[0].GetFontName());
- EXPECT_EQ("Symbol", fonts[1].GetFontName());
+ EXPECT_EQ(kSymbolFontName, fonts[1].GetFontName());
EXPECT_EQ(13, render_text->font_list().GetFontSize());
}
@@ -3394,12 +3403,12 @@ TEST_P(RenderTextTest, StringFitsOwnWidth) {
// falling back to other fonts.
TEST_P(RenderTextHarfBuzzTest, HarfBuzz_FontListFallback) {
// Double-check that the requested fonts are present.
- FontList font_list("Arial, Symbol, 12px");
+ FontList font_list(base::StringPrintf("Arial, %s, 12px", kSymbolFontName));
const std::vector<Font>& fonts = font_list.GetFonts();
ASSERT_EQ(2u, fonts.size());
ASSERT_EQ("arial",
base::ToLowerASCII(fonts[0].GetActualFontNameForTesting()));
- ASSERT_EQ("symbol",
+ ASSERT_EQ(base::ToLowerASCII(kSymbolFontName),
base::ToLowerASCII(fonts[1].GetActualFontNameForTesting()));
// "⊕" (CIRCLED PLUS) should be rendered with Symbol rather than falling back
@@ -3410,7 +3419,7 @@ TEST_P(RenderTextHarfBuzzTest, HarfBuzz_FontListFallback) {
const std::vector<RenderText::FontSpan> spans =
render_text->GetFontSpansForTesting();
ASSERT_EQ(static_cast<size_t>(1), spans.size());
- EXPECT_EQ("Symbol", spans[0].first.GetFontName());
+ EXPECT_STRCASEEQ(kSymbolFontName, spans[0].first.GetFontName().c_str());
}
#endif // !defined(OS_WIN)
« ui/gfx/font_names_testing.cc ('K') | « ui/gfx/font_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698