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"
28 #if defined(OS_ANDROID)
29 #include "base/android/jni_android.h"
30 #include "content/browser/android/browser_jni_registrar.h"
31 #include "content/common/android/common_jni_registrar.h"
32 #include "content/public/browser/android/compositor.h"
33 #include "media/base/android/media_jni_registrar.h"
34 #include "net/android/net_jni_registrar.h"
35 #include "ui/android/ui_android_jni_registrar.h"
36 #include "ui/base/android/ui_base_jni_registrar.h"
37 #include "ui/gfx/android/gfx_jni_registrar.h"
38 #include "ui/gl/android/gl_jni_registrar.h"
39 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h"
42 #if defined(USE_OZONE)
43 #include "ui/ozone/public/ozone_platform.h"
46 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
47 #include "gin/v8_initializer.h"
52 class ContentTestSuiteBaseListener
: public testing::EmptyTestEventListener
{
54 ContentTestSuiteBaseListener() {
56 virtual 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 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
76 gin::V8Initializer::LoadV8Snapshot();
79 #if defined(OS_ANDROID)
80 // Register JNI bindings for android.
81 JNIEnv
* env
= base::android::AttachCurrentThread();
82 content::android::RegisterCommonJni(env
);
83 content::android::RegisterBrowserJni(env
);
84 gfx::android::RegisterJni(env
);
85 media::RegisterJni(env
);
86 net::android::RegisterJni(env
);
87 ui::android::RegisterJni(env
);
88 ui::RegisterUIAndroidJni(env
);
89 ui::gl::android::RegisterJni(env
);
90 ui::shell_dialogs::RegisterJni(env
);
92 content::Compositor::Initialize();
95 #if defined(USE_OZONE)
96 ui::OzonePlatform::InitializeForUI();
99 testing::UnitTest::GetInstance()->listeners().Append(
100 new ContentTestSuiteBaseListener
);
103 void ContentTestSuiteBase::RegisterContentSchemes(
104 ContentClient
* content_client
) {
105 SetContentClient(content_client
);
106 content::RegisterContentSchemes(false);
107 SetContentClient(NULL
);
110 void ContentTestSuiteBase::RegisterInProcessThreads() {
112 UtilityProcessHostImpl::RegisterUtilityMainThreadFactory(
113 CreateInProcessUtilityThread
);
114 RenderProcessHostImpl::RegisterRendererMainThreadFactory(
115 CreateInProcessRendererThread
);
116 GpuProcessHost::RegisterGpuMainThreadFactory(CreateInProcessGpuThread
);
120 } // namespace content