| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_file.h" | 11 #include "base/files/scoped_file.h" |
| 12 #include "base/location.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/single_thread_task_runner.h" | |
| 16 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 17 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 18 #include "base/thread_task_runner_handle.h" | |
| 19 #include "content/browser/browser_thread_impl.h" | 17 #include "content/browser/browser_thread_impl.h" |
| 20 #include "content/browser/renderer_host/media/media_stream_manager.h" | 18 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 21 #include "content/browser/renderer_host/media/media_stream_requester.h" | 19 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 22 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 20 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 23 #include "content/browser/renderer_host/media/video_capture_host.h" | 21 #include "content/browser/renderer_host/media/video_capture_host.h" |
| 24 #include "content/browser/renderer_host/media/video_capture_manager.h" | 22 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 25 #include "content/common/media/video_capture_messages.h" | 23 #include "content/common/media/video_capture_messages.h" |
| 26 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/test/mock_resource_context.h" | 25 #include "content/public/test/mock_resource_context.h" |
| 28 #include "content/public/test/test_browser_context.h" | 26 #include "content/public/test/test_browser_context.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 OnStateChanged(device_id, state); | 265 OnStateChanged(device_id, state); |
| 268 } | 266 } |
| 269 | 267 |
| 270 std::map<int, base::SharedMemory*> filled_dib_; | 268 std::map<int, base::SharedMemory*> filled_dib_; |
| 271 bool return_buffers_; | 269 bool return_buffers_; |
| 272 bool dump_video_; | 270 bool dump_video_; |
| 273 media::VideoCaptureFormat format_; | 271 media::VideoCaptureFormat format_; |
| 274 DumpVideo dumper_; | 272 DumpVideo dumper_; |
| 275 }; | 273 }; |
| 276 | 274 |
| 277 ACTION_P2(ExitMessageLoop, task_runner, quit_closure) { | 275 ACTION_P2(ExitMessageLoop, message_loop, quit_closure) { |
| 278 task_runner->PostTask(FROM_HERE, quit_closure); | 276 message_loop->PostTask(FROM_HERE, quit_closure); |
| 279 } | 277 } |
| 280 | 278 |
| 281 // This is an integration test of VideoCaptureHost in conjunction with | 279 // This is an integration test of VideoCaptureHost in conjunction with |
| 282 // MediaStreamManager, VideoCaptureManager, VideoCaptureController, and | 280 // MediaStreamManager, VideoCaptureManager, VideoCaptureController, and |
| 283 // VideoCaptureDevice. | 281 // VideoCaptureDevice. |
| 284 class VideoCaptureHostTest : public testing::Test { | 282 class VideoCaptureHostTest : public testing::Test { |
| 285 public: | 283 public: |
| 286 VideoCaptureHostTest() | 284 VideoCaptureHostTest() |
| 287 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 285 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 288 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 286 message_loop_(base::MessageLoopProxy::current()), |
| 289 opened_session_id_(kInvalidMediaCaptureSessionId) {} | 287 opened_session_id_(kInvalidMediaCaptureSessionId) {} |
| 290 | 288 |
| 291 void SetUp() override { | 289 void SetUp() override { |
| 292 SetBrowserClientForTesting(&browser_client_); | 290 SetBrowserClientForTesting(&browser_client_); |
| 293 | 291 |
| 294 #if defined(OS_CHROMEOS) | 292 #if defined(OS_CHROMEOS) |
| 295 chromeos::CrasAudioHandler::InitializeForTesting(); | 293 chromeos::CrasAudioHandler::InitializeForTesting(); |
| 296 #endif | 294 #endif |
| 297 | 295 |
| 298 // Create our own MediaStreamManager. | 296 // Create our own MediaStreamManager. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 { | 342 { |
| 345 base::RunLoop run_loop; | 343 base::RunLoop run_loop; |
| 346 std::string label = media_stream_manager_->EnumerateDevices( | 344 std::string label = media_stream_manager_->EnumerateDevices( |
| 347 &stream_requester_, | 345 &stream_requester_, |
| 348 render_process_id, | 346 render_process_id, |
| 349 render_frame_id, | 347 render_frame_id, |
| 350 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 348 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 351 page_request_id, | 349 page_request_id, |
| 352 MEDIA_DEVICE_VIDEO_CAPTURE, | 350 MEDIA_DEVICE_VIDEO_CAPTURE, |
| 353 security_origin); | 351 security_origin); |
| 354 EXPECT_CALL(stream_requester_, | 352 EXPECT_CALL(stream_requester_, DevicesEnumerated(render_frame_id, |
| 355 DevicesEnumerated(render_frame_id, page_request_id, label, _)) | 353 page_request_id, |
| 356 .Times(1) | 354 label, |
| 357 .WillOnce(DoAll(ExitMessageLoop(task_runner_, run_loop.QuitClosure()), | 355 _)) |
| 358 SaveArg<3>(&devices))); | 356 .Times(1).WillOnce( |
| 357 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), |
| 358 SaveArg<3>(&devices))); |
| 359 run_loop.Run(); | 359 run_loop.Run(); |
| 360 Mock::VerifyAndClearExpectations(&stream_requester_); | 360 Mock::VerifyAndClearExpectations(&stream_requester_); |
| 361 media_stream_manager_->CancelRequest(label); | 361 media_stream_manager_->CancelRequest(label); |
| 362 } | 362 } |
| 363 ASSERT_FALSE(devices.empty()); | 363 ASSERT_FALSE(devices.empty()); |
| 364 ASSERT_EQ(StreamDeviceInfo::kNoId, devices[0].session_id); | 364 ASSERT_EQ(StreamDeviceInfo::kNoId, devices[0].session_id); |
| 365 | 365 |
| 366 // Open the first device. | 366 // Open the first device. |
| 367 { | 367 { |
| 368 base::RunLoop run_loop; | 368 base::RunLoop run_loop; |
| 369 StreamDeviceInfo opened_device; | 369 StreamDeviceInfo opened_device; |
| 370 media_stream_manager_->OpenDevice( | 370 media_stream_manager_->OpenDevice( |
| 371 &stream_requester_, | 371 &stream_requester_, |
| 372 render_process_id, | 372 render_process_id, |
| 373 render_frame_id, | 373 render_frame_id, |
| 374 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 374 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 375 page_request_id, | 375 page_request_id, |
| 376 devices[0].device.id, | 376 devices[0].device.id, |
| 377 MEDIA_DEVICE_VIDEO_CAPTURE, | 377 MEDIA_DEVICE_VIDEO_CAPTURE, |
| 378 security_origin); | 378 security_origin); |
| 379 EXPECT_CALL(stream_requester_, | 379 EXPECT_CALL(stream_requester_, DeviceOpened(render_frame_id, |
| 380 DeviceOpened(render_frame_id, page_request_id, _, _)) | 380 page_request_id, |
| 381 .Times(1) | 381 _, |
| 382 .WillOnce(DoAll(ExitMessageLoop(task_runner_, run_loop.QuitClosure()), | 382 _)) |
| 383 SaveArg<2>(&opened_device_label_), | 383 .Times(1).WillOnce( |
| 384 SaveArg<3>(&opened_device))); | 384 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), |
| 385 SaveArg<2>(&opened_device_label_), |
| 386 SaveArg<3>(&opened_device))); |
| 385 run_loop.Run(); | 387 run_loop.Run(); |
| 386 Mock::VerifyAndClearExpectations(&stream_requester_); | 388 Mock::VerifyAndClearExpectations(&stream_requester_); |
| 387 ASSERT_NE(StreamDeviceInfo::kNoId, opened_device.session_id); | 389 ASSERT_NE(StreamDeviceInfo::kNoId, opened_device.session_id); |
| 388 opened_session_id_ = opened_device.session_id; | 390 opened_session_id_ = opened_device.session_id; |
| 389 } | 391 } |
| 390 } | 392 } |
| 391 | 393 |
| 392 void CloseSession() { | 394 void CloseSession() { |
| 393 if (opened_device_label_.empty()) | 395 if (opened_device_label_.empty()) |
| 394 return; | 396 return; |
| 395 media_stream_manager_->CancelRequest(opened_device_label_); | 397 media_stream_manager_->CancelRequest(opened_device_label_); |
| 396 opened_device_label_.clear(); | 398 opened_device_label_.clear(); |
| 397 opened_session_id_ = kInvalidMediaCaptureSessionId; | 399 opened_session_id_ = kInvalidMediaCaptureSessionId; |
| 398 } | 400 } |
| 399 | 401 |
| 400 protected: | 402 protected: |
| 401 void StartCapture() { | 403 void StartCapture() { |
| 402 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) | 404 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) |
| 403 .Times(AnyNumber()) | 405 .Times(AnyNumber()) |
| 404 .WillRepeatedly(Return()); | 406 .WillRepeatedly(Return()); |
| 405 | 407 |
| 406 base::RunLoop run_loop; | 408 base::RunLoop run_loop; |
| 407 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _, _)) | 409 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _, _)) |
| 408 .Times(AnyNumber()) | 410 .Times(AnyNumber()) |
| 409 .WillOnce(ExitMessageLoop(task_runner_, run_loop.QuitClosure())); | 411 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); |
| 410 | 412 |
| 411 media::VideoCaptureParams params; | 413 media::VideoCaptureParams params; |
| 412 params.requested_format = media::VideoCaptureFormat( | 414 params.requested_format = media::VideoCaptureFormat( |
| 413 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); | 415 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); |
| 414 host_->OnStartCapture(kDeviceId, opened_session_id_, params); | 416 host_->OnStartCapture(kDeviceId, opened_session_id_, params); |
| 415 run_loop.Run(); | 417 run_loop.Run(); |
| 416 } | 418 } |
| 417 | 419 |
| 418 void StartStopCapture() { | 420 void StartStopCapture() { |
| 419 // Quickly start and then stop capture, without giving much chance for | 421 // Quickly start and then stop capture, without giving much chance for |
| (...skipping 28 matching lines...) Expand all Loading... |
| 448 host_->SetDumpVideo(true); | 450 host_->SetDumpVideo(true); |
| 449 host_->OnStartCapture(kDeviceId, opened_session_id_, params); | 451 host_->OnStartCapture(kDeviceId, opened_session_id_, params); |
| 450 run_loop.Run(); | 452 run_loop.Run(); |
| 451 } | 453 } |
| 452 #endif | 454 #endif |
| 453 | 455 |
| 454 void StopCapture() { | 456 void StopCapture() { |
| 455 base::RunLoop run_loop; | 457 base::RunLoop run_loop; |
| 456 EXPECT_CALL(*host_.get(), | 458 EXPECT_CALL(*host_.get(), |
| 457 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)) | 459 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)) |
| 458 .WillOnce(ExitMessageLoop(task_runner_, run_loop.QuitClosure())); | 460 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); |
| 459 | 461 |
| 460 host_->OnStopCapture(kDeviceId); | 462 host_->OnStopCapture(kDeviceId); |
| 461 host_->SetReturnReceivedDibs(true); | 463 host_->SetReturnReceivedDibs(true); |
| 462 host_->ReturnReceivedDibs(kDeviceId); | 464 host_->ReturnReceivedDibs(kDeviceId); |
| 463 | 465 |
| 464 run_loop.Run(); | 466 run_loop.Run(); |
| 465 | 467 |
| 466 host_->SetReturnReceivedDibs(false); | 468 host_->SetReturnReceivedDibs(false); |
| 467 // Expect the VideoCaptureDevice has been stopped | 469 // Expect the VideoCaptureDevice has been stopped |
| 468 EXPECT_EQ(0u, host_->entries_.size()); | 470 EXPECT_EQ(0u, host_->entries_.size()); |
| 469 } | 471 } |
| 470 | 472 |
| 471 void NotifyPacketReady() { | 473 void NotifyPacketReady() { |
| 472 base::RunLoop run_loop; | 474 base::RunLoop run_loop; |
| 473 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _, _)) | 475 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _, _)) |
| 474 .Times(AnyNumber()) | 476 .Times(AnyNumber()) |
| 475 .WillOnce(ExitMessageLoop(task_runner_, run_loop.QuitClosure())) | 477 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())) |
| 476 .RetiresOnSaturation(); | 478 .RetiresOnSaturation(); |
| 477 run_loop.Run(); | 479 run_loop.Run(); |
| 478 } | 480 } |
| 479 | 481 |
| 480 void ReturnReceivedPackets() { | 482 void ReturnReceivedPackets() { |
| 481 host_->ReturnReceivedDibs(kDeviceId); | 483 host_->ReturnReceivedDibs(kDeviceId); |
| 482 } | 484 } |
| 483 | 485 |
| 484 void SimulateError() { | 486 void SimulateError() { |
| 485 // Expect a change state to error state sent through IPC. | 487 // Expect a change state to error state sent through IPC. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 503 | 505 |
| 504 scoped_refptr<MockVideoCaptureHost> host_; | 506 scoped_refptr<MockVideoCaptureHost> host_; |
| 505 | 507 |
| 506 private: | 508 private: |
| 507 StrictMock<MockMediaStreamRequester> stream_requester_; | 509 StrictMock<MockMediaStreamRequester> stream_requester_; |
| 508 scoped_ptr<media::AudioManager> audio_manager_; | 510 scoped_ptr<media::AudioManager> audio_manager_; |
| 509 scoped_ptr<MediaStreamManager> media_stream_manager_; | 511 scoped_ptr<MediaStreamManager> media_stream_manager_; |
| 510 content::TestBrowserThreadBundle thread_bundle_; | 512 content::TestBrowserThreadBundle thread_bundle_; |
| 511 content::TestBrowserContext browser_context_; | 513 content::TestBrowserContext browser_context_; |
| 512 content::TestContentBrowserClient browser_client_; | 514 content::TestContentBrowserClient browser_client_; |
| 513 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 515 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 514 int opened_session_id_; | 516 int opened_session_id_; |
| 515 std::string opened_device_label_; | 517 std::string opened_device_label_; |
| 516 | 518 |
| 517 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); | 519 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); |
| 518 }; | 520 }; |
| 519 | 521 |
| 520 TEST_F(VideoCaptureHostTest, CloseSessionWithoutStopping) { | 522 TEST_F(VideoCaptureHostTest, CloseSessionWithoutStopping) { |
| 521 StartCapture(); | 523 StartCapture(); |
| 522 | 524 |
| 523 // When the session is closed via the stream without stopping capture, the | 525 // When the session is closed via the stream without stopping capture, the |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 #ifdef DUMP_VIDEO | 560 #ifdef DUMP_VIDEO |
| 559 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 561 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
| 560 CaptureAndDumpVideo(640, 480, 30); | 562 CaptureAndDumpVideo(640, 480, 30); |
| 561 } | 563 } |
| 562 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 564 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
| 563 CaptureAndDumpVideo(1280, 720, 30); | 565 CaptureAndDumpVideo(1280, 720, 30); |
| 564 } | 566 } |
| 565 #endif | 567 #endif |
| 566 | 568 |
| 567 } // namespace content | 569 } // namespace content |
| OLD | NEW |