Chromium Code Reviews| 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 <string> | 5 #include <string> |
| 6 #include <queue> | 6 #include <queue> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "content/browser/browser_thread_impl.h" | 12 #include "content/browser/browser_thread_impl.h" |
| 13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
| 14 #include "content/browser/renderer_host/media/media_stream_manager.h" | 14 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 16 #include "content/common/media/media_stream_messages.h" | 16 #include "content/common/media/media_stream_messages.h" |
| 17 #include "content/common/media/media_stream_options.h" | 17 #include "content/common/media/media_stream_options.h" |
| 18 #include "content/public/browser/media_device_id.h" | |
| 18 #include "content/public/test/mock_resource_context.h" | 19 #include "content/public/test/mock_resource_context.h" |
| 19 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 #include "content/test/test_content_browser_client.h" | 21 #include "content/test/test_content_browser_client.h" |
| 21 #include "content/test/test_content_client.h" | 22 #include "content/test/test_content_client.h" |
| 22 #include "ipc/ipc_message_macros.h" | 23 #include "ipc/ipc_message_macros.h" |
| 23 #include "media/audio/audio_manager.h" | 24 #include "media/audio/mock_audio_manager.h" |
| 24 #include "media/video/capture/fake_video_capture_device.h" | 25 #include "media/video/capture/fake_video_capture_device.h" |
| 25 #include "net/url_request/url_request_context.h" | 26 #include "net/url_request/url_request_context.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 using ::testing::_; | 30 using ::testing::_; |
| 30 using ::testing::DeleteArg; | 31 using ::testing::DeleteArg; |
| 31 using ::testing::DoAll; | 32 using ::testing::DoAll; |
| 32 using ::testing::Return; | 33 using ::testing::Return; |
| 33 using ::testing::SaveArg; | 34 using ::testing::SaveArg; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 52 void(int routing_id, int request_id, int audio_array_size, | 53 void(int routing_id, int request_id, int audio_array_size, |
| 53 int video_array_size)); | 54 int video_array_size)); |
| 54 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); | 55 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); |
| 55 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); | 56 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); |
| 56 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); | 57 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); |
| 57 | 58 |
| 58 // Accessor to private functions. | 59 // Accessor to private functions. |
| 59 void OnGenerateStream(int render_view_id, | 60 void OnGenerateStream(int render_view_id, |
| 60 int page_request_id, | 61 int page_request_id, |
| 61 const StreamOptions& components, | 62 const StreamOptions& components, |
| 63 const GURL& security_origin, | |
| 62 const base::Closure& quit_closure) { | 64 const base::Closure& quit_closure) { |
| 63 quit_closures_.push(quit_closure); | 65 quit_closures_.push(quit_closure); |
| 64 MediaStreamDispatcherHost::OnGenerateStream( | 66 MediaStreamDispatcherHost::OnGenerateStream( |
| 65 render_view_id, page_request_id, components, GURL()); | 67 render_view_id, page_request_id, components, security_origin); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void OnStopStreamDevice(int render_view_id, | 70 void OnStopStreamDevice(int render_view_id, |
| 69 const std::string& device_id) { | 71 const std::string& device_id) { |
| 70 MediaStreamDispatcherHost::OnStopStreamDevice(render_view_id, device_id); | 72 MediaStreamDispatcherHost::OnStopStreamDevice(render_view_id, device_id); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void OnOpenDevice(int render_view_id, | 75 void OnOpenDevice(int render_view_id, |
| 74 int page_request_id, | 76 int page_request_id, |
| 75 const std::string& device_id, | 77 const std::string& device_id, |
| 76 MediaStreamType type, | 78 MediaStreamType type, |
| 79 const GURL& security_origin, | |
| 77 const base::Closure& quit_closure) { | 80 const base::Closure& quit_closure) { |
| 78 quit_closures_.push(quit_closure); | 81 quit_closures_.push(quit_closure); |
| 79 MediaStreamDispatcherHost::OnOpenDevice( | 82 MediaStreamDispatcherHost::OnOpenDevice( |
| 80 render_view_id, page_request_id, device_id, type, GURL()); | 83 render_view_id, page_request_id, device_id, type, security_origin); |
| 81 } | 84 } |
| 82 | 85 |
| 83 bool FindExistingRequestedDeviceInfo(const std::string& device_id, | 86 void OnEnumerateDevices(int render_view_id, |
| 84 MediaStreamRequestType request_type, | 87 int page_request_id, |
| 85 StreamDeviceInfo* device_info) { | 88 MediaStreamType type, |
| 86 MediaRequestState request_state; | 89 const GURL& security_origin, |
| 87 return media_stream_manager_->FindExistingRequestedDeviceInfo( | 90 const base::Closure& quit_closure) { |
| 88 kProcessId, kRenderId, request_type, device_id, device_info, | 91 quit_closures_.push(quit_closure); |
| 89 &request_state); | 92 MediaStreamDispatcherHost::OnEnumerateDevices( |
| 93 render_view_id, page_request_id, type, security_origin); | |
| 90 } | 94 } |
| 91 | 95 |
| 92 std::string label_; | 96 std::string label_; |
| 93 StreamDeviceInfoArray audio_devices_; | 97 StreamDeviceInfoArray audio_devices_; |
| 94 StreamDeviceInfoArray video_devices_; | 98 StreamDeviceInfoArray video_devices_; |
| 95 StreamDeviceInfo opened_device_; | 99 StreamDeviceInfo opened_device_; |
| 100 StreamDeviceInfoArray enumerated_devices_; | |
| 96 | 101 |
| 97 private: | 102 private: |
| 98 virtual ~MockMediaStreamDispatcherHost() {} | 103 virtual ~MockMediaStreamDispatcherHost() {} |
| 99 | 104 |
| 100 // This method is used to dispatch IPC messages to the renderer. We intercept | 105 // This method is used to dispatch IPC messages to the renderer. We intercept |
| 101 // these messages here and dispatch to our mock methods to verify the | 106 // these messages here and dispatch to our mock methods to verify the |
| 102 // conversation between this object and the renderer. | 107 // conversation between this object and the renderer. |
| 103 virtual bool Send(IPC::Message* message) OVERRIDE { | 108 virtual bool Send(IPC::Message* message) OVERRIDE { |
| 104 CHECK(message); | 109 CHECK(message); |
| 105 | 110 |
| 106 // In this method we dispatch the messages to the according handlers as if | 111 // In this method we dispatch the messages to the according handlers as if |
| 107 // we are the renderer. | 112 // we are the renderer. |
| 108 bool handled = true; | 113 bool handled = true; |
| 109 IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message) | 114 IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message) |
| 110 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, OnStreamGenerated) | 115 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, OnStreamGenerated) |
| 111 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerationFailed, | 116 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerationFailed, |
| 112 OnStreamGenerationFailed) | 117 OnStreamGenerationFailed) |
| 113 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceStopped, OnDeviceStopped) | 118 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceStopped, OnDeviceStopped) |
| 114 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpened) | 119 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpened) |
| 120 IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerated, | |
| 121 OnDevicesEnumerated) | |
| 115 IPC_MESSAGE_UNHANDLED(handled = false) | 122 IPC_MESSAGE_UNHANDLED(handled = false) |
| 116 IPC_END_MESSAGE_MAP() | 123 IPC_END_MESSAGE_MAP() |
| 117 EXPECT_TRUE(handled); | 124 EXPECT_TRUE(handled); |
| 118 | 125 |
| 119 delete message; | 126 delete message; |
| 120 return true; | 127 return true; |
| 121 } | 128 } |
| 122 | 129 |
| 123 // These handler methods do minimal things and delegate to the mock methods. | 130 // These handler methods do minimal things and delegate to the mock methods. |
| 124 void OnStreamGenerated( | 131 void OnStreamGenerated( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 146 quit_closures_.pop(); | 153 quit_closures_.pop(); |
| 147 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); | 154 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); |
| 148 } | 155 } |
| 149 | 156 |
| 150 label_= ""; | 157 label_= ""; |
| 151 } | 158 } |
| 152 | 159 |
| 153 void OnDeviceStopped(const IPC::Message& msg, | 160 void OnDeviceStopped(const IPC::Message& msg, |
| 154 const std::string& label, | 161 const std::string& label, |
| 155 const content::StreamDeviceInfo& device) { | 162 const content::StreamDeviceInfo& device) { |
| 163 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.
| |
| 164 if (IsVideoMediaType(device.device.type)) | |
| 165 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0])); | |
| 166 if (IsAudioMediaType(device.device.type)) | |
| 167 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0])); | |
| 168 | |
| 156 OnDeviceStopped(msg.routing_id()); | 169 OnDeviceStopped(msg.routing_id()); |
| 157 // Notify that the event have occurred. | |
| 158 if (!quit_closures_.empty()) { | |
| 159 base::Closure quit_closure = quit_closures_.front(); | |
| 160 quit_closures_.pop(); | |
| 161 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); | |
| 162 } | |
| 163 label_ = ""; | |
| 164 } | 170 } |
| 165 | 171 |
| 166 void OnDeviceOpened(const IPC::Message& msg, | 172 void OnDeviceOpened(const IPC::Message& msg, |
| 167 int request_id, | 173 int request_id, |
| 168 const std::string& label, | 174 const std::string& label, |
| 169 const StreamDeviceInfo& device) { | 175 const StreamDeviceInfo& device) { |
| 170 base::Closure quit_closure = quit_closures_.front(); | 176 base::Closure quit_closure = quit_closures_.front(); |
| 171 quit_closures_.pop(); | 177 quit_closures_.pop(); |
| 172 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); | 178 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); |
| 173 label_ = label; | 179 label_ = label; |
| 174 opened_device_ = device; | 180 opened_device_ = device; |
| 175 } | 181 } |
| 176 | 182 |
| 183 void OnDevicesEnumerated(const IPC::Message& msg, | |
| 184 int request_id, | |
| 185 const std::string& label, | |
| 186 const StreamDeviceInfoArray& devices) { | |
| 187 base::Closure quit_closure = quit_closures_.front(); | |
| 188 quit_closures_.pop(); | |
| 189 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); | |
| 190 label_ = label; | |
| 191 enumerated_devices_ = devices; | |
| 192 } | |
| 193 | |
| 177 scoped_refptr<base::MessageLoopProxy> message_loop_; | 194 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 178 | 195 |
| 179 std::queue<base::Closure> quit_closures_; | 196 std::queue<base::Closure> quit_closures_; |
| 180 }; | 197 }; |
| 181 | 198 |
| 182 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { | 199 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { |
| 183 public: | 200 public: |
| 184 MOCK_METHOD1(OnStarted, void(const base::Closure& stop)); | 201 MOCK_METHOD1(OnStarted, void(const base::Closure& stop)); |
| 185 }; | 202 }; |
| 186 | 203 |
| 187 class MediaStreamDispatcherHostTest : public testing::Test { | 204 class MediaStreamDispatcherHostTest : public testing::Test { |
| 188 public: | 205 public: |
| 189 MediaStreamDispatcherHostTest() | 206 MediaStreamDispatcherHostTest() |
| 190 : old_browser_client_(NULL), | 207 : old_browser_client_(NULL), |
| 191 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 208 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 209 origin_("https://test.com") { | |
| 210 audio_manager_.reset( | |
| 211 new media::MockAudioManager(base::MessageLoopProxy::current())); | |
| 192 // Create our own MediaStreamManager. | 212 // Create our own MediaStreamManager. |
| 193 audio_manager_.reset(media::AudioManager::Create()); | |
| 194 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 213 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 195 // Make sure we use fake devices to avoid long delays. | 214 // Make sure we use fake devices to avoid long delays. |
| 196 media_stream_manager_->UseFakeDevice(); | 215 media_stream_manager_->UseFakeDevice(); |
| 197 | 216 |
| 198 host_ = new MockMediaStreamDispatcherHost(base::MessageLoopProxy::current(), | 217 host_ = new MockMediaStreamDispatcherHost(base::MessageLoopProxy::current(), |
| 199 media_stream_manager_.get()); | 218 media_stream_manager_.get()); |
| 200 | 219 |
| 201 // Use the fake content client and browser. | 220 // Use the fake content client and browser. |
| 202 content_client_.reset(new TestContentClient()); | 221 content_client_.reset(new TestContentClient()); |
| 203 SetContentClient(content_client_.get()); | 222 SetContentClient(content_client_.get()); |
| 204 old_browser_client_ = SetBrowserClientForTesting(host_.get()); | 223 old_browser_client_ = SetBrowserClientForTesting(host_.get()); |
| 205 } | 224 } |
| 206 | 225 |
| 207 virtual ~MediaStreamDispatcherHostTest() { | 226 virtual ~MediaStreamDispatcherHostTest() { |
| 208 // Recover the old browser client and content client. | 227 } |
| 209 SetBrowserClientForTesting(old_browser_client_); | 228 |
| 210 content_client_.reset(); | 229 virtual void SetUp() OVERRIDE { |
| 211 media_stream_manager_->WillDestroyCurrentMessageLoop(); | 230 media::FakeVideoCaptureDevice::GetDeviceNames(&physical_video_devices_); |
| 231 ASSERT_GT(physical_video_devices_.size(), 0u); | |
| 232 | |
| 233 audio_manager_->GetAudioInputDeviceNames(&physical_audio_devices_); | |
| 234 ASSERT_GT(physical_audio_devices_.size(), 0u); | |
| 212 } | 235 } |
| 213 | 236 |
| 214 virtual void TearDown() OVERRIDE { | 237 virtual void TearDown() OVERRIDE { |
| 215 host_->OnChannelClosing(); | 238 host_->OnChannelClosing(); |
| 216 } | 239 } |
| 217 | 240 |
| 218 protected: | 241 protected: |
| 219 virtual void SetupFakeUI(bool expect_started) { | 242 virtual void SetupFakeUI(bool expect_started) { |
| 220 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); | 243 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); |
| 221 if (expect_started) { | 244 if (expect_started) { |
| 222 EXPECT_CALL(*stream_ui, OnStarted(_)); | 245 EXPECT_CALL(*stream_ui, OnStarted(_)); |
| 223 } | 246 } |
| 224 media_stream_manager_->UseFakeUI( | 247 media_stream_manager_->UseFakeUI( |
| 225 stream_ui.PassAs<FakeMediaStreamUIProxy>()); | 248 stream_ui.PassAs<FakeMediaStreamUIProxy>()); |
| 226 } | 249 } |
| 227 | 250 |
| 228 void GenerateStreamAndWaitForResult(int render_view_id, | 251 void GenerateStreamAndWaitForResult(int render_view_id, |
| 229 int page_request_id, | 252 int page_request_id, |
| 230 const StreamOptions& options) { | 253 const StreamOptions& options) { |
| 231 base::RunLoop run_loop; | 254 base::RunLoop run_loop; |
| 232 host_->OnGenerateStream(render_view_id, page_request_id, options, | 255 int expected_audio_array_size = |
| 256 (options.audio_type != MEDIA_NO_SERVICE && | |
| 257 physical_audio_devices_.size() > 0) ? 1 : 0; | |
| 258 int expected_video_array_size = | |
| 259 (options.video_type != MEDIA_NO_SERVICE && | |
| 260 physical_video_devices_.size() > 0) ? 1 : 0; | |
| 261 EXPECT_CALL(*host_.get(), OnStreamGenerated(render_view_id, page_request_id, | |
| 262 expected_audio_array_size, | |
| 263 expected_video_array_size)); | |
| 264 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, | |
| 233 run_loop.QuitClosure()); | 265 run_loop.QuitClosure()); |
| 234 run_loop.Run(); | 266 run_loop.Run(); |
| 267 EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_)); | |
| 268 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); | |
| 269 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_)); | |
| 270 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); | |
| 271 } | |
| 272 | |
| 273 void GenerateStreamAndWaitForFailure(int render_view_id, | |
| 274 int page_request_id, | |
| 275 const StreamOptions& options) { | |
| 276 base::RunLoop run_loop; | |
| 277 EXPECT_CALL(*host_.get(), | |
| 278 OnStreamGenerationFailed(render_view_id, page_request_id)); | |
| 279 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, | |
| 280 run_loop.QuitClosure()); | |
| 281 run_loop.Run(); | |
| 235 } | 282 } |
| 236 | 283 |
| 237 void OpenVideoDeviceAndWaitForResult(int render_view_id, | 284 void OpenVideoDeviceAndWaitForResult(int render_view_id, |
| 238 int page_request_id, | 285 int page_request_id, |
| 239 const std::string& device_id) { | 286 const std::string& device_id) { |
| 240 base::RunLoop run_loop; | 287 base::RunLoop run_loop; |
| 241 host_->OnOpenDevice(render_view_id, page_request_id, device_id, | 288 host_->OnOpenDevice(render_view_id, page_request_id, device_id, |
| 242 MEDIA_DEVICE_VIDEO_CAPTURE, | 289 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, |
| 243 run_loop.QuitClosure()); | 290 run_loop.QuitClosure()); |
| 244 run_loop.Run(); | 291 run_loop.Run(); |
| 292 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); | |
| 293 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); | |
| 294 } | |
| 295 | |
| 296 void StopStreamDeviceAndWait(const std::string& device_id) { | |
| 297 EXPECT_TRUE(FindRequestedDeviceInfo(device_id, MEDIA_GENERATE_STREAM, | |
| 298 NULL)); | |
| 299 host_->OnStopStreamDevice(kRenderId, device_id); | |
| 300 base::RunLoop().RunUntilIdle(); | |
| 301 EXPECT_FALSE(FindRequestedDeviceInfo(device_id, MEDIA_GENERATE_STREAM, | |
| 302 NULL)); | |
| 303 } | |
| 304 | |
| 305 void EnumerateDevicesAndWaitForResult(int render_view_id, | |
| 306 int page_request_id, | |
| 307 MediaStreamType type) { | |
| 308 base::RunLoop run_loop; | |
| 309 host_->OnEnumerateDevices(render_view_id, page_request_id, type, origin_, | |
| 310 run_loop.QuitClosure()); | |
| 311 run_loop.Run(); | |
| 312 ASSERT_FALSE(host_->enumerated_devices_.empty()); | |
| 313 EXPECT_FALSE(DoesContainRawIds(host_->enumerated_devices_)); | |
| 314 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->enumerated_devices_, origin_)); | |
| 315 } | |
| 316 | |
| 317 bool FindRequestedDeviceInfo(const std::string& device_id, | |
| 318 MediaStreamRequestType request_type, | |
| 319 StreamDeviceInfo* device_info) { | |
| 320 const StreamDeviceInfo* found_device = | |
| 321 media_stream_manager_->FindRequestedDeviceInfoForTest(device_id, | |
| 322 kProcessId, | |
| 323 kRenderId, | |
| 324 request_type); | |
| 325 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.
| |
| 326 *device_info = *found_device; | |
| 327 } | |
| 328 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
| |
| 329 } | |
| 330 | |
| 331 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | |
| 332 for (size_t i = 0; i < devices.size(); ++i) { | |
| 333 media::AudioDeviceNames::const_iterator audio_it = | |
| 334 physical_audio_devices_.begin(); | |
| 335 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | |
| 336 if (audio_it->unique_id == devices[i].device.id) | |
| 337 return true; | |
| 338 } | |
| 339 media::VideoCaptureDevice::Names::const_iterator video_it = | |
| 340 physical_video_devices_.begin(); | |
| 341 for (; video_it != physical_video_devices_.end(); ++video_it) { | |
| 342 if (video_it->id() == devices[i].device.id) | |
| 343 return true; | |
| 344 } | |
| 345 } | |
| 346 return false; | |
| 347 } | |
| 348 | |
| 349 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | |
| 350 const GURL& origin) { | |
| 351 for (size_t i = 0; i < devices.size(); ++i) { | |
| 352 bool found_match = false; | |
| 353 media::AudioDeviceNames::const_iterator audio_it = | |
| 354 physical_audio_devices_.begin(); | |
| 355 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | |
| 356 if (content::DoesMediaDeviceIDMatchHMAC( | |
| 357 origin, | |
|
tommi (sloooow) - chröme
2013/11/26 14:44:21
indent?
perkj_chrome
2013/11/27 13:41:34
Done.
| |
| 358 devices[i].device.id, | |
| 359 audio_it->unique_id)) { | |
| 360 EXPECT_FALSE(found_match); | |
| 361 found_match = true; | |
| 362 } | |
| 363 } | |
| 364 media::VideoCaptureDevice::Names::const_iterator video_it = | |
| 365 physical_video_devices_.begin(); | |
| 366 for (; video_it != physical_video_devices_.end(); ++video_it) { | |
| 367 if (content::DoesMediaDeviceIDMatchHMAC( | |
| 368 origin, | |
|
tommi (sloooow) - chröme
2013/11/26 14:44:21
indent
perkj_chrome
2013/11/27 13:41:34
Done.
| |
| 369 devices[i].device.id, | |
| 370 video_it->id())) { | |
| 371 EXPECT_FALSE(found_match); | |
| 372 found_match = true; | |
| 373 } | |
| 374 } | |
| 375 if (!found_match) | |
| 376 return false; | |
| 377 } | |
| 378 return true; | |
| 245 } | 379 } |
| 246 | 380 |
| 247 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 381 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
| 248 scoped_ptr<media::AudioManager> audio_manager_; | 382 scoped_ptr<media::AudioManager> audio_manager_; |
| 249 scoped_ptr<MediaStreamManager> media_stream_manager_; | 383 scoped_ptr<MediaStreamManager> media_stream_manager_; |
| 250 ContentBrowserClient* old_browser_client_; | 384 ContentBrowserClient* old_browser_client_; |
| 251 scoped_ptr<ContentClient> content_client_; | 385 scoped_ptr<ContentClient> content_client_; |
| 252 content::TestBrowserThreadBundle thread_bundle_; | 386 content::TestBrowserThreadBundle thread_bundle_; |
| 387 media::AudioDeviceNames physical_audio_devices_; | |
| 388 media::VideoCaptureDevice::Names physical_video_devices_; | |
| 389 GURL origin_; | |
| 253 }; | 390 }; |
| 254 | 391 |
| 255 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { | 392 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { |
| 256 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 393 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 257 | 394 |
| 258 SetupFakeUI(true); | 395 SetupFakeUI(true); |
| 259 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | |
| 260 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 396 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 261 | 397 |
| 262 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 398 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 263 EXPECT_EQ(host_->video_devices_.size(), 1u); | 399 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 264 } | 400 } |
| 265 | 401 |
| 402 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioOnly) { | |
| 403 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE); | |
| 404 | |
| 405 SetupFakeUI(true); | |
| 406 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | |
| 407 | |
| 408 EXPECT_EQ(host_->audio_devices_.size(), 1u); | |
| 409 EXPECT_EQ(host_->video_devices_.size(), 0u); | |
| 410 } | |
| 411 | |
| 266 // This test generates two streams with video only using the same render view | 412 // This test generates two streams with video only using the same render view |
| 267 // id. The same capture device with the same device and session id is expected | 413 // id. The same capture device with the same device and session id is expected |
| 268 // to be used. | 414 // to be used. |
| 269 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { | 415 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { |
| 270 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 416 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 271 | 417 |
| 272 // Generate first stream. | 418 // Generate first stream. |
| 273 SetupFakeUI(true); | 419 SetupFakeUI(true); |
| 274 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | |
| 275 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 420 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 276 | 421 |
| 277 // Check the latest generated stream. | 422 // Check the latest generated stream. |
| 278 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 423 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 279 EXPECT_EQ(host_->video_devices_.size(), 1u); | 424 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 280 const std::string label1 = host_->label_; | 425 const std::string label1 = host_->label_; |
| 281 const std::string device_id1 = host_->video_devices_.front().device.id; | 426 const std::string device_id1 = host_->video_devices_.front().device.id; |
| 282 const int session_id1 = host_->video_devices_.front().session_id; | 427 const int session_id1 = host_->video_devices_.front().session_id; |
| 283 | 428 |
| 284 // Generate second stream. | 429 // Generate second stream. |
| 285 SetupFakeUI(true); | 430 SetupFakeUI(true); |
| 286 EXPECT_CALL(*host_.get(), | |
| 287 OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1)); | |
| 288 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + 1, options); | 431 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + 1, options); |
| 289 | 432 |
| 290 // Check the latest generated stream. | 433 // Check the latest generated stream. |
| 291 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 434 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 292 EXPECT_EQ(host_->video_devices_.size(), 1u); | 435 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 293 const std::string label2 = host_->label_; | 436 const std::string label2 = host_->label_; |
| 294 const std::string device_id2 = host_->video_devices_.front().device.id; | 437 const std::string device_id2 = host_->video_devices_.front().device.id; |
| 295 int session_id2 = host_->video_devices_.front().session_id; | 438 int session_id2 = host_->video_devices_.front().session_id; |
| 296 EXPECT_EQ(device_id1, device_id2); | 439 EXPECT_EQ(device_id1, device_id2); |
| 297 EXPECT_EQ(session_id1, session_id2); | 440 EXPECT_EQ(session_id1, session_id2); |
| 298 EXPECT_NE(label1, label2); | 441 EXPECT_NE(label1, label2); |
| 299 } | 442 } |
| 300 | 443 |
| 301 TEST_F(MediaStreamDispatcherHostTest, | 444 TEST_F(MediaStreamDispatcherHostTest, |
| 302 GenerateStreamAndOpenDeviceFromSameRenderId) { | 445 GenerateStreamAndOpenDeviceFromSameRenderId) { |
| 303 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 446 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 304 | 447 |
| 305 // Generate first stream. | 448 // Generate first stream. |
| 306 SetupFakeUI(true); | 449 SetupFakeUI(true); |
| 307 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | |
| 308 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 450 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 309 | 451 |
| 310 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 452 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 311 EXPECT_EQ(host_->video_devices_.size(), 1u); | 453 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 312 const std::string label1 = host_->label_; | 454 const std::string label1 = host_->label_; |
| 313 const std::string device_id1 = host_->video_devices_.front().device.id; | 455 const std::string device_id1 = host_->video_devices_.front().device.id; |
| 314 const int session_id1 = host_->video_devices_.front().session_id; | 456 const int session_id1 = host_->video_devices_.front().session_id; |
| 315 | 457 |
| 316 // Generate second stream. | 458 // Generate second stream. |
| 317 OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, device_id1); | 459 OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, device_id1); |
| 318 | 460 |
| 319 const std::string device_id2 = host_->opened_device_.device.id; | 461 const std::string device_id2 = host_->opened_device_.device.id; |
| 320 const int session_id2 = host_->opened_device_.session_id; | 462 const int session_id2 = host_->opened_device_.session_id; |
| 321 const std::string label2 = host_->label_; | 463 const std::string label2 = host_->label_; |
| 322 | 464 |
| 323 EXPECT_EQ(device_id1, device_id2); | 465 EXPECT_EQ(device_id1, device_id2); |
| 324 EXPECT_NE(session_id1, session_id2); | 466 EXPECT_NE(session_id1, session_id2); |
| 325 EXPECT_NE(label1, label2); | 467 EXPECT_NE(label1, label2); |
| 326 } | 468 } |
| 327 | 469 |
| 328 | 470 |
| 329 // This test generates two streams with video only using two separate render | 471 // This test generates two streams with video only using two separate render |
| 330 // view ids. The same device id but different session ids are expected. | 472 // view ids. The same device id but different session ids are expected. |
| 331 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) { | 473 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) { |
| 332 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 474 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 333 | 475 |
| 334 // Generate first stream. | 476 // Generate first stream. |
| 335 SetupFakeUI(true); | 477 SetupFakeUI(true); |
| 336 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | |
| 337 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 478 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 338 | 479 |
| 339 // Check the latest generated stream. | 480 // Check the latest generated stream. |
| 340 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 481 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 341 EXPECT_EQ(host_->video_devices_.size(), 1u); | 482 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 342 const std::string label1 = host_->label_; | 483 const std::string label1 = host_->label_; |
| 343 const std::string device_id1 = host_->video_devices_.front().device.id; | 484 const std::string device_id1 = host_->video_devices_.front().device.id; |
| 344 const int session_id1 = host_->video_devices_.front().session_id; | 485 const int session_id1 = host_->video_devices_.front().session_id; |
| 345 | 486 |
| 346 // Generate second stream from another render view. | 487 // Generate second stream from another render view. |
| 347 SetupFakeUI(true); | 488 SetupFakeUI(true); |
| 348 EXPECT_CALL(*host_.get(), | |
| 349 OnStreamGenerated(kRenderId+1, kPageRequestId + 1, 0, 1)); | |
| 350 GenerateStreamAndWaitForResult(kRenderId+1, kPageRequestId + 1, options); | 489 GenerateStreamAndWaitForResult(kRenderId+1, kPageRequestId + 1, options); |
| 351 | 490 |
| 352 // Check the latest generated stream. | 491 // Check the latest generated stream. |
| 353 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 492 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 354 EXPECT_EQ(host_->video_devices_.size(), 1u); | 493 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 355 const std::string label2 = host_->label_; | 494 const std::string label2 = host_->label_; |
| 356 const std::string device_id2 = host_->video_devices_.front().device.id; | 495 const std::string device_id2 = host_->video_devices_.front().device.id; |
| 357 const int session_id2 = host_->video_devices_.front().session_id; | 496 const int session_id2 = host_->video_devices_.front().session_id; |
| 358 EXPECT_EQ(device_id1, device_id2); | 497 EXPECT_EQ(device_id1, device_id2); |
| 359 EXPECT_NE(session_id1, session_id2); | 498 EXPECT_NE(session_id1, session_id2); |
| 360 EXPECT_NE(label1, label2); | 499 EXPECT_NE(label1, label2); |
| 361 } | 500 } |
| 362 | 501 |
| 363 // This test request two streams with video only without waiting for the first | 502 // This test request two streams with video only without waiting for the first |
| 364 // stream to be generated before requesting the second. | 503 // stream to be generated before requesting the second. |
| 365 // The same device id and session ids are expected. | 504 // The same device id and session ids are expected. |
| 366 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithoutWaiting) { | 505 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithoutWaiting) { |
| 367 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 506 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 368 | 507 |
| 369 // Generate first stream. | 508 // Generate first stream. |
| 370 SetupFakeUI(true); | 509 SetupFakeUI(true); |
| 371 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 510 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
| 372 | 511 |
| 373 // Generate second stream. | 512 // Generate second stream. |
| 374 EXPECT_CALL(*host_.get(), | 513 EXPECT_CALL(*host_.get(), |
| 375 OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1)); | 514 OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1)); |
| 376 | 515 |
| 377 base::RunLoop run_loop1; | 516 base::RunLoop run_loop1; |
| 378 base::RunLoop run_loop2; | 517 base::RunLoop run_loop2; |
| 379 host_->OnGenerateStream(kRenderId, kPageRequestId, options, | 518 host_->OnGenerateStream(kRenderId, kPageRequestId, options, origin_, |
| 380 run_loop1.QuitClosure()); | 519 run_loop1.QuitClosure()); |
| 381 host_->OnGenerateStream(kRenderId, kPageRequestId + 1, options, | 520 host_->OnGenerateStream(kRenderId, kPageRequestId + 1, options, origin_, |
| 382 run_loop2.QuitClosure()); | 521 run_loop2.QuitClosure()); |
| 383 | 522 |
| 384 run_loop1.Run(); | 523 run_loop1.Run(); |
| 385 run_loop2.Run(); | 524 run_loop2.Run(); |
| 386 } | 525 } |
| 387 | 526 |
| 527 // Test that we can generate streams where a sourceId is specified in the | |
| 528 // request. | |
| 529 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { | |
| 530 ASSERT_GE(physical_audio_devices_.size(), 1u); | |
| 531 ASSERT_GE(physical_video_devices_.size(), 1u); | |
| 532 | |
| 533 media::AudioDeviceNames::const_iterator audio_it = | |
| 534 physical_audio_devices_.begin(); | |
| 535 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | |
| 536 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | |
| 537 MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 538 options.audio_device_id = content::GetHMACForMediaDeviceID( | |
| 539 origin_, | |
| 540 audio_it->unique_id); | |
| 541 ASSERT_FALSE(options.audio_device_id.empty()); | |
| 542 | |
| 543 // Generate first stream. | |
| 544 SetupFakeUI(true); | |
| 545 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | |
| 546 EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id); | |
| 547 } | |
| 548 | |
| 549 media::VideoCaptureDevice::Names::const_iterator video_it = | |
| 550 physical_video_devices_.begin(); | |
| 551 for (; video_it != physical_video_devices_.end(); ++video_it) { | |
| 552 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | |
| 553 MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 554 options.video_device_id = content::GetHMACForMediaDeviceID( | |
| 555 origin_, | |
|
tommi (sloooow) - chröme
2013/11/26 14:44:21
strange indent
perkj_chrome
2013/11/27 13:41:34
Done.
| |
| 556 video_it->id()); | |
| 557 ASSERT_FALSE(options.video_device_id.empty()); | |
| 558 | |
| 559 // Generate first stream. | |
| 560 SetupFakeUI(true); | |
| 561 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | |
| 562 EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id); | |
| 563 } | |
| 564 } | |
| 565 | |
| 566 // Test that generating a stream with an invalid video source id fail. | |
| 567 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) { | |
| 568 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | |
| 569 MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 570 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.
| |
| 571 options.video_device_id = invalid_source_id; | |
| 572 | |
| 573 GenerateStreamAndWaitForFailure(kRenderId, kRenderId, options); | |
| 574 } | |
| 575 | |
| 576 // Test that generating a stream with an invalid audio source id fail. | |
| 577 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) { | |
| 578 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | |
| 579 MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 580 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.
| |
| 581 options.audio_device_id = invalid_source_id; | |
| 582 | |
| 583 GenerateStreamAndWaitForFailure(kRenderId, kRenderId, options); | |
| 584 } | |
| 585 | |
| 586 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { | |
| 587 size_t number_of_fake_devices = physical_video_devices_.size(); | |
| 588 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(0); | |
| 589 media::FakeVideoCaptureDevice::GetDeviceNames(&physical_video_devices_); | |
| 590 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 591 | |
| 592 SetupFakeUI(true); | |
| 593 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | |
| 594 EXPECT_TRUE(host_->video_devices_.empty()); | |
| 595 | |
| 596 // Reset the number of fake devices for next test. | |
| 597 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_fake_devices); | |
| 598 } | |
| 599 | |
| 388 TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) { | 600 TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) { |
| 389 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 601 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 390 | 602 |
| 391 SetupFakeUI(true); | 603 SetupFakeUI(true); |
| 392 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | |
| 393 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 604 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 394 | 605 |
| 395 const std::string device_id = host_->video_devices_.front().device.id; | 606 const std::string device_id = host_->video_devices_.front().device.id; |
| 396 const int session_id = host_->video_devices_.front().session_id; | 607 const int session_id = host_->video_devices_.front().session_id; |
| 397 StreamDeviceInfo video_device_info; | 608 StreamDeviceInfo video_device_info; |
| 398 EXPECT_TRUE(host_->FindExistingRequestedDeviceInfo(device_id, | 609 EXPECT_TRUE(FindRequestedDeviceInfo(device_id, MEDIA_GENERATE_STREAM, |
| 399 MEDIA_GENERATE_STREAM, | 610 &video_device_info)); |
| 400 &video_device_info)); | |
| 401 EXPECT_EQ(video_device_info.device.id, device_id); | 611 EXPECT_EQ(video_device_info.device.id, device_id); |
| 402 EXPECT_EQ(video_device_info.session_id, session_id); | 612 EXPECT_EQ(video_device_info.session_id, session_id); |
| 403 | 613 |
| 404 OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, device_id); | 614 OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, device_id); |
| 405 | 615 |
| 616 StopStreamDeviceAndWait(device_id); | |
| 617 | |
| 618 EXPECT_TRUE(FindRequestedDeviceInfo(device_id, MEDIA_OPEN_DEVICE, NULL)); | |
| 619 } | |
| 620 | |
| 621 TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStreamAndRestart) { | |
| 622 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | |
| 623 MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 624 | |
| 625 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
| |
| 626 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | |
| 627 | |
| 628 const std::string device_id = host_->video_devices_.front().device.id; | |
| 629 const int session_id = host_->video_devices_.front().session_id; | |
| 630 StreamDeviceInfo video_device_info; | |
| 631 EXPECT_TRUE(FindRequestedDeviceInfo(device_id, MEDIA_GENERATE_STREAM, | |
| 632 &video_device_info)); | |
| 633 EXPECT_EQ(video_device_info.device.id, device_id); | |
| 634 EXPECT_EQ(video_device_info.session_id, session_id); | |
| 406 host_->OnStopStreamDevice(kRenderId, device_id); | 635 host_->OnStopStreamDevice(kRenderId, device_id); |
| 407 | 636 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 408 EXPECT_FALSE(host_->FindExistingRequestedDeviceInfo(device_id, | |
| 409 MEDIA_GENERATE_STREAM, | |
| 410 &video_device_info)); | |
| 411 EXPECT_TRUE(host_->FindExistingRequestedDeviceInfo(device_id, | |
| 412 MEDIA_OPEN_DEVICE, | |
| 413 &video_device_info)); | |
| 414 } | 637 } |
| 415 | 638 |
| 416 TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) { | 639 TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) { |
| 417 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 640 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 418 | 641 |
| 419 base::RunLoop run_loop; | 642 base::RunLoop run_loop; |
| 420 | 643 |
| 421 // Create multiple GenerateStream requests. | 644 // Create multiple GenerateStream requests. |
| 422 size_t streams = 5; | 645 size_t streams = 5; |
| 423 for (size_t i = 1; i <= streams; ++i) { | 646 for (size_t i = 1; i <= streams; ++i) { |
| 424 host_->OnGenerateStream(kRenderId, kPageRequestId + i, options, | 647 host_->OnGenerateStream(kRenderId, kPageRequestId + i, options, origin_, |
| 425 run_loop.QuitClosure()); | 648 run_loop.QuitClosure()); |
| 426 } | 649 } |
| 427 | 650 |
| 428 // Calling OnChannelClosing() to cancel all the pending requests. | 651 // Calling OnChannelClosing() to cancel all the pending requests. |
| 429 host_->OnChannelClosing(); | 652 host_->OnChannelClosing(); |
| 430 run_loop.RunUntilIdle(); | 653 run_loop.RunUntilIdle(); |
| 431 } | 654 } |
| 432 | 655 |
| 433 TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreamsOnChannelClosing) { | 656 TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreamsOnChannelClosing) { |
| 434 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 657 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 435 | 658 |
| 436 // Create first group of streams. | 659 // Create first group of streams. |
| 437 size_t generated_streams = 3; | 660 size_t generated_streams = 3; |
| 438 for (size_t i = 0; i < generated_streams; ++i) { | 661 for (size_t i = 0; i < generated_streams; ++i) { |
| 439 SetupFakeUI(true); | 662 SetupFakeUI(true); |
| 440 EXPECT_CALL(*host_.get(), | |
| 441 OnStreamGenerated(kRenderId, kPageRequestId + i, 0, 1)); | |
| 442 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + i, options); | 663 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + i, options); |
| 443 } | 664 } |
| 444 | 665 |
| 445 // Calling OnChannelClosing() to cancel all the pending/generated streams. | 666 // Calling OnChannelClosing() to cancel all the pending/generated streams. |
| 446 host_->OnChannelClosing(); | 667 host_->OnChannelClosing(); |
| 447 base::RunLoop().RunUntilIdle(); | 668 base::RunLoop().RunUntilIdle(); |
| 448 } | 669 } |
| 449 | 670 |
| 450 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { | 671 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { |
| 451 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 672 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 452 | 673 |
| 453 base::Closure close_callback; | 674 base::Closure close_callback; |
| 454 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); | 675 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); |
| 455 EXPECT_CALL(*stream_ui, OnStarted(_)) | 676 EXPECT_CALL(*stream_ui, OnStarted(_)) |
| 456 .WillOnce(SaveArg<0>(&close_callback)); | 677 .WillOnce(SaveArg<0>(&close_callback)); |
| 457 media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>()); | 678 media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>()); |
| 458 | 679 |
| 459 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | |
| 460 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)); | |
| 461 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 680 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 462 | 681 |
| 463 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 682 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 464 EXPECT_EQ(host_->video_devices_.size(), 1u); | 683 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 465 | 684 |
| 466 ASSERT_FALSE(close_callback.is_null()); | 685 ASSERT_FALSE(close_callback.is_null()); |
| 686 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)); | |
| 467 close_callback.Run(); | 687 close_callback.Run(); |
| 468 base::RunLoop().RunUntilIdle(); | 688 base::RunLoop().RunUntilIdle(); |
| 469 } | 689 } |
| 470 | 690 |
| 691 // Test that the dispatcher is notified if a video device that is in use is | |
| 692 // being unplugged. | |
| 693 TEST_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) { | |
| 694 size_t number_of_fake_devices = physical_video_devices_.size(); | |
| 695 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 696 SetupFakeUI(true); | |
| 697 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | |
| 698 EXPECT_EQ(host_->audio_devices_.size(), 1u); | |
| 699 EXPECT_EQ(host_->video_devices_.size(), 1u); | |
| 700 | |
| 701 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(0); | |
| 702 | |
| 703 base::RunLoop run_loop; | |
| 704 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | |
| 705 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | |
| 706 media_stream_manager_->OnDevicesChanged( | |
| 707 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | |
| 708 | |
| 709 run_loop.Run(); | |
| 710 | |
| 711 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_fake_devices); | |
| 712 } | |
| 713 | |
| 714 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { | |
| 715 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | |
| 716 MEDIA_DEVICE_AUDIO_CAPTURE); | |
| 717 } | |
| 718 | |
| 719 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { | |
| 720 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | |
| 721 MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 722 } | |
| 723 | |
|
tommi (sloooow) - chröme
2013/11/26 14:44:21
one empty line
perkj_chrome
2013/11/27 13:41:34
Done.
| |
| 724 | |
| 471 }; // namespace content | 725 }; // namespace content |
| OLD | NEW |