#include "content/common/font_list.h"
#include <string_view>
#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_FUCHSIA)
bool HasFontWithName(const base::Value::List& list,
std::string_view expected_font_id,
std::string_view expected_display_name) { … }
#endif
}
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_FUCHSIA)
TEST(FontList, GetFontList) { … }
#endif
#if BUILDFLAG(IS_WIN)
TEST(FontList, GetFontListLocalized) {
base::i18n::SetICUDefaultLocale("ja-JP");
base::Value::List ja_fonts = content::GetFontList_SlowBlocking();
EXPECT_TRUE(HasFontWithName(ja_fonts, "MS Gothic", "MS ゴシック"));
base::i18n::SetICUDefaultLocale("ko-KR");
base::Value::List ko_fonts = content::GetFontList_SlowBlocking();
EXPECT_TRUE(HasFontWithName(ko_fonts, "Malgun Gothic", "맑은 고딕"));
}
#endif
#if BUILDFLAG(IS_MAC)
TEST(FontList, GetFontListDoesNotIncludeHiddenFonts) {
base::Value::List fonts = content::GetFontList_SlowBlocking();
for (const auto& font : fonts) {
const auto& font_names = font.GetList();
const std::string& font_id = font_names[0].GetString();
EXPECT_FALSE(base::EqualsCaseInsensitiveASCII(font_id, "lastresort"))
<< font_id << " seems to be LastResort, which should be filtered";
EXPECT_FALSE(font_id[0] == '.')
<< font_id << " seems like a hidden font, which should be filtered";
}
}
#endif