blob: c035c7b6deef436dabc9d4eee79d003d8c43e800 [file] [log] [blame]
Sergey Ulanov587827f2018-07-03 21:29:101// Copyright 2018 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
Sergey Ulanov587827f2018-07-03 21:29:105#include <fuchsia/fonts/cpp/fidl.h>
Sergey Ulanov587827f2018-07-03 21:29:106
Sergey Ulanov3b49dcb92019-05-04 01:10:277#include "skia/ext/test_fonts_fuchsia.h"
Sergey Ulanov587827f2018-07-03 21:29:108#include "testing/gtest/include/gtest/gtest.h"
Sergey Ulanova02ef2b2018-12-11 19:32:519#include "third_party/skia/include/core/SkFontMgr.h"
10#include "third_party/skia/include/core/SkTypeface.h"
11#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
Sergey Ulanov587827f2018-07-03 21:29:1012
13namespace skia {
14
Sergey Ulanova02ef2b2018-12-11 19:32:5115// Tests for SkFontMgr_Fuchsia in Skia.
Sergey Ulanov587827f2018-07-03 21:29:1016class FuchsiaFontManagerTest : public testing::Test {
17 public:
Greg Thompson5f319522022-08-03 23:18:4518 FuchsiaFontManagerTest()
19 : font_manager_(
20 SkFontMgr_New_Fuchsia(GetTestFontsProvider().BindSync())) {}
Sergey Ulanov587827f2018-07-03 21:29:1021
22 protected:
Sergey Ulanov587827f2018-07-03 21:29:1023 sk_sp<SkFontMgr> font_manager_;
24};
25
26// Verify that SkTypeface objects are cached.
Sergey Ulanov3b49dcb92019-05-04 01:10:2727TEST_F(FuchsiaFontManagerTest, Caching) {
Sergey Ulanov587827f2018-07-03 21:29:1028 sk_sp<SkTypeface> sans(
29 font_manager_->matchFamilyStyle("sans", SkFontStyle()));
Sergey Ulanova02ef2b2018-12-11 19:32:5130 EXPECT_TRUE(sans);
31
Sergey Ulanov587827f2018-07-03 21:29:1032 sk_sp<SkTypeface> sans2(
33 font_manager_->matchFamilyStyle("sans", SkFontStyle()));
34
35 // Expect that the same SkTypeface is returned for both requests.
36 EXPECT_EQ(sans.get(), sans2.get());
37
38 // Request serif and verify that a different SkTypeface is returned.
39 sk_sp<SkTypeface> serif(
40 font_manager_->matchFamilyStyle("serif", SkFontStyle()));
41 EXPECT_NE(sans.get(), serif.get());
42}
43
44// Verify that SkTypeface can outlive the manager.
45TEST_F(FuchsiaFontManagerTest, TypefaceOutlivesManager) {
46 sk_sp<SkTypeface> sans(
47 font_manager_->matchFamilyStyle("sans", SkFontStyle()));
48 font_manager_.reset();
49}
50
51// Verify that we can query a font after releasing a previous instance.
52TEST_F(FuchsiaFontManagerTest, ReleaseThenCreateAgain) {
53 sk_sp<SkTypeface> serif(
54 font_manager_->matchFamilyStyle("serif", SkFontStyle()));
55 EXPECT_TRUE(serif);
56 serif.reset();
57
58 sk_sp<SkTypeface> serif2(
59 font_manager_->matchFamilyStyle("serif", SkFontStyle()));
60 EXPECT_TRUE(serif2);
61}
62
Wez8682e6982018-07-18 12:51:1263} // namespace skia