Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / base / test / run_all_unittests.cc
blob19adcedbda98c4983b74952d3d7140240dc5a6b3
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 #include "base/test/mock_chrome_application_mac.h"
23 #endif
25 #if defined(OS_WIN)
26 #include "ui/gfx/win/dpi.h"
27 #endif
29 namespace {
31 class UIBaseTestSuite : public base::TestSuite {
32 public:
33 UIBaseTestSuite(int argc, char** argv);
35 protected:
36 // base::TestSuite:
37 void Initialize() override;
38 void Shutdown() override;
40 private:
41 DISALLOW_COPY_AND_ASSIGN(UIBaseTestSuite);
44 UIBaseTestSuite::UIBaseTestSuite(int argc, char** argv)
45 : base::TestSuite(argc, argv) {}
47 void UIBaseTestSuite::Initialize() {
48 base::TestSuite::Initialize();
50 #if defined(OS_WIN)
51 gfx::InitDeviceScaleFactor(1.0);
52 #endif
54 #if defined(OS_ANDROID)
55 // Register JNI bindings for android.
56 gfx::android::RegisterJni(base::android::AttachCurrentThread());
57 ui::android::RegisterJni(base::android::AttachCurrentThread());
58 #endif
60 ui::RegisterPathProvider();
62 base::FilePath exe_path;
63 PathService::Get(base::DIR_EXE, &exe_path);
65 #if defined(OS_MACOSX) && !defined(OS_IOS)
66 mock_cr_app::RegisterMockCrApp();
68 // On Mac, a test Framework bundle is created that links locale.pak and
69 // chrome_100_percent.pak at the appropriate places to ui_test.pak.
70 base::mac::SetOverrideFrameworkBundlePath(
71 exe_path.AppendASCII("ui_unittests Framework.framework"));
72 ui::ResourceBundle::InitSharedInstanceWithLocale(
73 "en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
75 #elif defined(OS_IOS) || defined(OS_ANDROID)
76 // On iOS, the ui_base_unittests binary is itself a mini bundle, with
77 // resources built in. On Android, ui_base_unittests_apk provides the
78 // necessary framework.
79 ui::ResourceBundle::InitSharedInstanceWithLocale(
80 "en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
82 #else
83 // On other platforms, the (hardcoded) paths for chrome_100_percent.pak and
84 // locale.pak get populated by later build steps. To avoid clobbering them,
85 // load the test .pak files directly.
86 ui::ResourceBundle::InitSharedInstanceWithPakPath(
87 exe_path.AppendASCII("ui_test.pak"));
89 // ui_base_unittests can't depend on the locales folder which Chrome will make
90 // later, so use the path created by ui_test_pak.
91 PathService::Override(ui::DIR_LOCALES, exe_path.AppendASCII("ui"));
92 #endif
95 void UIBaseTestSuite::Shutdown() {
96 ui::ResourceBundle::CleanupSharedInstance();
98 #if defined(OS_MACOSX) && !defined(OS_IOS)
99 base::mac::SetOverrideFrameworkBundle(NULL);
100 #endif
101 base::TestSuite::Shutdown();
104 } // namespace
106 int main(int argc, char** argv) {
107 UIBaseTestSuite test_suite(argc, argv);
109 return base::LaunchUnitTests(argc,
110 argv,
111 base::Bind(&UIBaseTestSuite::Run,
112 base::Unretained(&test_suite)));