Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Unified Diff: content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc

Issue 88283002: Reland review 34393006: Refactor MediaStreamManager to not output real device id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes since the revert. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5c3be5d146a239b542ff09b3cabe82afdf6f4cd4 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,13 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
void OnDeviceStopped(const IPC::Message& msg,
const std::string& label,
const content::StreamDeviceInfo& device) {
- 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_ = "";
tommi (sloooow) - chröme 2013/11/26 14:44:21 do you want to dcheck/expect_eq first that the lab
perkj_chrome 2013/11/27 13:41:34 I will remove this line.
+ 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());
}
void OnDeviceOpened(const IPC::Message& msg,
@@ -174,6 +180,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 +205,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 +224,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 +252,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 +286,96 @@ 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 StopStreamDeviceAndWait(const std::string& device_id) {
+ EXPECT_TRUE(FindRequestedDeviceInfo(device_id, MEDIA_GENERATE_STREAM,
+ NULL));
+ host_->OnStopStreamDevice(kRenderId, device_id);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(FindRequestedDeviceInfo(device_id, MEDIA_GENERATE_STREAM,
+ NULL));
+ }
+
+ 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 FindRequestedDeviceInfo(const std::string& device_id,
+ MediaStreamRequestType request_type,
+ StreamDeviceInfo* device_info) {
+ const StreamDeviceInfo* found_device =
+ media_stream_manager_->FindRequestedDeviceInfoForTest(device_id,
+ kProcessId,
+ kRenderId,
+ request_type);
+ if (found_device && device_info) {
tommi (sloooow) - chröme 2013/11/26 14:44:21 nit: no {}
perkj_chrome 2013/11/27 13:41:34 Done.
+ *device_info = *found_device;
+ }
+ return found_device;
tommi (sloooow) - chröme 2013/11/26 14:44:21 does this compile?
tommi (sloooow) - chröme 2013/11/26 14:46:47 Just to clarify, imho this shouldn't compile even
perkj_chrome 2013/11/27 13:41:34 Done.
perkj_chrome 2013/11/27 13:41:34 It actually compiles and do something sensible. sa
+ }
+
+ 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,
tommi (sloooow) - chröme 2013/11/26 14:44:21 indent?
perkj_chrome 2013/11/27 13:41:34 Done.
+ 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,
tommi (sloooow) - chröme 2013/11/26 14:44:21 indent
perkj_chrome 2013/11/27 13:41:34 Done.
+ 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 +384,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 +417,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 +428,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 +447,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 +475,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 +486,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 +515,125 @@ 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_,
tommi (sloooow) - chröme 2013/11/26 14:44:21 strange indent
perkj_chrome 2013/11/27 13:41:34 Done.
+ 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);
+ std::string invalid_source_id = "invalid source id";
tommi (sloooow) - chröme 2013/11/26 14:44:21 unnecessary variable
perkj_chrome 2013/11/27 13:41:34 Done.
+ 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);
+ std::string invalid_source_id = "invalid source id";
tommi (sloooow) - chröme 2013/11/26 14:44:21 ditto.
perkj_chrome 2013/11/27 13:41:34 Done.
+ 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_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_TRUE(FindRequestedDeviceInfo(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);
+ StopStreamDeviceAndWait(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));
+ EXPECT_TRUE(FindRequestedDeviceInfo(device_id, MEDIA_OPEN_DEVICE, NULL));
+}
+
+TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStreamAndRestart) {
+ StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE,
+ MEDIA_DEVICE_VIDEO_CAPTURE);
+
+ SetupFakeUI(true);
tommi (sloooow) - chröme 2013/11/26 14:44:21 nit: call before creating the options object
perkj_chrome 2013/11/27 13:41:34 prefer to ignore this. Most other tests have this
+ 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(FindRequestedDeviceInfo(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);
+ host_->OnStopStreamDevice(kRenderId, device_id);
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
}
TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) {
@@ -421,7 +644,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 +660,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 +677,49 @@ 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);
+}
+
tommi (sloooow) - chröme 2013/11/26 14:44:21 one empty line
perkj_chrome 2013/11/27 13:41:34 Done.
+
}; // namespace content

Powered by Google App Engine
This is Rietveld 408576698