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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
16 #include "content/browser/renderer_host/media/media_stream_manager.h" | 16 #include "content/browser/renderer_host/media/media_stream_manager.h" |
17 #include "content/browser/renderer_host/media/media_stream_requester.h" | 17 #include "content/browser/renderer_host/media/media_stream_requester.h" |
18 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 18 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
19 #include "content/browser/renderer_host/media/video_capture_host.h" | 19 #include "content/browser/renderer_host/media/video_capture_host.h" |
20 #include "content/browser/renderer_host/media/video_capture_manager.h" | 20 #include "content/browser/renderer_host/media/video_capture_manager.h" |
21 #include "content/common/media/video_capture_messages.h" | 21 #include "content/common/media/video_capture_messages.h" |
22 #include "content/public/test/mock_resource_context.h" | 22 #include "content/public/test/mock_resource_context.h" |
| 23 #include "content/public/test/test_browser_context.h" |
23 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "content/test/test_content_browser_client.h" |
24 #include "media/audio/audio_manager.h" | 26 #include "media/audio/audio_manager.h" |
25 #include "media/base/video_frame.h" | 27 #include "media/base/video_frame.h" |
26 #include "media/video/capture/video_capture_types.h" | 28 #include "media/video/capture/video_capture_types.h" |
27 #include "net/url_request/url_request_context.h" | 29 #include "net/url_request/url_request_context.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
30 | 32 |
31 using ::testing::_; | 33 using ::testing::_; |
32 using ::testing::AtLeast; | 34 using ::testing::AtLeast; |
33 using ::testing::AnyNumber; | 35 using ::testing::AnyNumber; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // MediaStreamManager, VideoCaptureManager, VideoCaptureController, and | 238 // MediaStreamManager, VideoCaptureManager, VideoCaptureController, and |
237 // VideoCaptureDevice. | 239 // VideoCaptureDevice. |
238 class VideoCaptureHostTest : public testing::Test { | 240 class VideoCaptureHostTest : public testing::Test { |
239 public: | 241 public: |
240 VideoCaptureHostTest() | 242 VideoCaptureHostTest() |
241 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 243 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
242 message_loop_(base::MessageLoopProxy::current()), | 244 message_loop_(base::MessageLoopProxy::current()), |
243 opened_session_id_(kInvalidMediaCaptureSessionId) {} | 245 opened_session_id_(kInvalidMediaCaptureSessionId) {} |
244 | 246 |
245 virtual void SetUp() OVERRIDE { | 247 virtual void SetUp() OVERRIDE { |
| 248 SetBrowserClientForTesting(&browser_client_); |
246 // Create our own MediaStreamManager. | 249 // Create our own MediaStreamManager. |
247 audio_manager_.reset(media::AudioManager::Create()); | 250 audio_manager_.reset(media::AudioManager::Create()); |
248 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 251 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
249 #ifndef TEST_REAL_CAPTURE_DEVICE | 252 #ifndef TEST_REAL_CAPTURE_DEVICE |
250 media_stream_manager_->UseFakeDevice(); | 253 media_stream_manager_->UseFakeDevice(); |
251 #endif | 254 #endif |
252 media_stream_manager_->UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 255 media_stream_manager_->UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
253 | 256 |
254 // Create a Host and connect it to a simulated IPC channel. | 257 // Create a Host and connect it to a simulated IPC channel. |
255 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); | 258 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); |
(...skipping 27 matching lines...) Expand all Loading... |
283 ASSERT_TRUE(opened_device_label_.empty()); | 286 ASSERT_TRUE(opened_device_label_.empty()); |
284 | 287 |
285 // Enumerate video devices. | 288 // Enumerate video devices. |
286 StreamDeviceInfoArray devices; | 289 StreamDeviceInfoArray devices; |
287 { | 290 { |
288 base::RunLoop run_loop; | 291 base::RunLoop run_loop; |
289 std::string label = media_stream_manager_->EnumerateDevices( | 292 std::string label = media_stream_manager_->EnumerateDevices( |
290 &stream_requester_, | 293 &stream_requester_, |
291 render_process_id, | 294 render_process_id, |
292 render_view_id, | 295 render_view_id, |
| 296 browser_context_.GetResourceContext(), |
293 page_request_id, | 297 page_request_id, |
294 MEDIA_DEVICE_VIDEO_CAPTURE, | 298 MEDIA_DEVICE_VIDEO_CAPTURE, |
295 security_origin); | 299 security_origin); |
296 EXPECT_CALL(stream_requester_, DevicesEnumerated(label, _)) | 300 EXPECT_CALL(stream_requester_, DevicesEnumerated(label, _)) |
297 .Times(1).WillOnce( | 301 .Times(1).WillOnce( |
298 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), | 302 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), |
299 SaveArg<1>(&devices))); | 303 SaveArg<1>(&devices))); |
300 run_loop.Run(); | 304 run_loop.Run(); |
301 Mock::VerifyAndClearExpectations(&stream_requester_); | 305 Mock::VerifyAndClearExpectations(&stream_requester_); |
302 media_stream_manager_->CancelRequest(label); | 306 media_stream_manager_->CancelRequest(label); |
303 } | 307 } |
304 ASSERT_FALSE(devices.empty()); | 308 ASSERT_FALSE(devices.empty()); |
305 ASSERT_EQ(StreamDeviceInfo::kNoId, devices[0].session_id); | 309 ASSERT_EQ(StreamDeviceInfo::kNoId, devices[0].session_id); |
306 | 310 |
307 // Open the first device. | 311 // Open the first device. |
308 { | 312 { |
309 base::RunLoop run_loop; | 313 base::RunLoop run_loop; |
310 StreamDeviceInfo opened_device; | 314 StreamDeviceInfo opened_device; |
311 opened_device_label_ = media_stream_manager_->OpenDevice( | 315 opened_device_label_ = media_stream_manager_->OpenDevice( |
312 &stream_requester_, | 316 &stream_requester_, |
313 render_process_id, | 317 render_process_id, |
314 render_view_id, | 318 render_view_id, |
| 319 browser_context_.GetResourceContext(), |
315 page_request_id, | 320 page_request_id, |
316 devices[0].device.id, | 321 devices[0].device.id, |
317 MEDIA_DEVICE_VIDEO_CAPTURE, | 322 MEDIA_DEVICE_VIDEO_CAPTURE, |
318 security_origin); | 323 security_origin); |
319 EXPECT_CALL(stream_requester_, DeviceOpened(opened_device_label_, _)) | 324 EXPECT_CALL(stream_requester_, DeviceOpened(opened_device_label_, _)) |
320 .Times(1).WillOnce( | 325 .Times(1).WillOnce( |
321 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), | 326 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), |
322 SaveArg<1>(&opened_device))); | 327 SaveArg<1>(&opened_device))); |
323 run_loop.Run(); | 328 run_loop.Run(); |
324 Mock::VerifyAndClearExpectations(&stream_requester_); | 329 Mock::VerifyAndClearExpectations(&stream_requester_); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 base::RunLoop().RunUntilIdle(); | 430 base::RunLoop().RunUntilIdle(); |
426 } | 431 } |
427 | 432 |
428 scoped_refptr<MockVideoCaptureHost> host_; | 433 scoped_refptr<MockVideoCaptureHost> host_; |
429 | 434 |
430 private: | 435 private: |
431 StrictMock<MockMediaStreamRequester> stream_requester_; | 436 StrictMock<MockMediaStreamRequester> stream_requester_; |
432 scoped_ptr<media::AudioManager> audio_manager_; | 437 scoped_ptr<media::AudioManager> audio_manager_; |
433 scoped_ptr<MediaStreamManager> media_stream_manager_; | 438 scoped_ptr<MediaStreamManager> media_stream_manager_; |
434 content::TestBrowserThreadBundle thread_bundle_; | 439 content::TestBrowserThreadBundle thread_bundle_; |
| 440 content::TestBrowserContext browser_context_; |
| 441 content::TestContentBrowserClient browser_client_; |
435 scoped_refptr<base::MessageLoopProxy> message_loop_; | 442 scoped_refptr<base::MessageLoopProxy> message_loop_; |
436 int opened_session_id_; | 443 int opened_session_id_; |
437 std::string opened_device_label_; | 444 std::string opened_device_label_; |
438 | 445 |
439 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); | 446 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); |
440 }; | 447 }; |
441 | 448 |
442 TEST_F(VideoCaptureHostTest, CloseSessionWithoutStopping) { | 449 TEST_F(VideoCaptureHostTest, CloseSessionWithoutStopping) { |
443 StartCapture(); | 450 StartCapture(); |
444 | 451 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 #ifdef DUMP_VIDEO | 487 #ifdef DUMP_VIDEO |
481 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 488 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
482 CaptureAndDumpVideo(640, 480, 30); | 489 CaptureAndDumpVideo(640, 480, 30); |
483 } | 490 } |
484 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 491 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
485 CaptureAndDumpVideo(1280, 720, 30); | 492 CaptureAndDumpVideo(1280, 720, 30); |
486 } | 493 } |
487 #endif | 494 #endif |
488 | 495 |
489 } // namespace content | 496 } // namespace content |
OLD | NEW |