Add field trial check for InstanceID API.
[chromium-blink-merge.git] / ui / gfx / font_fallback_win_unittest.cc
blob3d5eaadbbcd08cb2277d6ed8acd5c2e94a06d8f0
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"
8 namespace gfx {
10 namespace {
12 // Subclass of LinkedFontsIterator for testing that allows mocking the linked
13 // fonts vector.
14 class TestLinkedFontsIterator : public internal::LinkedFontsIterator {
15 public:
16 explicit TestLinkedFontsIterator(Font font) : LinkedFontsIterator(font) {
19 ~TestLinkedFontsIterator() override {}
21 // Add a linked font to the mocked vector of linked fonts.
22 void AddLinkedFontForTesting(Font font) {
23 test_linked_fonts.push_back(font);
26 const std::vector<Font>* GetLinkedFonts() const override {
27 return &test_linked_fonts;
30 private:
31 std::vector<Font> test_linked_fonts;
33 DISALLOW_COPY_AND_ASSIGN(TestLinkedFontsIterator);
36 } // namespace
38 TEST(FontFallbackWinTest, ParseFontLinkEntry) {
39 std::string file;
40 std::string font;
42 internal::ParseFontLinkEntry("TAHOMA.TTF", &file, &font);
43 EXPECT_EQ("TAHOMA.TTF", file);
44 EXPECT_EQ("", font);
46 internal::ParseFontLinkEntry("MSGOTHIC.TTC,MS UI Gothic", &file, &font);
47 EXPECT_EQ("MSGOTHIC.TTC", file);
48 EXPECT_EQ("MS UI Gothic", font);
50 internal::ParseFontLinkEntry("MALGUN.TTF,128,96", &file, &font);
51 EXPECT_EQ("MALGUN.TTF", file);
52 EXPECT_EQ("", font);
54 internal::ParseFontLinkEntry("MEIRYO.TTC,Meiryo,128,85", &file, &font);
55 EXPECT_EQ("MEIRYO.TTC", file);
56 EXPECT_EQ("Meiryo", font);
59 TEST(FontFallbackWinTest, ParseFontFamilyString) {
60 std::vector<std::string> font_names;
62 internal::ParseFontFamilyString("Times New Roman (TrueType)", &font_names);
63 ASSERT_EQ(1U, font_names.size());
64 EXPECT_EQ("Times New Roman", font_names[0]);
65 font_names.clear();
67 internal::ParseFontFamilyString("Cambria & Cambria Math (TrueType)",
68 &font_names);
69 ASSERT_EQ(2U, font_names.size());
70 EXPECT_EQ("Cambria", font_names[0]);
71 EXPECT_EQ("Cambria Math", font_names[1]);
72 font_names.clear();
74 internal::ParseFontFamilyString(
75 "Meiryo & Meiryo Italic & Meiryo UI & Meiryo UI Italic (TrueType)",
76 &font_names);
77 ASSERT_EQ(4U, font_names.size());
78 EXPECT_EQ("Meiryo", font_names[0]);
79 EXPECT_EQ("Meiryo Italic", font_names[1]);
80 EXPECT_EQ("Meiryo UI", font_names[2]);
81 EXPECT_EQ("Meiryo UI Italic", font_names[3]);
84 TEST(FontFallbackWinTest, LinkedFontsIterator) {
85 TestLinkedFontsIterator iterator(Font("Arial", 16));
86 iterator.AddLinkedFontForTesting(Font("Times New Roman", 16));
88 Font font;
89 EXPECT_TRUE(iterator.NextFont(&font));
90 ASSERT_EQ("Arial", font.GetFontName());
92 EXPECT_TRUE(iterator.NextFont(&font));
93 ASSERT_EQ("Times New Roman", font.GetFontName());
95 EXPECT_FALSE(iterator.NextFont(&font));
98 TEST(FontFallbackWinTest, LinkedFontsIteratorSetNextFont) {
99 TestLinkedFontsIterator iterator(Font("Arial", 16));
100 iterator.AddLinkedFontForTesting(Font("Times New Roman", 16));
102 Font font;
103 EXPECT_TRUE(iterator.NextFont(&font));
104 ASSERT_EQ("Arial", font.GetFontName());
106 iterator.SetNextFont(Font("Tahoma", 16));
107 EXPECT_TRUE(iterator.NextFont(&font));
108 ASSERT_EQ("Tahoma", font.GetFontName());
110 EXPECT_TRUE(iterator.NextFont(&font));
111 ASSERT_EQ("Times New Roman", font.GetFontName());
113 EXPECT_FALSE(iterator.NextFont(&font));
116 } // namespace gfx