Avi Drissman | 0987565 | 2022-09-15 20:03:19 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 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> |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 6 | |
Sergey Ulanov | 3b49dcb9 | 2019-05-04 01:10:27 | [diff] [blame] | 7 | #include "skia/ext/test_fonts_fuchsia.h" |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 8 | #include "testing/gtest/include/gtest/gtest.h" |
Sergey Ulanov | a02ef2b | 2018-12-11 19:32:51 | [diff] [blame] | 9 | #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 Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 12 | |
| 13 | namespace skia { |
| 14 | |
Sergey Ulanov | a02ef2b | 2018-12-11 19:32:51 | [diff] [blame] | 15 | // Tests for SkFontMgr_Fuchsia in Skia. |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 16 | class FuchsiaFontManagerTest : public testing::Test { |
| 17 | public: |
Greg Thompson | 5f31952 | 2022-08-03 23:18:45 | [diff] [blame] | 18 | FuchsiaFontManagerTest() |
| 19 | : font_manager_( |
| 20 | SkFontMgr_New_Fuchsia(GetTestFontsProvider().BindSync())) {} |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 21 | |
| 22 | protected: |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 23 | sk_sp<SkFontMgr> font_manager_; |
| 24 | }; |
| 25 | |
| 26 | // Verify that SkTypeface objects are cached. |
Sergey Ulanov | 3b49dcb9 | 2019-05-04 01:10:27 | [diff] [blame] | 27 | TEST_F(FuchsiaFontManagerTest, Caching) { |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 28 | sk_sp<SkTypeface> sans( |
| 29 | font_manager_->matchFamilyStyle("sans", SkFontStyle())); |
Sergey Ulanov | a02ef2b | 2018-12-11 19:32:51 | [diff] [blame] | 30 | EXPECT_TRUE(sans); |
| 31 | |
Sergey Ulanov | 587827f | 2018-07-03 21:29:10 | [diff] [blame] | 32 | 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. |
| 45 | TEST_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. |
| 52 | TEST_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 | |
Wez | 8682e698 | 2018-07-18 12:51:12 | [diff] [blame] | 63 | } // namespace skia |