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
3 // found in the LICENSE file.
5 #include "ui/gfx/font_fallback_win.h"
6 #include "testing/gtest/include/gtest/gtest.h"
12 // Subclass of LinkedFontsIterator for testing that allows mocking the linked
14 class TestLinkedFontsIterator
: public internal::LinkedFontsIterator
{
16 explicit TestLinkedFontsIterator(Font font
) : LinkedFontsIterator(font
) {
19 virtual ~TestLinkedFontsIterator() {
22 // Add a linked font to the mocked vector of linked fonts.
23 void AddLinkedFontForTesting(Font font
) {
24 test_linked_fonts
.push_back(font
);
27 virtual const std::vector
<Font
>* GetLinkedFonts() const OVERRIDE
{
28 return &test_linked_fonts
;
32 std::vector
<Font
> test_linked_fonts
;
34 DISALLOW_COPY_AND_ASSIGN(TestLinkedFontsIterator
);
39 TEST(FontFallbackWinTest
, ParseFontLinkEntry
) {
43 internal::ParseFontLinkEntry("TAHOMA.TTF", &file
, &font
);
44 EXPECT_EQ("TAHOMA.TTF", file
);
47 internal::ParseFontLinkEntry("MSGOTHIC.TTC,MS UI Gothic", &file
, &font
);
48 EXPECT_EQ("MSGOTHIC.TTC", file
);
49 EXPECT_EQ("MS UI Gothic", font
);
51 internal::ParseFontLinkEntry("MALGUN.TTF,128,96", &file
, &font
);
52 EXPECT_EQ("MALGUN.TTF", file
);
55 internal::ParseFontLinkEntry("MEIRYO.TTC,Meiryo,128,85", &file
, &font
);
56 EXPECT_EQ("MEIRYO.TTC", file
);
57 EXPECT_EQ("Meiryo", font
);
60 TEST(FontFallbackWinTest
, ParseFontFamilyString
) {
61 std::vector
<std::string
> font_names
;
63 internal::ParseFontFamilyString("Times New Roman (TrueType)", &font_names
);
64 ASSERT_EQ(1U, font_names
.size());
65 EXPECT_EQ("Times New Roman", font_names
[0]);
68 internal::ParseFontFamilyString("Cambria & Cambria Math (TrueType)",
70 ASSERT_EQ(2U, font_names
.size());
71 EXPECT_EQ("Cambria", font_names
[0]);
72 EXPECT_EQ("Cambria Math", font_names
[1]);
75 internal::ParseFontFamilyString(
76 "Meiryo & Meiryo Italic & Meiryo UI & Meiryo UI Italic (TrueType)",
78 ASSERT_EQ(4U, font_names
.size());
79 EXPECT_EQ("Meiryo", font_names
[0]);
80 EXPECT_EQ("Meiryo Italic", font_names
[1]);
81 EXPECT_EQ("Meiryo UI", font_names
[2]);
82 EXPECT_EQ("Meiryo UI Italic", font_names
[3]);
85 TEST(FontFallbackWinTest
, LinkedFontsIterator
) {
86 TestLinkedFontsIterator
iterator(Font("Arial", 16));
87 iterator
.AddLinkedFontForTesting(Font("Times New Roman", 16));
90 EXPECT_TRUE(iterator
.NextFont(&font
));
91 ASSERT_EQ("Arial", font
.GetFontName());
93 EXPECT_TRUE(iterator
.NextFont(&font
));
94 ASSERT_EQ("Times New Roman", font
.GetFontName());
96 EXPECT_FALSE(iterator
.NextFont(&font
));
99 TEST(FontFallbackWinTest
, LinkedFontsIteratorSetNextFont
) {
100 TestLinkedFontsIterator
iterator(Font("Arial", 16));
101 iterator
.AddLinkedFontForTesting(Font("Times New Roman", 16));
104 EXPECT_TRUE(iterator
.NextFont(&font
));
105 ASSERT_EQ("Arial", font
.GetFontName());
107 iterator
.SetNextFont(Font("Tahoma", 16));
108 EXPECT_TRUE(iterator
.NextFont(&font
));
109 ASSERT_EQ("Tahoma", font
.GetFontName());
111 EXPECT_TRUE(iterator
.NextFont(&font
));
112 ASSERT_EQ("Times New Roman", font
.GetFontName());
114 EXPECT_FALSE(iterator
.NextFont(&font
));