- add sources.
[platform/framework/web/crosswalk.git] / src / ui / test / test_suite.cc
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.
4
5 #include "ui/test/test_suite.h"
6
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"
14
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"
19 #endif
20
21 #if defined(OS_MACOSX) && !defined(OS_IOS)
22 #include "base/mac/bundle_locations.h"
23 #endif
24
25 namespace ui {
26 namespace test {
27
28 UITestSuite::UITestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
29
30 void UITestSuite::Initialize() {
31   base::TestSuite::Initialize();
32
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());
37 #endif
38
39   ui::RegisterPathProvider();
40   gfx::RegisterPathProvider();
41
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.
47   base::FilePath path;
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");
53 #else
54 #error Unknown branding
55 #endif
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);
61 #else
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)
67
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);
71
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);
76 #endif
77 }
78
79 void UITestSuite::Shutdown() {
80   ui::ResourceBundle::CleanupSharedInstance();
81
82 #if defined(OS_MACOSX) && !defined(OS_IOS)
83   base::mac::SetOverrideFrameworkBundle(NULL);
84 #endif
85   base::TestSuite::Shutdown();
86 }
87
88 }  // namespace test
89 }  // namespace ui