1 // Copyright (c) 2012 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 "ui/test/test_suite.h"
7 #include "base/files/file_path.h"
8 #include "base/path_service.h"
9 #include "build/build_config.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/base/resource/resource_handle.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_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"
28 UITestSuite::UITestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
30 void UITestSuite::Initialize() {
31 base::TestSuite::Initialize();
33 #if defined(OS_ANDROID)
34 // Register JNI bindings for android.
35 gfx::android::RegisterJni(base::android::AttachCurrentThread());
36 ui::android::RegisterJni(base::android::AttachCurrentThread());
39 ui::RegisterPathProvider();
40 gfx::RegisterPathProvider();
42 #if defined(OS_MACOSX) && !defined(OS_IOS)
43 // Look in the framework bundle for resources.
44 // TODO(port): make a resource bundle for non-app exes. What's done here
45 // isn't really right because this code needs to depend on chrome_dll
46 // being built. This is inappropriate in app.
48 PathService::Get(base::DIR_EXE, &path);
49 #if defined(GOOGLE_CHROME_BUILD)
50 path = path.AppendASCII("Google Chrome Framework.framework");
51 #elif defined(CHROMIUM_BUILD)
52 path = path.AppendASCII("Chromium Framework.framework");
54 #error Unknown branding
56 base::mac::SetOverrideFrameworkBundlePath(path);
57 #elif defined(OS_POSIX)
58 base::FilePath pak_dir;
59 #if defined(OS_ANDROID)
60 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_dir);
62 PathService::Get(base::DIR_MODULE, &pak_dir);
63 pak_dir = pak_dir.AppendASCII("ui_unittests_strings");
64 PathService::Override(ui::DIR_LOCALES, pak_dir);
65 #endif // defined(OS_ANDROID)
66 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
68 // Force unittests to run using en-US so if we test against string
69 // output, it'll pass regardless of the system language.
70 ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
72 #if !defined(OS_MACOSX) && defined(OS_POSIX)
73 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
74 pak_dir.AppendASCII("chrome_100_percent.pak"),
75 ui::SCALE_FACTOR_100P);
79 void UITestSuite::Shutdown() {
80 ui::ResourceBundle::CleanupSharedInstance();
82 #if defined(OS_MACOSX) && !defined(OS_IOS)
83 base::mac::SetOverrideFrameworkBundle(NULL);
85 base::TestSuite::Shutdown();