diff --git a/third_party/txt/BUILD.gn b/third_party/txt/BUILD.gn index 6abab7cba017b..1f57ef313a84e 100644 --- a/third_party/txt/BUILD.gn +++ b/third_party/txt/BUILD.gn @@ -141,11 +141,17 @@ if (enable_unittests) { executable("txt_unittests") { testonly = true - sources = [ "tests/txt_run_all_unittests.cc" ] + sources = [ + "tests/font_collection_tests.cc", + "tests/txt_run_all_unittests.cc", + ] + + public_configs = [ ":txt_config" ] configs += [ ":allow_posix_names" ] deps = [ + ":txt", ":txt_fixtures", "//flutter/fml", "//flutter/testing:testing_lib", diff --git a/third_party/txt/src/txt/font_collection.cc b/third_party/txt/src/txt/font_collection.cc index 9d1e8b51be4ce..5cef503cb87bf 100644 --- a/third_party/txt/src/txt/font_collection.cc +++ b/third_party/txt/src/txt/font_collection.cc @@ -46,6 +46,7 @@ size_t FontCollection::GetFontManagersCount() const { void FontCollection::SetupDefaultFontManager( uint32_t font_initialization_data) { default_font_manager_ = GetDefaultFontManager(font_initialization_data); + skt_collection_.reset(); } void FontCollection::SetDefaultFontManager(sk_sp font_manager) { diff --git a/third_party/txt/tests/font_collection_tests.cc b/third_party/txt/tests/font_collection_tests.cc new file mode 100644 index 0000000000000..051d378de17d6 --- /dev/null +++ b/third_party/txt/tests/font_collection_tests.cc @@ -0,0 +1,43 @@ +/* + * Copyright 2017 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include + +#include "txt/font_collection.h" + +namespace txt { +namespace testing { + +class FontCollectionTests : public ::testing::Test { + public: + FontCollectionTests() {} + + void SetUp() override {} +}; + +TEST_F(FontCollectionTests, SettingUpDefaultFontManagerClearsCache) { + FontCollection font_collection; + sk_sp sk_font_collection = + font_collection.CreateSktFontCollection(); + ASSERT_EQ(sk_font_collection->getFallbackManager().get(), nullptr); + font_collection.SetupDefaultFontManager(0); + sk_font_collection = font_collection.CreateSktFontCollection(); + ASSERT_NE(sk_font_collection->getFallbackManager().get(), nullptr); +} +} // namespace testing +} // namespace txt