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/test/content_test_suite.h"
7 #if defined(OS_ANDROID)
8 #include <android/native_window.h>
9 #include <android/native_window_jni.h>
13 #include "base/base_paths.h"
14 #include "base/logging.h"
15 #include "content/public/common/content_client.h"
16 #include "content/public/common/content_paths.h"
17 #include "content/public/test/test_content_client_initializer.h"
18 #include "gpu/config/gpu_util.h"
19 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/gfx/win/dpi.h"
25 #if defined(OS_MACOSX)
26 #include "base/mac/scoped_nsautorelease_pool.h"
28 #include "base/test/mock_chrome_application_mac.h"
33 #include "base/base_switches.h"
34 #include "base/command_line.h"
35 #include "media/base/media.h"
36 #include "ui/gl/gl_surface.h"
39 #if defined(OS_ANDROID)
40 #include "base/android/jni_android.h"
41 #include "base/memory/linked_ptr.h"
42 #include "content/common/android/surface_texture_manager.h"
43 #include "ui/gl/android/scoped_java_surface.h"
44 #include "ui/gl/android/surface_texture.h"
50 class TestInitializationListener
: public testing::EmptyTestEventListener
{
52 TestInitializationListener() : test_content_client_initializer_(NULL
) {
55 virtual void OnTestStart(const testing::TestInfo
& test_info
) override
{
56 test_content_client_initializer_
=
57 new content::TestContentClientInitializer();
60 virtual void OnTestEnd(const testing::TestInfo
& test_info
) override
{
61 delete test_content_client_initializer_
;
65 content::TestContentClientInitializer
* test_content_client_initializer_
;
67 DISALLOW_COPY_AND_ASSIGN(TestInitializationListener
);
70 #if defined(OS_ANDROID)
71 class SurfaceTextureManagerImpl
: public SurfaceTextureManager
{
73 // Overridden from SurfaceTextureManager:
74 void RegisterSurfaceTexture(int surface_texture_id
,
76 gfx::SurfaceTexture
* surface_texture
) override
{
77 surfaces_
[surface_texture_id
] =
78 make_linked_ptr(new gfx::ScopedJavaSurface(surface_texture
));
80 void UnregisterSurfaceTexture(int surface_texture_id
,
81 int client_id
) override
{
82 surfaces_
.erase(surface_texture_id
);
84 gfx::AcceleratedWidget
AcquireNativeWidgetForSurfaceTexture(
85 int surface_texture_id
) override
{
86 JNIEnv
* env
= base::android::AttachCurrentThread();
87 return ANativeWindow_fromSurface(
88 env
, surfaces_
[surface_texture_id
]->j_surface().obj());
92 typedef std::map
<int, linked_ptr
<gfx::ScopedJavaSurface
>> SurfaceMap
;
99 ContentTestSuite::ContentTestSuite(int argc
, char** argv
)
100 : ContentTestSuiteBase(argc
, argv
) {
103 ContentTestSuite::~ContentTestSuite() {
106 void ContentTestSuite::Initialize() {
107 #if defined(OS_MACOSX)
108 base::mac::ScopedNSAutoreleasePool autorelease_pool
;
110 mock_cr_app::RegisterMockCrApp();
115 gfx::InitDeviceScaleFactor(1.0f
);
118 ContentTestSuiteBase::Initialize();
120 ContentClient client
;
121 ContentTestSuiteBase::RegisterContentSchemes(&client
);
123 RegisterPathProvider();
125 media::InitializeMediaLibraryForTesting();
126 // When running in a child process for Mac sandbox tests, the sandbox exists
127 // to initialize GL, so don't do it here.
128 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
129 switches::kTestChildProcess
)) {
130 gfx::GLSurface::InitializeOneOffForTests();
131 gpu::ApplyGpuDriverBugWorkarounds(base::CommandLine::ForCurrentProcess());
134 testing::TestEventListeners
& listeners
=
135 testing::UnitTest::GetInstance()->listeners();
136 listeners
.Append(new TestInitializationListener
);
137 #if defined(OS_ANDROID)
138 SurfaceTextureManager::InitInstance(new SurfaceTextureManagerImpl
);
142 } // namespace content