font_fallback_mac_unittest.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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
  3. // found in the LICENSE file.
  4. #include "ui/gfx/font_fallback.h"
  5. #include "base/strings/string_piece.h"
  6. #include "base/strings/stringprintf.h"
  7. #include "base/strings/utf_string_conversions.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. #include "ui/gfx/font.h"
  10. namespace gfx {
  11. namespace {
  12. const char kDefaultApplicationLocale[] = "us-en";
  13. } // namespace
  14. // A targeted test for GetFallbackFonts on Mac. It uses a system API that
  15. // only became publicly available in the 10.8 SDK. This test is to ensure it
  16. // behaves sensibly on all supported OS versions.
  17. TEST(FontFallbackMacTest, GetFallbackFonts) {
  18. Font font("Arial", 12);
  19. std::vector<Font> fallback_fonts = GetFallbackFonts(font);
  20. // If there is only one fallback, it means the only fallback is the font
  21. // itself.
  22. EXPECT_LT(1u, fallback_fonts.size());
  23. }
  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 std::u16string ascii = u"abc";
  29. const std::u16string hebrew = u"\x5d0\x5d1\x5d2";
  30. const std::u16string emoji = u"😋";
  31. Font fallback;
  32. EXPECT_TRUE(
  33. GetFallbackFont(arial, kDefaultApplicationLocale, hebrew, &fallback));
  34. EXPECT_EQ("Lucida Grande", fallback.GetFontName());
  35. EXPECT_TRUE(
  36. GetFallbackFont(arial, kDefaultApplicationLocale, emoji, &fallback));
  37. EXPECT_EQ("Apple Color Emoji", fallback.GetFontName());
  38. }
  39. TEST(FontFallbackMacTest, GetFallbackFontForEmoji) {
  40. static struct {
  41. const char* test_name;
  42. const wchar_t* text;
  43. } kEmojiTests[] = {
  44. {"aries", L"\u2648"},
  45. {"candle", L"\U0001F56F"},
  46. {"anchor", L"\u2693"},
  47. {"grinning_face", L"\U0001F600"},
  48. {"flag_andorra", L"\U0001F1E6\U0001F1E9"},
  49. {"woman_man_hands_light", L"\U0001F46B\U0001F3FB"},
  50. {"hole_text", L"\U0001F573\uFE0E"},
  51. {"hole_emoji", L"\U0001F573\uFE0F"},
  52. {"man_judge_medium", L"\U0001F468\U0001F3FD\u200D\u2696\uFE0F"},
  53. {"woman_turban", L"\U0001F473\u200D\u2640\uFE0F"},
  54. {"rainbow_flag", L"\U0001F3F3\uFE0F\u200D\U0001F308"},
  55. {"eye_bubble", L"\U0001F441\uFE0F\u200D\U0001F5E8\uFE0F"},
  56. };
  57. Font font;
  58. for (const auto& test : kEmojiTests) {
  59. SCOPED_TRACE(
  60. base::StringPrintf("GetFallbackFontForEmoji [%s]", test.test_name));
  61. Font fallback;
  62. EXPECT_TRUE(GetFallbackFont(font, kDefaultApplicationLocale,
  63. base::WideToUTF16(test.text), &fallback));
  64. EXPECT_EQ("Apple Color Emoji", fallback.GetFontName());
  65. }
  66. }
  67. } // namespace gfx