| 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/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 int expected_size_; | 79 int expected_size_; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 class MockMediaStreamRequester : public MediaStreamRequester { | 82 class MockMediaStreamRequester : public MediaStreamRequester { |
| 83 public: | 83 public: |
| 84 MockMediaStreamRequester() {} | 84 MockMediaStreamRequester() {} |
| 85 virtual ~MockMediaStreamRequester() {} | 85 virtual ~MockMediaStreamRequester() {} |
| 86 | 86 |
| 87 // MediaStreamRequester implementation. | 87 // MediaStreamRequester implementation. |
| 88 MOCK_METHOD5(StreamGenerated, | 88 MOCK_METHOD5(StreamGenerated, |
| 89 void(int render_view_id, | 89 void(int render_frame_id, |
| 90 int page_request_id, | 90 int page_request_id, |
| 91 const std::string& label, | 91 const std::string& label, |
| 92 const StreamDeviceInfoArray& audio_devices, | 92 const StreamDeviceInfoArray& audio_devices, |
| 93 const StreamDeviceInfoArray& video_devices)); | 93 const StreamDeviceInfoArray& video_devices)); |
| 94 MOCK_METHOD3(StreamGenerationFailed, | 94 MOCK_METHOD3(StreamGenerationFailed, |
| 95 void(int render_view_id, | 95 void(int render_frame_id, |
| 96 int page_request_id, | 96 int page_request_id, |
| 97 content::MediaStreamRequestResult result)); | 97 content::MediaStreamRequestResult result)); |
| 98 MOCK_METHOD3(DeviceStopped, void(int render_view_id, | 98 MOCK_METHOD3(DeviceStopped, void(int render_frame_id, |
| 99 const std::string& label, | 99 const std::string& label, |
| 100 const StreamDeviceInfo& device)); | 100 const StreamDeviceInfo& device)); |
| 101 MOCK_METHOD4(DevicesEnumerated, void(int render_view_id, | 101 MOCK_METHOD4(DevicesEnumerated, void(int render_frame_id, |
| 102 int page_request_id, | 102 int page_request_id, |
| 103 const std::string& label, | 103 const std::string& label, |
| 104 const StreamDeviceInfoArray& devices)); | 104 const StreamDeviceInfoArray& devices)); |
| 105 MOCK_METHOD4(DeviceOpened, void(int render_view_id, | 105 MOCK_METHOD4(DeviceOpened, void(int render_frame_id, |
| 106 int page_request_id, | 106 int page_request_id, |
| 107 const std::string& label, | 107 const std::string& label, |
| 108 const StreamDeviceInfo& device_info)); | 108 const StreamDeviceInfo& device_info)); |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamRequester); | 111 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamRequester); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 class MockVideoCaptureHost : public VideoCaptureHost { | 114 class MockVideoCaptureHost : public VideoCaptureHost { |
| 115 public: | 115 public: |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // Simulate closing the IPC sender. | 312 // Simulate closing the IPC sender. |
| 313 host_->OnChannelClosing(); | 313 host_->OnChannelClosing(); |
| 314 | 314 |
| 315 // Release the reference to the mock object. The object will be destructed | 315 // Release the reference to the mock object. The object will be destructed |
| 316 // on the current message loop. | 316 // on the current message loop. |
| 317 host_ = NULL; | 317 host_ = NULL; |
| 318 } | 318 } |
| 319 | 319 |
| 320 void OpenSession() { | 320 void OpenSession() { |
| 321 const int render_process_id = 1; | 321 const int render_process_id = 1; |
| 322 const int render_view_id = 1; | 322 const int render_frame_id = 1; |
| 323 const int page_request_id = 1; | 323 const int page_request_id = 1; |
| 324 const GURL security_origin("http://test.com"); | 324 const GURL security_origin("http://test.com"); |
| 325 | 325 |
| 326 ASSERT_TRUE(opened_device_label_.empty()); | 326 ASSERT_TRUE(opened_device_label_.empty()); |
| 327 | 327 |
| 328 // Enumerate video devices. | 328 // Enumerate video devices. |
| 329 StreamDeviceInfoArray devices; | 329 StreamDeviceInfoArray devices; |
| 330 { | 330 { |
| 331 base::RunLoop run_loop; | 331 base::RunLoop run_loop; |
| 332 std::string label = media_stream_manager_->EnumerateDevices( | 332 std::string label = media_stream_manager_->EnumerateDevices( |
| 333 &stream_requester_, | 333 &stream_requester_, |
| 334 render_process_id, | 334 render_process_id, |
| 335 render_view_id, | 335 render_frame_id, |
| 336 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 336 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 337 page_request_id, | 337 page_request_id, |
| 338 MEDIA_DEVICE_VIDEO_CAPTURE, | 338 MEDIA_DEVICE_VIDEO_CAPTURE, |
| 339 security_origin, | 339 security_origin, |
| 340 true); | 340 true); |
| 341 EXPECT_CALL(stream_requester_, DevicesEnumerated(render_view_id, | 341 EXPECT_CALL(stream_requester_, DevicesEnumerated(render_frame_id, |
| 342 page_request_id, | 342 page_request_id, |
| 343 label, | 343 label, |
| 344 _)) | 344 _)) |
| 345 .Times(1).WillOnce( | 345 .Times(1).WillOnce( |
| 346 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), | 346 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), |
| 347 SaveArg<3>(&devices))); | 347 SaveArg<3>(&devices))); |
| 348 run_loop.Run(); | 348 run_loop.Run(); |
| 349 Mock::VerifyAndClearExpectations(&stream_requester_); | 349 Mock::VerifyAndClearExpectations(&stream_requester_); |
| 350 media_stream_manager_->CancelRequest(label); | 350 media_stream_manager_->CancelRequest(label); |
| 351 } | 351 } |
| 352 ASSERT_FALSE(devices.empty()); | 352 ASSERT_FALSE(devices.empty()); |
| 353 ASSERT_EQ(StreamDeviceInfo::kNoId, devices[0].session_id); | 353 ASSERT_EQ(StreamDeviceInfo::kNoId, devices[0].session_id); |
| 354 | 354 |
| 355 // Open the first device. | 355 // Open the first device. |
| 356 { | 356 { |
| 357 base::RunLoop run_loop; | 357 base::RunLoop run_loop; |
| 358 StreamDeviceInfo opened_device; | 358 StreamDeviceInfo opened_device; |
| 359 media_stream_manager_->OpenDevice( | 359 media_stream_manager_->OpenDevice( |
| 360 &stream_requester_, | 360 &stream_requester_, |
| 361 render_process_id, | 361 render_process_id, |
| 362 render_view_id, | 362 render_frame_id, |
| 363 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 363 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 364 page_request_id, | 364 page_request_id, |
| 365 devices[0].device.id, | 365 devices[0].device.id, |
| 366 MEDIA_DEVICE_VIDEO_CAPTURE, | 366 MEDIA_DEVICE_VIDEO_CAPTURE, |
| 367 security_origin); | 367 security_origin); |
| 368 EXPECT_CALL(stream_requester_, DeviceOpened(render_view_id, | 368 EXPECT_CALL(stream_requester_, DeviceOpened(render_frame_id, |
| 369 page_request_id, | 369 page_request_id, |
| 370 _, | 370 _, |
| 371 _)) | 371 _)) |
| 372 .Times(1).WillOnce( | 372 .Times(1).WillOnce( |
| 373 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), | 373 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), |
| 374 SaveArg<2>(&opened_device_label_), | 374 SaveArg<2>(&opened_device_label_), |
| 375 SaveArg<3>(&opened_device))); | 375 SaveArg<3>(&opened_device))); |
| 376 run_loop.Run(); | 376 run_loop.Run(); |
| 377 Mock::VerifyAndClearExpectations(&stream_requester_); | 377 Mock::VerifyAndClearExpectations(&stream_requester_); |
| 378 ASSERT_NE(StreamDeviceInfo::kNoId, opened_device.session_id); | 378 ASSERT_NE(StreamDeviceInfo::kNoId, opened_device.session_id); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 #ifdef DUMP_VIDEO | 535 #ifdef DUMP_VIDEO |
| 536 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 536 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
| 537 CaptureAndDumpVideo(640, 480, 30); | 537 CaptureAndDumpVideo(640, 480, 30); |
| 538 } | 538 } |
| 539 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 539 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
| 540 CaptureAndDumpVideo(1280, 720, 30); | 540 CaptureAndDumpVideo(1280, 720, 30); |
| 541 } | 541 } |
| 542 #endif | 542 #endif |
| 543 | 543 |
| 544 } // namespace content | 544 } // namespace content |
| OLD | NEW |