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 "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 const int kProcessId = 5; | 58 const int kProcessId = 5; |
59 const int kRenderId = 6; | 59 const int kRenderId = 6; |
60 const int kPageRequestId = 7; | 60 const int kPageRequestId = 7; |
61 | 61 |
62 namespace content { | 62 namespace content { |
63 | 63 |
64 namespace { | 64 namespace { |
65 | 65 |
66 void AudioInputDevicesEnumerated(base::Closure quit_closure, | 66 void AudioInputDevicesEnumerated(base::Closure quit_closure, |
67 media::AudioDeviceNames* out, | 67 media::AudioDeviceDescriptions* out, |
68 const MediaDeviceEnumeration& enumeration) { | 68 const MediaDeviceEnumeration& enumeration) { |
69 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { | 69 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { |
70 out->emplace_back(info.label, info.device_id); | 70 out->emplace_back(info.label, info.device_id, info.group_id); |
71 } | 71 } |
72 quit_closure.Run(); | 72 quit_closure.Run(); |
73 } | 73 } |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, | 77 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
78 public TestContentBrowserClient { | 78 public TestContentBrowserClient { |
79 public: | 79 public: |
80 MockMediaStreamDispatcherHost( | 80 MockMediaStreamDispatcherHost( |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 host_->OnOpenDevice(render_frame_id, page_request_id, device_id, | 340 host_->OnOpenDevice(render_frame_id, page_request_id, device_id, |
341 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, | 341 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, |
342 run_loop.QuitClosure()); | 342 run_loop.QuitClosure()); |
343 run_loop.Run(); | 343 run_loop.Run(); |
344 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); | 344 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); |
345 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); | 345 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); |
346 } | 346 } |
347 | 347 |
348 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | 348 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { |
349 for (size_t i = 0; i < devices.size(); ++i) { | 349 for (size_t i = 0; i < devices.size(); ++i) { |
350 media::AudioDeviceNames::const_iterator audio_it = | 350 if (devices[i].device.id != |
351 physical_audio_devices_.begin(); | 351 media::AudioDeviceDescription::kDefaultDeviceId && |
352 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 352 devices[i].device.id != |
353 // Skip default and communications audio devices, whose IDs are not | 353 media::AudioDeviceDescription::kCommunicationsDeviceId) { |
354 // translated. | 354 for (const auto& audio_device : physical_audio_devices_) { |
355 if (devices[i].device.id == | 355 if (audio_device.unique_id == devices[i].device.id) |
356 media::AudioDeviceDescription::kDefaultDeviceId || | 356 return true; |
357 devices[i].device.id == | |
358 media::AudioDeviceDescription::kCommunicationsDeviceId) { | |
359 continue; | |
360 } | 357 } |
361 if (audio_it->unique_id == devices[i].device.id) | |
362 return true; | |
363 } | 358 } |
364 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | 359 for (const auto& video_device : physical_video_devices_) { |
365 physical_video_devices_.begin(); | 360 if (video_device.device_id == devices[i].device.id) |
366 for (; video_it != physical_video_devices_.end(); ++video_it) { | |
367 if (video_it->device_id == devices[i].device.id) | |
368 return true; | 361 return true; |
369 } | 362 } |
370 } | 363 } |
371 return false; | 364 return false; |
372 } | 365 } |
373 | 366 |
374 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | 367 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, |
375 const url::Origin& origin) { | 368 const url::Origin& origin) { |
376 for (size_t i = 0; i < devices.size(); ++i) { | 369 for (size_t i = 0; i < devices.size(); ++i) { |
377 bool found_match = false; | 370 bool found_match = false; |
378 media::AudioDeviceNames::const_iterator audio_it = | 371 media::AudioDeviceDescriptions::const_iterator audio_it = |
379 physical_audio_devices_.begin(); | 372 physical_audio_devices_.begin(); |
380 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 373 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
381 if (content::DoesMediaDeviceIDMatchHMAC( | 374 if (content::DoesMediaDeviceIDMatchHMAC( |
382 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 375 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
383 origin, | 376 origin, |
384 devices[i].device.id, | 377 devices[i].device.id, |
385 audio_it->unique_id)) { | 378 audio_it->unique_id)) { |
386 EXPECT_FALSE(found_match); | 379 EXPECT_FALSE(found_match); |
387 found_match = true; | 380 found_match = true; |
388 } | 381 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 416 |
424 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 417 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
425 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 418 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
426 content::TestBrowserThreadBundle thread_bundle_; | 419 content::TestBrowserThreadBundle thread_bundle_; |
427 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> | 420 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> |
428 audio_manager_; | 421 audio_manager_; |
429 MockMediaStreamUIProxy* stream_ui_; | 422 MockMediaStreamUIProxy* stream_ui_; |
430 ContentBrowserClient* old_browser_client_; | 423 ContentBrowserClient* old_browser_client_; |
431 std::unique_ptr<ContentClient> content_client_; | 424 std::unique_ptr<ContentClient> content_client_; |
432 content::TestBrowserContext browser_context_; | 425 content::TestBrowserContext browser_context_; |
433 media::AudioDeviceNames physical_audio_devices_; | 426 media::AudioDeviceDescriptions physical_audio_devices_; |
434 media::VideoCaptureDeviceDescriptors physical_video_devices_; | 427 media::VideoCaptureDeviceDescriptors physical_video_devices_; |
435 url::Origin origin_; | 428 url::Origin origin_; |
436 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; | 429 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; |
437 }; | 430 }; |
438 | 431 |
439 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { | 432 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { |
440 StreamControls controls(false, true); | 433 StreamControls controls(false, true); |
441 | 434 |
442 SetupFakeUI(true); | 435 SetupFakeUI(true); |
443 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 436 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 run_loop1.Run(); | 586 run_loop1.Run(); |
594 run_loop2.Run(); | 587 run_loop2.Run(); |
595 } | 588 } |
596 | 589 |
597 // Test that we can generate streams where a sourceId is specified in | 590 // Test that we can generate streams where a sourceId is specified in |
598 // the request. | 591 // the request. |
599 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { | 592 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { |
600 ASSERT_GE(physical_audio_devices_.size(), 1u); | 593 ASSERT_GE(physical_audio_devices_.size(), 1u); |
601 ASSERT_GE(physical_video_devices_.size(), 1u); | 594 ASSERT_GE(physical_video_devices_.size(), 1u); |
602 | 595 |
603 media::AudioDeviceNames::const_iterator audio_it = | 596 media::AudioDeviceDescriptions::const_iterator audio_it = |
604 physical_audio_devices_.begin(); | 597 physical_audio_devices_.begin(); |
605 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 598 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
606 std::string source_id = content::GetHMACForMediaDeviceID( | 599 std::string source_id = content::GetHMACForMediaDeviceID( |
607 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 600 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
608 origin_, | 601 origin_, |
609 audio_it->unique_id); | 602 audio_it->unique_id); |
610 ASSERT_FALSE(source_id.empty()); | 603 ASSERT_FALSE(source_id.empty()); |
611 StreamControls controls(true, true); | 604 StreamControls controls(true, true); |
612 controls.audio.device_id = source_id; | 605 controls.audio.device_id = source_id; |
613 | 606 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 base::RunLoop run_loop; | 807 base::RunLoop run_loop; |
815 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 808 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
816 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 809 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
817 media_stream_manager_->media_devices_manager()->OnDevicesChanged( | 810 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
818 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 811 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
819 | 812 |
820 run_loop.Run(); | 813 run_loop.Run(); |
821 } | 814 } |
822 | 815 |
823 }; // namespace content | 816 }; // namespace content |
OLD | NEW |