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 <string> | 5 #include <string> |
6 #include <queue> | 6 #include <queue> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "content/browser/browser_thread_impl.h" | 12 #include "content/browser/browser_thread_impl.h" |
13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
14 #include "content/browser/renderer_host/media/media_stream_manager.h" | 14 #include "content/browser/renderer_host/media/media_stream_manager.h" |
15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
16 #include "content/common/media/media_stream_messages.h" | 16 #include "content/common/media/media_stream_messages.h" |
17 #include "content/common/media/media_stream_options.h" | 17 #include "content/common/media/media_stream_options.h" |
18 #include "content/public/browser/media_device_id.h" | 18 #include "content/public/browser/media_device_id.h" |
19 #include "content/public/test/mock_resource_context.h" | 19 #include "content/public/test/mock_resource_context.h" |
| 20 #include "content/public/test/test_browser_context.h" |
20 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "content/test/test_content_browser_client.h" | 22 #include "content/test/test_content_browser_client.h" |
22 #include "content/test/test_content_client.h" | 23 #include "content/test/test_content_client.h" |
23 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
24 #include "media/audio/mock_audio_manager.h" | 25 #include "media/audio/mock_audio_manager.h" |
25 #include "media/video/capture/fake_video_capture_device.h" | 26 #include "media/video/capture/fake_video_capture_device.h" |
26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 | 30 |
30 using ::testing::_; | 31 using ::testing::_; |
31 using ::testing::DeleteArg; | 32 using ::testing::DeleteArg; |
32 using ::testing::DoAll; | 33 using ::testing::DoAll; |
33 using ::testing::Return; | 34 using ::testing::Return; |
34 using ::testing::SaveArg; | 35 using ::testing::SaveArg; |
35 | 36 |
36 const int kProcessId = 5; | 37 const int kProcessId = 5; |
37 const int kRenderId = 6; | 38 const int kRenderId = 6; |
38 const int kPageRequestId = 7; | 39 const int kPageRequestId = 7; |
39 | 40 |
40 namespace content { | 41 namespace content { |
41 | 42 |
42 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, | 43 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
43 public TestContentBrowserClient { | 44 public TestContentBrowserClient { |
44 public: | 45 public: |
45 MockMediaStreamDispatcherHost( | 46 MockMediaStreamDispatcherHost( |
| 47 ResourceContext* resource_context, |
46 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 48 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
47 MediaStreamManager* manager) | 49 MediaStreamManager* manager) |
48 : MediaStreamDispatcherHost(kProcessId, manager), | 50 : MediaStreamDispatcherHost(kProcessId, resource_context, manager), |
49 message_loop_(message_loop) {} | 51 message_loop_(message_loop) {} |
50 | 52 |
51 // A list of mock methods. | 53 // A list of mock methods. |
52 MOCK_METHOD4(OnStreamGenerated, | 54 MOCK_METHOD4(OnStreamGenerated, |
53 void(int routing_id, int request_id, int audio_array_size, | 55 void(int routing_id, int request_id, int audio_array_size, |
54 int video_array_size)); | 56 int video_array_size)); |
55 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); | 57 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); |
56 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); | 58 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); |
57 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); | 59 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); |
58 | 60 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 : old_browser_client_(NULL), | 208 : old_browser_client_(NULL), |
207 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 209 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
208 origin_("https://test.com") { | 210 origin_("https://test.com") { |
209 audio_manager_.reset( | 211 audio_manager_.reset( |
210 new media::MockAudioManager(base::MessageLoopProxy::current())); | 212 new media::MockAudioManager(base::MessageLoopProxy::current())); |
211 // Create our own MediaStreamManager. | 213 // Create our own MediaStreamManager. |
212 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 214 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
213 // Make sure we use fake devices to avoid long delays. | 215 // Make sure we use fake devices to avoid long delays. |
214 media_stream_manager_->UseFakeDevice(); | 216 media_stream_manager_->UseFakeDevice(); |
215 | 217 |
216 host_ = new MockMediaStreamDispatcherHost(base::MessageLoopProxy::current(), | 218 host_ = new MockMediaStreamDispatcherHost( |
217 media_stream_manager_.get()); | 219 browser_context_.GetResourceContext(), |
| 220 base::MessageLoopProxy::current(), |
| 221 media_stream_manager_.get()); |
218 | 222 |
219 // Use the fake content client and browser. | 223 // Use the fake content client and browser. |
220 content_client_.reset(new TestContentClient()); | 224 content_client_.reset(new TestContentClient()); |
221 SetContentClient(content_client_.get()); | 225 SetContentClient(content_client_.get()); |
222 old_browser_client_ = SetBrowserClientForTesting(host_.get()); | 226 old_browser_client_ = SetBrowserClientForTesting(host_.get()); |
223 } | 227 } |
224 | 228 |
225 virtual ~MediaStreamDispatcherHostTest() { | 229 virtual ~MediaStreamDispatcherHostTest() { |
226 } | 230 } |
227 | 231 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 return false; | 326 return false; |
323 } | 327 } |
324 | 328 |
325 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | 329 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, |
326 const GURL& origin) { | 330 const GURL& origin) { |
327 for (size_t i = 0; i < devices.size(); ++i) { | 331 for (size_t i = 0; i < devices.size(); ++i) { |
328 bool found_match = false; | 332 bool found_match = false; |
329 media::AudioDeviceNames::const_iterator audio_it = | 333 media::AudioDeviceNames::const_iterator audio_it = |
330 physical_audio_devices_.begin(); | 334 physical_audio_devices_.begin(); |
331 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 335 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
332 if (content::DoesMediaDeviceIDMatchHMAC(origin, | 336 if (content::DoesMediaDeviceIDMatchHMAC( |
333 devices[i].device.id, | 337 browser_context_.GetResourceContext(), |
334 audio_it->unique_id)) { | 338 origin, |
| 339 devices[i].device.id, |
| 340 audio_it->unique_id)) { |
335 EXPECT_FALSE(found_match); | 341 EXPECT_FALSE(found_match); |
336 found_match = true; | 342 found_match = true; |
337 } | 343 } |
338 } | 344 } |
339 media::VideoCaptureDevice::Names::const_iterator video_it = | 345 media::VideoCaptureDevice::Names::const_iterator video_it = |
340 physical_video_devices_.begin(); | 346 physical_video_devices_.begin(); |
341 for (; video_it != physical_video_devices_.end(); ++video_it) { | 347 for (; video_it != physical_video_devices_.end(); ++video_it) { |
342 if (content::DoesMediaDeviceIDMatchHMAC(origin, | 348 if (content::DoesMediaDeviceIDMatchHMAC( |
343 devices[i].device.id, | 349 browser_context_.GetResourceContext(), |
344 video_it->id())) { | 350 origin, |
| 351 devices[i].device.id, |
| 352 video_it->id())) { |
345 EXPECT_FALSE(found_match); | 353 EXPECT_FALSE(found_match); |
346 found_match = true; | 354 found_match = true; |
347 } | 355 } |
348 } | 356 } |
349 if (!found_match) | 357 if (!found_match) |
350 return false; | 358 return false; |
351 } | 359 } |
352 return true; | 360 return true; |
353 } | 361 } |
354 | 362 |
355 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 363 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
356 scoped_ptr<media::AudioManager> audio_manager_; | 364 scoped_ptr<media::AudioManager> audio_manager_; |
357 scoped_ptr<MediaStreamManager> media_stream_manager_; | 365 scoped_ptr<MediaStreamManager> media_stream_manager_; |
358 ContentBrowserClient* old_browser_client_; | 366 ContentBrowserClient* old_browser_client_; |
359 scoped_ptr<ContentClient> content_client_; | 367 scoped_ptr<ContentClient> content_client_; |
360 content::TestBrowserThreadBundle thread_bundle_; | 368 content::TestBrowserThreadBundle thread_bundle_; |
| 369 content::TestBrowserContext browser_context_; |
361 media::AudioDeviceNames physical_audio_devices_; | 370 media::AudioDeviceNames physical_audio_devices_; |
362 media::VideoCaptureDevice::Names physical_video_devices_; | 371 media::VideoCaptureDevice::Names physical_video_devices_; |
363 GURL origin_; | 372 GURL origin_; |
364 }; | 373 }; |
365 | 374 |
366 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { | 375 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { |
367 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 376 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
368 | 377 |
369 SetupFakeUI(true); | 378 SetupFakeUI(true); |
370 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 379 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { | 512 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { |
504 ASSERT_GE(physical_audio_devices_.size(), 1u); | 513 ASSERT_GE(physical_audio_devices_.size(), 1u); |
505 ASSERT_GE(physical_video_devices_.size(), 1u); | 514 ASSERT_GE(physical_video_devices_.size(), 1u); |
506 | 515 |
507 media::AudioDeviceNames::const_iterator audio_it = | 516 media::AudioDeviceNames::const_iterator audio_it = |
508 physical_audio_devices_.begin(); | 517 physical_audio_devices_.begin(); |
509 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 518 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
510 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | 519 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
511 MEDIA_DEVICE_VIDEO_CAPTURE); | 520 MEDIA_DEVICE_VIDEO_CAPTURE); |
512 options.audio_device_id = content::GetHMACForMediaDeviceID( | 521 options.audio_device_id = content::GetHMACForMediaDeviceID( |
| 522 browser_context_.GetResourceContext(), |
513 origin_, | 523 origin_, |
514 audio_it->unique_id); | 524 audio_it->unique_id); |
515 ASSERT_FALSE(options.audio_device_id.empty()); | 525 ASSERT_FALSE(options.audio_device_id.empty()); |
516 | 526 |
517 // Generate first stream. | 527 // Generate first stream. |
518 SetupFakeUI(true); | 528 SetupFakeUI(true); |
519 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 529 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
520 EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id); | 530 EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id); |
521 } | 531 } |
522 | 532 |
523 media::VideoCaptureDevice::Names::const_iterator video_it = | 533 media::VideoCaptureDevice::Names::const_iterator video_it = |
524 physical_video_devices_.begin(); | 534 physical_video_devices_.begin(); |
525 for (; video_it != physical_video_devices_.end(); ++video_it) { | 535 for (; video_it != physical_video_devices_.end(); ++video_it) { |
526 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | 536 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
527 MEDIA_DEVICE_VIDEO_CAPTURE); | 537 MEDIA_DEVICE_VIDEO_CAPTURE); |
528 options.video_device_id = content::GetHMACForMediaDeviceID(origin_, | 538 options.video_device_id = content::GetHMACForMediaDeviceID( |
529 video_it->id()); | 539 browser_context_.GetResourceContext(), |
| 540 origin_, |
| 541 video_it->id()); |
530 ASSERT_FALSE(options.video_device_id.empty()); | 542 ASSERT_FALSE(options.video_device_id.empty()); |
531 | 543 |
532 // Generate first stream. | 544 // Generate first stream. |
533 SetupFakeUI(true); | 545 SetupFakeUI(true); |
534 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 546 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
535 EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id); | 547 EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id); |
536 } | 548 } |
537 } | 549 } |
538 | 550 |
539 // Test that generating a stream with an invalid video source id fail. | 551 // Test that generating a stream with an invalid video source id fail. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 722 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
711 MEDIA_DEVICE_AUDIO_CAPTURE); | 723 MEDIA_DEVICE_AUDIO_CAPTURE); |
712 } | 724 } |
713 | 725 |
714 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { | 726 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { |
715 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 727 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
716 MEDIA_DEVICE_VIDEO_CAPTURE); | 728 MEDIA_DEVICE_VIDEO_CAPTURE); |
717 } | 729 } |
718 | 730 |
719 }; // namespace content | 731 }; // namespace content |
OLD | NEW |