content_test_suite_base.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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.
4
5#include "content/public/test/content_test_suite_base.h"
6
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"
21
22#if !defined(OS_IOS)
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#endif
27
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 "media/base/android/media_jni_registrar.h"
33#include "net/android/net_jni_registrar.h"
34#include "ui/base/android/ui_base_jni_registrar.h"
35#include "ui/gfx/android/gfx_jni_registrar.h"
36#include "ui/gl/android/gl_jni_registrar.h"
37#include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h"
38#endif
39
40namespace content {
41
42class ContentTestSuiteBaseListener : public testing::EmptyTestEventListener {
43 public:
44  ContentTestSuiteBaseListener() {
45  }
46  virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
47    BrowserThreadImpl::FlushThreadPoolHelper();
48  }
49 private:
50  DISALLOW_COPY_AND_ASSIGN(ContentTestSuiteBaseListener);
51};
52
53ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv)
54    : base::TestSuite(argc, argv) {
55}
56
57void ContentTestSuiteBase::Initialize() {
58  base::TestSuite::Initialize();
59
60  // Initialize the histograms subsystem, so that any histograms hit in tests
61  // are correctly registered with the statistics recorder and can be queried
62  // by tests.
63  base::StatisticsRecorder::Initialize();
64
65#if defined(OS_ANDROID)
66  // Register JNI bindings for android.
67  JNIEnv* env = base::android::AttachCurrentThread();
68  content::android::RegisterCommonJni(env);
69  content::android::RegisterBrowserJni(env);
70  gfx::android::RegisterJni(env);
71  media::RegisterJni(env);
72  net::android::RegisterJni(env);
73  ui::android::RegisterJni(env);
74  ui::shell_dialogs::RegisterJni(env);
75#endif
76
77  testing::UnitTest::GetInstance()->listeners().Append(
78      new ContentTestSuiteBaseListener);
79}
80
81void ContentTestSuiteBase::RegisterContentSchemes(
82    ContentClient* content_client) {
83  SetContentClient(content_client);
84  content::RegisterContentSchemes(false);
85  SetContentClient(NULL);
86}
87
88void ContentTestSuiteBase::RegisterInProcessThreads() {
89#if !defined(OS_IOS)
90  UtilityProcessHostImpl::RegisterUtilityMainThreadFactory(
91      CreateInProcessUtilityThread);
92  RenderProcessHostImpl::RegisterRendererMainThreadFactory(
93      CreateInProcessRendererThread);
94  GpuProcessHost::RegisterGpuMainThreadFactory(CreateInProcessGpuThread);
95#endif
96}
97
98}  // namespace content
99