blob: a5381b83b698a801ca3794b4a877b4b0637b4e8c [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>
6#include <lib/fidl/cpp/binding.h>
7
Sergey Ulanova02ef2b2018-12-11 19:32:518#include "base/fuchsia/component_context.h"
Sergey Ulanov587827f2018-07-03 21:29:109#include "base/path_service.h"
Sergey Ulanov587827f2018-07-03 21:29:1010#include "testing/gtest/include/gtest/gtest.h"
Sergey Ulanova02ef2b2018-12-11 19:32:5111#include "third_party/skia/include/core/SkFontMgr.h"
12#include "third_party/skia/include/core/SkTypeface.h"
13#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
Sergey Ulanov587827f2018-07-03 21:29:1014
15namespace skia {
16
Sergey Ulanova02ef2b2018-12-11 19:32:5117// Tests for SkFontMgr_Fuchsia in Skia.
Sergey Ulanov587827f2018-07-03 21:29:1018class FuchsiaFontManagerTest : public testing::Test {
19 public:
20 FuchsiaFontManagerTest() {
Sergey Ulanova02ef2b2018-12-11 19:32:5121 font_manager_ = SkFontMgr_New_Fuchsia(
22 base::fuchsia::ComponentContext::GetDefault()
23 ->ConnectToServiceSync<fuchsia::fonts::Provider>());
Sergey Ulanov587827f2018-07-03 21:29:1024 }
25
26 protected:
Sergey Ulanov587827f2018-07-03 21:29:1027 sk_sp<SkFontMgr> font_manager_;
28};
29
30// Verify that SkTypeface objects are cached.
31TEST_F(FuchsiaFontManagerTest, Caching) {
32 sk_sp<SkTypeface> sans(
33 font_manager_->matchFamilyStyle("sans", SkFontStyle()));
Sergey Ulanova02ef2b2018-12-11 19:32:5134 EXPECT_TRUE(sans);
35
Sergey Ulanov587827f2018-07-03 21:29:1036 sk_sp<SkTypeface> sans2(
37 font_manager_->matchFamilyStyle("sans", SkFontStyle()));
38
39 // Expect that the same SkTypeface is returned for both requests.
40 EXPECT_EQ(sans.get(), sans2.get());
41
42 // Request serif and verify that a different SkTypeface is returned.
43 sk_sp<SkTypeface> serif(
44 font_manager_->matchFamilyStyle("serif", SkFontStyle()));
45 EXPECT_NE(sans.get(), serif.get());
46}
47
48// Verify that SkTypeface can outlive the manager.
49TEST_F(FuchsiaFontManagerTest, TypefaceOutlivesManager) {
50 sk_sp<SkTypeface> sans(
51 font_manager_->matchFamilyStyle("sans", SkFontStyle()));
52 font_manager_.reset();
53}
54
55// Verify that we can query a font after releasing a previous instance.
56TEST_F(FuchsiaFontManagerTest, ReleaseThenCreateAgain) {
57 sk_sp<SkTypeface> serif(
58 font_manager_->matchFamilyStyle("serif", SkFontStyle()));
59 EXPECT_TRUE(serif);
60 serif.reset();
61
62 sk_sp<SkTypeface> serif2(
63 font_manager_->matchFamilyStyle("serif", SkFontStyle()));
64 EXPECT_TRUE(serif2);
65}
66
Wez8682e6982018-07-18 12:51:1267} // namespace skia