OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <array> | 5 #include <array> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "content/child/child_process.h" | 14 #include "content/child/child_process.h" |
| 15 #include "content/common/media/media_stream_options.h" |
15 #include "content/common/video_capture.mojom.h" | 16 #include "content/common/video_capture.mojom.h" |
16 #include "content/renderer/media/video_capture_impl.h" | 17 #include "content/renderer/media/video_capture_impl.h" |
17 #include "content/renderer/media/video_capture_impl_manager.h" | 18 #include "content/renderer/media/video_capture_impl_manager.h" |
18 #include "media/base/bind_to_current_loop.h" | 19 #include "media/base/bind_to_current_loop.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using ::testing::_; | 23 using ::testing::_; |
23 using ::testing::DoAll; | 24 using ::testing::DoAll; |
24 using ::testing::InSequence; | 25 using ::testing::InSequence; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 222 } |
222 | 223 |
223 TEST_F(VideoCaptureImplManagerTest, NoLeak) { | 224 TEST_F(VideoCaptureImplManagerTest, NoLeak) { |
224 manager_->UseDevice(0).Reset(); | 225 manager_->UseDevice(0).Reset(); |
225 manager_.reset(); | 226 manager_.reset(); |
226 cleanup_run_loop_.Run(); | 227 cleanup_run_loop_.Run(); |
227 } | 228 } |
228 | 229 |
229 TEST_F(VideoCaptureImplManagerTest, SuspendAndResumeSessions) { | 230 TEST_F(VideoCaptureImplManagerTest, SuspendAndResumeSessions) { |
230 std::array<base::Closure, kNumClients> release_callbacks; | 231 std::array<base::Closure, kNumClients> release_callbacks; |
| 232 StreamDeviceInfoArray video_device_array; |
231 for (size_t i = 0; i < kNumClients; ++i) { | 233 for (size_t i = 0; i < kNumClients; ++i) { |
232 release_callbacks[i] = | 234 release_callbacks[i] = |
233 manager_->UseDevice(static_cast<media::VideoCaptureSessionId>(i)); | 235 manager_->UseDevice(static_cast<media::VideoCaptureSessionId>(i)); |
| 236 StreamDeviceInfo video_device_info; |
| 237 video_device_info.session_id = static_cast<media::VideoCaptureSessionId>(i); |
| 238 video_device_array.push_back(video_device_info); |
234 } | 239 } |
235 std::array<base::Closure, kNumClients> stop_callbacks = | 240 std::array<base::Closure, kNumClients> stop_callbacks = |
236 StartCaptureForAllClients(false); | 241 StartCaptureForAllClients(false); |
237 | 242 |
238 // Call SuspendDevices(true) to suspend all clients, and expect all to be | 243 // Call SuspendDevices(true) to suspend all clients, and expect all to be |
239 // paused. | 244 // paused. |
240 { | 245 { |
241 base::RunLoop run_loop; | 246 base::RunLoop run_loop; |
242 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | 247 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); |
243 EXPECT_CALL(*this, OnPaused(0)).Times(1).RetiresOnSaturation(); | 248 EXPECT_CALL(*this, OnPaused(0)).Times(1).RetiresOnSaturation(); |
244 EXPECT_CALL(*this, OnPaused(1)).Times(1).RetiresOnSaturation(); | 249 EXPECT_CALL(*this, OnPaused(1)).Times(1).RetiresOnSaturation(); |
245 EXPECT_CALL(*this, OnPaused(2)).WillOnce(RunClosure(quit_closure)) | 250 EXPECT_CALL(*this, OnPaused(2)).WillOnce(RunClosure(quit_closure)) |
246 .RetiresOnSaturation(); | 251 .RetiresOnSaturation(); |
247 manager_->SuspendDevices(true); | 252 manager_->SuspendDevices(video_device_array, true); |
248 run_loop.Run(); | 253 run_loop.Run(); |
249 } | 254 } |
250 | 255 |
251 // Call SuspendDevices(false) and expect all to be resumed. | 256 // Call SuspendDevices(false) and expect all to be resumed. |
252 { | 257 { |
253 base::RunLoop run_loop; | 258 base::RunLoop run_loop; |
254 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | 259 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); |
255 EXPECT_CALL(*this, OnResumed(0)).Times(1).RetiresOnSaturation(); | 260 EXPECT_CALL(*this, OnResumed(0)).Times(1).RetiresOnSaturation(); |
256 EXPECT_CALL(*this, OnResumed(1)).Times(1).RetiresOnSaturation(); | 261 EXPECT_CALL(*this, OnResumed(1)).Times(1).RetiresOnSaturation(); |
257 EXPECT_CALL(*this, OnResumed(2)).WillOnce(RunClosure(quit_closure)) | 262 EXPECT_CALL(*this, OnResumed(2)).WillOnce(RunClosure(quit_closure)) |
258 .RetiresOnSaturation(); | 263 .RetiresOnSaturation(); |
259 manager_->SuspendDevices(false); | 264 manager_->SuspendDevices(video_device_array, false); |
260 run_loop.Run(); | 265 run_loop.Run(); |
261 } | 266 } |
262 | 267 |
263 // Suspend just the first client and expect just the first client to be | 268 // Suspend just the first client and expect just the first client to be |
264 // paused. | 269 // paused. |
265 { | 270 { |
266 base::RunLoop run_loop; | 271 base::RunLoop run_loop; |
267 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | 272 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); |
268 EXPECT_CALL(*this, OnPaused(0)).WillOnce(RunClosure(quit_closure)) | 273 EXPECT_CALL(*this, OnPaused(0)).WillOnce(RunClosure(quit_closure)) |
269 .RetiresOnSaturation(); | 274 .RetiresOnSaturation(); |
270 manager_->Suspend(0); | 275 manager_->Suspend(0); |
271 run_loop.Run(); | 276 run_loop.Run(); |
272 } | 277 } |
273 | 278 |
274 // Now call SuspendDevices(true) again, and expect just the second and third | 279 // Now call SuspendDevices(true) again, and expect just the second and third |
275 // clients to be paused. | 280 // clients to be paused. |
276 { | 281 { |
277 base::RunLoop run_loop; | 282 base::RunLoop run_loop; |
278 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | 283 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); |
279 EXPECT_CALL(*this, OnPaused(1)).Times(1).RetiresOnSaturation(); | 284 EXPECT_CALL(*this, OnPaused(1)).Times(1).RetiresOnSaturation(); |
280 EXPECT_CALL(*this, OnPaused(2)).WillOnce(RunClosure(quit_closure)) | 285 EXPECT_CALL(*this, OnPaused(2)).WillOnce(RunClosure(quit_closure)) |
281 .RetiresOnSaturation(); | 286 .RetiresOnSaturation(); |
282 manager_->SuspendDevices(true); | 287 manager_->SuspendDevices(video_device_array, true); |
283 run_loop.Run(); | 288 run_loop.Run(); |
284 } | 289 } |
285 | 290 |
286 // Resume just the first client, but it should not resume because all devices | 291 // Resume just the first client, but it should not resume because all devices |
287 // are supposed to be suspended. | 292 // are supposed to be suspended. |
288 { | 293 { |
289 manager_->Resume(0); | 294 manager_->Resume(0); |
290 base::RunLoop().RunUntilIdle(); | 295 base::RunLoop().RunUntilIdle(); |
291 } | 296 } |
292 | 297 |
293 // Now, call SuspendDevices(false) and expect all to be resumed. | 298 // Now, call SuspendDevices(false) and expect all to be resumed. |
294 { | 299 { |
295 base::RunLoop run_loop; | 300 base::RunLoop run_loop; |
296 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | 301 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); |
297 EXPECT_CALL(*this, OnResumed(0)).Times(1).RetiresOnSaturation(); | 302 EXPECT_CALL(*this, OnResumed(0)).Times(1).RetiresOnSaturation(); |
298 EXPECT_CALL(*this, OnResumed(1)).Times(1).RetiresOnSaturation(); | 303 EXPECT_CALL(*this, OnResumed(1)).Times(1).RetiresOnSaturation(); |
299 EXPECT_CALL(*this, OnResumed(2)).WillOnce(RunClosure(quit_closure)) | 304 EXPECT_CALL(*this, OnResumed(2)).WillOnce(RunClosure(quit_closure)) |
300 .RetiresOnSaturation(); | 305 .RetiresOnSaturation(); |
301 manager_->SuspendDevices(false); | 306 manager_->SuspendDevices(video_device_array, false); |
302 run_loop.Run(); | 307 run_loop.Run(); |
303 } | 308 } |
304 | 309 |
305 StopCaptureForAllClients(&stop_callbacks); | 310 StopCaptureForAllClients(&stop_callbacks); |
306 for (const auto& release_callback : release_callbacks) | 311 for (const auto& release_callback : release_callbacks) |
307 release_callback.Run(); | 312 release_callback.Run(); |
308 cleanup_run_loop_.Run(); | 313 cleanup_run_loop_.Run(); |
309 } | 314 } |
310 | 315 |
311 } // namespace content | 316 } // namespace content |
OLD | NEW |