| 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 8e435a785a91d82fd2beb40f19a54a77a9f6b569..6ef2152923e8e1f322d4a47ed7a431a83d758b15 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,6 +15,7 @@
|
| #include "base/location.h"
|
| #include "base/run_loop.h"
|
| #include "base/single_thread_task_runner.h"
|
| +#include "base/system_monitor/system_monitor.h"
|
| #include "base/thread_task_runner_handle.h"
|
| #include "build/build_config.h"
|
| #include "content/browser/browser_thread_impl.h"
|
| @@ -65,7 +66,7 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
|
| const ResourceContext::SaltCallback salt_callback,
|
| const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
|
| MediaStreamManager* manager)
|
| - : MediaStreamDispatcherHost(kProcessId, salt_callback, manager),
|
| + : MediaStreamDispatcherHost(kProcessId, salt_callback, manager, true),
|
| task_runner_(task_runner),
|
| current_ipc_(NULL) {}
|
|
|
| @@ -116,6 +117,20 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
|
| render_frame_id, page_request_id, type, security_origin);
|
| }
|
|
|
| + void OnCancelEnumerateDevices(int render_frame_id, int page_request_id) {
|
| + MediaStreamDispatcherHost::OnCancelEnumerateDevices(render_frame_id,
|
| + page_request_id);
|
| + }
|
| +
|
| + void OnSubscribeToDeviceChangeNotifications(
|
| + int render_frame_id,
|
| + const url::Origin& security_origin,
|
| + const base::Closure& quit_closure) {
|
| + quit_closures_.push(quit_closure);
|
| + MediaStreamDispatcherHost::OnSubscribeToDeviceChangeNotifications(
|
| + render_frame_id, security_origin);
|
| + }
|
| +
|
| std::string label_;
|
| StreamDeviceInfoArray audio_devices_;
|
| StreamDeviceInfoArray video_devices_;
|
| @@ -132,8 +147,8 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
|
| CHECK(message);
|
| current_ipc_ = message;
|
|
|
| - // In this method we dispatch the messages to the according handlers as if
|
| - // we are the renderer.
|
| + // In this method we dispatch the messages to the corresponding handlers as
|
| + // if we are the renderer.
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message)
|
| IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated,
|
| @@ -143,6 +158,7 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
|
| IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceStopped, OnDeviceStoppedInternal)
|
| IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpenedInternal)
|
| IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerated, OnDevicesEnumerated)
|
| + IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesChanged, OnDevicesChanged)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP()
|
| EXPECT_TRUE(handled);
|
| @@ -211,6 +227,12 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
|
| enumerated_devices_ = devices;
|
| }
|
|
|
| + void OnDevicesChanged() {
|
| + base::Closure quit_closure = quit_closures_.front();
|
| + quit_closures_.pop();
|
| + task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
|
| + }
|
| +
|
| const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
| IPC::Message* current_ipc_;
|
| std::queue<base::Closure> quit_closures_;
|
| @@ -351,6 +373,20 @@ class MediaStreamDispatcherHostTest : public testing::Test {
|
| ASSERT_FALSE(host_->enumerated_devices_.empty());
|
| EXPECT_FALSE(DoesContainRawIds(host_->enumerated_devices_));
|
| EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->enumerated_devices_, origin_));
|
| + // Enumeration requests must be cancelled manually.
|
| + host_->OnCancelEnumerateDevices(render_frame_id, page_request_id);
|
| + }
|
| +
|
| + void SubscribeToDeviceChangeNotificationsAndWaitForNotification(
|
| + int render_frame_id) {
|
| + base::RunLoop run_loop;
|
| + host_->OnSubscribeToDeviceChangeNotifications(render_frame_id, origin_,
|
| + run_loop.QuitClosure());
|
| + // Simulate a change in the set of devices.
|
| + video_capture_device_factory_->set_number_of_devices(5);
|
| + media_stream_manager_->OnDevicesChanged(
|
| + base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
|
| + run_loop.Run();
|
| }
|
|
|
| bool DoesContainRawIds(const StreamDeviceInfoArray& devices) {
|
| @@ -916,4 +952,12 @@ TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevicesNoAccess) {
|
| EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_));
|
| }
|
|
|
| +TEST_F(MediaStreamDispatcherHostTest, DeviceChangeNotification) {
|
| + SetupFakeUI(false);
|
| + // warm up the cache
|
| + EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
|
| + MEDIA_DEVICE_VIDEO_CAPTURE);
|
| + SubscribeToDeviceChangeNotificationsAndWaitForNotification(kRenderId);
|
| +}
|
| +
|
| }; // namespace content
|
|
|