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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
16 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | |
17 #include "content/browser/renderer_host/media/media_stream_manager.h" | 16 #include "content/browser/renderer_host/media/media_stream_manager.h" |
18 #include "content/browser/renderer_host/media/video_capture_host.h" | 17 #include "content/browser/renderer_host/media/video_capture_host.h" |
19 #include "content/browser/renderer_host/media/video_capture_manager.h" | 18 #include "content/browser/renderer_host/media/video_capture_manager.h" |
20 #include "content/common/media/video_capture_messages.h" | 19 #include "content/common/media/video_capture_messages.h" |
| 20 #include "content/public/common/media_stream_request.h" |
21 #include "content/public/test/mock_resource_context.h" | 21 #include "content/public/test/mock_resource_context.h" |
22 #include "media/audio/audio_manager.h" | |
23 #include "media/video/capture/video_capture_types.h" | 22 #include "media/video/capture/video_capture_types.h" |
24 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 | 26 |
28 using ::testing::_; | 27 using ::testing::_; |
29 using ::testing::AtLeast; | 28 using ::testing::AtLeast; |
30 using ::testing::AnyNumber; | 29 using ::testing::AnyNumber; |
31 using ::testing::DoAll; | 30 using ::testing::DoAll; |
32 using ::testing::InSequence; | 31 using ::testing::InSequence; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceInfo, OnDeviceInfoDispatch) | 138 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceInfo, OnDeviceInfoDispatch) |
140 IPC_MESSAGE_UNHANDLED(handled = false) | 139 IPC_MESSAGE_UNHANDLED(handled = false) |
141 IPC_END_MESSAGE_MAP() | 140 IPC_END_MESSAGE_MAP() |
142 EXPECT_TRUE(handled); | 141 EXPECT_TRUE(handled); |
143 | 142 |
144 delete message; | 143 delete message; |
145 return true; | 144 return true; |
146 } | 145 } |
147 | 146 |
148 virtual media_stream::VideoCaptureManager* GetVideoCaptureManager() OVERRIDE { | 147 virtual media_stream::VideoCaptureManager* GetVideoCaptureManager() OVERRIDE { |
149 return manager_->video_capture_manager(); | 148 return manager_->GetVideoCaptureManager(content::MEDIA_USER_VIDEO_CAPTURE); |
150 } | 149 } |
151 | 150 |
152 // These handler methods do minimal things and delegate to the mock methods. | 151 // These handler methods do minimal things and delegate to the mock methods. |
153 void OnNewBufferCreatedDispatch(int device_id, | 152 void OnNewBufferCreatedDispatch(int device_id, |
154 base::SharedMemoryHandle handle, | 153 base::SharedMemoryHandle handle, |
155 int length, int buffer_id) { | 154 int length, int buffer_id) { |
156 OnNewBufferCreated(device_id, handle, length, buffer_id); | 155 OnNewBufferCreated(device_id, handle, length, buffer_id); |
157 base::SharedMemory* dib = new base::SharedMemory(handle, false); | 156 base::SharedMemory* dib = new base::SharedMemory(handle, false); |
158 dib->Map(length); | 157 dib->Map(length); |
159 filled_dib_[buffer_id] = dib; | 158 filled_dib_[buffer_id] = dib; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 protected: | 203 protected: |
205 virtual void SetUp() OVERRIDE { | 204 virtual void SetUp() OVERRIDE { |
206 // Create a message loop so VideoCaptureHostTest can use it. | 205 // Create a message loop so VideoCaptureHostTest can use it. |
207 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 206 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
208 | 207 |
209 // MediaStreamManager must be created on the IO thread. | 208 // MediaStreamManager must be created on the IO thread. |
210 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, | 209 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
211 message_loop_.get())); | 210 message_loop_.get())); |
212 | 211 |
213 // Create our own MediaStreamManager. | 212 // Create our own MediaStreamManager. |
214 audio_manager_.reset(media::AudioManager::Create()); | 213 media_stream_manager_.reset(new media_stream::MediaStreamManager()); |
215 scoped_refptr<media_stream::AudioInputDeviceManager> | |
216 audio_input_device_manager( | |
217 new media_stream::AudioInputDeviceManager(audio_manager_.get())); | |
218 scoped_refptr<media_stream::VideoCaptureManager> video_capture_manager( | |
219 new media_stream::VideoCaptureManager()); | |
220 media_stream_manager_.reset(new media_stream::MediaStreamManager( | |
221 audio_input_device_manager, video_capture_manager)); | |
222 | |
223 #ifndef TEST_REAL_CAPTURE_DEVICE | 214 #ifndef TEST_REAL_CAPTURE_DEVICE |
224 media_stream_manager_->UseFakeDevice(); | 215 media_stream_manager_->UseFakeDevice(); |
225 #endif | 216 #endif |
226 | 217 |
227 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); | 218 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); |
228 | 219 |
229 // Simulate IPC channel connected. | 220 // Simulate IPC channel connected. |
230 host_->OnChannelConnected(base::GetCurrentProcId()); | 221 host_->OnChannelConnected(base::GetCurrentProcId()); |
231 } | 222 } |
232 | 223 |
233 virtual void TearDown() OVERRIDE { | 224 virtual void TearDown() OVERRIDE { |
234 // Verifies and removes the expectations on host_ and | 225 // Verifies and removes the expectations on host_ and |
235 // returns true iff successful. | 226 // returns true iff successful. |
236 Mock::VerifyAndClearExpectations(host_); | 227 Mock::VerifyAndClearExpectations(host_); |
237 | 228 |
238 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 229 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, |
239 video_capture::kStopped)) | 230 video_capture::kStopped)) |
240 .Times(AnyNumber()); | 231 .Times(AnyNumber()); |
241 | 232 |
242 // Simulate closing the IPC channel. | 233 // Simulate closing the IPC channel. |
243 host_->OnChannelClosing(); | 234 host_->OnChannelClosing(); |
244 | 235 |
245 // Release the reference to the mock object. The object will be destructed | 236 // Release the reference to the mock object. The object will be destructed |
246 // on message_loop_. | 237 // on message_loop_. |
247 host_ = NULL; | 238 host_ = NULL; |
248 | 239 |
249 // We need to continue running message_loop_ to complete all destructions. | 240 // We need to continue running message_loop_ to complete all destructions. |
250 message_loop_->RunAllPending(); | 241 message_loop_->RunAllPending(); |
251 | 242 |
252 // Delete the IO message loop to delete the device thread, | 243 // Delete the IO message loop. This will cause the MediaStreamManager to be |
253 // AudioInputDeviceManager and VideoCaptureManager. | 244 // notified so it will stop its device thread and device managers. |
254 message_loop_.reset(); | 245 message_loop_.reset(); |
255 } | 246 } |
256 | 247 |
257 void StartCapture() { | 248 void StartCapture() { |
258 InSequence s; | 249 InSequence s; |
259 // 1. First - get info about the new resolution | 250 // 1. First - get info about the new resolution |
260 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); | 251 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); |
261 | 252 |
262 // 2. Change state to started | 253 // 2. Change state to started |
263 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 254 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 host_->OnError(id); | 336 host_->OnError(id); |
346 // Wait for the error callback. | 337 // Wait for the error callback. |
347 message_loop_->RunAllPending(); | 338 message_loop_->RunAllPending(); |
348 } | 339 } |
349 | 340 |
350 scoped_refptr<MockVideoCaptureHost> host_; | 341 scoped_refptr<MockVideoCaptureHost> host_; |
351 | 342 |
352 private: | 343 private: |
353 scoped_ptr<MessageLoop> message_loop_; | 344 scoped_ptr<MessageLoop> message_loop_; |
354 scoped_ptr<BrowserThreadImpl> io_thread_; | 345 scoped_ptr<BrowserThreadImpl> io_thread_; |
355 scoped_ptr<media::AudioManager> audio_manager_; | |
356 scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_; | 346 scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_; |
357 | 347 |
358 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); | 348 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); |
359 }; | 349 }; |
360 | 350 |
361 TEST_F(VideoCaptureHostTest, StartCapture) { | 351 TEST_F(VideoCaptureHostTest, StartCapture) { |
362 StartCapture(); | 352 StartCapture(); |
363 } | 353 } |
364 | 354 |
365 TEST_F(VideoCaptureHostTest, StartCapturePlayStop) { | 355 TEST_F(VideoCaptureHostTest, StartCapturePlayStop) { |
(...skipping 21 matching lines...) Expand all Loading... |
387 } | 377 } |
388 | 378 |
389 #ifdef DUMP_VIDEO | 379 #ifdef DUMP_VIDEO |
390 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 380 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
391 CaptureAndDumpVideo(640, 480, 30); | 381 CaptureAndDumpVideo(640, 480, 30); |
392 } | 382 } |
393 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 383 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
394 CaptureAndDumpVideo(1280, 720, 30); | 384 CaptureAndDumpVideo(1280, 720, 30); |
395 } | 385 } |
396 #endif | 386 #endif |
OLD | NEW |