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

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

Issue 60193002: Revert 232766 "Refactor MediaStreamManager to never output real ..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1700/src/
Patch Set: 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
===================================================================
--- content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc (revision 232998)
+++ content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc (working copy)
@@ -15,13 +15,12 @@
#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/mock_audio_manager.h"
+#include "media/audio/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"
@@ -62,11 +61,10 @@
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, security_origin);
+ render_view_id, page_request_id, components, GURL());
}
void OnStopStreamDevice(int render_view_id,
@@ -78,28 +76,25 @@
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, security_origin);
+ render_view_id, page_request_id, device_id, type, GURL());
}
- 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);
+ 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);
}
std::string label_;
StreamDeviceInfoArray audio_devices_;
StreamDeviceInfoArray video_devices_;
StreamDeviceInfo opened_device_;
- StreamDeviceInfoArray enumerated_devices_;
private:
virtual ~MockMediaStreamDispatcherHost() {}
@@ -120,8 +115,6 @@
IPC_MESSAGE_HANDLER(MediaStreamMsg_StopGeneratedStream,
OnStopGeneratedStreamFromBrowser)
IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpened)
- IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerated,
- OnDevicesEnumerated)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
EXPECT_TRUE(handled);
@@ -183,17 +176,6 @@
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_;
@@ -208,11 +190,9 @@
public:
MediaStreamDispatcherHostTest()
: old_browser_client_(NULL),
- thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
- origin_("https://test.com") {
- audio_manager_.reset(
- new media::MockAudioManager(base::MessageLoopProxy::current()));
+ thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
// 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();
@@ -227,16 +207,12 @@
}
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 {
host_->OnChannelClosing();
}
@@ -255,158 +231,40 @@
int page_request_id,
const StreamOptions& options) {
base::RunLoop run_loop;
- EXPECT_CALL(*host_.get(), OnStreamGenerated(
- render_view_id, page_request_id,
- options.audio_type != MEDIA_NO_SERVICE ? 1 : 0,
- options.video_type != MEDIA_NO_SERVICE ? 1 : 0));
- host_->OnGenerateStream(render_view_id, page_request_id, options, origin_,
+ host_->OnGenerateStream(render_view_id, page_request_id, options,
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,
int page_request_id,
const std::string& device_id) {
base::RunLoop run_loop;
host_->OnOpenDevice(render_view_id, page_request_id, device_id,
- MEDIA_DEVICE_VIDEO_CAPTURE, origin_,
+ MEDIA_DEVICE_VIDEO_CAPTURE,
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) {
- *device_info = *found_device;
- }
- return found_device;
- }
-
- 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_;
scoped_ptr<media::AudioManager> audio_manager_;
scoped_ptr<MediaStreamManager> media_stream_manager_;
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.
@@ -415,6 +273,7 @@
// Generate first stream.
SetupFakeUI(true);
+ EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
// Check the latest generated stream.
@@ -426,6 +285,8 @@
// 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.
@@ -445,6 +306,7 @@
// 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);
@@ -473,6 +335,7 @@
// Generate first stream.
SetupFakeUI(true);
+ EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
// Check the latest generated stream.
@@ -484,6 +347,8 @@
// 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.
@@ -513,93 +378,41 @@
base::RunLoop run_loop1;
base::RunLoop run_loop2;
- host_->OnGenerateStream(kRenderId, kPageRequestId, options, origin_,
+ host_->OnGenerateStream(kRenderId, kPageRequestId, options,
run_loop1.QuitClosure());
- host_->OnGenerateStream(kRenderId, kPageRequestId + 1, options, origin_,
+ host_->OnGenerateStream(kRenderId, kPageRequestId + 1, options,
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);
- std::string invalid_source_id = "invalid source id";
- 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";
- options.audio_device_id = invalid_source_id;
-
- GenerateStreamAndWaitForFailure(kRenderId, kRenderId, options);
-}
-
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(FindRequestedDeviceInfo(device_id, MEDIA_GENERATE_STREAM,
- &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);
- StopStreamDeviceAndWait(device_id);
+ host_->OnStopStreamDevice(kRenderId, device_id);
- EXPECT_TRUE(FindRequestedDeviceInfo(device_id, MEDIA_OPEN_DEVICE, NULL));
+ EXPECT_FALSE(host_->FindExistingRequestedDeviceInfo(device_id,
+ MEDIA_GENERATE_STREAM,
+ &video_device_info));
+ EXPECT_TRUE(host_->FindExistingRequestedDeviceInfo(device_id,
+ MEDIA_OPEN_DEVICE,
+ &video_device_info));
}
TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) {
@@ -610,15 +423,13 @@
// Create multiple GenerateStream requests.
size_t streams = 5;
for (size_t i = 1; i <= streams; ++i) {
- host_->OnGenerateStream(kRenderId, kPageRequestId + i, options, origin_,
+ host_->OnGenerateStream(kRenderId, kPageRequestId + i, options,
run_loop.QuitClosure());
}
// Calling OnChannelClosing() to cancel all the pending requests.
host_->OnChannelClosing();
run_loop.RunUntilIdle();
-
- media_stream_manager_->WillDestroyCurrentMessageLoop();
}
TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreamsOnChannelClosing) {
@@ -628,6 +439,8 @@
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);
}
@@ -645,8 +458,9 @@
.WillOnce(SaveArg<0>(&close_callback));
media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>());
- GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
+ EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
EXPECT_CALL(*host_.get(), OnStopGeneratedStreamFromBrowser(kRenderId));
+ GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
EXPECT_EQ(host_->audio_devices_.size(), 0u);
EXPECT_EQ(host_->video_devices_.size(), 1u);
@@ -656,15 +470,4 @@
base::RunLoop().RunUntilIdle();
}
-TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) {
- EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
- MEDIA_DEVICE_AUDIO_CAPTURE);
-}
-
-TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) {
- EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
- MEDIA_DEVICE_VIDEO_CAPTURE);
-}
-
-
}; // namespace content

Powered by Google App Engine
This is Rietveld 408576698