• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/test/test_suite.h"
11 #include "base/threading/sequenced_worker_pool.h"
12 #include "content/browser/browser_thread_impl.h"
13 #include "content/browser/gpu/gpu_process_host.h"
14 #include "content/common/url_schemes.h"
15 #include "content/gpu/in_process_gpu_thread.h"
16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/utility_process_host.h"
18 #include "content/public/common/content_client.h"
19 #include "content/public/common/content_paths.h"
20 #include "content/renderer/in_process_renderer_thread.h"
21 #include "content/utility/in_process_utility_thread.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/base/ui_base_paths.h"
24 
25 #if defined(OS_ANDROID)
26 #include "base/android/jni_android.h"
27 #include "content/browser/android/browser_jni_registrar.h"
28 #include "content/common/android/common_jni_registrar.h"
29 #include "media/base/android/media_jni_registrar.h"
30 #include "net/android/net_jni_registrar.h"
31 #include "ui/base/android/ui_base_jni_registrar.h"
32 #include "ui/gfx/android/gfx_jni_registrar.h"
33 #include "ui/gl/android/gl_jni_registrar.h"
34 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h"
35 #endif
36 
37 #if !defined(OS_IOS)
38 #include "media/base/media.h"
39 #endif
40 
41 namespace content {
42 
43 class ContentTestSuiteBaseListener : public testing::EmptyTestEventListener {
44  public:
ContentTestSuiteBaseListener()45   ContentTestSuiteBaseListener() {
46   }
OnTestEnd(const testing::TestInfo & test_info)47   virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
48     BrowserThreadImpl::FlushThreadPoolHelper();
49   }
50  private:
51   DISALLOW_COPY_AND_ASSIGN(ContentTestSuiteBaseListener);
52 };
53 
ContentTestSuiteBase(int argc,char ** argv)54 ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv)
55     : base::TestSuite(argc, argv),
56       external_libraries_enabled_(true) {
57 }
58 
Initialize()59 void ContentTestSuiteBase::Initialize() {
60   base::TestSuite::Initialize();
61 
62 #if defined(OS_ANDROID)
63   // Register JNI bindings for android.
64   JNIEnv* env = base::android::AttachCurrentThread();
65   content::android::RegisterCommonJni(env);
66   content::android::RegisterBrowserJni(env);
67   gfx::android::RegisterJni(env);
68   media::RegisterJni(env);
69   net::android::RegisterJni(env);
70   ui::android::RegisterJni(env);
71   ui::shell_dialogs::RegisterJni(env);
72 #endif
73 
74 #if !defined(OS_IOS)
75   UtilityProcessHost::RegisterUtilityMainThreadFactory(
76       CreateInProcessUtilityThread);
77   RenderProcessHost::RegisterRendererMainThreadFactory(
78       CreateInProcessRendererThread);
79   GpuProcessHost::RegisterGpuMainThreadFactory(CreateInProcessGpuThread);
80   if (external_libraries_enabled_)
81     media::InitializeMediaLibraryForTesting();
82 #endif
83 
84   scoped_ptr<ContentClient> client_for_init(CreateClientForInitialization());
85   SetContentClient(client_for_init.get());
86   RegisterContentSchemes(false);
87   SetContentClient(NULL);
88 
89   RegisterPathProvider();
90   ui::RegisterPathProvider();
91 
92   testing::UnitTest::GetInstance()->listeners().Append(
93       new ContentTestSuiteBaseListener);
94 }
95 
96 }  // namespace content
97