Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / base / test / run_all_unittests.cc
blob26885c888575d3739304cb3d084b42e78755ef21
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/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"
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
20 #if defined(OS_MACOSX) && !defined(OS_IOS)
21 #include "base/mac/bundle_locations.h"
22 #endif
24 #if defined(OS_WIN)
25 #include "ui/gfx/win/dpi.h"
26 #endif
28 namespace {
30 class UIBaseTestSuite : public base::TestSuite {
31 public:
32 UIBaseTestSuite(int argc, char** argv);
34 protected:
35 // base::TestSuite:
36 virtual void Initialize() OVERRIDE;
37 virtual void Shutdown() OVERRIDE;
39 private:
40 DISALLOW_COPY_AND_ASSIGN(UIBaseTestSuite);
43 UIBaseTestSuite::UIBaseTestSuite(int argc, char** argv)
44 : base::TestSuite(argc, argv) {}
46 void UIBaseTestSuite::Initialize() {
47 base::TestSuite::Initialize();
49 #if defined(OS_WIN)
50 gfx::ForceHighDPISupportForTesting(1.0);
51 #endif
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
59 ui::RegisterPathProvider();
61 base::FilePath exe_path;
62 PathService::Get(base::DIR_EXE, &exe_path);
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);
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);
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"));
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
91 void UIBaseTestSuite::Shutdown() {
92 ui::ResourceBundle::CleanupSharedInstance();
94 #if defined(OS_MACOSX) && !defined(OS_IOS)
95 base::mac::SetOverrideFrameworkBundle(NULL);
96 #endif
97 base::TestSuite::Shutdown();
100 } // namespace
102 int main(int argc, char** argv) {
103 UIBaseTestSuite test_suite(argc, argv);
105 return base::LaunchUnitTests(argc,
106 argv,
107 base::Bind(&UIBaseTestSuite::Run,
108 base::Unretained(&test_suite)));