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" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 const ResourceContext::SaltCallback salt_callback, | 47 const ResourceContext::SaltCallback salt_callback, |
48 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 48 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
49 MediaStreamManager* manager) | 49 MediaStreamManager* manager) |
50 : MediaStreamDispatcherHost(kProcessId, salt_callback, manager), | 50 : MediaStreamDispatcherHost(kProcessId, salt_callback, manager), |
51 message_loop_(message_loop) {} | 51 message_loop_(message_loop) {} |
52 | 52 |
53 // A list of mock methods. | 53 // A list of mock methods. |
54 MOCK_METHOD4(OnStreamGenerated, | 54 MOCK_METHOD4(OnStreamGenerated, |
55 void(int routing_id, int request_id, int audio_array_size, | 55 void(int routing_id, int request_id, int audio_array_size, |
56 int video_array_size)); | 56 int video_array_size)); |
57 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); | 57 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, |
| 58 int request_id, |
| 59 MediaStreamRequestResult result)); |
58 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); | 60 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); |
59 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); | 61 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); |
60 | 62 |
61 // Accessor to private functions. | 63 // Accessor to private functions. |
62 void OnGenerateStream(int render_view_id, | 64 void OnGenerateStream(int render_view_id, |
63 int page_request_id, | 65 int page_request_id, |
64 const StreamOptions& components, | 66 const StreamOptions& components, |
65 const GURL& security_origin, | 67 const GURL& security_origin, |
66 const base::Closure& quit_closure) { | 68 const base::Closure& quit_closure) { |
67 quit_closures_.push(quit_closure); | 69 quit_closures_.push(quit_closure); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Notify that the event have occurred. | 143 // Notify that the event have occurred. |
142 base::Closure quit_closure = quit_closures_.front(); | 144 base::Closure quit_closure = quit_closures_.front(); |
143 quit_closures_.pop(); | 145 quit_closures_.pop(); |
144 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); | 146 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); |
145 | 147 |
146 label_ = label; | 148 label_ = label; |
147 audio_devices_ = audio_device_list; | 149 audio_devices_ = audio_device_list; |
148 video_devices_ = video_device_list; | 150 video_devices_ = video_device_list; |
149 } | 151 } |
150 | 152 |
151 void OnStreamGenerationFailed(const IPC::Message& msg, int request_id) { | 153 void OnStreamGenerationFailed( |
152 OnStreamGenerationFailed(msg.routing_id(), request_id); | 154 const IPC::Message& msg, |
| 155 int request_id, |
| 156 content::MediaStreamRequestResult result) { |
| 157 OnStreamGenerationFailed(msg.routing_id(), request_id, result); |
153 if (!quit_closures_.empty()) { | 158 if (!quit_closures_.empty()) { |
154 base::Closure quit_closure = quit_closures_.front(); | 159 base::Closure quit_closure = quit_closures_.front(); |
155 quit_closures_.pop(); | 160 quit_closures_.pop(); |
156 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); | 161 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); |
157 } | 162 } |
158 | 163 |
159 label_= ""; | 164 label_= ""; |
160 } | 165 } |
161 | 166 |
162 void OnDeviceStopped(const IPC::Message& msg, | 167 void OnDeviceStopped(const IPC::Message& msg, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 expected_video_array_size)); | 269 expected_video_array_size)); |
265 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, | 270 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, |
266 run_loop.QuitClosure()); | 271 run_loop.QuitClosure()); |
267 run_loop.Run(); | 272 run_loop.Run(); |
268 EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_)); | 273 EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_)); |
269 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); | 274 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); |
270 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_)); | 275 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_)); |
271 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); | 276 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); |
272 } | 277 } |
273 | 278 |
274 void GenerateStreamAndWaitForFailure(int render_view_id, | 279 void GenerateStreamAndWaitForFailure( |
275 int page_request_id, | 280 int render_view_id, |
276 const StreamOptions& options) { | 281 int page_request_id, |
| 282 const StreamOptions& options, |
| 283 MediaStreamRequestResult expected_result) { |
277 base::RunLoop run_loop; | 284 base::RunLoop run_loop; |
278 EXPECT_CALL(*host_.get(), | 285 EXPECT_CALL(*host_.get(), |
279 OnStreamGenerationFailed(render_view_id, page_request_id)); | 286 OnStreamGenerationFailed(render_view_id, |
| 287 page_request_id, |
| 288 expected_result)); |
280 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, | 289 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_, |
281 run_loop.QuitClosure()); | 290 run_loop.QuitClosure()); |
282 run_loop.Run(); | 291 run_loop.Run(); |
283 } | 292 } |
284 | 293 |
285 void OpenVideoDeviceAndWaitForResult(int render_view_id, | 294 void OpenVideoDeviceAndWaitForResult(int render_view_id, |
286 int page_request_id, | 295 int page_request_id, |
287 const std::string& device_id) { | 296 const std::string& device_id) { |
288 base::RunLoop run_loop; | 297 base::RunLoop run_loop; |
289 host_->OnOpenDevice(render_view_id, page_request_id, device_id, | 298 host_->OnOpenDevice(render_view_id, page_request_id, device_id, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 SetupFakeUI(true); | 401 SetupFakeUI(true); |
393 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 402 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
394 | 403 |
395 EXPECT_EQ(host_->audio_devices_.size(), 1u); | 404 EXPECT_EQ(host_->audio_devices_.size(), 1u); |
396 EXPECT_EQ(host_->video_devices_.size(), 0u); | 405 EXPECT_EQ(host_->video_devices_.size(), 0u); |
397 } | 406 } |
398 | 407 |
399 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithNothing) { | 408 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithNothing) { |
400 StreamOptions options(false, false); | 409 StreamOptions options(false, false); |
401 | 410 |
402 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, options); | 411 GenerateStreamAndWaitForFailure( |
| 412 kRenderId, |
| 413 kPageRequestId, |
| 414 options, |
| 415 MEDIA_DEVICE_INVALID_STATE); |
403 } | 416 } |
404 | 417 |
405 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioAndVideo) { | 418 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioAndVideo) { |
406 StreamOptions options(true, true); | 419 StreamOptions options(true, true); |
407 | 420 |
408 SetupFakeUI(true); | 421 SetupFakeUI(true); |
409 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 422 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
410 | 423 |
411 EXPECT_EQ(host_->audio_devices_.size(), 1u); | 424 EXPECT_EQ(host_->audio_devices_.size(), 1u); |
412 EXPECT_EQ(host_->video_devices_.size(), 1u); | 425 EXPECT_EQ(host_->video_devices_.size(), 1u); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); | 617 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); |
605 } | 618 } |
606 } | 619 } |
607 | 620 |
608 // Test that generating a stream with an invalid mandatory video source id fail. | 621 // Test that generating a stream with an invalid mandatory video source id fail. |
609 TEST_F(MediaStreamDispatcherHostTest, | 622 TEST_F(MediaStreamDispatcherHostTest, |
610 GenerateStreamsWithInvalidMandatoryVideoSourceId) { | 623 GenerateStreamsWithInvalidMandatoryVideoSourceId) { |
611 StreamOptions options(true, true); | 624 StreamOptions options(true, true); |
612 AddSourceIdConstraint("invalid source id", &options.mandatory_video); | 625 AddSourceIdConstraint("invalid source id", &options.mandatory_video); |
613 | 626 |
614 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, options); | 627 GenerateStreamAndWaitForFailure( |
| 628 kRenderId, |
| 629 kPageRequestId, |
| 630 options, |
| 631 MEDIA_DEVICE_CAPTURE_FAILURE); |
615 } | 632 } |
616 | 633 |
617 // Test that generating a stream with an invalid mandatory audio source id fail. | 634 // Test that generating a stream with an invalid mandatory audio source id fail. |
618 TEST_F(MediaStreamDispatcherHostTest, | 635 TEST_F(MediaStreamDispatcherHostTest, |
619 GenerateStreamsWithInvalidMandatoryAudioSourceId) { | 636 GenerateStreamsWithInvalidMandatoryAudioSourceId) { |
620 StreamOptions options(true, true); | 637 StreamOptions options(true, true); |
621 AddSourceIdConstraint("invalid source id", &options.mandatory_audio); | 638 AddSourceIdConstraint("invalid source id", &options.mandatory_audio); |
622 | 639 |
623 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, options); | 640 GenerateStreamAndWaitForFailure( |
| 641 kRenderId, |
| 642 kPageRequestId, |
| 643 options, |
| 644 MEDIA_DEVICE_CAPTURE_FAILURE); |
624 } | 645 } |
625 | 646 |
626 // Test that generating a stream with an invalid optional video source id | 647 // Test that generating a stream with an invalid optional video source id |
627 // succeed. | 648 // succeed. |
628 TEST_F(MediaStreamDispatcherHostTest, | 649 TEST_F(MediaStreamDispatcherHostTest, |
629 GenerateStreamsWithInvalidOptionalVideoSourceId) { | 650 GenerateStreamsWithInvalidOptionalVideoSourceId) { |
630 StreamOptions options(true, true); | 651 StreamOptions options(true, true); |
631 AddSourceIdConstraint("invalid source id", &options.optional_video); | 652 AddSourceIdConstraint("invalid source id", &options.optional_video); |
632 | 653 |
633 SetupFakeUI(true); | 654 SetupFakeUI(true); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 845 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
825 MEDIA_DEVICE_AUDIO_CAPTURE); | 846 MEDIA_DEVICE_AUDIO_CAPTURE); |
826 } | 847 } |
827 | 848 |
828 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { | 849 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { |
829 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 850 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
830 MEDIA_DEVICE_VIDEO_CAPTURE); | 851 MEDIA_DEVICE_VIDEO_CAPTURE); |
831 } | 852 } |
832 | 853 |
833 }; // namespace content | 854 }; // namespace content |
OLD | NEW |