| Index: ui/gfx/font_list_unittest.cc
|
| diff --git a/ui/gfx/font_list_unittest.cc b/ui/gfx/font_list_unittest.cc
|
| index 826eefa5e208d142b85d751b99dca5651f30e464..4e1d9f0cc9a3f796368d41fc56c0ade1c33bc1ee 100644
|
| --- a/ui/gfx/font_list_unittest.cc
|
| +++ b/ui/gfx/font_list_unittest.cc
|
| @@ -33,63 +33,51 @@ std::string FontToString(const gfx::Font& font) {
|
|
|
| namespace gfx {
|
|
|
| -TEST(FontListTest, FontDescString_FromDescString) {
|
| - // Test init from font name style size string.
|
| - FontList font_list = FontList("Droid Sans serif, Sans serif, 10px");
|
| - EXPECT_EQ("Droid Sans serif, Sans serif, 10px",
|
| - font_list.GetFontDescriptionString());
|
| -}
|
| -
|
| -TEST(FontListTest, FontDescString_FromFontNamesStyleAndSize) {
|
| - // Test init from font names, style and size.
|
| - std::vector<std::string> font_names;
|
| - font_names.push_back("Arial");
|
| - font_names.push_back("Droid Sans serif");
|
| - int font_style = Font::BOLD | Font::ITALIC | Font::UNDERLINE;
|
| - int font_size = 11;
|
| - FontList font_list = FontList(font_names, font_style, font_size);
|
| - // "Underline" doesn't appear in the font description string.
|
| - EXPECT_EQ("Arial,Droid Sans serif,Bold Italic 11px",
|
| - font_list.GetFontDescriptionString());
|
| -}
|
| -
|
| -TEST(FontListTest, FontDescString_FromFont) {
|
| - // Test init from Font.
|
| - Font font("Arial", 8);
|
| - FontList font_list = FontList(font);
|
| - EXPECT_EQ("Arial,8px", font_list.GetFontDescriptionString());
|
| -}
|
| -
|
| -TEST(FontListTest, FontDescString_FromFontWithNonNormalStyle) {
|
| - // Test init from Font with non-normal style.
|
| - Font font("Arial", 8);
|
| - FontList font_list = FontList(font.Derive(2, Font::BOLD));
|
| - EXPECT_EQ("Arial,Bold 10px", font_list.GetFontDescriptionString());
|
| -
|
| - font_list = FontList(font.Derive(-2, Font::ITALIC));
|
| - EXPECT_EQ("Arial,Italic 6px", font_list.GetFontDescriptionString());
|
| -
|
| - // "Underline" doesn't appear in the font description string.
|
| - font_list = FontList(font.Derive(-4, Font::UNDERLINE));
|
| - EXPECT_EQ("Arial,4px", font_list.GetFontDescriptionString());
|
| -}
|
| -
|
| -TEST(FontListTest, FontDescString_FromFontVector) {
|
| - // Test init from Font vector.
|
| - Font font("Arial", 8);
|
| - Font font_1("Sans serif", 10);
|
| - std::vector<Font> fonts;
|
| - fonts.push_back(font.Derive(0, Font::BOLD));
|
| - fonts.push_back(font_1.Derive(-2, Font::BOLD));
|
| - FontList font_list = FontList(fonts);
|
| - EXPECT_EQ("Arial,Sans serif,Bold 8px", font_list.GetFontDescriptionString());
|
| +TEST(FontListTest, ParseDescription) {
|
| + std::vector<std::string> families;
|
| + int style = gfx::Font::NORMAL;
|
| + int size_pixels = 0;
|
| +
|
| + // Parse a well-formed description containing styles and a size.
|
| + EXPECT_TRUE(FontList::ParseDescription("Arial,Helvetica,Bold Italic 12px",
|
| + &families, &style, &size_pixels));
|
| + ASSERT_EQ(2U, families.size());
|
| + EXPECT_EQ("Arial", families[0]);
|
| + EXPECT_EQ("Helvetica", families[1]);
|
| + EXPECT_EQ(gfx::Font::BOLD | gfx::Font::ITALIC, style);
|
| + EXPECT_EQ(12, size_pixels);
|
| +
|
| + // Whitespace should be removed.
|
| + EXPECT_TRUE(FontList::ParseDescription(" Verdana , Italic Bold 10px ",
|
| + &families, &style, &size_pixels));
|
| + ASSERT_EQ(1U, families.size());
|
| + EXPECT_EQ("Verdana", families[0]);
|
| + EXPECT_EQ(gfx::Font::BOLD | gfx::Font::ITALIC, style);
|
| + EXPECT_EQ(10, size_pixels);
|
| +
|
| + // Invalid descriptions should be rejected.
|
| + EXPECT_FALSE(FontList::ParseDescription("", &families, &style, &size_pixels));
|
| + EXPECT_FALSE(FontList::ParseDescription("Arial", &families, &style,
|
| + &size_pixels));
|
| + EXPECT_FALSE(FontList::ParseDescription("Arial,12", &families, &style,
|
| + &size_pixels));
|
| + EXPECT_FALSE(FontList::ParseDescription("Arial 12px", &families, &style,
|
| + &size_pixels));
|
| + EXPECT_FALSE(FontList::ParseDescription("Arial,12px,", &families, &style,
|
| + &size_pixels));
|
| + EXPECT_FALSE(FontList::ParseDescription("Arial,0px", &families, &style,
|
| + &size_pixels));
|
| + EXPECT_FALSE(FontList::ParseDescription("Arial,-1px", &families, &style,
|
| + &size_pixels));
|
| + EXPECT_FALSE(FontList::ParseDescription("Arial,foo 12px", &families, &style,
|
| + &size_pixels));
|
| }
|
|
|
| TEST(FontListTest, Fonts_FromDescString) {
|
| // Test init from font name size string.
|
| FontList font_list = FontList("serif,Sans serif, 13px");
|
| const std::vector<Font>& fonts = font_list.GetFonts();
|
| - EXPECT_EQ(2U, fonts.size());
|
| + ASSERT_EQ(2U, fonts.size());
|
| EXPECT_EQ("serif|13", FontToString(fonts[0]));
|
| EXPECT_EQ("Sans serif|13", FontToString(fonts[1]));
|
| }
|
| @@ -98,7 +86,7 @@ TEST(FontListTest, Fonts_FromDescStringInFlexibleFormat) {
|
| // Test init from font name size string with flexible format.
|
| FontList font_list = FontList(" serif , Sans serif , 13px");
|
| const std::vector<Font>& fonts = font_list.GetFonts();
|
| - EXPECT_EQ(2U, fonts.size());
|
| + ASSERT_EQ(2U, fonts.size());
|
| EXPECT_EQ("serif|13", FontToString(fonts[0]));
|
| EXPECT_EQ("Sans serif|13", FontToString(fonts[1]));
|
| }
|
| @@ -108,7 +96,7 @@ TEST(FontListTest, Fonts_FromDescStringWithStyleInFlexibleFormat) {
|
| FontList font_list = FontList(" serif , Sans serif , Bold "
|
| " Italic 13px");
|
| const std::vector<Font>& fonts = font_list.GetFonts();
|
| - EXPECT_EQ(2U, fonts.size());
|
| + ASSERT_EQ(2U, fonts.size());
|
| EXPECT_EQ("serif|13|bold|italic", FontToString(fonts[0]));
|
| EXPECT_EQ("Sans serif|13|bold|italic", FontToString(fonts[1]));
|
| }
|
| @@ -118,7 +106,7 @@ TEST(FontListTest, Fonts_FromFont) {
|
| Font font("Arial", 8);
|
| FontList font_list = FontList(font);
|
| const std::vector<Font>& fonts = font_list.GetFonts();
|
| - EXPECT_EQ(1U, fonts.size());
|
| + ASSERT_EQ(1U, fonts.size());
|
| EXPECT_EQ("Arial|8", FontToString(fonts[0]));
|
| }
|
|
|
| @@ -127,12 +115,12 @@ TEST(FontListTest, Fonts_FromFontWithNonNormalStyle) {
|
| Font font("Arial", 8);
|
| FontList font_list = FontList(font.Derive(2, Font::BOLD));
|
| std::vector<Font> fonts = font_list.GetFonts();
|
| - EXPECT_EQ(1U, fonts.size());
|
| + ASSERT_EQ(1U, fonts.size());
|
| EXPECT_EQ("Arial|10|bold", FontToString(fonts[0]));
|
|
|
| font_list = FontList(font.Derive(-2, Font::ITALIC));
|
| fonts = font_list.GetFonts();
|
| - EXPECT_EQ(1U, fonts.size());
|
| + ASSERT_EQ(1U, fonts.size());
|
| EXPECT_EQ("Arial|6|italic", FontToString(fonts[0]));
|
| }
|
|
|
| @@ -145,42 +133,11 @@ TEST(FontListTest, Fonts_FromFontVector) {
|
| input_fonts.push_back(font_1.Derive(-2, Font::BOLD));
|
| FontList font_list = FontList(input_fonts);
|
| const std::vector<Font>& fonts = font_list.GetFonts();
|
| - EXPECT_EQ(2U, fonts.size());
|
| + ASSERT_EQ(2U, fonts.size());
|
| EXPECT_EQ("Arial|8|bold", FontToString(fonts[0]));
|
| EXPECT_EQ("Sans serif|8|bold", FontToString(fonts[1]));
|
| }
|
|
|
| -TEST(FontListTest, Fonts_DescStringWithStyleInFlexibleFormat_RoundTrip) {
|
| - // Test round trip from font description string to font vector to
|
| - // font description string.
|
| - FontList font_list = FontList(" serif , Sans serif , Bold "
|
| - " Italic 13px");
|
| -
|
| - const std::vector<Font>& fonts = font_list.GetFonts();
|
| - FontList font_list_1 = FontList(fonts);
|
| - const std::string& desc_str = font_list_1.GetFontDescriptionString();
|
| -
|
| - EXPECT_EQ("serif,Sans serif,Bold Italic 13px", desc_str);
|
| -}
|
| -
|
| -TEST(FontListTest, Fonts_FontVector_RoundTrip) {
|
| - // Test round trip from font vector to font description string to font vector.
|
| - Font font("Arial", 8);
|
| - Font font_1("Sans serif", 10);
|
| - std::vector<Font> input_fonts;
|
| - input_fonts.push_back(font.Derive(0, Font::BOLD));
|
| - input_fonts.push_back(font_1.Derive(-2, Font::BOLD));
|
| - FontList font_list = FontList(input_fonts);
|
| -
|
| - const std::string& desc_string = font_list.GetFontDescriptionString();
|
| - FontList font_list_1 = FontList(desc_string);
|
| - const std::vector<Font>& round_trip_fonts = font_list_1.GetFonts();
|
| -
|
| - EXPECT_EQ(2U, round_trip_fonts.size());
|
| - EXPECT_EQ("Arial|8|bold", FontToString(round_trip_fonts[0]));
|
| - EXPECT_EQ("Sans serif|8|bold", FontToString(round_trip_fonts[1]));
|
| -}
|
| -
|
| TEST(FontListTest, FontDescString_GetStyle) {
|
| FontList font_list = FontList("Arial,Sans serif, 8px");
|
| EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle());
|
| @@ -207,19 +164,6 @@ TEST(FontListTest, Fonts_GetStyle) {
|
| EXPECT_EQ(Font::ITALIC | Font::BOLD, font_list.GetFontStyle());
|
| }
|
|
|
| -TEST(FontListTest, FontDescString_Derive) {
|
| - FontList font_list = FontList("Arial,Sans serif,Bold Italic 8px");
|
| -
|
| - FontList derived = font_list.Derive(10, Font::ITALIC | Font::UNDERLINE);
|
| - EXPECT_EQ("Arial,Sans serif,Italic 18px", derived.GetFontDescriptionString());
|
| - EXPECT_EQ(Font::ITALIC | Font::UNDERLINE, derived.GetFontStyle());
|
| -
|
| - // FontList has a special case for Font::UNDERLINE. See if the handling of
|
| - // Font::UNDERLINE in GetFonts() is okay or not.
|
| - derived.GetFonts();
|
| - EXPECT_EQ(Font::ITALIC | Font::UNDERLINE, derived.GetFontStyle());
|
| -}
|
| -
|
| TEST(FontListTest, Fonts_Derive) {
|
| std::vector<Font> fonts;
|
| fonts.push_back(gfx::Font("Arial", 8));
|
| @@ -234,14 +178,6 @@ TEST(FontListTest, Fonts_Derive) {
|
| EXPECT_EQ("Sans serif|13|bold|underline", FontToString(derived_fonts[1]));
|
| }
|
|
|
| -TEST(FontListTest, FontDescString_DeriveWithSizeDelta) {
|
| - FontList font_list = FontList("Arial,Sans serif,Bold 18px");
|
| -
|
| - FontList derived = font_list.DeriveWithSizeDelta(-8);
|
| - EXPECT_EQ("Arial,Sans serif,Bold 10px",
|
| - derived.GetFontDescriptionString());
|
| -}
|
| -
|
| TEST(FontListTest, Fonts_DeriveWithSizeDelta) {
|
| std::vector<Font> fonts;
|
| fonts.push_back(gfx::Font("Arial", 18).Derive(0, Font::ITALIC));
|
|
|