| 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 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "content/common/media/media_stream_messages.h" | 10 #include "content/common/media/media_stream_messages.h" |
| 11 #include "content/public/common/media_stream_request.h" |
| 11 #include "content/renderer/media/media_stream_dispatcher.h" | 12 #include "content/renderer/media/media_stream_dispatcher.h" |
| 12 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 13 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const int kRouteId = 0; | 19 const int kRouteId = 0; |
| 19 const int kAudioSessionId = 3; | 20 const int kAudioSessionId = 3; |
| 20 const int kVideoSessionId = 5; | 21 const int kVideoSessionId = 5; |
| 21 const int kRequestId1 = 10; | 22 const int kRequestId1 = 10; |
| 22 const int kRequestId2 = 20; | 23 const int kRequestId2 = 20; |
| 23 const int kRequestId3 = 30; | 24 const int kRequestId3 = 30; |
| 24 const int kRequestId4 = 40; | 25 const int kRequestId4 = 40; |
| 25 static const char kLabel[] = "test"; | 26 static const char kLabel[] = "test"; |
| 26 | 27 |
| 28 const content::MediaStreamDeviceType kAudioType = |
| 29 content::MEDIA_STREAM_DEVICE_TYPE_USER_AUDIO_CAPTURE; |
| 30 const content::MediaStreamDeviceType kVideoType = |
| 31 content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE; |
| 32 |
| 27 class MockMediaStreamDispatcherEventHandler | 33 class MockMediaStreamDispatcherEventHandler |
| 28 : public MediaStreamDispatcherEventHandler, | 34 : public MediaStreamDispatcherEventHandler, |
| 29 public base::SupportsWeakPtr<MockMediaStreamDispatcherEventHandler> { | 35 public base::SupportsWeakPtr<MockMediaStreamDispatcherEventHandler> { |
| 30 public: | 36 public: |
| 31 MockMediaStreamDispatcherEventHandler() | 37 MockMediaStreamDispatcherEventHandler() |
| 32 : request_id_(-1), | 38 : request_id_(-1), |
| 33 audio_failed(false), | 39 audio_failed(false), |
| 34 video_failed(false) {} | 40 video_failed(false) {} |
| 35 | 41 |
| 36 virtual void OnStreamGenerated( | 42 virtual void OnStreamGenerated( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 components, security_origin); | 107 components, security_origin); |
| 102 int ipc_request_id2 = dispatcher->next_ipc_id_; | 108 int ipc_request_id2 = dispatcher->next_ipc_id_; |
| 103 EXPECT_NE(ipc_request_id1, ipc_request_id2); | 109 EXPECT_NE(ipc_request_id1, ipc_request_id2); |
| 104 dispatcher->GenerateStream(kRequestId2, handler.get()->AsWeakPtr(), | 110 dispatcher->GenerateStream(kRequestId2, handler.get()->AsWeakPtr(), |
| 105 components, security_origin); | 111 components, security_origin); |
| 106 EXPECT_EQ(dispatcher->requests_.size(), size_t(2)); | 112 EXPECT_EQ(dispatcher->requests_.size(), size_t(2)); |
| 107 | 113 |
| 108 media_stream::StreamDeviceInfoArray audio_device_array(1); | 114 media_stream::StreamDeviceInfoArray audio_device_array(1); |
| 109 media_stream::StreamDeviceInfo audio_device_info; | 115 media_stream::StreamDeviceInfo audio_device_info; |
| 110 audio_device_info.name = "Microphone"; | 116 audio_device_info.name = "Microphone"; |
| 111 audio_device_info.stream_type = | 117 audio_device_info.stream_type = kAudioType; |
| 112 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; | |
| 113 audio_device_info.session_id = kAudioSessionId; | 118 audio_device_info.session_id = kAudioSessionId; |
| 114 audio_device_array[0] = audio_device_info; | 119 audio_device_array[0] = audio_device_info; |
| 115 | 120 |
| 116 media_stream::StreamDeviceInfoArray video_device_array(1); | 121 media_stream::StreamDeviceInfoArray video_device_array(1); |
| 117 media_stream::StreamDeviceInfo video_device_info; | 122 media_stream::StreamDeviceInfo video_device_info; |
| 118 video_device_info.name = "Camera"; | 123 video_device_info.name = "Camera"; |
| 119 video_device_info.stream_type = | 124 video_device_info.stream_type = kVideoType; |
| 120 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; | |
| 121 video_device_info.session_id = kVideoSessionId; | 125 video_device_info.session_id = kVideoSessionId; |
| 122 video_device_array[0] = video_device_info; | 126 video_device_array[0] = video_device_info; |
| 123 | 127 |
| 124 // Complete the creation of stream1. | 128 // Complete the creation of stream1. |
| 125 std::string stream_label1 = std::string("stream1"); | 129 std::string stream_label1 = std::string("stream1"); |
| 126 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( | 130 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( |
| 127 kRouteId, ipc_request_id1, stream_label1, | 131 kRouteId, ipc_request_id1, stream_label1, |
| 128 audio_device_array, video_device_array)); | 132 audio_device_array, video_device_array)); |
| 129 EXPECT_EQ(handler->request_id_, kRequestId1); | 133 EXPECT_EQ(handler->request_id_, kRequestId1); |
| 130 EXPECT_EQ(handler->label_, stream_label1); | 134 EXPECT_EQ(handler->label_, stream_label1); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 TEST(MediaStreamDispatcherTest, BasicVideoDevice) { | 171 TEST(MediaStreamDispatcherTest, BasicVideoDevice) { |
| 168 scoped_ptr<MessageLoop> message_loop(new MessageLoop()); | 172 scoped_ptr<MessageLoop> message_loop(new MessageLoop()); |
| 169 scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL)); | 173 scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL)); |
| 170 scoped_ptr<MockMediaStreamDispatcherEventHandler> | 174 scoped_ptr<MockMediaStreamDispatcherEventHandler> |
| 171 handler1(new MockMediaStreamDispatcherEventHandler); | 175 handler1(new MockMediaStreamDispatcherEventHandler); |
| 172 scoped_ptr<MockMediaStreamDispatcherEventHandler> | 176 scoped_ptr<MockMediaStreamDispatcherEventHandler> |
| 173 handler2(new MockMediaStreamDispatcherEventHandler); | 177 handler2(new MockMediaStreamDispatcherEventHandler); |
| 174 GURL security_origin; | 178 GURL security_origin; |
| 175 | 179 |
| 176 int ipc_request_id1 = dispatcher->next_ipc_id_; | 180 int ipc_request_id1 = dispatcher->next_ipc_id_; |
| 177 dispatcher->EnumerateDevices(kRequestId1, handler1.get()->AsWeakPtr(), | 181 dispatcher->EnumerateDevices( |
| 178 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 182 kRequestId1, handler1.get()->AsWeakPtr(), |
| 179 security_origin); | 183 kVideoType, |
| 184 security_origin); |
| 180 int ipc_request_id2 = dispatcher->next_ipc_id_; | 185 int ipc_request_id2 = dispatcher->next_ipc_id_; |
| 181 EXPECT_NE(ipc_request_id1, ipc_request_id2); | 186 EXPECT_NE(ipc_request_id1, ipc_request_id2); |
| 182 dispatcher->EnumerateDevices(kRequestId2, handler2.get()->AsWeakPtr(), | 187 dispatcher->EnumerateDevices( |
| 183 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 188 kRequestId2, handler2.get()->AsWeakPtr(), |
| 184 security_origin); | 189 kVideoType, |
| 185 EXPECT_EQ(dispatcher->video_enumeration_state_.requests.size(), size_t(2)); | 190 security_origin); |
| 191 EXPECT_EQ(dispatcher->enumeration_state_[kVideoType].requests.size(), |
| 192 size_t(2)); |
| 186 | 193 |
| 187 media_stream::StreamDeviceInfoArray video_device_array(1); | 194 media_stream::StreamDeviceInfoArray video_device_array(1); |
| 188 media_stream::StreamDeviceInfo video_device_info; | 195 media_stream::StreamDeviceInfo video_device_info; |
| 189 video_device_info.name = "Camera"; | 196 video_device_info.name = "Camera"; |
| 190 video_device_info.device_id = "device_path"; | 197 video_device_info.device_id = "device_path"; |
| 191 video_device_info.stream_type = | 198 video_device_info.stream_type = kVideoType; |
| 192 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; | |
| 193 video_device_info.session_id = kVideoSessionId; | 199 video_device_info.session_id = kVideoSessionId; |
| 194 video_device_array[0] = video_device_info; | 200 video_device_array[0] = video_device_info; |
| 195 | 201 |
| 196 // Complete the enumeration request and all requesters should receive reply. | 202 // Complete the enumeration request and all requesters should receive reply. |
| 197 dispatcher->OnMessageReceived(MediaStreamMsg_DevicesEnumerated( | 203 dispatcher->OnMessageReceived(MediaStreamMsg_DevicesEnumerated( |
| 198 kRouteId, ipc_request_id1, kLabel, video_device_array)); | 204 kRouteId, ipc_request_id1, kLabel, video_device_array)); |
| 199 EXPECT_EQ(handler1->request_id_, kRequestId1); | 205 EXPECT_EQ(handler1->request_id_, kRequestId1); |
| 200 EXPECT_EQ(handler2->request_id_, kRequestId2); | 206 EXPECT_EQ(handler2->request_id_, kRequestId2); |
| 201 | 207 |
| 202 EXPECT_EQ(dispatcher->video_enumeration_state_.requests.size(), size_t(2)); | 208 EXPECT_EQ(dispatcher->enumeration_state_[kVideoType].requests.size(), |
| 209 size_t(2)); |
| 203 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); | 210 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); |
| 204 | 211 |
| 205 int ipc_request_id3 = dispatcher->next_ipc_id_; | 212 int ipc_request_id3 = dispatcher->next_ipc_id_; |
| 206 dispatcher->OpenDevice(kRequestId3, handler1.get()->AsWeakPtr(), | 213 dispatcher->OpenDevice(kRequestId3, handler1.get()->AsWeakPtr(), |
| 207 video_device_info.device_id, | 214 video_device_info.device_id, |
| 208 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 215 kVideoType, |
| 209 security_origin); | 216 security_origin); |
| 210 int ipc_request_id4 = dispatcher->next_ipc_id_; | 217 int ipc_request_id4 = dispatcher->next_ipc_id_; |
| 211 EXPECT_NE(ipc_request_id3, ipc_request_id4); | 218 EXPECT_NE(ipc_request_id3, ipc_request_id4); |
| 212 dispatcher->OpenDevice(kRequestId4, handler1.get()->AsWeakPtr(), | 219 dispatcher->OpenDevice(kRequestId4, handler1.get()->AsWeakPtr(), |
| 213 video_device_info.device_id, | 220 video_device_info.device_id, |
| 214 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 221 kVideoType, |
| 215 security_origin); | 222 security_origin); |
| 216 EXPECT_EQ(dispatcher->requests_.size(), size_t(2)); | 223 EXPECT_EQ(dispatcher->requests_.size(), size_t(2)); |
| 217 | 224 |
| 218 // Complete the OpenDevice of request 1. | 225 // Complete the OpenDevice of request 1. |
| 219 std::string stream_label1 = std::string("stream1"); | 226 std::string stream_label1 = std::string("stream1"); |
| 220 dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened( | 227 dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened( |
| 221 kRouteId, ipc_request_id3, stream_label1, video_device_info)); | 228 kRouteId, ipc_request_id3, stream_label1, video_device_info)); |
| 222 EXPECT_EQ(handler1->request_id_, kRequestId3); | 229 EXPECT_EQ(handler1->request_id_, kRequestId3); |
| 223 | 230 |
| 224 // Complete the OpenDevice of request 2. | 231 // Complete the OpenDevice of request 2. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 EXPECT_EQ(dispatcher->requests_.size(), size_t(0)); | 277 EXPECT_EQ(dispatcher->requests_.size(), size_t(0)); |
| 271 | 278 |
| 272 // Create a new stream. | 279 // Create a new stream. |
| 273 ipc_request_id1 = dispatcher->next_ipc_id_; | 280 ipc_request_id1 = dispatcher->next_ipc_id_; |
| 274 dispatcher->GenerateStream(kRequestId1, handler.get()->AsWeakPtr(), | 281 dispatcher->GenerateStream(kRequestId1, handler.get()->AsWeakPtr(), |
| 275 components, security_origin); | 282 components, security_origin); |
| 276 | 283 |
| 277 media_stream::StreamDeviceInfoArray audio_device_array(1); | 284 media_stream::StreamDeviceInfoArray audio_device_array(1); |
| 278 media_stream::StreamDeviceInfo audio_device_info; | 285 media_stream::StreamDeviceInfo audio_device_info; |
| 279 audio_device_info.name = "Microphone"; | 286 audio_device_info.name = "Microphone"; |
| 280 audio_device_info.stream_type = | 287 audio_device_info.stream_type = kAudioType; |
| 281 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; | |
| 282 audio_device_info.session_id = kAudioSessionId; | 288 audio_device_info.session_id = kAudioSessionId; |
| 283 audio_device_array[0] = audio_device_info; | 289 audio_device_array[0] = audio_device_info; |
| 284 | 290 |
| 285 media_stream::StreamDeviceInfoArray video_device_array(1); | 291 media_stream::StreamDeviceInfoArray video_device_array(1); |
| 286 media_stream::StreamDeviceInfo video_device_info; | 292 media_stream::StreamDeviceInfo video_device_info; |
| 287 video_device_info.name = "Camera"; | 293 video_device_info.name = "Camera"; |
| 288 video_device_info.stream_type = | 294 video_device_info.stream_type = kVideoType; |
| 289 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; | |
| 290 video_device_info.session_id = kVideoSessionId; | 295 video_device_info.session_id = kVideoSessionId; |
| 291 video_device_array[0] = video_device_info; | 296 video_device_array[0] = video_device_info; |
| 292 | 297 |
| 293 // Complete the creation of stream1. | 298 // Complete the creation of stream1. |
| 294 std::string stream_label1 = std::string("stream1"); | 299 std::string stream_label1 = std::string("stream1"); |
| 295 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( | 300 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( |
| 296 kRouteId, ipc_request_id1, stream_label1, | 301 kRouteId, ipc_request_id1, stream_label1, |
| 297 audio_device_array, video_device_array)); | 302 audio_device_array, video_device_array)); |
| 298 EXPECT_EQ(handler->request_id_, kRequestId1); | 303 EXPECT_EQ(handler->request_id_, kRequestId1); |
| 299 EXPECT_EQ(handler->label_, stream_label1); | 304 EXPECT_EQ(handler->label_, stream_label1); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 330 dispatcher->GenerateStream(kRequestId2, handler.get()->AsWeakPtr(), | 335 dispatcher->GenerateStream(kRequestId2, handler.get()->AsWeakPtr(), |
| 331 components, GURL()); | 336 components, GURL()); |
| 332 | 337 |
| 333 EXPECT_EQ(2u, dispatcher->requests_.size()); | 338 EXPECT_EQ(2u, dispatcher->requests_.size()); |
| 334 dispatcher->CancelGenerateStream(kRequestId2); | 339 dispatcher->CancelGenerateStream(kRequestId2); |
| 335 EXPECT_EQ(1u, dispatcher->requests_.size()); | 340 EXPECT_EQ(1u, dispatcher->requests_.size()); |
| 336 | 341 |
| 337 // Complete the creation of stream1. | 342 // Complete the creation of stream1. |
| 338 media_stream::StreamDeviceInfo audio_device_info; | 343 media_stream::StreamDeviceInfo audio_device_info; |
| 339 audio_device_info.name = "Microphone"; | 344 audio_device_info.name = "Microphone"; |
| 340 audio_device_info.stream_type = | 345 audio_device_info.stream_type = kAudioType; |
| 341 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; | |
| 342 audio_device_info.session_id = kAudioSessionId; | 346 audio_device_info.session_id = kAudioSessionId; |
| 343 media_stream::StreamDeviceInfoArray audio_device_array(1); | 347 media_stream::StreamDeviceInfoArray audio_device_array(1); |
| 344 audio_device_array[0] = audio_device_info; | 348 audio_device_array[0] = audio_device_info; |
| 345 | 349 |
| 346 media_stream::StreamDeviceInfo video_device_info; | 350 media_stream::StreamDeviceInfo video_device_info; |
| 347 video_device_info.name = "Camera"; | 351 video_device_info.name = "Camera"; |
| 348 video_device_info.stream_type = | 352 video_device_info.stream_type = kVideoType; |
| 349 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; | |
| 350 video_device_info.session_id = kVideoSessionId; | 353 video_device_info.session_id = kVideoSessionId; |
| 351 media_stream::StreamDeviceInfoArray video_device_array(1); | 354 media_stream::StreamDeviceInfoArray video_device_array(1); |
| 352 video_device_array[0] = video_device_info; | 355 video_device_array[0] = video_device_info; |
| 353 | 356 |
| 354 std::string stream_label1 = "stream1"; | 357 std::string stream_label1 = "stream1"; |
| 355 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( | 358 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( |
| 356 kRouteId, ipc_request_id1, stream_label1, | 359 kRouteId, ipc_request_id1, stream_label1, |
| 357 audio_device_array, video_device_array)); | 360 audio_device_array, video_device_array)); |
| 358 EXPECT_EQ(handler->request_id_, kRequestId1); | 361 EXPECT_EQ(handler->request_id_, kRequestId1); |
| 359 EXPECT_EQ(handler->label_, stream_label1); | 362 EXPECT_EQ(handler->label_, stream_label1); |
| 360 EXPECT_EQ(0u, dispatcher->requests_.size()); | 363 EXPECT_EQ(0u, dispatcher->requests_.size()); |
| 361 } | 364 } |
| OLD | NEW |