Chromium Code Reviews| 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/renderer/media/media_stream_dispatcher.h" | 11 #include "content/renderer/media/media_stream_dispatcher.h" |
| 12 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 12 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const int kRouteId = 0; | 18 const int kRouteId = 0; |
| 19 const int kAudioSessionId = 3; | 19 const int kAudioSessionId = 3; |
| 20 const int kVideoSessionId = 5; | 20 const int kVideoSessionId = 5; |
| 21 const int kRequestId1 = 10; | 21 const int kRequestId1 = 10; |
| 22 const int kRequestId2 = 20; | 22 const int kRequestId2 = 20; |
| 23 const int kRequestId3 = 30; | 23 const int kRequestId3 = 30; |
| 24 const int kRequestId4 = 40; | 24 const int kRequestId4 = 40; |
| 25 static const char* kLabel = "test"; | |
|
tommi (sloooow) - chröme
2012/07/30 12:10:21
[]
wjia(left Chromium)
2012/08/01 01:28:59
Done.
| |
| 25 | 26 |
| 26 class MockMediaStreamDispatcherEventHandler | 27 class MockMediaStreamDispatcherEventHandler |
| 27 : public MediaStreamDispatcherEventHandler, | 28 : public MediaStreamDispatcherEventHandler, |
| 28 public base::SupportsWeakPtr<MockMediaStreamDispatcherEventHandler> { | 29 public base::SupportsWeakPtr<MockMediaStreamDispatcherEventHandler> { |
| 29 public: | 30 public: |
| 30 MockMediaStreamDispatcherEventHandler() | 31 MockMediaStreamDispatcherEventHandler() |
| 31 : request_id_(-1), | 32 : request_id_(-1), |
| 32 audio_failed(false), | 33 audio_failed(false), |
| 33 video_failed(false) {} | 34 video_failed(false) {} |
| 34 | 35 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); | 159 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); |
| 159 | 160 |
| 160 // Verify that the request have been completed. | 161 // Verify that the request have been completed. |
| 161 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); | 162 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); |
| 162 EXPECT_EQ(dispatcher->requests_.size(), size_t(0)); | 163 EXPECT_EQ(dispatcher->requests_.size(), size_t(0)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 TEST(MediaStreamDispatcherTest, BasicVideoDevice) { | 166 TEST(MediaStreamDispatcherTest, BasicVideoDevice) { |
| 166 scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL)); | 167 scoped_ptr<MediaStreamDispatcher> dispatcher(new MediaStreamDispatcher(NULL)); |
| 167 scoped_ptr<MockMediaStreamDispatcherEventHandler> | 168 scoped_ptr<MockMediaStreamDispatcherEventHandler> |
| 168 handler(new MockMediaStreamDispatcherEventHandler); | 169 handler1(new MockMediaStreamDispatcherEventHandler); |
| 170 scoped_ptr<MockMediaStreamDispatcherEventHandler> | |
| 171 handler2(new MockMediaStreamDispatcherEventHandler); | |
| 169 GURL security_origin; | 172 GURL security_origin; |
| 170 | 173 |
| 171 int ipc_request_id1 = dispatcher->next_ipc_id_; | 174 int ipc_request_id1 = dispatcher->next_ipc_id_; |
| 172 dispatcher->EnumerateDevices(kRequestId1, handler.get()->AsWeakPtr(), | 175 dispatcher->EnumerateDevices(kRequestId1, handler1.get()->AsWeakPtr(), |
| 173 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 176 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, |
| 174 security_origin); | 177 security_origin); |
| 175 int ipc_request_id2 = dispatcher->next_ipc_id_; | 178 int ipc_request_id2 = dispatcher->next_ipc_id_; |
| 176 EXPECT_NE(ipc_request_id1, ipc_request_id2); | 179 EXPECT_NE(ipc_request_id1, ipc_request_id2); |
| 177 dispatcher->EnumerateDevices(kRequestId2, handler.get()->AsWeakPtr(), | 180 dispatcher->EnumerateDevices(kRequestId2, handler2.get()->AsWeakPtr(), |
| 178 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 181 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, |
| 179 security_origin); | 182 security_origin); |
| 180 EXPECT_EQ(dispatcher->requests_.size(), size_t(2)); | 183 EXPECT_EQ(dispatcher->video_enumeration_state_.requests.size(), size_t(2)); |
| 181 | 184 |
| 182 media_stream::StreamDeviceInfoArray video_device_array(1); | 185 media_stream::StreamDeviceInfoArray video_device_array(1); |
| 183 media_stream::StreamDeviceInfo video_device_info; | 186 media_stream::StreamDeviceInfo video_device_info; |
| 184 video_device_info.name = "Camera"; | 187 video_device_info.name = "Camera"; |
| 185 video_device_info.device_id = "device_path"; | 188 video_device_info.device_id = "device_path"; |
| 186 video_device_info.stream_type = | 189 video_device_info.stream_type = |
| 187 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; | 190 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; |
| 188 video_device_info.session_id = kVideoSessionId; | 191 video_device_info.session_id = kVideoSessionId; |
| 189 video_device_array[0] = video_device_info; | 192 video_device_array[0] = video_device_info; |
| 190 | 193 |
| 191 // Complete the enumeration of request 1. | 194 // Complete the enumeration request and all requesters should receive reply. |
| 192 dispatcher->OnMessageReceived(MediaStreamMsg_DevicesEnumerated( | 195 dispatcher->OnMessageReceived(MediaStreamMsg_DevicesEnumerated( |
| 193 kRouteId, ipc_request_id1, video_device_array)); | 196 kRouteId, ipc_request_id1, kLabel, video_device_array)); |
| 194 EXPECT_EQ(handler->request_id_, kRequestId1); | 197 EXPECT_EQ(handler1->request_id_, kRequestId1); |
| 198 EXPECT_EQ(handler2->request_id_, kRequestId2); | |
| 195 | 199 |
| 196 // Complete the enumeration of request 2. | 200 EXPECT_EQ(dispatcher->video_enumeration_state_.requests.size(), size_t(2)); |
| 197 dispatcher->OnMessageReceived(MediaStreamMsg_DevicesEnumerated( | |
| 198 kRouteId, ipc_request_id2, video_device_array)); | |
| 199 EXPECT_EQ(handler->request_id_, kRequestId2); | |
| 200 | |
| 201 EXPECT_EQ(dispatcher->requests_.size(), size_t(0)); | |
| 202 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); | 201 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(0)); |
| 203 | 202 |
| 204 int ipc_request_id3 = dispatcher->next_ipc_id_; | 203 int ipc_request_id3 = dispatcher->next_ipc_id_; |
| 205 dispatcher->OpenDevice(kRequestId3, handler.get()->AsWeakPtr(), | 204 dispatcher->OpenDevice(kRequestId3, handler1.get()->AsWeakPtr(), |
| 206 video_device_info.device_id, | 205 video_device_info.device_id, |
| 207 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 206 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, |
| 208 security_origin); | 207 security_origin); |
| 209 int ipc_request_id4 = dispatcher->next_ipc_id_; | 208 int ipc_request_id4 = dispatcher->next_ipc_id_; |
| 210 EXPECT_NE(ipc_request_id3, ipc_request_id4); | 209 EXPECT_NE(ipc_request_id3, ipc_request_id4); |
| 211 dispatcher->OpenDevice(kRequestId4, handler.get()->AsWeakPtr(), | 210 dispatcher->OpenDevice(kRequestId4, handler1.get()->AsWeakPtr(), |
| 212 video_device_info.device_id, | 211 video_device_info.device_id, |
| 213 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 212 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, |
| 214 security_origin); | 213 security_origin); |
| 215 EXPECT_EQ(dispatcher->requests_.size(), size_t(2)); | 214 EXPECT_EQ(dispatcher->requests_.size(), size_t(2)); |
| 216 | 215 |
| 217 // Complete the OpenDevice of request 1. | 216 // Complete the OpenDevice of request 1. |
| 218 std::string stream_label1 = std::string("stream1"); | 217 std::string stream_label1 = std::string("stream1"); |
| 219 dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened( | 218 dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened( |
| 220 kRouteId, ipc_request_id3, stream_label1, video_device_info)); | 219 kRouteId, ipc_request_id3, stream_label1, video_device_info)); |
| 221 EXPECT_EQ(handler->request_id_, kRequestId3); | 220 EXPECT_EQ(handler1->request_id_, kRequestId3); |
| 222 | 221 |
| 223 // Complete the OpenDevice of request 2. | 222 // Complete the OpenDevice of request 2. |
| 224 std::string stream_label2 = std::string("stream2"); | 223 std::string stream_label2 = std::string("stream2"); |
| 225 dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened( | 224 dispatcher->OnMessageReceived(MediaStreamMsg_DeviceOpened( |
| 226 kRouteId, ipc_request_id4, stream_label2, video_device_info)); | 225 kRouteId, ipc_request_id4, stream_label2, video_device_info)); |
| 227 EXPECT_EQ(handler->request_id_, kRequestId4); | 226 EXPECT_EQ(handler1->request_id_, kRequestId4); |
| 228 | 227 |
| 229 EXPECT_EQ(dispatcher->requests_.size(), size_t(0)); | 228 EXPECT_EQ(dispatcher->requests_.size(), size_t(0)); |
| 230 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(2)); | 229 EXPECT_EQ(dispatcher->label_stream_map_.size(), size_t(2)); |
| 231 | 230 |
| 232 // Check the video_session_id. | 231 // Check the video_session_id. |
| 233 EXPECT_EQ(dispatcher->video_session_id(stream_label1, 0), kVideoSessionId); | 232 EXPECT_EQ(dispatcher->video_session_id(stream_label1, 0), kVideoSessionId); |
| 234 EXPECT_EQ(dispatcher->video_session_id(stream_label2, 0), kVideoSessionId); | 233 EXPECT_EQ(dispatcher->video_session_id(stream_label2, 0), kVideoSessionId); |
| 235 | 234 |
| 236 // Stop stream2. | 235 // Stop stream2. |
| 237 dispatcher->StopStream(stream_label2); | 236 dispatcher->StopStream(stream_label2); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 video_device_array[0] = video_device_info; | 348 video_device_array[0] = video_device_info; |
| 350 | 349 |
| 351 std::string stream_label1 = "stream1"; | 350 std::string stream_label1 = "stream1"; |
| 352 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( | 351 dispatcher->OnMessageReceived(MediaStreamMsg_StreamGenerated( |
| 353 kRouteId, ipc_request_id1, stream_label1, | 352 kRouteId, ipc_request_id1, stream_label1, |
| 354 audio_device_array, video_device_array)); | 353 audio_device_array, video_device_array)); |
| 355 EXPECT_EQ(handler->request_id_, kRequestId1); | 354 EXPECT_EQ(handler->request_id_, kRequestId1); |
| 356 EXPECT_EQ(handler->label_, stream_label1); | 355 EXPECT_EQ(handler->label_, stream_label1); |
| 357 EXPECT_EQ(0u, dispatcher->requests_.size()); | 356 EXPECT_EQ(0u, dispatcher->requests_.size()); |
| 358 } | 357 } |
| OLD | NEW |