1 // Copyright 2019 PDFium 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 5 #include "testing/xfa_unit_test_support.h" 6 7 #include <memory> 8 #include <utility> 9 10 #include "core/fxge/cfx_fontmgr.h" 11 #include "core/fxge/cfx_gemodule.h" 12 #include "core/fxge/systemfontinfo_iface.h" 13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "third_party/base/ptr_util.h" 15 #include "xfa/fgas/font/cfgas_fontmgr.h" 16 17 namespace { 18 19 // The loading time of the CFGAS_FontMgr is linear in the number of times it is 20 // loaded. So, if a test suite has a lot of tests that need a font manager they 21 // can end up executing very, very slowly. 22 class XFATestEnvironment final : public testing::Environment { 23 public: 24 // testing::Environment: SetUp()25 void SetUp() override { 26 auto font_mgr = pdfium::MakeUnique<CFGAS_FontMgr>(); 27 if (font_mgr->EnumFonts()) 28 font_mgr_ = std::move(font_mgr); 29 } TearDown()30 void TearDown() override { font_mgr_.reset(); } 31 FontManager() const32 CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); } 33 34 private: 35 std::unique_ptr<CFGAS_FontMgr> font_mgr_; 36 }; 37 38 XFATestEnvironment* g_env = nullptr; 39 40 } // namespace 41 InitializeXFATestEnvironment()42void InitializeXFATestEnvironment() { 43 // |g_env| will be deleted by gtest. 44 g_env = new XFATestEnvironment(); 45 AddGlobalTestEnvironment(g_env); 46 47 // TODO(dsinclair): This font loading is slow. We should make a test font 48 // loader which loads up a single font we use in all tests. 49 CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo( 50 SystemFontInfoIface::CreateDefault(nullptr)); 51 } 52 GetGlobalFontManager()53CFGAS_FontMgr* GetGlobalFontManager() { 54 return g_env->FontManager(); 55 } 56