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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // MediaStreamManager, VideoCaptureManager, VideoCaptureController, and | 236 // MediaStreamManager, VideoCaptureManager, VideoCaptureController, and |
235 // VideoCaptureDevice. | 237 // VideoCaptureDevice. |
236 class VideoCaptureHostTest : public testing::Test { | 238 class VideoCaptureHostTest : public testing::Test { |
237 public: | 239 public: |
238 VideoCaptureHostTest() | 240 VideoCaptureHostTest() |
239 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 241 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
240 message_loop_(base::MessageLoopProxy::current()), | 242 message_loop_(base::MessageLoopProxy::current()), |
241 opened_session_id_(kInvalidMediaCaptureSessionId) {} | 243 opened_session_id_(kInvalidMediaCaptureSessionId) {} |
242 | 244 |
243 virtual void SetUp() OVERRIDE { | 245 virtual void SetUp() OVERRIDE { |
| 246 SetBrowserClientForTesting(&browser_client_); |
244 // Create our own MediaStreamManager. | 247 // Create our own MediaStreamManager. |
245 audio_manager_.reset(media::AudioManager::Create()); | 248 audio_manager_.reset(media::AudioManager::Create()); |
246 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 249 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
247 #ifndef TEST_REAL_CAPTURE_DEVICE | 250 #ifndef TEST_REAL_CAPTURE_DEVICE |
248 media_stream_manager_->UseFakeDevice(); | 251 media_stream_manager_->UseFakeDevice(); |
249 #endif | 252 #endif |
250 media_stream_manager_->UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 253 media_stream_manager_->UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
251 | 254 |
252 // Create a Host and connect it to a simulated IPC channel. | 255 // Create a Host and connect it to a simulated IPC channel. |
253 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); | 256 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); |
(...skipping 27 matching lines...) Expand all Loading... |
281 ASSERT_TRUE(opened_device_label_.empty()); | 284 ASSERT_TRUE(opened_device_label_.empty()); |
282 | 285 |
283 // Enumerate video devices. | 286 // Enumerate video devices. |
284 StreamDeviceInfoArray devices; | 287 StreamDeviceInfoArray devices; |
285 { | 288 { |
286 base::RunLoop run_loop; | 289 base::RunLoop run_loop; |
287 std::string label = media_stream_manager_->EnumerateDevices( | 290 std::string label = media_stream_manager_->EnumerateDevices( |
288 &stream_requester_, | 291 &stream_requester_, |
289 render_process_id, | 292 render_process_id, |
290 render_view_id, | 293 render_view_id, |
| 294 browser_context_.GetResourceContext(), |
291 page_request_id, | 295 page_request_id, |
292 MEDIA_DEVICE_VIDEO_CAPTURE, | 296 MEDIA_DEVICE_VIDEO_CAPTURE, |
293 security_origin); | 297 security_origin); |
294 EXPECT_CALL(stream_requester_, DevicesEnumerated(label, _)) | 298 EXPECT_CALL(stream_requester_, DevicesEnumerated(label, _)) |
295 .Times(1).WillOnce( | 299 .Times(1).WillOnce( |
296 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), | 300 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), |
297 SaveArg<1>(&devices))); | 301 SaveArg<1>(&devices))); |
298 run_loop.Run(); | 302 run_loop.Run(); |
299 Mock::VerifyAndClearExpectations(&stream_requester_); | 303 Mock::VerifyAndClearExpectations(&stream_requester_); |
300 media_stream_manager_->CancelRequest(label); | 304 media_stream_manager_->CancelRequest(label); |
301 } | 305 } |
302 ASSERT_FALSE(devices.empty()); | 306 ASSERT_FALSE(devices.empty()); |
303 ASSERT_EQ(StreamDeviceInfo::kNoId, devices[0].session_id); | 307 ASSERT_EQ(StreamDeviceInfo::kNoId, devices[0].session_id); |
304 | 308 |
305 // Open the first device. | 309 // Open the first device. |
306 { | 310 { |
307 base::RunLoop run_loop; | 311 base::RunLoop run_loop; |
308 StreamDeviceInfo opened_device; | 312 StreamDeviceInfo opened_device; |
309 opened_device_label_ = media_stream_manager_->OpenDevice( | 313 opened_device_label_ = media_stream_manager_->OpenDevice( |
310 &stream_requester_, | 314 &stream_requester_, |
311 render_process_id, | 315 render_process_id, |
312 render_view_id, | 316 render_view_id, |
| 317 browser_context_.GetResourceContext(), |
313 page_request_id, | 318 page_request_id, |
314 devices[0].device.id, | 319 devices[0].device.id, |
315 MEDIA_DEVICE_VIDEO_CAPTURE, | 320 MEDIA_DEVICE_VIDEO_CAPTURE, |
316 security_origin); | 321 security_origin); |
317 EXPECT_CALL(stream_requester_, DeviceOpened(opened_device_label_, _)) | 322 EXPECT_CALL(stream_requester_, DeviceOpened(opened_device_label_, _)) |
318 .Times(1).WillOnce( | 323 .Times(1).WillOnce( |
319 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), | 324 DoAll(ExitMessageLoop(message_loop_, run_loop.QuitClosure()), |
320 SaveArg<1>(&opened_device))); | 325 SaveArg<1>(&opened_device))); |
321 run_loop.Run(); | 326 run_loop.Run(); |
322 Mock::VerifyAndClearExpectations(&stream_requester_); | 327 Mock::VerifyAndClearExpectations(&stream_requester_); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 base::RunLoop().RunUntilIdle(); | 431 base::RunLoop().RunUntilIdle(); |
427 } | 432 } |
428 | 433 |
429 scoped_refptr<MockVideoCaptureHost> host_; | 434 scoped_refptr<MockVideoCaptureHost> host_; |
430 | 435 |
431 private: | 436 private: |
432 StrictMock<MockMediaStreamRequester> stream_requester_; | 437 StrictMock<MockMediaStreamRequester> stream_requester_; |
433 scoped_ptr<media::AudioManager> audio_manager_; | 438 scoped_ptr<media::AudioManager> audio_manager_; |
434 scoped_ptr<MediaStreamManager> media_stream_manager_; | 439 scoped_ptr<MediaStreamManager> media_stream_manager_; |
435 content::TestBrowserThreadBundle thread_bundle_; | 440 content::TestBrowserThreadBundle thread_bundle_; |
| 441 content::TestBrowserContext browser_context_; |
| 442 content::TestContentBrowserClient browser_client_; |
436 scoped_refptr<base::MessageLoopProxy> message_loop_; | 443 scoped_refptr<base::MessageLoopProxy> message_loop_; |
437 int opened_session_id_; | 444 int opened_session_id_; |
438 std::string opened_device_label_; | 445 std::string opened_device_label_; |
439 | 446 |
440 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); | 447 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); |
441 }; | 448 }; |
442 | 449 |
443 TEST_F(VideoCaptureHostTest, CloseSessionWithoutStopping) { | 450 TEST_F(VideoCaptureHostTest, CloseSessionWithoutStopping) { |
444 StartCapture(); | 451 StartCapture(); |
445 | 452 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 #ifdef DUMP_VIDEO | 488 #ifdef DUMP_VIDEO |
482 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 489 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
483 CaptureAndDumpVideo(640, 480, 30); | 490 CaptureAndDumpVideo(640, 480, 30); |
484 } | 491 } |
485 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 492 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
486 CaptureAndDumpVideo(1280, 720, 30); | 493 CaptureAndDumpVideo(1280, 720, 30); |
487 } | 494 } |
488 #endif | 495 #endif |
489 | 496 |
490 } // namespace content | 497 } // namespace content |
OLD | NEW |