Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 1 | // 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 Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 5 | #include <fuchsia/fonts/cpp/fidl.h> |
| 6 | #include <lib/fidl/cpp/binding.h> |
| 7 | |
Sergey Ulanov | a02ef2b | 2018-12-11 19:32:51 | [diff] [blame^] | 8 | #include "base/fuchsia/component_context.h" |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 9 | #include "base/path_service.h" |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 10 | #include "testing/gtest/include/gtest/gtest.h" |
Sergey Ulanov | a02ef2b | 2018-12-11 19:32:51 | [diff] [blame^] | 11 | #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 Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 14 | |
| 15 | namespace skia { |
| 16 | |
Sergey Ulanov | a02ef2b | 2018-12-11 19:32:51 | [diff] [blame^] | 17 | // Tests for SkFontMgr_Fuchsia in Skia. |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 18 | class FuchsiaFontManagerTest : public testing::Test { |
| 19 | public: |
| 20 | FuchsiaFontManagerTest() { |
Sergey Ulanov | a02ef2b | 2018-12-11 19:32:51 | [diff] [blame^] | 21 | font_manager_ = SkFontMgr_New_Fuchsia( |
| 22 | base::fuchsia::ComponentContext::GetDefault() |
| 23 | ->ConnectToServiceSync<fuchsia::fonts::Provider>()); |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | protected: |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 27 | sk_sp<SkFontMgr> font_manager_; |
| 28 | }; |
| 29 | |
| 30 | // Verify that SkTypeface objects are cached. |
| 31 | TEST_F(FuchsiaFontManagerTest, Caching) { |
| 32 | sk_sp<SkTypeface> sans( |
| 33 | font_manager_->matchFamilyStyle("sans", SkFontStyle())); |
Sergey Ulanov | a02ef2b | 2018-12-11 19:32:51 | [diff] [blame^] | 34 | EXPECT_TRUE(sans); |
| 35 | |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 36 | 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. |
| 49 | TEST_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. |
| 56 | TEST_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 | |
Wez | 8682e698 | 2018-07-18 12:51:12 | [diff] [blame] | 67 | } // namespace skia |