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.
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"
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"
21 #if defined(OS_MACOSX) && !defined(OS_IOS)
22 #include "base/mac/bundle_locations.h"
27 class UIBaseTestSuite : public base::TestSuite {
29 UIBaseTestSuite(int argc, char** argv);
33 virtual void Initialize() OVERRIDE;
34 virtual void Shutdown() OVERRIDE;
37 DISALLOW_COPY_AND_ASSIGN(UIBaseTestSuite);
40 UIBaseTestSuite::UIBaseTestSuite(int argc, char** argv)
41 : base::TestSuite(argc, argv) {}
43 void UIBaseTestSuite::Initialize() {
44 base::TestSuite::Initialize();
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());
52 ui::RegisterPathProvider();
53 gfx::RegisterPathProvider();
55 base::FilePath exe_path;
56 PathService::Get(base::DIR_EXE, &exe_path);
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);
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);
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"));
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"));
83 void UIBaseTestSuite::Shutdown() {
84 ui::ResourceBundle::CleanupSharedInstance();
86 #if defined(OS_MACOSX) && !defined(OS_IOS)
87 base::mac::SetOverrideFrameworkBundle(NULL);
89 base::TestSuite::Shutdown();
94 int main(int argc, char** argv) {
95 UIBaseTestSuite test_suite(argc, argv);
97 return base::LaunchUnitTests(argc,
99 base::Bind(&UIBaseTestSuite::Run,
100 base::Unretained(&test_suite)));