[Cronet] Delay StartNetLog and StopNetLog until native request context is initialized
[chromium-blink-merge.git] / ui / gfx / font_fallback_win_unittest.cc
blobe378db8e41da21503f727a66efd9993e6e9da779
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 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;
31 private:
32 std::vector<Font> test_linked_fonts;
34 DISALLOW_COPY_AND_ASSIGN(TestLinkedFontsIterator);
37 } // namespace
39 TEST(FontFallbackWinTest, ParseFontLinkEntry) {
40 std::string file;
41 std::string font;
43 internal::ParseFontLinkEntry("TAHOMA.TTF", &file, &font);
44 EXPECT_EQ("TAHOMA.TTF", file);
45 EXPECT_EQ("", font);
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);
53 EXPECT_EQ("", font);
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]);
66 font_names.clear();
68 internal::ParseFontFamilyString("Cambria & Cambria Math (TrueType)",
69 &font_names);
70 ASSERT_EQ(2U, font_names.size());
71 EXPECT_EQ("Cambria", font_names[0]);
72 EXPECT_EQ("Cambria Math", font_names[1]);
73 font_names.clear();
75 internal::ParseFontFamilyString(
76 "Meiryo & Meiryo Italic & Meiryo UI & Meiryo UI Italic (TrueType)",
77 &font_names);
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));
89 Font font;
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));
103 Font font;
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));
117 } // namespace gfx