blob: 4be3da54c6c58125ba4442207383a8643fbbf0d0 [file] [log] [blame]
Etienne Bergeron326e11b2019-05-23 23:29:211// Copyright 2019 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
5#include "content/common/font_list.h"
6
7#include "base/bind.h"
8#include "base/i18n/rtl.h"
9#include "base/sequenced_task_runner.h"
10#include "base/strings/string_piece.h"
11#include "base/task/post_task.h"
12#include "base/task_runner_util.h"
13#include "base/test/scoped_task_environment.h"
14#include "base/values.h"
15#include "build/build_config.h"
16#include "testing/gtest/include/gtest/gtest.h"
17
18namespace {
19
20#if !defined(OS_ANDROID) && !defined(OS_FUCHSIA)
21bool HasFontWithName(const base::ListValue& list,
22 base::StringPiece expected_font_id,
23 base::StringPiece expected_display_name) {
24 for (const auto& font : list.GetList()) {
25 const auto& font_names = font.GetList();
26 std::string font_id = font_names[0].GetString();
27 std::string display_name = font_names[1].GetString();
28 if (font_id == expected_font_id && display_name == expected_display_name)
29 return true;
30 }
31
32 return false;
33}
34#endif // !defined(OS_ANDROID) && !defined(OS_FUCHSI
35
36} // namespace
37
38#if !defined(OS_ANDROID) && !defined(OS_FUCHSIA)
39// GetFontList is not implemented on Android and Fuchsia.
40TEST(FontList, GetFontList) {
Gabriel Charette694c3c332019-08-19 14:53:0541 base::test::TaskEnvironment task_environment;
Etienne Bergeron326e11b2019-05-23 23:29:2142
43 content::GetFontListTaskRunner()->PostTask(
44 FROM_HERE, base::BindOnce([] {
45 std::unique_ptr<base::ListValue> fonts =
46 content::GetFontList_SlowBlocking();
47 ASSERT_TRUE(fonts);
48
49#if defined(OS_WIN)
50 EXPECT_TRUE(HasFontWithName(*fonts, "MS Gothic", "MS Gothic"));
51 EXPECT_TRUE(HasFontWithName(*fonts, "Segoe UI", "Segoe UI"));
52 EXPECT_TRUE(HasFontWithName(*fonts, "Verdana", "Verdana"));
53#elif defined(OS_LINUX)
54 EXPECT_TRUE(HasFontWithName(*fonts, "Arimo", "Arimo"));
55#else
56 EXPECT_TRUE(HasFontWithName(*fonts, "Arial", "Arial"));
57#endif
58 }));
Gabriel Charette694c3c332019-08-19 14:53:0559 task_environment.RunUntilIdle();
Etienne Bergeron326e11b2019-05-23 23:29:2160}
61#endif // !defined(OS_ANDROID) && !defined(OS_FUCHSIA)
62
63#if defined(OS_WIN)
64TEST(FontList, GetFontListLocalized) {
65 base::i18n::SetICUDefaultLocale("ja-JP");
66 std::unique_ptr<base::ListValue> ja_fonts =
67 content::GetFontList_SlowBlocking();
68 ASSERT_TRUE(ja_fonts);
69 EXPECT_TRUE(HasFontWithName(*ja_fonts, "MS Gothic", "MS ゴシック"));
70
71 base::i18n::SetICUDefaultLocale("ko-KR");
72 std::unique_ptr<base::ListValue> ko_fonts =
73 content::GetFontList_SlowBlocking();
74 ASSERT_TRUE(ko_fonts);
75 EXPECT_TRUE(HasFontWithName(*ko_fonts, "Malgun Gothic", "맑은 고딕"));
76}
77#endif // defined(OS_WIN)