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.
6 #include "base/memory/scoped_ptr.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 "content/public/test/test_content_client_initializer.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/base/ui_base_paths.h"
15 #if defined(OS_MACOSX)
16 #include "base/mac/bundle_locations.h"
20 #include "ui/gl/gl_surface.h"
23 #if defined(OS_ANDROID)
24 #include "base/android/jni_android.h"
25 #include "ui/base/android/ui_base_jni_registrar.h"
26 #include "ui/gfx/android/gfx_jni_registrar.h"
31 class ComponentsTestSuite
: public base::TestSuite
{
33 ComponentsTestSuite(int argc
, char** argv
) : base::TestSuite(argc
, argv
) {}
36 virtual void Initialize() OVERRIDE
{
37 base::TestSuite::Initialize();
39 gfx::GLSurface::InitializeOneOffForTests();
41 #if defined(OS_ANDROID)
42 // Register JNI bindings for android.
43 JNIEnv
* env
= base::android::AttachCurrentThread();
44 gfx::android::RegisterJni(env
);
45 ui::android::RegisterJni(env
);
48 #if defined(OS_MACOSX) && !defined(OS_IOS)
49 // Look in the framework bundle for resources.
51 PathService::Get(base::DIR_EXE
, &path
);
53 // TODO(tfarina): This is temporary. The right fix is to write a
54 // framework-Info.plist and integrate that into the build.
55 // Hardcode the framework name here to avoid having to depend on chrome's
56 // common target for chrome::kFrameworkName.
57 #if defined(GOOGLE_CHROME_BUILD)
58 path
= path
.AppendASCII("Google Chrome Framework.framework");
59 #elif defined(CHROMIUM_BUILD)
60 path
= path
.AppendASCII("Chromium Framework.framework");
62 #error Unknown branding
65 base::mac::SetOverrideFrameworkBundlePath(path
);
68 ui::RegisterPathProvider();
70 // TODO(tfarina): This should be changed to InitSharedInstanceWithPakFile()
71 // so we can load our pak file instead of chrome.pak. crbug.com/348563
72 ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL
);
73 base::FilePath resources_pack_path
;
74 PathService::Get(base::DIR_MODULE
, &resources_pack_path
);
75 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
76 resources_pack_path
.AppendASCII("resources.pak"),
77 ui::SCALE_FACTOR_NONE
);
80 virtual void Shutdown() OVERRIDE
{
81 ui::ResourceBundle::CleanupSharedInstance();
83 #if defined(OS_MACOSX) && !defined(OS_IOS)
84 base::mac::SetOverrideFrameworkBundle(NULL
);
87 base::TestSuite::Shutdown();
90 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite
);
93 class ComponentsUnitTestEventListener
: public testing::EmptyTestEventListener
{
95 ComponentsUnitTestEventListener() {}
96 virtual ~ComponentsUnitTestEventListener() {}
98 virtual void OnTestStart(const testing::TestInfo
& test_info
) OVERRIDE
{
99 content_initializer_
.reset(new content::TestContentClientInitializer());
102 virtual void OnTestEnd(const testing::TestInfo
& test_info
) OVERRIDE
{
103 content_initializer_
.reset();
107 scoped_ptr
<content::TestContentClientInitializer
> content_initializer_
;
109 DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener
);
114 int main(int argc
, char** argv
) {
115 ComponentsTestSuite
test_suite(argc
, argv
);
117 // The listener will set up common test environment for all components unit
119 testing::TestEventListeners
& listeners
=
120 testing::UnitTest::GetInstance()->listeners();
121 listeners
.Append(new ComponentsUnitTestEventListener());
123 return base::LaunchUnitTests(
124 argc
, argv
, base::Bind(&base::TestSuite::Run
,
125 base::Unretained(&test_suite
)));