Index: content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc |
diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc b/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc |
index e17302ff0468c0c6016085dd8939b13b68c0d353..0bc380ebd39c0c89cf3a06c7913a5cd6f3eae664 100644 |
--- a/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc |
+++ b/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc |
@@ -15,12 +15,13 @@ |
#include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
#include "content/common/media/media_stream_messages.h" |
#include "content/common/media/media_stream_options.h" |
+#include "content/public/browser/media_device_id.h" |
#include "content/public/test/mock_resource_context.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
#include "content/test/test_content_browser_client.h" |
#include "content/test/test_content_client.h" |
#include "ipc/ipc_message_macros.h" |
-#include "media/audio/audio_manager.h" |
+#include "media/audio/mock_audio_manager.h" |
#include "media/video/capture/fake_video_capture_device.h" |
#include "net/url_request/url_request_context.h" |
#include "testing/gmock/include/gmock/gmock.h" |
@@ -59,10 +60,11 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
void OnGenerateStream(int render_view_id, |
int page_request_id, |
const StreamOptions& components, |
+ const GURL& security_origin, |
const base::Closure& quit_closure) { |
quit_closures_.push(quit_closure); |
MediaStreamDispatcherHost::OnGenerateStream( |
- render_view_id, page_request_id, components, GURL()); |
+ render_view_id, page_request_id, components, security_origin); |
} |
void OnStopStreamDevice(int render_view_id, |
@@ -74,25 +76,28 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
int page_request_id, |
const std::string& device_id, |
MediaStreamType type, |
+ const GURL& security_origin, |
const base::Closure& quit_closure) { |
quit_closures_.push(quit_closure); |
MediaStreamDispatcherHost::OnOpenDevice( |
- render_view_id, page_request_id, device_id, type, GURL()); |
+ render_view_id, page_request_id, device_id, type, security_origin); |
} |
- bool FindExistingRequestedDeviceInfo(const std::string& device_id, |
- MediaStreamRequestType request_type, |
- StreamDeviceInfo* device_info) { |
- MediaRequestState request_state; |
- return media_stream_manager_->FindExistingRequestedDeviceInfo( |
- kProcessId, kRenderId, request_type, device_id, device_info, |
- &request_state); |
+ void OnEnumerateDevices(int render_view_id, |
+ int page_request_id, |
+ MediaStreamType type, |
+ const GURL& security_origin, |
+ const base::Closure& quit_closure) { |
+ quit_closures_.push(quit_closure); |
+ MediaStreamDispatcherHost::OnEnumerateDevices( |
+ render_view_id, page_request_id, type, security_origin); |
} |
std::string label_; |
StreamDeviceInfoArray audio_devices_; |
StreamDeviceInfoArray video_devices_; |
StreamDeviceInfo opened_device_; |
+ StreamDeviceInfoArray enumerated_devices_; |
private: |
virtual ~MockMediaStreamDispatcherHost() {} |
@@ -112,6 +117,8 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
OnStreamGenerationFailed) |
IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceStopped, OnDeviceStopped) |
IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpened) |
+ IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerated, |
+ OnDevicesEnumerated) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
EXPECT_TRUE(handled); |
@@ -153,14 +160,12 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
void OnDeviceStopped(const IPC::Message& msg, |
const std::string& label, |
const content::StreamDeviceInfo& device) { |
+ if (IsVideoMediaType(device.device.type)) |
+ EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0])); |
+ if (IsAudioMediaType(device.device.type)) |
+ EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0])); |
+ |
OnDeviceStopped(msg.routing_id()); |
- // Notify that the event have occurred. |
- if (!quit_closures_.empty()) { |
- base::Closure quit_closure = quit_closures_.front(); |
- quit_closures_.pop(); |
- message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); |
- } |
- label_ = ""; |
} |
void OnDeviceOpened(const IPC::Message& msg, |
@@ -174,6 +179,17 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
opened_device_ = device; |
} |
+ void OnDevicesEnumerated(const IPC::Message& msg, |
+ int request_id, |
+ const std::string& label, |
+ const StreamDeviceInfoArray& devices) { |
+ base::Closure quit_closure = quit_closures_.front(); |
+ quit_closures_.pop(); |
+ message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); |
+ label_ = label; |
+ enumerated_devices_ = devices; |
+ } |
+ |
scoped_refptr<base::MessageLoopProxy> message_loop_; |
std::queue<base::Closure> quit_closures_; |
@@ -188,9 +204,11 @@ class MediaStreamDispatcherHostTest : public testing::Test { |
public: |
MediaStreamDispatcherHostTest() |
: old_browser_client_(NULL), |
- thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
+ thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
+ origin_("https://test.com") { |
+ audio_manager_.reset( |
+ new media::MockAudioManager(base::MessageLoopProxy::current())); |
// Create our own MediaStreamManager. |
- audio_manager_.reset(media::AudioManager::Create()); |
media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
// Make sure we use fake devices to avoid long delays. |
media_stream_manager_->UseFakeDevice(); |
@@ -205,10 +223,14 @@ class MediaStreamDispatcherHostTest : public testing::Test { |
} |
virtual ~MediaStreamDispatcherHostTest() { |
- // Recover the old browser client and content client. |
- SetBrowserClientForTesting(old_browser_client_); |
- content_client_.reset(); |
- media_stream_manager_->WillDestroyCurrentMessageLoop(); |
+ } |
+ |
+ virtual void SetUp() OVERRIDE { |
+ media::FakeVideoCaptureDevice::GetDeviceNames(&physical_video_devices_); |
+ ASSERT_GT(physical_video_devices_.size(), 0u); |
+ |
+ audio_manager_->GetAudioInputDeviceNames(&physical_audio_devices_); |
+ ASSERT_GT(physical_audio_devices_.size(), 0u); |
} |
virtual void TearDown() OVERRIDE { |
@@ -229,9 +251,33 @@ class MediaStreamDispatcherHostTest : public testing::Test { |
int page_request_id, |
const StreamOptions& options) { |
base::RunLoop run_loop; |
- host_->OnGenerateStream(render_view_id, page_request_id, options, |
+ int expected_audio_array_size = |
+ (options.audio_type != MEDIA_NO_SERVICE && |
+ physical_audio_devices_.size() > 0) ? 1 : 0; |
+ int expected_video_array_size = |
+ (options.video_type != MEDIA_NO_SERVICE && |
+ physical_video_devices_.size() > 0) ? 1 : 0; |
+ EXPECT_CALL(*host_.get(), OnStreamGenerated(render_view_id, page_request_id, |
+ expected_audio_array_size, |
+ expected_video_array_size)); |
+ host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, |
run_loop.QuitClosure()); |
run_loop.Run(); |
+ EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_)); |
+ EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); |
+ EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_)); |
+ EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); |
+ } |
+ |
+ void GenerateStreamAndWaitForFailure(int render_view_id, |
+ int page_request_id, |
+ const StreamOptions& options) { |
+ base::RunLoop run_loop; |
+ EXPECT_CALL(*host_.get(), |
+ OnStreamGenerationFailed(render_view_id, page_request_id)); |
+ host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, |
+ run_loop.QuitClosure()); |
+ run_loop.Run(); |
} |
void OpenVideoDeviceAndWaitForResult(int render_view_id, |
@@ -239,9 +285,71 @@ class MediaStreamDispatcherHostTest : public testing::Test { |
const std::string& device_id) { |
base::RunLoop run_loop; |
host_->OnOpenDevice(render_view_id, page_request_id, device_id, |
- MEDIA_DEVICE_VIDEO_CAPTURE, |
+ MEDIA_DEVICE_VIDEO_CAPTURE, origin_, |
run_loop.QuitClosure()); |
run_loop.Run(); |
+ EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); |
+ EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); |
+ } |
+ |
+ void EnumerateDevicesAndWaitForResult(int render_view_id, |
+ int page_request_id, |
+ MediaStreamType type) { |
+ base::RunLoop run_loop; |
+ host_->OnEnumerateDevices(render_view_id, page_request_id, type, origin_, |
+ run_loop.QuitClosure()); |
+ run_loop.Run(); |
+ ASSERT_FALSE(host_->enumerated_devices_.empty()); |
+ EXPECT_FALSE(DoesContainRawIds(host_->enumerated_devices_)); |
+ EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->enumerated_devices_, origin_)); |
+ } |
+ |
+ bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { |
+ for (size_t i = 0; i < devices.size(); ++i) { |
+ media::AudioDeviceNames::const_iterator audio_it = |
+ physical_audio_devices_.begin(); |
+ for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
+ if (audio_it->unique_id == devices[i].device.id) |
+ return true; |
+ } |
+ media::VideoCaptureDevice::Names::const_iterator video_it = |
+ physical_video_devices_.begin(); |
+ for (; video_it != physical_video_devices_.end(); ++video_it) { |
+ if (video_it->id() == devices[i].device.id) |
+ return true; |
+ } |
+ } |
+ return false; |
+ } |
+ |
+ bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, |
+ const GURL& origin) { |
+ for (size_t i = 0; i < devices.size(); ++i) { |
+ bool found_match = false; |
+ media::AudioDeviceNames::const_iterator audio_it = |
+ physical_audio_devices_.begin(); |
+ for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
+ if (content::DoesMediaDeviceIDMatchHMAC(origin, |
+ devices[i].device.id, |
+ audio_it->unique_id)) { |
+ EXPECT_FALSE(found_match); |
+ found_match = true; |
+ } |
+ } |
+ media::VideoCaptureDevice::Names::const_iterator video_it = |
+ physical_video_devices_.begin(); |
+ for (; video_it != physical_video_devices_.end(); ++video_it) { |
+ if (content::DoesMediaDeviceIDMatchHMAC(origin, |
+ devices[i].device.id, |
+ video_it->id())) { |
+ EXPECT_FALSE(found_match); |
+ found_match = true; |
+ } |
+ } |
+ if (!found_match) |
+ return false; |
+ } |
+ return true; |
} |
scoped_refptr<MockMediaStreamDispatcherHost> host_; |
@@ -250,19 +358,31 @@ class MediaStreamDispatcherHostTest : public testing::Test { |
ContentBrowserClient* old_browser_client_; |
scoped_ptr<ContentClient> content_client_; |
content::TestBrowserThreadBundle thread_bundle_; |
+ media::AudioDeviceNames physical_audio_devices_; |
+ media::VideoCaptureDevice::Names physical_video_devices_; |
+ GURL origin_; |
}; |
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { |
StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
SetupFakeUI(true); |
- EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
EXPECT_EQ(host_->audio_devices_.size(), 0u); |
EXPECT_EQ(host_->video_devices_.size(), 1u); |
} |
+TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioOnly) { |
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE); |
+ |
+ SetupFakeUI(true); |
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
+ |
+ EXPECT_EQ(host_->audio_devices_.size(), 1u); |
+ EXPECT_EQ(host_->video_devices_.size(), 0u); |
+} |
+ |
// This test generates two streams with video only using the same render view |
// id. The same capture device with the same device and session id is expected |
// to be used. |
@@ -271,7 +391,6 @@ TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { |
// Generate first stream. |
SetupFakeUI(true); |
- EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
// Check the latest generated stream. |
@@ -283,8 +402,6 @@ TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { |
// Generate second stream. |
SetupFakeUI(true); |
- EXPECT_CALL(*host_.get(), |
- OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1)); |
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + 1, options); |
// Check the latest generated stream. |
@@ -304,7 +421,6 @@ TEST_F(MediaStreamDispatcherHostTest, |
// Generate first stream. |
SetupFakeUI(true); |
- EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
EXPECT_EQ(host_->audio_devices_.size(), 0u); |
@@ -333,7 +449,6 @@ TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) { |
// Generate first stream. |
SetupFakeUI(true); |
- EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
// Check the latest generated stream. |
@@ -345,8 +460,6 @@ TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) { |
// Generate second stream from another render view. |
SetupFakeUI(true); |
- EXPECT_CALL(*host_.get(), |
- OnStreamGenerated(kRenderId+1, kPageRequestId + 1, 0, 1)); |
GenerateStreamAndWaitForResult(kRenderId+1, kPageRequestId + 1, options); |
// Check the latest generated stream. |
@@ -376,41 +489,146 @@ TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithoutWaiting) { |
base::RunLoop run_loop1; |
base::RunLoop run_loop2; |
- host_->OnGenerateStream(kRenderId, kPageRequestId, options, |
+ host_->OnGenerateStream(kRenderId, kPageRequestId, options, origin_, |
run_loop1.QuitClosure()); |
- host_->OnGenerateStream(kRenderId, kPageRequestId + 1, options, |
+ host_->OnGenerateStream(kRenderId, kPageRequestId + 1, options, origin_, |
run_loop2.QuitClosure()); |
run_loop1.Run(); |
run_loop2.Run(); |
} |
+// Test that we can generate streams where a sourceId is specified in the |
+// request. |
+TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { |
+ ASSERT_GE(physical_audio_devices_.size(), 1u); |
+ ASSERT_GE(physical_video_devices_.size(), 1u); |
+ |
+ media::AudioDeviceNames::const_iterator audio_it = |
+ physical_audio_devices_.begin(); |
+ for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
+ MEDIA_DEVICE_VIDEO_CAPTURE); |
+ options.audio_device_id = content::GetHMACForMediaDeviceID( |
+ origin_, |
+ audio_it->unique_id); |
+ ASSERT_FALSE(options.audio_device_id.empty()); |
+ |
+ // Generate first stream. |
+ SetupFakeUI(true); |
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
+ EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id); |
+ } |
+ |
+ media::VideoCaptureDevice::Names::const_iterator video_it = |
+ physical_video_devices_.begin(); |
+ for (; video_it != physical_video_devices_.end(); ++video_it) { |
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
+ MEDIA_DEVICE_VIDEO_CAPTURE); |
+ options.video_device_id = content::GetHMACForMediaDeviceID(origin_, |
+ video_it->id()); |
+ ASSERT_FALSE(options.video_device_id.empty()); |
+ |
+ // Generate first stream. |
+ SetupFakeUI(true); |
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
+ EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id); |
+ } |
+} |
+ |
+// Test that generating a stream with an invalid video source id fail. |
+TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) { |
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
+ MEDIA_DEVICE_VIDEO_CAPTURE); |
+ options.video_device_id = "invalid source id"; |
+ |
+ GenerateStreamAndWaitForFailure(kRenderId, kRenderId, options); |
+} |
+ |
+// Test that generating a stream with an invalid audio source id fail. |
+TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) { |
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
+ MEDIA_DEVICE_VIDEO_CAPTURE); |
+ options.audio_device_id = "invalid source id"; |
+ |
+ GenerateStreamAndWaitForFailure(kRenderId, kRenderId, options); |
+} |
+ |
+TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { |
+ size_t number_of_fake_devices = physical_video_devices_.size(); |
+ media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(0); |
+ media::FakeVideoCaptureDevice::GetDeviceNames(&physical_video_devices_); |
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_DEVICE_VIDEO_CAPTURE); |
+ |
+ SetupFakeUI(true); |
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
+ EXPECT_TRUE(host_->video_devices_.empty()); |
+ |
+ // Reset the number of fake devices for next test. |
+ media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_fake_devices); |
+} |
+ |
+// Test that if a OnStopStreamDevice message is received for a device that has |
+// been opened in a MediaStream and by pepper, the device is only stopped for |
+// the MediaStream. |
TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) { |
StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
SetupFakeUI(true); |
- EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
- const std::string device_id = host_->video_devices_.front().device.id; |
- const int session_id = host_->video_devices_.front().session_id; |
- StreamDeviceInfo video_device_info; |
- EXPECT_TRUE(host_->FindExistingRequestedDeviceInfo(device_id, |
- MEDIA_GENERATE_STREAM, |
- &video_device_info)); |
- EXPECT_EQ(video_device_info.device.id, device_id); |
- EXPECT_EQ(video_device_info.session_id, session_id); |
- |
- OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, device_id); |
- |
- host_->OnStopStreamDevice(kRenderId, device_id); |
- |
- EXPECT_FALSE(host_->FindExistingRequestedDeviceInfo(device_id, |
- MEDIA_GENERATE_STREAM, |
- &video_device_info)); |
- EXPECT_TRUE(host_->FindExistingRequestedDeviceInfo(device_id, |
- MEDIA_OPEN_DEVICE, |
- &video_device_info)); |
+ std::string stream_request_label = host_->label_; |
+ StreamDeviceInfo video_device_info = host_->video_devices_.front(); |
+ ASSERT_EQ(1u, media_stream_manager_->GetDevicesOpenedByRequest( |
+ stream_request_label).size()); |
+ |
+ // Open the same device by Pepper. |
+ OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, |
+ video_device_info.device.id); |
+ std::string open_device_request_label = host_->label_; |
+ |
+ // Stop the device in the MediaStream. |
+ host_->OnStopStreamDevice(kRenderId, video_device_info.device.id); |
+ |
+ EXPECT_EQ(0u, media_stream_manager_->GetDevicesOpenedByRequest( |
+ stream_request_label).size()); |
+ EXPECT_EQ(1u, media_stream_manager_->GetDevicesOpenedByRequest( |
+ open_device_request_label).size()); |
+} |
+ |
+TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStreamAndRestart) { |
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
+ MEDIA_DEVICE_VIDEO_CAPTURE); |
+ |
+ SetupFakeUI(true); |
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
+ |
+ std::string request_label1 = host_->label_; |
+ StreamDeviceInfo video_device_info = host_->video_devices_.front(); |
+ // Expect that 1 audio and 1 video device has been opened. |
+ EXPECT_EQ(2u, media_stream_manager_->GetDevicesOpenedByRequest( |
+ request_label1).size()); |
+ |
+ host_->OnStopStreamDevice(kRenderId, video_device_info.device.id); |
+ EXPECT_EQ(1u, media_stream_manager_->GetDevicesOpenedByRequest( |
+ request_label1).size()); |
+ |
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
+ std::string request_label2 = host_->label_; |
+ |
+ StreamDeviceInfoArray request1_devices = |
+ media_stream_manager_->GetDevicesOpenedByRequest(request_label1); |
+ StreamDeviceInfoArray request2_devices = |
+ media_stream_manager_->GetDevicesOpenedByRequest(request_label2); |
+ |
+ ASSERT_EQ(1u, request1_devices.size()); |
+ ASSERT_EQ(2u, request2_devices.size()); |
+ |
+ // Test that the same audio device has been opened in both streams. |
+ EXPECT_TRUE(StreamDeviceInfo::IsEqual(request1_devices[0], |
+ request2_devices[0]) || |
+ StreamDeviceInfo::IsEqual(request1_devices[0], |
+ request2_devices[1])); |
} |
TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) { |
@@ -421,7 +639,7 @@ TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) { |
// Create multiple GenerateStream requests. |
size_t streams = 5; |
for (size_t i = 1; i <= streams; ++i) { |
- host_->OnGenerateStream(kRenderId, kPageRequestId + i, options, |
+ host_->OnGenerateStream(kRenderId, kPageRequestId + i, options, origin_, |
run_loop.QuitClosure()); |
} |
@@ -437,8 +655,6 @@ TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreamsOnChannelClosing) { |
size_t generated_streams = 3; |
for (size_t i = 0; i < generated_streams; ++i) { |
SetupFakeUI(true); |
- EXPECT_CALL(*host_.get(), |
- OnStreamGenerated(kRenderId, kPageRequestId + i, 0, 1)); |
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + i, options); |
} |
@@ -456,16 +672,48 @@ TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { |
.WillOnce(SaveArg<0>(&close_callback)); |
media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>()); |
- EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
- EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)); |
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
EXPECT_EQ(host_->audio_devices_.size(), 0u); |
EXPECT_EQ(host_->video_devices_.size(), 1u); |
ASSERT_FALSE(close_callback.is_null()); |
+ EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)); |
close_callback.Run(); |
base::RunLoop().RunUntilIdle(); |
} |
+// Test that the dispatcher is notified if a video device that is in use is |
+// being unplugged. |
+TEST_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) { |
+ size_t number_of_fake_devices = physical_video_devices_.size(); |
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_DEVICE_VIDEO_CAPTURE); |
+ SetupFakeUI(true); |
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
+ EXPECT_EQ(host_->audio_devices_.size(), 1u); |
+ EXPECT_EQ(host_->video_devices_.size(), 1u); |
+ |
+ media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(0); |
+ |
+ base::RunLoop run_loop; |
+ EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
+ .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
+ media_stream_manager_->OnDevicesChanged( |
+ base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
+ |
+ run_loop.Run(); |
+ |
+ media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_fake_devices); |
+} |
+ |
+TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { |
+ EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
+ MEDIA_DEVICE_AUDIO_CAPTURE); |
+} |
+ |
+TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { |
+ EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
+ MEDIA_DEVICE_VIDEO_CAPTURE); |
+} |
+ |
}; // namespace content |