OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/test/content_test_suite.h" | 5 #include "content/test/content_test_suite.h" |
6 | 6 |
7 #if defined(OS_ANDROID) | |
8 #include <android/native_window.h> | |
9 #include <android/native_window_jni.h> | |
10 #endif | |
11 | |
12 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
13 #include "base/logging.h" | 8 #include "base/logging.h" |
14 #include "content/public/common/content_client.h" | 9 #include "content/public/common/content_client.h" |
15 #include "content/public/common/content_paths.h" | 10 #include "content/public/common/content_paths.h" |
16 #include "content/public/test/test_content_client_initializer.h" | 11 #include "content/public/test/test_content_client_initializer.h" |
17 #include "gpu/config/gpu_util.h" | 12 #include "gpu/config/gpu_util.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
19 | 14 |
20 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
21 #include "ui/gfx/win/dpi.h" | 16 #include "ui/gfx/win/dpi.h" |
22 #endif | 17 #endif |
23 | 18 |
24 #if defined(OS_MACOSX) | 19 #if defined(OS_MACOSX) |
25 #include "base/mac/scoped_nsautorelease_pool.h" | 20 #include "base/mac/scoped_nsautorelease_pool.h" |
26 #if !defined(OS_IOS) | 21 #if !defined(OS_IOS) |
27 #include "base/containers/scoped_ptr_hash_map.h" | |
28 #include "base/mac/scoped_mach_port.h" | |
29 #include "base/memory/scoped_ptr.h" | |
30 #include "base/test/mock_chrome_application_mac.h" | 22 #include "base/test/mock_chrome_application_mac.h" |
31 #include "content/common/mac/io_surface_manager.h" | 23 #include "content/browser/in_process_io_surface_manager_mac.h" |
32 #endif | 24 #endif |
33 #endif | 25 #endif |
34 | 26 |
35 #if !defined(OS_IOS) | 27 #if !defined(OS_IOS) |
36 #include "base/base_switches.h" | 28 #include "base/base_switches.h" |
37 #include "base/command_line.h" | 29 #include "base/command_line.h" |
38 #include "media/base/media.h" | 30 #include "media/base/media.h" |
39 #include "ui/gl/gl_surface.h" | 31 #include "ui/gl/gl_surface.h" |
40 #endif | 32 #endif |
41 | 33 |
42 #if defined(OS_ANDROID) | 34 #if defined(OS_ANDROID) |
43 #include "base/android/jni_android.h" | 35 #include "content/browser/android/in_process_surface_texture_manager.h" |
44 #include "base/containers/scoped_ptr_hash_map.h" | |
45 #include "base/memory/scoped_ptr.h" | |
46 #include "content/common/android/surface_texture_manager.h" | |
47 #include "ui/gl/android/scoped_java_surface.h" | |
48 #include "ui/gl/android/surface_texture.h" | |
49 #endif | 36 #endif |
50 | 37 |
51 namespace content { | 38 namespace content { |
52 namespace { | 39 namespace { |
53 | 40 |
54 class TestInitializationListener : public testing::EmptyTestEventListener { | 41 class TestInitializationListener : public testing::EmptyTestEventListener { |
55 public: | 42 public: |
56 TestInitializationListener() : test_content_client_initializer_(NULL) { | 43 TestInitializationListener() : test_content_client_initializer_(NULL) { |
57 } | 44 } |
58 | 45 |
59 void OnTestStart(const testing::TestInfo& test_info) override { | 46 void OnTestStart(const testing::TestInfo& test_info) override { |
60 test_content_client_initializer_ = | 47 test_content_client_initializer_ = |
61 new content::TestContentClientInitializer(); | 48 new content::TestContentClientInitializer(); |
62 } | 49 } |
63 | 50 |
64 void OnTestEnd(const testing::TestInfo& test_info) override { | 51 void OnTestEnd(const testing::TestInfo& test_info) override { |
65 delete test_content_client_initializer_; | 52 delete test_content_client_initializer_; |
66 } | 53 } |
67 | 54 |
68 private: | 55 private: |
69 content::TestContentClientInitializer* test_content_client_initializer_; | 56 content::TestContentClientInitializer* test_content_client_initializer_; |
70 | 57 |
71 DISALLOW_COPY_AND_ASSIGN(TestInitializationListener); | 58 DISALLOW_COPY_AND_ASSIGN(TestInitializationListener); |
72 }; | 59 }; |
73 | 60 |
74 #if defined(OS_ANDROID) | |
75 class TestSurfaceTextureManager : public SurfaceTextureManager { | |
76 public: | |
77 // Overridden from SurfaceTextureManager: | |
78 void RegisterSurfaceTexture(int surface_texture_id, | |
79 int client_id, | |
80 gfx::SurfaceTexture* surface_texture) override { | |
81 surfaces_.add(surface_texture_id, | |
82 make_scoped_ptr(new gfx::ScopedJavaSurface(surface_texture))); | |
83 } | |
84 void UnregisterSurfaceTexture(int surface_texture_id, | |
85 int client_id) override { | |
86 surfaces_.erase(surface_texture_id); | |
87 } | |
88 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( | |
89 int surface_texture_id) override { | |
90 JNIEnv* env = base::android::AttachCurrentThread(); | |
91 return ANativeWindow_fromSurface( | |
92 env, surfaces_.get(surface_texture_id)->j_surface().obj()); | |
93 } | |
94 | |
95 private: | |
96 using SurfaceMap = | |
97 base::ScopedPtrHashMap<int, scoped_ptr<gfx::ScopedJavaSurface>>; | |
98 SurfaceMap surfaces_; | |
99 }; | |
100 #endif | |
101 | |
102 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
103 class TestIOSurfaceManager : public IOSurfaceManager { | |
104 public: | |
105 // Overridden from IOSurfaceManager: | |
106 bool RegisterIOSurface(int io_surface_id, | |
107 int client_id, | |
108 IOSurfaceRef io_surface) override { | |
109 io_surfaces_.add(io_surface_id, | |
110 make_scoped_ptr(new base::mac::ScopedMachSendRight( | |
111 IOSurfaceCreateMachPort(io_surface)))); | |
112 return true; | |
113 } | |
114 void UnregisterIOSurface(int io_surface_id, int client_id) override { | |
115 io_surfaces_.erase(io_surface_id); | |
116 } | |
117 IOSurfaceRef AcquireIOSurface(int io_surface_id) override { | |
118 return IOSurfaceLookupFromMachPort(io_surfaces_.get(io_surface_id)->get()); | |
119 } | |
120 | |
121 private: | |
122 using IOSurfaceMap = | |
123 base::ScopedPtrHashMap<int, scoped_ptr<base::mac::ScopedMachSendRight>>; | |
124 IOSurfaceMap io_surfaces_; | |
125 }; | |
126 #endif | |
127 | |
128 } // namespace | 61 } // namespace |
129 | 62 |
130 ContentTestSuite::ContentTestSuite(int argc, char** argv) | 63 ContentTestSuite::ContentTestSuite(int argc, char** argv) |
131 : ContentTestSuiteBase(argc, argv) { | 64 : ContentTestSuiteBase(argc, argv) { |
132 } | 65 } |
133 | 66 |
134 ContentTestSuite::~ContentTestSuite() { | 67 ContentTestSuite::~ContentTestSuite() { |
135 } | 68 } |
136 | 69 |
137 void ContentTestSuite::Initialize() { | 70 void ContentTestSuite::Initialize() { |
(...skipping 21 matching lines...) Expand all Loading... |
159 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 92 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
160 switches::kTestChildProcess)) { | 93 switches::kTestChildProcess)) { |
161 gfx::GLSurface::InitializeOneOffForTests(); | 94 gfx::GLSurface::InitializeOneOffForTests(); |
162 gpu::ApplyGpuDriverBugWorkarounds(base::CommandLine::ForCurrentProcess()); | 95 gpu::ApplyGpuDriverBugWorkarounds(base::CommandLine::ForCurrentProcess()); |
163 } | 96 } |
164 #endif | 97 #endif |
165 testing::TestEventListeners& listeners = | 98 testing::TestEventListeners& listeners = |
166 testing::UnitTest::GetInstance()->listeners(); | 99 testing::UnitTest::GetInstance()->listeners(); |
167 listeners.Append(new TestInitializationListener); | 100 listeners.Append(new TestInitializationListener); |
168 #if defined(OS_ANDROID) | 101 #if defined(OS_ANDROID) |
169 SurfaceTextureManager::SetInstance(new TestSurfaceTextureManager); | 102 SurfaceTextureManager::SetInstance( |
| 103 InProcessSurfaceTextureManager::GetInstance()); |
170 #endif | 104 #endif |
171 #if defined(OS_MACOSX) && !defined(OS_IOS) | 105 #if defined(OS_MACOSX) && !defined(OS_IOS) |
172 IOSurfaceManager::SetInstance(new TestIOSurfaceManager); | 106 IOSurfaceManager::SetInstance(InProcessIOSurfaceManager::GetInstance()); |
173 #endif | 107 #endif |
174 } | 108 } |
175 | 109 |
176 } // namespace content | 110 } // namespace content |
OLD | NEW |