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/files/file_path.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/metrics/statistics_recorder.h"
9 #include "base/path_service.h"
10 #include "base/test/launcher/unit_test_launcher.h"
11 #include "base/test/test_suite.h"
12 #include "components/content_settings/core/common/content_settings_pattern.h"
13 #include "content/public/test/test_content_client_initializer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/ui_base_paths.h"
17 #include "url/url_util.h"
20 #include "ui/gl/gl_surface.h"
23 #if defined(OS_ANDROID)
24 #include "base/android/jni_android.h"
25 #include "components/invalidation/android/component_jni_registrar.h"
26 #include "ui/base/android/ui_base_jni_registrar.h"
27 #include "ui/gfx/android/gfx_jni_registrar.h"
32 class ComponentsTestSuite
: public base::TestSuite
{
34 ComponentsTestSuite(int argc
, char** argv
) : base::TestSuite(argc
, argv
) {}
37 void Initialize() override
{
38 base::TestSuite::Initialize();
40 // Initialize the histograms subsystem, so that any histograms hit in tests
41 // are correctly registered with the statistics recorder and can be queried
43 base::StatisticsRecorder::Initialize();
46 gfx::GLSurface::InitializeOneOffForTests();
48 #if defined(OS_ANDROID)
49 // Register JNI bindings for android.
50 JNIEnv
* env
= base::android::AttachCurrentThread();
51 gfx::android::RegisterJni(env
);
52 ui::android::RegisterJni(env
);
53 invalidation::android::RegisterInvalidationJni(env
);
56 ui::RegisterPathProvider();
58 base::FilePath pak_path
;
59 #if defined(OS_ANDROID)
60 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &pak_path
);
62 PathService::Get(base::DIR_MODULE
, &pak_path
);
64 ui::ResourceBundle::InitSharedInstanceWithPakPath(
65 pak_path
.AppendASCII("components_tests_resources.pak"));
67 // These schemes need to be added globally to pass tests of
68 // autocomplete_input_unittest.cc and content_settings_pattern*
69 url::AddStandardScheme("chrome");
70 url::AddStandardScheme("chrome-extension");
71 url::AddStandardScheme("chrome-devtools");
72 url::AddStandardScheme("chrome-search");
74 // Not using kExtensionScheme to avoid the dependency to extensions.
75 ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
79 void Shutdown() override
{
80 ui::ResourceBundle::CleanupSharedInstance();
82 base::TestSuite::Shutdown();
85 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite
);
88 class ComponentsUnitTestEventListener
: public testing::EmptyTestEventListener
{
90 ComponentsUnitTestEventListener() {}
91 virtual ~ComponentsUnitTestEventListener() {}
93 virtual void OnTestStart(const testing::TestInfo
& test_info
) override
{
94 content_initializer_
.reset(new content::TestContentClientInitializer());
97 virtual void OnTestEnd(const testing::TestInfo
& test_info
) override
{
98 content_initializer_
.reset();
102 scoped_ptr
<content::TestContentClientInitializer
> content_initializer_
;
104 DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener
);
109 int main(int argc
, char** argv
) {
110 ComponentsTestSuite
test_suite(argc
, argv
);
112 // The listener will set up common test environment for all components unit
114 testing::TestEventListeners
& listeners
=
115 testing::UnitTest::GetInstance()->listeners();
116 listeners
.Append(new ComponentsUnitTestEventListener());
118 return base::LaunchUnitTests(
119 argc
, argv
, base::Bind(&base::TestSuite::Run
,
120 base::Unretained(&test_suite
)));