OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/font_fallback.h" | 5 #include "ui/gfx/font_fallback.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/font.h" | 8 #include "ui/gfx/font.h" |
10 | 9 |
11 namespace gfx { | 10 namespace gfx { |
12 | 11 |
13 // A targeted test for GetFallbackFonts on Mac. It uses a system API that | 12 // A targeted test for GetFallbackFonts on Mac. It uses a system API that |
14 // only became publicly available in the 10.8 SDK. This test is to ensure it | 13 // only became publicly available in the 10.8 SDK. This test is to ensure it |
15 // behaves sensibly on all supported OS versions. | 14 // behaves sensibly on all supported OS versions. |
16 TEST(FontFallbackMacTest, GetFallbackFonts) { | 15 GTEST_TEST(FontFallbackMacTest, GetFallbackFonts) { |
17 Font font("Arial", 12); | 16 Font font("Arial", 12); |
18 std::vector<Font> fallback_fonts = GetFallbackFonts(font); | 17 std::vector<Font> fallback_fonts = GetFallbackFonts(font); |
19 // If there is only one fallback, it means the only fallback is the font | 18 // If there is only one fallback, it means the only fallback is the font |
20 // itself. | 19 // itself. |
21 EXPECT_LT(1u, fallback_fonts.size()); | 20 EXPECT_LT(1u, fallback_fonts.size()); |
22 } | 21 } |
23 | 22 |
24 // Sanity check GetFallbackFont() behavior on Mac. This test makes assumptions | |
25 // about font properties and availability on specific macOS versions. | |
26 TEST(FontFallbackMacTest, GetFallbackFont) { | |
27 Font arial("Helvetica", 12); | |
28 const base::string16 ascii = base::ASCIIToUTF16("abc"); | |
29 const base::string16 hebrew = base::WideToUTF16(L"\x5d0\x5d1\x5d2"); | |
30 const base::string16 emoji = base::UTF8ToUTF16("😋"); | |
31 | |
32 gfx::Font fallback; | |
33 EXPECT_FALSE(GetFallbackFont(arial, ascii.data(), ascii.size(), &fallback)); | |
34 EXPECT_TRUE(GetFallbackFont(arial, hebrew.data(), hebrew.size(), &fallback)); | |
35 EXPECT_EQ("Lucida Grande", fallback.GetFontName()); | |
36 EXPECT_TRUE(GetFallbackFont(arial, emoji.data(), emoji.size(), &fallback)); | |
37 EXPECT_EQ("Apple Color Emoji", fallback.GetFontName()); | |
38 } | |
39 | |
40 } // namespace gfx | 23 } // namespace gfx |
OLD | NEW |