| 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 "content/renderer/media/mock_media_stream_dispatcher.h" | 5 #include "content/renderer/media/mock_media_stream_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "content/public/common/media_stream_request.h" | 8 #include "content/public/common/media_stream_request.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 audio_input_request_id_ = request_id; | 37 audio_input_request_id_ = request_id; |
| 38 | 38 |
| 39 stream_label_ = "local_stream" + base::IntToString(request_id); | 39 stream_label_ = "local_stream" + base::IntToString(request_id); |
| 40 audio_input_array_.clear(); | 40 audio_input_array_.clear(); |
| 41 video_array_.clear(); | 41 video_array_.clear(); |
| 42 | 42 |
| 43 if (components.audio_requested) { | 43 if (components.audio_requested) { |
| 44 AddAudioInputDeviceToArray(false); | 44 AddAudioInputDeviceToArray(false); |
| 45 } | 45 } |
| 46 if (components.video_requested) { | 46 if (components.video_requested) { |
| 47 AddVideoDeviceToArray(); | 47 AddVideoDeviceToArray(true); |
| 48 } | 48 } |
| 49 ++request_stream_counter_; | 49 ++request_stream_counter_; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void MockMediaStreamDispatcher::CancelGenerateStream( | 52 void MockMediaStreamDispatcher::CancelGenerateStream( |
| 53 int request_id, | 53 int request_id, |
| 54 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | 54 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { |
| 55 EXPECT_EQ(request_id, audio_input_request_id_); | 55 EXPECT_EQ(request_id, audio_input_request_id_); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void MockMediaStreamDispatcher::EnumerateDevices( | 58 void MockMediaStreamDispatcher::EnumerateDevices( |
| 59 int request_id, | 59 int request_id, |
| 60 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 60 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 61 MediaStreamType type, | 61 MediaStreamType type, |
| 62 const GURL& security_origin) { | 62 const GURL& security_origin) { |
| 63 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { | 63 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 64 audio_input_request_id_ = request_id; | 64 audio_input_request_id_ = request_id; |
| 65 audio_input_array_.clear(); | 65 audio_input_array_.clear(); |
| 66 AddAudioInputDeviceToArray(true); | 66 AddAudioInputDeviceToArray(true); |
| 67 AddAudioInputDeviceToArray(false); | 67 AddAudioInputDeviceToArray(false); |
| 68 } else if (type == MEDIA_DEVICE_AUDIO_OUTPUT) { | 68 } else if (type == MEDIA_DEVICE_AUDIO_OUTPUT) { |
| 69 audio_output_request_id_ = request_id; | 69 audio_output_request_id_ = request_id; |
| 70 audio_output_array_.clear(); | 70 audio_output_array_.clear(); |
| 71 AddAudioOutputDeviceToArray(); | 71 AddAudioOutputDeviceToArray(); |
| 72 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { | 72 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
| 73 video_request_id_ = request_id; | 73 video_request_id_ = request_id; |
| 74 video_array_.clear(); | 74 video_array_.clear(); |
| 75 AddVideoDeviceToArray(); | 75 AddVideoDeviceToArray(true); |
| 76 AddVideoDeviceToArray(false); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 void MockMediaStreamDispatcher::StopStreamDevice( | 80 void MockMediaStreamDispatcher::StopStreamDevice( |
| 80 const StreamDeviceInfo& device_info) { | 81 const StreamDeviceInfo& device_info) { |
| 81 if (IsAudioInputMediaType(device_info.device.type)) { | 82 if (IsAudioInputMediaType(device_info.device.type)) { |
| 82 ++stop_audio_device_counter_; | 83 ++stop_audio_device_counter_; |
| 83 return; | 84 return; |
| 84 } | 85 } |
| 85 if (IsVideoMediaType(device_info.device.type)) { | 86 if (IsVideoMediaType(device_info.device.type)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 102 int index) { | 103 int index) { |
| 103 return -1; | 104 return -1; |
| 104 } | 105 } |
| 105 | 106 |
| 106 void MockMediaStreamDispatcher::AddAudioInputDeviceToArray( | 107 void MockMediaStreamDispatcher::AddAudioInputDeviceToArray( |
| 107 bool matched_output) { | 108 bool matched_output) { |
| 108 StreamDeviceInfo audio; | 109 StreamDeviceInfo audio; |
| 109 audio.device.id = "audio_input_device_id" + base::IntToString(session_id_); | 110 audio.device.id = "audio_input_device_id" + base::IntToString(session_id_); |
| 110 audio.device.name = "microphone"; | 111 audio.device.name = "microphone"; |
| 111 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE; | 112 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 113 audio.device.video_facing = MEDIA_VIDEO_FACING_NONE; |
| 112 if (matched_output) { | 114 if (matched_output) { |
| 113 audio.device.matched_output_device_id = | 115 audio.device.matched_output_device_id = |
| 114 kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); | 116 kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); |
| 115 } | 117 } |
| 116 audio.session_id = session_id_; | 118 audio.session_id = session_id_; |
| 117 audio_input_array_.push_back(audio); | 119 audio_input_array_.push_back(audio); |
| 118 } | 120 } |
| 119 | 121 |
| 120 void MockMediaStreamDispatcher::AddAudioOutputDeviceToArray() { | 122 void MockMediaStreamDispatcher::AddAudioOutputDeviceToArray() { |
| 121 StreamDeviceInfo audio; | 123 StreamDeviceInfo audio; |
| 122 audio.device.id = kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); | 124 audio.device.id = kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); |
| 123 audio.device.name = "speaker"; | 125 audio.device.name = "speaker"; |
| 124 audio.device.type = MEDIA_DEVICE_AUDIO_OUTPUT; | 126 audio.device.type = MEDIA_DEVICE_AUDIO_OUTPUT; |
| 127 audio.device.video_facing = MEDIA_VIDEO_FACING_NONE; |
| 125 audio.session_id = session_id_; | 128 audio.session_id = session_id_; |
| 126 audio_output_array_.push_back(audio); | 129 audio_output_array_.push_back(audio); |
| 127 } | 130 } |
| 128 | 131 |
| 129 void MockMediaStreamDispatcher::AddVideoDeviceToArray() { | 132 void MockMediaStreamDispatcher::AddVideoDeviceToArray(bool facing_user) { |
| 130 StreamDeviceInfo video; | 133 StreamDeviceInfo video; |
| 131 video.device.id = "video_device_id" + base::IntToString(session_id_); | 134 video.device.id = "video_device_id" + base::IntToString(session_id_); |
| 132 video.device.name = "usb video camera"; | 135 video.device.name = "usb video camera"; |
| 133 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; | 136 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 137 video.device.video_facing = facing_user ? MEDIA_VIDEO_FACING_USER |
| 138 : MEDIA_VIDEO_FACING_ENVIRONMENT; |
| 134 video.session_id = session_id_; | 139 video.session_id = session_id_; |
| 135 video_array_.push_back(video); | 140 video_array_.push_back(video); |
| 136 } | 141 } |
| 137 | 142 |
| 138 } // namespace content | 143 } // namespace content |
| OLD | NEW |