1 // Copyright 2014 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.
6 #include "base/compiler_specific.h"
7 #include "base/macros.h"
8 #include "base/path_service.h"
9 #include "base/test/launcher/unit_test_launcher.h"
10 #include "base/test/test_suite.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/base/ui_base_paths.h"
15 #if defined(OS_ANDROID)
16 #include "base/android/jni_android.h"
17 #include "ui/gfx/android/gfx_jni_registrar.h"
20 #if defined(OS_MACOSX) && !defined(OS_IOS)
21 #include "base/test/mock_chrome_application_mac.h"
27 #include "ui/gfx/win/direct_write.h"
32 class GfxTestSuite
: public base::TestSuite
{
34 GfxTestSuite(int argc
, char** argv
) : base::TestSuite(argc
, argv
) {
36 reset_antialiasing_on_shutdown_
= false;
41 void Initialize() override
{
42 base::TestSuite::Initialize();
44 #if defined(OS_ANDROID)
45 gfx::android::RegisterJni(base::android::AttachCurrentThread());
48 #if defined(OS_MACOSX) && !defined(OS_IOS)
49 mock_cr_app::RegisterMockCrApp();
52 ui::RegisterPathProvider();
54 base::FilePath ui_test_pak_path
;
55 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK
, &ui_test_pak_path
));
56 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path
);
59 gfx::win::MaybeInitializeDirectWrite();
60 if (gfx::win::IsDirectWriteEnabled()) {
61 // Force antialiasing to true if DirectWrite is enabled for font metrics.
62 // With antialiasing off, Skia returns GDI compatible metrics which are
63 // larger by 1-2 points which cause some tests to fail.
64 // TODO(ananta): Investigate and fix.
65 BOOL antialiasing
= TRUE
;
66 SystemParametersInfo(SPI_GETFONTSMOOTHING
, 0, &antialiasing
, 0);
68 SystemParametersInfo(SPI_SETFONTSMOOTHING
, TRUE
, NULL
, 0);
69 reset_antialiasing_on_shutdown_
= true;
75 void Shutdown() override
{
76 ui::ResourceBundle::CleanupSharedInstance();
77 base::TestSuite::Shutdown();
79 if (reset_antialiasing_on_shutdown_
)
80 SystemParametersInfo(SPI_SETFONTSMOOTHING
, FALSE
, NULL
, 0);
86 // Set to true if we forced antialiasing to true on Windows for the
87 // duration of the test. We reset antialiasing back on shutdown
88 bool reset_antialiasing_on_shutdown_
;
90 DISALLOW_COPY_AND_ASSIGN(GfxTestSuite
);
95 int main(int argc
, char** argv
) {
96 GfxTestSuite
test_suite(argc
, argv
);
98 return base::LaunchUnitTests(
101 base::Bind(&GfxTestSuite::Run
, base::Unretained(&test_suite
)));