summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authoryukishiino@chromium.org <yukishiino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 08:43:06 +0000
committeryukishiino@chromium.org <yukishiino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 08:43:06 +0000
commit2fb2657edf859b1b31c41f5a44cfb9a91dc79840 (patch)
tree1f49fb44649c1e2bf38a3971250e4e6cce46306c /ui/gfx
parent65b5b4a4152e18547fdd7ec689336cd4db72c65b (diff)
downloadchromium_src-2fb2657edf859b1b31c41f5a44cfb9a91dc79840.zip
chromium_src-2fb2657edf859b1b31c41f5a44cfb9a91dc79840.tar.gz
chromium_src-2fb2657edf859b1b31c41f5a44cfb9a91dc79840.tar.bz2
Enables font-related unittests again.
Enables the unittests which got disabled because Symbol font was missing on trybots. See http://crrev.com/67523002 Symbol font has been installed on trybots. See http://crbug.com/320391 BUG=316955 TEST=none Review URL: https://codereview.chromium.org/79263004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240048 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/font.cc4
-rw-r--r--ui/gfx/font.h5
-rw-r--r--ui/gfx/font_list_unittest.cc6
-rw-r--r--ui/gfx/font_unittest.cc19
-rw-r--r--ui/gfx/platform_font.h5
-rw-r--r--ui/gfx/platform_font_ios.h1
-rw-r--r--ui/gfx/platform_font_ios.mm4
-rw-r--r--ui/gfx/platform_font_mac.h1
-rw-r--r--ui/gfx/platform_font_mac.mm4
-rw-r--r--ui/gfx/platform_font_ozone.cc3
-rw-r--r--ui/gfx/platform_font_pango.cc9
-rw-r--r--ui/gfx/platform_font_pango.h5
-rw-r--r--ui/gfx/platform_font_win.cc7
-rw-r--r--ui/gfx/platform_font_win.h1
-rw-r--r--ui/gfx/render_text_unittest.cc11
15 files changed, 74 insertions, 11 deletions
diff --git a/ui/gfx/font.cc b/ui/gfx/font.cc
index 7f6ac7c..9eea73b 100644
--- a/ui/gfx/font.cc
+++ b/ui/gfx/font.cc
@@ -78,6 +78,10 @@ std::string Font::GetFontName() const {
return platform_font_->GetFontName();
}
+std::string Font::GetActualFontNameForTesting() const {
+ return platform_font_->GetActualFontNameForTesting();
+}
+
int Font::GetFontSize() const {
return platform_font_->GetFontSize();
}
diff --git a/ui/gfx/font.h b/ui/gfx/font.h
index f84bfa2..963dde7 100644
--- a/ui/gfx/font.h
+++ b/ui/gfx/font.h
@@ -96,9 +96,12 @@ class GFX_EXPORT Font {
// Returns the style of the font.
int GetStyle() const;
- // Returns the font name in UTF-8.
+ // Returns the specified font name in UTF-8.
std::string GetFontName() const;
+ // Returns the actually used font name in UTF-8.
+ std::string GetActualFontNameForTesting() const;
+
// Returns the font size in pixels.
int GetFontSize() const;
diff --git a/ui/gfx/font_list_unittest.cc b/ui/gfx/font_list_unittest.cc
index f263673..6cbb41f 100644
--- a/ui/gfx/font_list_unittest.cc
+++ b/ui/gfx/font_list_unittest.cc
@@ -9,6 +9,7 @@
#include <vector>
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -289,10 +290,10 @@ TEST(FontListTest, Fonts_DeriveFontListWithSizeDeltaAndStyle) {
EXPECT_EQ("Sans serif|13|bold", FontToString(derived_fonts[1]));
}
-// Disabled. http://crbug.com/316955
-TEST(FontListTest, DISABLED_Fonts_GetHeight_GetBaseline) {
+TEST(FontListTest, Fonts_GetHeight_GetBaseline) {
// If a font list has only one font, the height and baseline must be the same.
Font font1("Arial", 16);
+ ASSERT_EQ("arial", StringToLowerASCII(font1.GetActualFontNameForTesting()));
FontList font_list1("Arial, 16px");
EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight());
EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline());
@@ -300,6 +301,7 @@ TEST(FontListTest, DISABLED_Fonts_GetHeight_GetBaseline) {
// If there are two different fonts, the font list returns the max value
// for ascent and descent.
Font font2("Symbol", 16);
+ ASSERT_EQ("symbol", StringToLowerASCII(font2.GetActualFontNameForTesting()));
EXPECT_NE(font1.GetBaseline(), font2.GetBaseline());
EXPECT_NE(font1.GetHeight() - font1.GetBaseline(),
font2.GetHeight() - font2.GetBaseline());
diff --git a/ui/gfx/font_unittest.cc b/ui/gfx/font_unittest.cc
index 2fe6193..2fdaab8 100644
--- a/ui/gfx/font_unittest.cc
+++ b/ui/gfx/font_unittest.cc
@@ -5,6 +5,7 @@
#include "ui/gfx/font.h"
#include "base/strings/string16.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -63,6 +64,7 @@ TEST_F(FontTest, LoadArial) {
EXPECT_EQ(cf.GetStyle(), Font::NORMAL);
EXPECT_EQ(cf.GetFontSize(), 16);
EXPECT_EQ(cf.GetFontName(), "Arial");
+ EXPECT_EQ("arial", StringToLowerASCII(cf.GetActualFontNameForTesting()));
FreeIfNecessary(native);
}
@@ -72,6 +74,7 @@ TEST_F(FontTest, LoadArialBold) {
NativeFont native = bold.GetNativeFont();
EXPECT_TRUE(native);
EXPECT_EQ(bold.GetStyle(), Font::BOLD);
+ EXPECT_EQ("arial", StringToLowerASCII(cf.GetActualFontNameForTesting()));
FreeIfNecessary(native);
}
@@ -123,6 +126,22 @@ TEST_F(FontTest, Widths) {
cf.GetStringWidth(ASCIIToUTF16("ab")));
}
+#if !defined(OS_WIN)
+// On Windows, Font::GetActualFontNameForTesting() doesn't work well for now.
+// http://crbug.com/327287
+TEST_F(FontTest, GetActualFontNameForTesting) {
+ Font arial("Arial", 16);
+ EXPECT_EQ("arial", StringToLowerASCII(arial.GetActualFontNameForTesting()));
+ Font symbol("Symbol", 16);
+ EXPECT_EQ("symbol", StringToLowerASCII(symbol.GetActualFontNameForTesting()));
+
+ const char* const invalid_font_name = "no_such_font_name";
+ Font fallback_font(invalid_font_name, 16);
+ EXPECT_NE(invalid_font_name,
+ StringToLowerASCII(fallback_font.GetActualFontNameForTesting()));
+}
+#endif
+
#if defined(OS_WIN)
TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) {
Font cf("Arial", 8);
diff --git a/ui/gfx/platform_font.h b/ui/gfx/platform_font.h
index d576bcd..bf47098 100644
--- a/ui/gfx/platform_font.h
+++ b/ui/gfx/platform_font.h
@@ -60,9 +60,12 @@ class GFX_EXPORT PlatformFont : public base::RefCounted<PlatformFont> {
// Returns the style of the font.
virtual int GetStyle() const = 0;
- // Returns the font name in UTF-8.
+ // Returns the specified font name in UTF-8.
virtual std::string GetFontName() const = 0;
+ // Returns the actually used font name in UTF-8.
+ virtual std::string GetActualFontNameForTesting() const = 0;
+
// Returns the font size in pixels.
virtual int GetFontSize() const = 0;
diff --git a/ui/gfx/platform_font_ios.h b/ui/gfx/platform_font_ios.h
index 2b30955..ed93a6b 100644
--- a/ui/gfx/platform_font_ios.h
+++ b/ui/gfx/platform_font_ios.h
@@ -26,6 +26,7 @@ class PlatformFontIOS : public PlatformFont {
virtual int GetExpectedTextWidth(int length) const OVERRIDE;
virtual int GetStyle() const OVERRIDE;
virtual std::string GetFontName() const OVERRIDE;
+ virtual std::string GetActualFontNameForTesting() const OVERRIDE;
virtual int GetFontSize() const OVERRIDE;
virtual NativeFont GetNativeFont() const OVERRIDE;
diff --git a/ui/gfx/platform_font_ios.mm b/ui/gfx/platform_font_ios.mm
index 92608d3..32dcca4 100644
--- a/ui/gfx/platform_font_ios.mm
+++ b/ui/gfx/platform_font_ios.mm
@@ -76,6 +76,10 @@ std::string PlatformFontIOS::GetFontName() const {
return font_name_;
}
+std::string PlatformFontIOS::GetActualFontNameForTesting() const {
+ return base::SysNSStringToUTF8([GetNativeFont() familyName]);
+}
+
int PlatformFontIOS::GetFontSize() const {
return font_size_;
}
diff --git a/ui/gfx/platform_font_mac.h b/ui/gfx/platform_font_mac.h
index 02006c3..2f5f8de 100644
--- a/ui/gfx/platform_font_mac.h
+++ b/ui/gfx/platform_font_mac.h
@@ -28,6 +28,7 @@ class PlatformFontMac : public PlatformFont {
virtual int GetExpectedTextWidth(int length) const OVERRIDE;
virtual int GetStyle() const OVERRIDE;
virtual std::string GetFontName() const OVERRIDE;
+ virtual std::string GetActualFontNameForTesting() const OVERRIDE;
virtual int GetFontSize() const OVERRIDE;
virtual NativeFont GetNativeFont() const OVERRIDE;
diff --git a/ui/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm
index fa9d589..877507e 100644
--- a/ui/gfx/platform_font_mac.mm
+++ b/ui/gfx/platform_font_mac.mm
@@ -126,6 +126,10 @@ std::string PlatformFontMac::GetFontName() const {
return font_name_;
}
+std::string PlatformFontMac::GetActualFontNameForTesting() const {
+ return base::SysNSStringToUTF8([native_font_ familyName]);
+}
+
int PlatformFontMac::GetFontSize() const {
return font_size_;
}
diff --git a/ui/gfx/platform_font_ozone.cc b/ui/gfx/platform_font_ozone.cc
index f93b737..aef042a 100644
--- a/ui/gfx/platform_font_ozone.cc
+++ b/ui/gfx/platform_font_ozone.cc
@@ -6,14 +6,17 @@
namespace gfx {
+// static
PlatformFont* PlatformFont::CreateDefault() {
return NULL;
}
+// static
PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) {
return NULL;
}
+// static
PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
int font_size) {
return NULL;
diff --git a/ui/gfx/platform_font_pango.cc b/ui/gfx/platform_font_pango.cc
index 020cc7f..db1d7dc 100644
--- a/ui/gfx/platform_font_pango.cc
+++ b/ui/gfx/platform_font_pango.cc
@@ -15,6 +15,7 @@
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
@@ -215,6 +216,12 @@ std::string PlatformFontPango::GetFontName() const {
return font_family_;
}
+std::string PlatformFontPango::GetActualFontNameForTesting() const {
+ SkString family_name;
+ typeface_->getFamilyName(&family_name);
+ return family_name.c_str();
+}
+
int PlatformFontPango::GetFontSize() const {
return font_size_pixels_;
}
@@ -293,7 +300,7 @@ void PlatformFontPango::InitWithNameAndSize(const std::string& font_name,
std::string fallback;
skia::RefPtr<SkTypeface> typeface = skia::AdoptRef(
- SkTypeface::CreateFromName(font_name.c_str(), SkTypeface::kNormal));
+ SkTypeface::CreateFromName(font_name.c_str(), SkTypeface::kNormal));
if (!typeface) {
// A non-scalable font such as .pcf is specified. Falls back to a default
// scalable font.
diff --git a/ui/gfx/platform_font_pango.h b/ui/gfx/platform_font_pango.h
index 136bf671..739a633 100644
--- a/ui/gfx/platform_font_pango.h
+++ b/ui/gfx/platform_font_pango.h
@@ -55,6 +55,7 @@ class GFX_EXPORT PlatformFontPango : public PlatformFont {
virtual int GetExpectedTextWidth(int length) const OVERRIDE;
virtual int GetStyle() const OVERRIDE;
virtual std::string GetFontName() const OVERRIDE;
+ virtual std::string GetActualFontNameForTesting() const OVERRIDE;
virtual int GetFontSize() const OVERRIDE;
virtual NativeFont GetNativeFont() const OVERRIDE;
@@ -75,8 +76,8 @@ class GFX_EXPORT PlatformFontPango : public PlatformFont {
void InitWithNameAndSize(const std::string& font_name, int font_size);
void InitWithTypefaceNameSizeAndStyle(
const skia::RefPtr<SkTypeface>& typeface,
- const std::string& name,
- int size,
+ const std::string& font_family,
+ int font_size,
int style);
void InitFromPlatformFont(const PlatformFontPango* other);
diff --git a/ui/gfx/platform_font_win.cc b/ui/gfx/platform_font_win.cc
index a97da2e..0209be6 100644
--- a/ui/gfx/platform_font_win.cc
+++ b/ui/gfx/platform_font_win.cc
@@ -167,6 +167,13 @@ std::string PlatformFontWin::GetFontName() const {
return font_ref_->font_name();
}
+std::string PlatformFontWin::GetActualFontNameForTesting() const {
+ // With the current implementation on Windows, HFontRef::font_name() returns
+ // the font name taken from the HFONT handle, but it's not the name that comes
+ // from the font's metadata. See http://crbug.com/327287
+ return font_ref_->font_name();
+}
+
std::string PlatformFontWin::GetLocalizedFontName() const {
base::win::ScopedCreateDC memory_dc(CreateCompatibleDC(NULL));
if (!memory_dc.Get())
diff --git a/ui/gfx/platform_font_win.h b/ui/gfx/platform_font_win.h
index 035ce8a..4826f77 100644
--- a/ui/gfx/platform_font_win.h
+++ b/ui/gfx/platform_font_win.h
@@ -63,6 +63,7 @@ class GFX_EXPORT PlatformFontWin : public PlatformFont {
virtual int GetExpectedTextWidth(int length) const OVERRIDE;
virtual int GetStyle() const OVERRIDE;
virtual std::string GetFontName() const OVERRIDE;
+ virtual std::string GetActualFontNameForTesting() const OVERRIDE;
virtual int GetFontSize() const OVERRIDE;
virtual NativeFont GetNativeFont() const OVERRIDE;
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index ffa1917..c8c50d4 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -8,6 +8,7 @@
#include "base/format_macros.h"
#include "base/memory/scoped_ptr.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -1156,11 +1157,14 @@ TEST_F(RenderTextTest, StringSizeEmptyString) {
}
#endif // !defined(OS_MACOSX)
-// Disabled. http://crbug.com/316955
-TEST_F(RenderTextTest, DISABLED_StringSizeRespectsFontListMetrics) {
+TEST_F(RenderTextTest, StringSizeRespectsFontListMetrics) {
// Check that Arial and Symbol have different font metrics.
Font arial_font("Arial", 16);
+ ASSERT_EQ("arial",
+ StringToLowerASCII(arial_font.GetActualFontNameForTesting()));
Font symbol_font("Symbol", 16);
+ ASSERT_EQ("symbol",
+ StringToLowerASCII(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.
@@ -1213,8 +1217,7 @@ TEST_F(RenderTextTest, SetFont) {
EXPECT_EQ(12, render_text->GetPrimaryFont().GetFontSize());
}
-// Disabled. http://crbug.com/316955
-TEST_F(RenderTextTest, DISABLED_SetFontList) {
+TEST_F(RenderTextTest, SetFontList) {
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->SetFontList(FontList("Arial,Symbol, 13px"));
const std::vector<Font>& fonts = render_text->font_list().GetFonts();