Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ui / base / test / run_all_unittests.cc
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.
4
5 #include "base/bind.h"
6 #include "base/files/file_path.h"
7 #include "base/path_service.h"
8 #include "base/test/launcher/unit_test_launcher.h"
9 #include "base/test/test_suite.h"
10 #include "build/build_config.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/base/ui_base_paths.h"
13
14 #if defined(OS_ANDROID)
15 #include "base/android/jni_android.h"
16 #include "ui/base/android/ui_base_jni_registrar.h"
17 #include "ui/gfx/android/gfx_jni_registrar.h"
18 #endif
19
20 #if defined(OS_MACOSX) && !defined(OS_IOS)
21 #include "base/mac/bundle_locations.h"
22 #endif
23
24 #if defined(OS_WIN)
25 #include "ui/gfx/win/dpi.h"
26 #endif
27
28 namespace {
29
30 class UIBaseTestSuite : public base::TestSuite {
31  public:
32   UIBaseTestSuite(int argc, char** argv);
33
34  protected:
35   // base::TestSuite:
36   virtual void Initialize() OVERRIDE;
37   virtual void Shutdown() OVERRIDE;
38
39  private:
40   DISALLOW_COPY_AND_ASSIGN(UIBaseTestSuite);
41 };
42
43 UIBaseTestSuite::UIBaseTestSuite(int argc, char** argv)
44     : base::TestSuite(argc, argv) {}
45
46 void UIBaseTestSuite::Initialize() {
47   base::TestSuite::Initialize();
48
49 #if defined(OS_WIN)
50   gfx::ForceHighDPISupportForTesting(1.0);
51 #endif
52
53 #if defined(OS_ANDROID)
54   // Register JNI bindings for android.
55   gfx::android::RegisterJni(base::android::AttachCurrentThread());
56   ui::android::RegisterJni(base::android::AttachCurrentThread());
57 #endif
58
59   ui::RegisterPathProvider();
60
61   base::FilePath exe_path;
62   PathService::Get(base::DIR_EXE, &exe_path);
63
64 #if defined(OS_MACOSX) && !defined(OS_IOS)
65   // On Mac, a test Framework bundle is created that links locale.pak and
66   // chrome_100_percent.pak at the appropriate places to ui_test.pak.
67   base::mac::SetOverrideFrameworkBundlePath(
68       exe_path.AppendASCII("ui_unittests Framework.framework"));
69   ui::ResourceBundle::InitSharedInstanceWithLocale(
70       "en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
71
72 #elif defined(OS_IOS) || defined(OS_ANDROID)
73   // On iOS, the ui_unittests binary is itself a mini bundle, with resources
74   // built in. On Android, ui_unittests_apk provides the necessary framework.
75   ui::ResourceBundle::InitSharedInstanceWithLocale(
76       "en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
77
78 #else
79   // On other platforms, the (hardcoded) paths for chrome_100_percent.pak and
80   // locale.pak get populated by later build steps. To avoid clobbering them,
81   // load the test .pak files directly.
82   ui::ResourceBundle::InitSharedInstanceWithPakPath(
83       exe_path.AppendASCII("ui_test.pak"));
84
85   // ui_unittests can't depend on the locales folder which Chrome will make
86   // later, so use the path created by ui_test_pak.
87   PathService::Override(ui::DIR_LOCALES, exe_path.AppendASCII("ui"));
88 #endif
89 }
90
91 void UIBaseTestSuite::Shutdown() {
92   ui::ResourceBundle::CleanupSharedInstance();
93
94 #if defined(OS_MACOSX) && !defined(OS_IOS)
95   base::mac::SetOverrideFrameworkBundle(NULL);
96 #endif
97   base::TestSuite::Shutdown();
98 }
99
100 }  // namespace
101
102 int main(int argc, char** argv) {
103   UIBaseTestSuite test_suite(argc, argv);
104
105   return base::LaunchUnitTests(argc,
106                                argv,
107                                base::Bind(&UIBaseTestSuite::Run,
108                                           base::Unretained(&test_suite)));
109 }