[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ui / gfx / test / run_all_unittests.cc
blob97572c27945f3c58fa8d7ac146f748889dccf248
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.
5 #include "base/bind.h"
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"
18 #endif
20 #if defined(OS_MACOSX) && !defined(OS_IOS)
21 #include "base/test/mock_chrome_application_mac.h"
22 #endif
24 #if defined(OS_WIN)
25 #include <windows.h>
26 #include <winuser.h>
27 #include "ui/gfx/win/direct_write.h"
28 #endif
30 namespace {
32 class GfxTestSuite : public base::TestSuite {
33 public:
34 GfxTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {
35 #if defined(OS_WIN)
36 reset_antialiasing_on_shutdown_ = false;
37 #endif
40 protected:
41 void Initialize() override {
42 base::TestSuite::Initialize();
44 #if defined(OS_ANDROID)
45 gfx::android::RegisterJni(base::android::AttachCurrentThread());
46 #endif
48 #if defined(OS_MACOSX) && !defined(OS_IOS)
49 mock_cr_app::RegisterMockCrApp();
50 #endif
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);
58 #if defined(OS_WIN)
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);
67 if (!antialiasing) {
68 SystemParametersInfo(SPI_SETFONTSMOOTHING, TRUE, NULL, 0);
69 reset_antialiasing_on_shutdown_ = true;
72 #endif
75 void Shutdown() override {
76 ui::ResourceBundle::CleanupSharedInstance();
77 base::TestSuite::Shutdown();
78 #if defined(OS_WIN)
79 if (reset_antialiasing_on_shutdown_)
80 SystemParametersInfo(SPI_SETFONTSMOOTHING, FALSE, NULL, 0);
81 #endif
84 private:
85 #if defined(OS_WIN)
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_;
89 #endif
90 DISALLOW_COPY_AND_ASSIGN(GfxTestSuite);
93 } // namespace
95 int main(int argc, char** argv) {
96 GfxTestSuite test_suite(argc, argv);
98 return base::LaunchUnitTests(
99 argc,
100 argv,
101 base::Bind(&GfxTestSuite::Run, base::Unretained(&test_suite)));