Automated Commit: Committing new LKGM version 6953.0.0 for chromeos.
[chromium-blink-merge.git] / components / test / run_all_unittests.cc
blob6476e591f7a93d539755a2d1bbc8770d2d1f2170
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 "base/bind.h"
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"
19 #if !defined(OS_IOS)
20 #include "ui/gl/gl_surface.h"
21 #endif
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"
28 #endif
30 namespace {
32 class ComponentsTestSuite : public base::TestSuite {
33 public:
34 ComponentsTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
36 private:
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
42 // by tests.
43 base::StatisticsRecorder::Initialize();
45 #if !defined(OS_IOS)
46 gfx::GLSurface::InitializeOneOffForTests();
47 #endif
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);
54 #endif
56 ui::RegisterPathProvider();
58 base::FilePath pak_path;
59 #if defined(OS_ANDROID)
60 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path);
61 #else
62 PathService::Get(base::DIR_MODULE, &pak_path);
63 #endif
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(
76 "chrome-extension");
79 void Shutdown() override {
80 ui::ResourceBundle::CleanupSharedInstance();
82 base::TestSuite::Shutdown();
85 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite);
88 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener {
89 public:
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();
101 private:
102 scoped_ptr<content::TestContentClientInitializer> content_initializer_;
104 DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener);
107 } // namespace
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
113 // tests.
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)));