Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / test / run_all_unittests.cc
blobd04085ea80db4c8c89031f3b98e67826684f67d7
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 "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/base/ui_base_paths.h"
16 #include "url/url_util.h"
18 #if !defined(OS_IOS)
19 #include "content/public/test/test_content_client_initializer.h"
20 #include "ui/gl/test/gl_surface_test_support.h"
21 #endif
23 #if defined(OS_ANDROID)
24 #include "base/android/jni_android.h"
25 #include "components/invalidation/impl/android/component_jni_registrar.h"
26 #include "components/policy/core/browser/android/component_jni_registrar.h"
27 #include "components/safe_json/android/component_jni_registrar.h"
28 #include "components/signin/core/browser/android/component_jni_registrar.h"
29 #include "ui/base/android/ui_base_jni_registrar.h"
30 #include "ui/gfx/android/gfx_jni_registrar.h"
31 #endif
33 namespace {
35 class ComponentsTestSuite : public base::TestSuite {
36 public:
37 ComponentsTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
39 private:
40 void Initialize() override {
41 base::TestSuite::Initialize();
43 // Initialize the histograms subsystem, so that any histograms hit in tests
44 // are correctly registered with the statistics recorder and can be queried
45 // by tests.
46 base::StatisticsRecorder::Initialize();
48 #if !defined(OS_IOS)
49 gfx::GLSurfaceTestSupport::InitializeOneOff();
50 #endif
51 #if defined(OS_ANDROID)
52 // Register JNI bindings for android.
53 JNIEnv* env = base::android::AttachCurrentThread();
54 ASSERT_TRUE(gfx::android::RegisterJni(env));
55 ASSERT_TRUE(ui::android::RegisterJni(env));
56 ASSERT_TRUE(invalidation::android::RegisterInvalidationJni(env));
57 ASSERT_TRUE(policy::android::RegisterPolicy(env));
58 ASSERT_TRUE(safe_json::android::RegisterSafeJsonJni(env));
59 ASSERT_TRUE(signin::android::RegisterSigninJni(env));
60 #endif
62 ui::RegisterPathProvider();
64 base::FilePath pak_path;
65 #if defined(OS_ANDROID)
66 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path);
67 #else
68 PathService::Get(base::DIR_MODULE, &pak_path);
69 #endif
71 base::FilePath ui_test_pak_path;
72 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
73 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
75 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
76 pak_path.AppendASCII("components_tests_resources.pak"),
77 ui::SCALE_FACTOR_NONE);
79 // These schemes need to be added globally to pass tests of
80 // autocomplete_input_unittest.cc and content_settings_pattern*
81 url::AddStandardScheme("chrome", url::SCHEME_WITHOUT_PORT);
82 url::AddStandardScheme("chrome-extension", url::SCHEME_WITHOUT_PORT);
83 url::AddStandardScheme("chrome-devtools", url::SCHEME_WITHOUT_PORT);
84 url::AddStandardScheme("chrome-search", url::SCHEME_WITHOUT_PORT);
86 // Not using kExtensionScheme to avoid the dependency to extensions.
87 ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
88 "chrome-extension");
91 void Shutdown() override {
92 ui::ResourceBundle::CleanupSharedInstance();
94 base::TestSuite::Shutdown();
97 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite);
100 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener {
101 public:
102 ComponentsUnitTestEventListener() {}
103 ~ComponentsUnitTestEventListener() override {}
105 void OnTestStart(const testing::TestInfo& test_info) override {
106 #if !defined(OS_IOS)
107 content_initializer_.reset(new content::TestContentClientInitializer());
108 #endif
111 void OnTestEnd(const testing::TestInfo& test_info) override {
112 #if !defined(OS_IOS)
113 content_initializer_.reset();
114 #endif
117 private:
118 #if !defined(OS_IOS)
119 scoped_ptr<content::TestContentClientInitializer> content_initializer_;
120 #endif
122 DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener);
125 } // namespace
127 int main(int argc, char** argv) {
128 ComponentsTestSuite test_suite(argc, argv);
130 // The listener will set up common test environment for all components unit
131 // tests.
132 testing::TestEventListeners& listeners =
133 testing::UnitTest::GetInstance()->listeners();
134 listeners.Append(new ComponentsUnitTestEventListener());
136 return base::LaunchUnitTests(
137 argc, argv, base::Bind(&base::TestSuite::Run,
138 base::Unretained(&test_suite)));