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 "content/public/test/content_test_suite_base.h"
7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/statistics_recorder.h"
11 #include "base/test/test_suite.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "content/browser/browser_thread_impl.h"
14 #include "content/common/url_schemes.h"
15 #include "content/gpu/in_process_gpu_thread.h"
16 #include "content/public/common/content_client.h"
17 #include "content/renderer/in_process_renderer_thread.h"
18 #include "content/utility/in_process_utility_thread.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/base/ui_base_paths.h"
23 #include "content/browser/gpu/gpu_process_host.h"
24 #include "content/browser/renderer_host/render_process_host_impl.h"
25 #include "content/browser/utility_process_host_impl.h"
26 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
27 #include "gin/v8_initializer.h"
31 #if defined(OS_ANDROID)
32 #include "base/android/jni_android.h"
33 #include "content/browser/android/browser_jni_registrar.h"
34 #include "content/common/android/common_jni_registrar.h"
35 #include "content/public/browser/android/compositor.h"
36 #include "media/base/android/media_jni_registrar.h"
37 #include "net/android/net_jni_registrar.h"
38 #include "ui/android/ui_android_jni_registrar.h"
39 #include "ui/base/android/ui_base_jni_registrar.h"
40 #include "ui/gfx/android/gfx_jni_registrar.h"
41 #include "ui/gl/android/gl_jni_registrar.h"
42 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h"
45 #if defined(USE_OZONE)
46 #include "ui/ozone/public/ozone_platform.h"
52 class ContentTestSuiteBaseListener
: public testing::EmptyTestEventListener
{
54 ContentTestSuiteBaseListener() {
56 void OnTestEnd(const testing::TestInfo
& test_info
) override
{
57 BrowserThreadImpl::FlushThreadPoolHelperForTesting();
60 DISALLOW_COPY_AND_ASSIGN(ContentTestSuiteBaseListener
);
63 ContentTestSuiteBase::ContentTestSuiteBase(int argc
, char** argv
)
64 : base::TestSuite(argc
, argv
) {
67 void ContentTestSuiteBase::Initialize() {
68 base::TestSuite::Initialize();
70 // Initialize the histograms subsystem, so that any histograms hit in tests
71 // are correctly registered with the statistics recorder and can be queried
73 base::StatisticsRecorder::Initialize();
75 #if !defined(OS_IOS) && defined(V8_USE_EXTERNAL_STARTUP_DATA)
76 gin::V8Initializer::LoadV8Snapshot();
77 gin::V8Initializer::LoadV8Natives();
80 #if defined(OS_ANDROID)
81 // Register JNI bindings for android.
82 JNIEnv
* env
= base::android::AttachCurrentThread();
83 content::android::RegisterCommonJni(env
);
84 content::android::RegisterBrowserJni(env
);
85 gfx::android::RegisterJni(env
);
86 media::RegisterJni(env
);
87 net::android::RegisterJni(env
);
88 ui::android::RegisterJni(env
);
89 ui::RegisterUIAndroidJni(env
);
90 ui::gl::android::RegisterJni(env
);
91 ui::shell_dialogs::RegisterJni(env
);
93 content::Compositor::Initialize();
96 #if defined(USE_OZONE)
97 ui::OzonePlatform::InitializeForUI();
100 testing::UnitTest::GetInstance()->listeners().Append(
101 new ContentTestSuiteBaseListener
);
104 void ContentTestSuiteBase::RegisterContentSchemes(
105 ContentClient
* content_client
) {
106 SetContentClient(content_client
);
107 content::RegisterContentSchemes(false);
108 SetContentClient(NULL
);
111 void ContentTestSuiteBase::RegisterInProcessThreads() {
113 UtilityProcessHostImpl::RegisterUtilityMainThreadFactory(
114 CreateInProcessUtilityThread
);
115 RenderProcessHostImpl::RegisterRendererMainThreadFactory(
116 CreateInProcessRendererThread
);
117 GpuProcessHost::RegisterGpuMainThreadFactory(CreateInProcessGpuThread
);
121 } // namespace content