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