OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "media/base/cdm_config.h" | 15 #include "media/base/cdm_config.h" |
16 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
17 #include "media/base/test_helpers.h" | 17 #include "media/base/test_helpers.h" |
18 #include "media/mojo/clients/mojo_demuxer_stream_impl.h" | 18 #include "media/mojo/clients/mojo_demuxer_stream_impl.h" |
19 #include "media/mojo/common/media_type_converters.h" | 19 #include "media/mojo/common/media_type_converters.h" |
| 20 #include "media/mojo/features.h" |
20 #include "media/mojo/interfaces/content_decryption_module.mojom.h" | 21 #include "media/mojo/interfaces/content_decryption_module.mojom.h" |
21 #include "media/mojo/interfaces/decryptor.mojom.h" | 22 #include "media/mojo/interfaces/decryptor.mojom.h" |
22 #include "media/mojo/interfaces/interface_factory.mojom.h" | 23 #include "media/mojo/interfaces/interface_factory.mojom.h" |
23 #include "media/mojo/interfaces/media_service.mojom.h" | 24 #include "media/mojo/interfaces/media_service.mojom.h" |
24 #include "media/mojo/interfaces/renderer.mojom.h" | 25 #include "media/mojo/interfaces/renderer.mojom.h" |
25 #include "media/mojo/services/media_interface_provider.h" | 26 #include "media/mojo/services/media_interface_provider.h" |
26 #include "mojo/public/cpp/bindings/associated_binding.h" | 27 #include "mojo/public/cpp/bindings/associated_binding.h" |
27 #include "mojo/public/cpp/bindings/interface_request.h" | 28 #include "mojo/public/cpp/bindings/interface_request.h" |
28 #include "services/service_manager/public/cpp/service_test.h" | 29 #include "services/service_manager/public/cpp/service_test.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
30 | 31 |
31 using testing::Exactly; | 32 using testing::Exactly; |
32 using testing::Invoke; | 33 using testing::Invoke; |
33 using testing::InvokeWithoutArgs; | 34 using testing::InvokeWithoutArgs; |
34 using testing::StrictMock; | 35 using testing::StrictMock; |
35 | 36 |
36 namespace media { | 37 namespace media { |
37 namespace { | 38 namespace { |
38 | 39 |
39 #if defined(ENABLE_MOJO_CDM) | 40 #if BUILDFLAG(ENABLE_MOJO_CDM) |
40 const char kClearKeyKeySystem[] = "org.w3.clearkey"; | 41 const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
41 const char kInvalidKeySystem[] = "invalid.key.system"; | 42 const char kInvalidKeySystem[] = "invalid.key.system"; |
42 #endif | 43 #endif |
43 const char kSecurityOrigin[] = "http://foo.com"; | 44 const char kSecurityOrigin[] = "http://foo.com"; |
44 | 45 |
45 class MockRendererClient : public mojom::RendererClient { | 46 class MockRendererClient : public mojom::RendererClient { |
46 public: | 47 public: |
47 MockRendererClient() {} | 48 MockRendererClient() {} |
48 ~MockRendererClient() override {} | 49 ~MockRendererClient() override {} |
49 | 50 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 157 |
157 private: | 158 private: |
158 DISALLOW_COPY_AND_ASSIGN(MediaServiceTest); | 159 DISALLOW_COPY_AND_ASSIGN(MediaServiceTest); |
159 }; | 160 }; |
160 | 161 |
161 } // namespace | 162 } // namespace |
162 | 163 |
163 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because | 164 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because |
164 // even when the loop is idle, we may still have pending events in the pipe. | 165 // even when the loop is idle, we may still have pending events in the pipe. |
165 | 166 |
166 #if defined(ENABLE_MOJO_CDM) | 167 #if BUILDFLAG(ENABLE_MOJO_CDM) |
167 TEST_F(MediaServiceTest, InitializeCdm_Success) { | 168 TEST_F(MediaServiceTest, InitializeCdm_Success) { |
168 InitializeCdm(kClearKeyKeySystem, true, 1); | 169 InitializeCdm(kClearKeyKeySystem, true, 1); |
169 run_loop_->Run(); | 170 run_loop_->Run(); |
170 } | 171 } |
171 | 172 |
172 TEST_F(MediaServiceTest, InitializeCdm_InvalidKeySystem) { | 173 TEST_F(MediaServiceTest, InitializeCdm_InvalidKeySystem) { |
173 InitializeCdm(kInvalidKeySystem, false, 0); | 174 InitializeCdm(kInvalidKeySystem, false, 0); |
174 run_loop_->Run(); | 175 run_loop_->Run(); |
175 } | 176 } |
176 #endif // defined(ENABLE_MOJO_CDM) | 177 #endif // BUILDFLAG(ENABLE_MOJO_CDM) |
177 | 178 |
178 #if defined(ENABLE_MOJO_RENDERER) | 179 #if BUILDFLAG(ENABLE_MOJO_RENDERER) |
179 // Sometimes fails on Linux. http://crbug.com/594977 | 180 // Sometimes fails on Linux. http://crbug.com/594977 |
180 #if defined(OS_LINUX) | 181 #if defined(OS_LINUX) |
181 #define MAYBE_InitializeRenderer_Success DISABLED_InitializeRenderer_Success | 182 #define MAYBE_InitializeRenderer_Success DISABLED_InitializeRenderer_Success |
182 #else | 183 #else |
183 #define MAYBE_InitializeRenderer_Success InitializeRenderer_Success | 184 #define MAYBE_InitializeRenderer_Success InitializeRenderer_Success |
184 #endif | 185 #endif |
185 | 186 |
186 TEST_F(MediaServiceTest, MAYBE_InitializeRenderer_Success) { | 187 TEST_F(MediaServiceTest, MAYBE_InitializeRenderer_Success) { |
187 InitializeRenderer(TestVideoConfig::Normal(), true); | 188 InitializeRenderer(TestVideoConfig::Normal(), true); |
188 run_loop_->Run(); | 189 run_loop_->Run(); |
189 } | 190 } |
190 | 191 |
191 TEST_F(MediaServiceTest, InitializeRenderer_InvalidConfig) { | 192 TEST_F(MediaServiceTest, InitializeRenderer_InvalidConfig) { |
192 InitializeRenderer(TestVideoConfig::Invalid(), false); | 193 InitializeRenderer(TestVideoConfig::Invalid(), false); |
193 run_loop_->Run(); | 194 run_loop_->Run(); |
194 } | 195 } |
195 #endif // defined(ENABLE_MOJO_RENDERER) | 196 #endif // BUILDFLAG(ENABLE_MOJO_RENDERER) |
196 | 197 |
197 TEST_F(MediaServiceTest, Lifetime) { | 198 TEST_F(MediaServiceTest, Lifetime) { |
198 // The lifetime of the media service is controlled by the number of | 199 // The lifetime of the media service is controlled by the number of |
199 // live InterfaceFactory impls, not MediaService impls, so this pipe should | 200 // live InterfaceFactory impls, not MediaService impls, so this pipe should |
200 // be closed when the last InterfaceFactory is destroyed. | 201 // be closed when the last InterfaceFactory is destroyed. |
201 media::mojom::MediaServicePtr media_service; | 202 media::mojom::MediaServicePtr media_service; |
202 connector()->BindInterface("media", &media_service); | 203 connector()->BindInterface("media", &media_service); |
203 media_service.set_connection_error_handler( | 204 media_service.set_connection_error_handler( |
204 base::Bind(&MediaServiceTest::ConnectionClosed, base::Unretained(this))); | 205 base::Bind(&MediaServiceTest::ConnectionClosed, base::Unretained(this))); |
205 | 206 |
206 // Disconnecting CDM and Renderer services doesn't terminate the app. | 207 // Disconnecting CDM and Renderer services doesn't terminate the app. |
207 cdm_.reset(); | 208 cdm_.reset(); |
208 renderer_.reset(); | 209 renderer_.reset(); |
209 | 210 |
210 // Disconnecting InterfaceFactory service should terminate the app, which will | 211 // Disconnecting InterfaceFactory service should terminate the app, which will |
211 // close the connection. | 212 // close the connection. |
212 EXPECT_CALL(*this, ConnectionClosed()) | 213 EXPECT_CALL(*this, ConnectionClosed()) |
213 .Times(Exactly(1)) | 214 .Times(Exactly(1)) |
214 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); | 215 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); |
215 interface_factory_.reset(); | 216 interface_factory_.reset(); |
216 | 217 |
217 run_loop_->Run(); | 218 run_loop_->Run(); |
218 } | 219 } |
219 | 220 |
220 } // namespace media | 221 } // namespace media |
OLD | NEW |