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