0

Avoid unnecessarily initializing fontconfig in tests

Some tests like base_unittests don't actually need fontconfig initialized, so it
saves a bit of time to omit the call to FcInit().  Luckily, in all cases,
FcInit() is already called everywhere FontConfig is needed.

BUG=None
R=thakis,derat

Change-Id: I5ccad01e252499b2137d67004482f3a3652484b5
Reviewed-on: https://chromium-review.googlesource.com/c/1487186
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635357}
This commit is contained in:
Tom Anderson
2019-02-26 01:43:24 +00:00
committed by Commit Bot
parent d15d1acd36
commit 82a5ed7b5f
5 changed files with 7 additions and 24 deletions

@ -24,12 +24,6 @@ void SetUpFontconfig() {
// TODO(thomasanderson): This still stat()'s the real /etc/fonts/fonts.conf.
// Prevent fontconfig from doing this.
CHECK(env->SetVar("FONTCONFIG_SYSROOT", dir_module.value().c_str()));
CHECK(FcInit());
}
void TearDownFontconfig() {
FcFini();
}
} // namespace base

@ -7,12 +7,10 @@
namespace base {
// Initializes Fontconfig with a custom configuration suitable for tests.
// Prepares Fontconfig with a custom configuration suitable for tests. FcInit()
// must still be called.
void SetUpFontconfig();
// Deinitializes Fontconfig.
void TearDownFontconfig();
} // namespace base
#endif // BASE_TEST_FONTCONFIG_UTIL_LINUX_H_

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fontconfig/fontconfig.h>
#include <sys/stat.h>
#include <time.h>
#include <utime.h>
@ -54,7 +55,8 @@ int main() {
CHECK(base::DeleteFile(fontconfig_caches, /*recursive=*/true));
base::SetUpFontconfig();
base::TearDownFontconfig();
FcInit();
FcFini();
// Check existence of intended fontconfig cache file.
CHECK(base::PathExists(

@ -487,8 +487,6 @@ void TestSuite::Initialize() {
#endif
#if defined(OS_LINUX)
// TODO(thomasanderson): Call TearDownFontconfig() in Shutdown(). It would
// currently crash because of leaked FcFontSet's in font_fallback_linux.cc.
SetUpFontconfig();
#endif

@ -108,24 +108,15 @@ class FontRenderParamsTest : public testing::Test {
original_font_delegate_ = SkiaFontDelegate::instance();
SkiaFontDelegate::SetInstance(&test_font_delegate_);
ClearFontRenderParamsCacheForTest();
FcInit();
}
~FontRenderParamsTest() override {
FcFini();
SkiaFontDelegate::SetInstance(
const_cast<SkiaFontDelegate*>(original_font_delegate_));
}
void SetUp() override {
// Fontconfig should already be set up by the test runner.
DCHECK(FcConfigGetCurrent());
}
void TearDown() override {
// We might have made a mess introducing new fontconfig settings. Reset the
// state of fontconfig for the next test.
base::SetUpFontconfig();
}
protected:
const SkiaFontDelegate* original_font_delegate_;
TestFontDelegate test_font_delegate_;