File: font_fallback_mac_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (76 lines) | stat: -rw-r--r-- 2,695 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/gfx/font_fallback.h"

#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/font.h"

namespace gfx {

namespace {
const char kDefaultApplicationLocale[] = "us-en";
}  // namespace

// A targeted test for GetFallbackFonts on Mac. It uses a system API that
// only became publicly available in the 10.8 SDK. This test is to ensure it
// behaves sensibly on all supported OS versions.
TEST(FontFallbackMacTest, GetFallbackFonts) {
  Font font("Arial", 12);
  std::vector<Font> fallback_fonts = GetFallbackFonts(font);
  // If there is only one fallback, it means the only fallback is the font
  // itself.
  EXPECT_LT(1u, fallback_fonts.size());
}

// Sanity check GetFallbackFont() behavior on Mac. This test makes assumptions
// about font properties and availability on specific macOS versions.
TEST(FontFallbackMacTest, GetFallbackFont) {
  Font arial("Helvetica", 12);
  const std::u16string ascii = u"abc";
  const std::u16string hebrew = u"\x5d0\x5d1\x5d2";
  const std::u16string emoji = u"😋";

  Font fallback;
  EXPECT_TRUE(
      GetFallbackFont(arial, kDefaultApplicationLocale, hebrew, &fallback));
  EXPECT_EQ("Lucida Grande", fallback.GetFontName());
  EXPECT_TRUE(
      GetFallbackFont(arial, kDefaultApplicationLocale, emoji, &fallback));
  EXPECT_EQ("Apple Color Emoji", fallback.GetFontName());
}

TEST(FontFallbackMacTest, GetFallbackFontForEmoji) {
  static struct {
    const char* test_name;
    const wchar_t* text;
  } kEmojiTests[] = {
      {"aries", L"\u2648"},
      {"candle", L"\U0001F56F"},
      {"anchor", L"\u2693"},
      {"grinning_face", L"\U0001F600"},
      {"flag_andorra", L"\U0001F1E6\U0001F1E9"},
      {"woman_man_hands_light", L"\U0001F46B\U0001F3FB"},
      {"hole_text", L"\U0001F573\uFE0E"},
      {"hole_emoji", L"\U0001F573\uFE0F"},
      {"man_judge_medium", L"\U0001F468\U0001F3FD\u200D\u2696\uFE0F"},
      {"woman_turban", L"\U0001F473\u200D\u2640\uFE0F"},
      {"rainbow_flag", L"\U0001F3F3\uFE0F\u200D\U0001F308"},
      {"eye_bubble", L"\U0001F441\uFE0F\u200D\U0001F5E8\uFE0F"},
  };

  Font font;
  for (const auto& test : kEmojiTests) {
    SCOPED_TRACE(
        base::StringPrintf("GetFallbackFontForEmoji [%s]", test.test_name));
    Font fallback;
    EXPECT_TRUE(GetFallbackFont(font, kDefaultApplicationLocale,
                                base::WideToUTF16(test.text), &fallback));
    EXPECT_EQ("Apple Color Emoji", fallback.GetFontName());
  }
}

}  // namespace gfx