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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 MOCK_METHOD4(OnStreamGenerated, | 63 MOCK_METHOD4(OnStreamGenerated, |
64 void(int routing_id, int request_id, int audio_array_size, | 64 void(int routing_id, int request_id, int audio_array_size, |
65 int video_array_size)); | 65 int video_array_size)); |
66 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, | 66 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, |
67 int request_id, | 67 int request_id, |
68 MediaStreamRequestResult result)); | 68 MediaStreamRequestResult result)); |
69 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); | 69 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); |
70 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); | 70 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); |
71 | 71 |
72 // Accessor to private functions. | 72 // Accessor to private functions. |
73 void OnGenerateStream(int render_view_id, | 73 void OnGenerateStream(int render_frame_id, |
74 int page_request_id, | 74 int page_request_id, |
75 const StreamOptions& components, | 75 const StreamOptions& components, |
76 const GURL& security_origin, | 76 const GURL& security_origin, |
77 const base::Closure& quit_closure) { | 77 const base::Closure& quit_closure) { |
78 quit_closures_.push(quit_closure); | 78 quit_closures_.push(quit_closure); |
79 MediaStreamDispatcherHost::OnGenerateStream( | 79 MediaStreamDispatcherHost::OnGenerateStream( |
80 render_view_id, page_request_id, components, security_origin, false); | 80 render_frame_id, page_request_id, components, security_origin, false); |
81 } | 81 } |
82 | 82 |
83 void OnStopStreamDevice(int render_view_id, | 83 void OnStopStreamDevice(int render_frame_id, |
84 const std::string& device_id) { | 84 const std::string& device_id) { |
85 MediaStreamDispatcherHost::OnStopStreamDevice(render_view_id, device_id); | 85 MediaStreamDispatcherHost::OnStopStreamDevice(render_frame_id, device_id); |
86 } | 86 } |
87 | 87 |
88 void OnOpenDevice(int render_view_id, | 88 void OnOpenDevice(int render_frame_id, |
89 int page_request_id, | 89 int page_request_id, |
90 const std::string& device_id, | 90 const std::string& device_id, |
91 MediaStreamType type, | 91 MediaStreamType type, |
92 const GURL& security_origin, | 92 const GURL& security_origin, |
93 const base::Closure& quit_closure) { | 93 const base::Closure& quit_closure) { |
94 quit_closures_.push(quit_closure); | 94 quit_closures_.push(quit_closure); |
95 MediaStreamDispatcherHost::OnOpenDevice( | 95 MediaStreamDispatcherHost::OnOpenDevice( |
96 render_view_id, page_request_id, device_id, type, security_origin); | 96 render_frame_id, page_request_id, device_id, type, security_origin); |
97 } | 97 } |
98 | 98 |
99 void OnEnumerateDevices(int render_view_id, | 99 void OnEnumerateDevices(int render_frame_id, |
100 int page_request_id, | 100 int page_request_id, |
101 MediaStreamType type, | 101 MediaStreamType type, |
102 const GURL& security_origin, | 102 const GURL& security_origin, |
103 bool hide_labels_if_no_access, | 103 bool hide_labels_if_no_access, |
104 const base::Closure& quit_closure) { | 104 const base::Closure& quit_closure) { |
105 quit_closures_.push(quit_closure); | 105 quit_closures_.push(quit_closure); |
106 MediaStreamDispatcherHost::OnEnumerateDevices( | 106 MediaStreamDispatcherHost::OnEnumerateDevices( |
107 render_view_id, page_request_id, type, security_origin, | 107 render_frame_id, page_request_id, type, security_origin, |
108 hide_labels_if_no_access); | 108 hide_labels_if_no_access); |
109 } | 109 } |
110 | 110 |
111 std::string label_; | 111 std::string label_; |
112 StreamDeviceInfoArray audio_devices_; | 112 StreamDeviceInfoArray audio_devices_; |
113 StreamDeviceInfoArray video_devices_; | 113 StreamDeviceInfoArray video_devices_; |
114 StreamDeviceInfo opened_device_; | 114 StreamDeviceInfo opened_device_; |
115 StreamDeviceInfoArray enumerated_devices_; | 115 StreamDeviceInfoArray enumerated_devices_; |
116 | 116 |
117 private: | 117 private: |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 protected: | 272 protected: |
273 virtual void SetupFakeUI(bool expect_started) { | 273 virtual void SetupFakeUI(bool expect_started) { |
274 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); | 274 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); |
275 if (expect_started) { | 275 if (expect_started) { |
276 EXPECT_CALL(*stream_ui, OnStarted(_, _)); | 276 EXPECT_CALL(*stream_ui, OnStarted(_, _)); |
277 } | 277 } |
278 media_stream_manager_->UseFakeUI( | 278 media_stream_manager_->UseFakeUI( |
279 stream_ui.PassAs<FakeMediaStreamUIProxy>()); | 279 stream_ui.PassAs<FakeMediaStreamUIProxy>()); |
280 } | 280 } |
281 | 281 |
282 void GenerateStreamAndWaitForResult(int render_view_id, | 282 void GenerateStreamAndWaitForResult(int render_frame_id, |
283 int page_request_id, | 283 int page_request_id, |
284 const StreamOptions& options) { | 284 const StreamOptions& options) { |
285 base::RunLoop run_loop; | 285 base::RunLoop run_loop; |
286 int expected_audio_array_size = | 286 int expected_audio_array_size = |
287 (options.audio_requested && | 287 (options.audio_requested && |
288 physical_audio_devices_.size() > 0) ? 1 : 0; | 288 physical_audio_devices_.size() > 0) ? 1 : 0; |
289 int expected_video_array_size = | 289 int expected_video_array_size = |
290 (options.video_requested && | 290 (options.video_requested && |
291 physical_video_devices_.size() > 0) ? 1 : 0; | 291 physical_video_devices_.size() > 0) ? 1 : 0; |
292 EXPECT_CALL(*host_.get(), OnStreamGenerated(render_view_id, page_request_id, | 292 EXPECT_CALL(*host_.get(), OnStreamGenerated(render_frame_id, |
| 293 page_request_id, |
293 expected_audio_array_size, | 294 expected_audio_array_size, |
294 expected_video_array_size)); | 295 expected_video_array_size)); |
295 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, | 296 host_->OnGenerateStream(render_frame_id, page_request_id, options, origin_, |
296 run_loop.QuitClosure()); | 297 run_loop.QuitClosure()); |
297 run_loop.Run(); | 298 run_loop.Run(); |
298 EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_)); | 299 EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_)); |
299 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); | 300 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); |
300 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_)); | 301 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_)); |
301 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); | 302 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); |
302 } | 303 } |
303 | 304 |
304 void GenerateStreamAndWaitForFailure( | 305 void GenerateStreamAndWaitForFailure( |
305 int render_view_id, | 306 int render_frame_id, |
306 int page_request_id, | 307 int page_request_id, |
307 const StreamOptions& options, | 308 const StreamOptions& options, |
308 MediaStreamRequestResult expected_result) { | 309 MediaStreamRequestResult expected_result) { |
309 base::RunLoop run_loop; | 310 base::RunLoop run_loop; |
310 EXPECT_CALL(*host_.get(), | 311 EXPECT_CALL(*host_.get(), |
311 OnStreamGenerationFailed(render_view_id, | 312 OnStreamGenerationFailed(render_frame_id, |
312 page_request_id, | 313 page_request_id, |
313 expected_result)); | 314 expected_result)); |
314 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, | 315 host_->OnGenerateStream(render_frame_id, page_request_id, options, |
315 run_loop.QuitClosure()); | 316 origin_, run_loop.QuitClosure()); |
316 run_loop.Run(); | 317 run_loop.Run(); |
317 } | 318 } |
318 | 319 |
319 void OpenVideoDeviceAndWaitForResult(int render_view_id, | 320 void OpenVideoDeviceAndWaitForResult(int render_frame_id, |
320 int page_request_id, | 321 int page_request_id, |
321 const std::string& device_id) { | 322 const std::string& device_id) { |
322 base::RunLoop run_loop; | 323 base::RunLoop run_loop; |
323 host_->OnOpenDevice(render_view_id, page_request_id, device_id, | 324 host_->OnOpenDevice(render_frame_id, page_request_id, device_id, |
324 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, | 325 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, |
325 run_loop.QuitClosure()); | 326 run_loop.QuitClosure()); |
326 run_loop.Run(); | 327 run_loop.Run(); |
327 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); | 328 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); |
328 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); | 329 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); |
329 } | 330 } |
330 | 331 |
331 void EnumerateDevicesAndWaitForResult(int render_view_id, | 332 void EnumerateDevicesAndWaitForResult(int render_frame_id, |
332 int page_request_id, | 333 int page_request_id, |
333 MediaStreamType type, | 334 MediaStreamType type, |
334 bool hide_labels_if_no_access) { | 335 bool hide_labels_if_no_access) { |
335 base::RunLoop run_loop; | 336 base::RunLoop run_loop; |
336 host_->OnEnumerateDevices(render_view_id, page_request_id, type, origin_, | 337 host_->OnEnumerateDevices(render_frame_id, page_request_id, type, origin_, |
337 hide_labels_if_no_access, run_loop.QuitClosure()); | 338 hide_labels_if_no_access, run_loop.QuitClosure()); |
338 run_loop.Run(); | 339 run_loop.Run(); |
339 ASSERT_FALSE(host_->enumerated_devices_.empty()); | 340 ASSERT_FALSE(host_->enumerated_devices_.empty()); |
340 EXPECT_FALSE(DoesContainRawIds(host_->enumerated_devices_)); | 341 EXPECT_FALSE(DoesContainRawIds(host_->enumerated_devices_)); |
341 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->enumerated_devices_, origin_)); | 342 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->enumerated_devices_, origin_)); |
342 } | 343 } |
343 | 344 |
344 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | 345 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { |
345 for (size_t i = 0; i < devices.size(); ++i) { | 346 for (size_t i = 0; i < devices.size(); ++i) { |
346 media::AudioDeviceNames::const_iterator audio_it = | 347 media::AudioDeviceNames::const_iterator audio_it = |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioAndVideo) { | 464 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioAndVideo) { |
464 StreamOptions options(true, true); | 465 StreamOptions options(true, true); |
465 | 466 |
466 SetupFakeUI(true); | 467 SetupFakeUI(true); |
467 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 468 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
468 | 469 |
469 EXPECT_EQ(host_->audio_devices_.size(), 1u); | 470 EXPECT_EQ(host_->audio_devices_.size(), 1u); |
470 EXPECT_EQ(host_->video_devices_.size(), 1u); | 471 EXPECT_EQ(host_->video_devices_.size(), 1u); |
471 } | 472 } |
472 | 473 |
473 // This test generates two streams with video only using the same render view | 474 // This test generates two streams with video only using the same render frame |
474 // id. The same capture device with the same device and session id is expected | 475 // id. The same capture device with the same device and session id is expected |
475 // to be used. | 476 // to be used. |
476 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { | 477 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { |
477 StreamOptions options(false, true); | 478 StreamOptions options(false, true); |
478 | 479 |
479 // Generate first stream. | 480 // Generate first stream. |
480 SetupFakeUI(true); | 481 SetupFakeUI(true); |
481 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 482 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
482 | 483 |
483 // Check the latest generated stream. | 484 // Check the latest generated stream. |
484 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 485 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 const int session_id2 = host_->opened_device_.session_id; | 524 const int session_id2 = host_->opened_device_.session_id; |
524 const std::string label2 = host_->label_; | 525 const std::string label2 = host_->label_; |
525 | 526 |
526 EXPECT_EQ(device_id1, device_id2); | 527 EXPECT_EQ(device_id1, device_id2); |
527 EXPECT_NE(session_id1, session_id2); | 528 EXPECT_NE(session_id1, session_id2); |
528 EXPECT_NE(label1, label2); | 529 EXPECT_NE(label1, label2); |
529 } | 530 } |
530 | 531 |
531 | 532 |
532 // This test generates two streams with video only using two separate render | 533 // This test generates two streams with video only using two separate render |
533 // view ids. The same device id but different session ids are expected. | 534 // frame ids. The same device id but different session ids are expected. |
534 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) { | 535 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) { |
535 StreamOptions options(false, true); | 536 StreamOptions options(false, true); |
536 | 537 |
537 // Generate first stream. | 538 // Generate first stream. |
538 SetupFakeUI(true); | 539 SetupFakeUI(true); |
539 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 540 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
540 | 541 |
541 // Check the latest generated stream. | 542 // Check the latest generated stream. |
542 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 543 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
543 EXPECT_EQ(host_->video_devices_.size(), 1u); | 544 EXPECT_EQ(host_->video_devices_.size(), 1u); |
544 const std::string label1 = host_->label_; | 545 const std::string label1 = host_->label_; |
545 const std::string device_id1 = host_->video_devices_.front().device.id; | 546 const std::string device_id1 = host_->video_devices_.front().device.id; |
546 const int session_id1 = host_->video_devices_.front().session_id; | 547 const int session_id1 = host_->video_devices_.front().session_id; |
547 | 548 |
548 // Generate second stream from another render view. | 549 // Generate second stream from another render frame. |
549 SetupFakeUI(true); | 550 SetupFakeUI(true); |
550 GenerateStreamAndWaitForResult(kRenderId+1, kPageRequestId + 1, options); | 551 GenerateStreamAndWaitForResult(kRenderId+1, kPageRequestId + 1, options); |
551 | 552 |
552 // Check the latest generated stream. | 553 // Check the latest generated stream. |
553 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 554 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
554 EXPECT_EQ(host_->video_devices_.size(), 1u); | 555 EXPECT_EQ(host_->video_devices_.size(), 1u); |
555 const std::string label2 = host_->label_; | 556 const std::string label2 = host_->label_; |
556 const std::string device_id2 = host_->video_devices_.front().device.id; | 557 const std::string device_id2 = host_->video_devices_.front().device.id; |
557 const int session_id2 = host_->video_devices_.front().session_id; | 558 const int session_id2 = host_->video_devices_.front().session_id; |
558 EXPECT_EQ(device_id1, device_id2); | 559 EXPECT_EQ(device_id1, device_id2); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 EnumerateVideoDevicesNoAccessNoHideLabels) { | 928 EnumerateVideoDevicesNoAccessNoHideLabels) { |
928 MockResourceContext* mock_resource_context = | 929 MockResourceContext* mock_resource_context = |
929 static_cast<MockResourceContext*>(browser_context_.GetResourceContext()); | 930 static_cast<MockResourceContext*>(browser_context_.GetResourceContext()); |
930 mock_resource_context->set_camera_access(false); | 931 mock_resource_context->set_camera_access(false); |
931 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 932 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
932 MEDIA_DEVICE_VIDEO_CAPTURE, false); | 933 MEDIA_DEVICE_VIDEO_CAPTURE, false); |
933 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); | 934 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); |
934 } | 935 } |
935 | 936 |
936 }; // namespace content | 937 }; // namespace content |
OLD | NEW |