| 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" |
| 21 #include "content/public/test/mock_resource_context.h" | 20 #include "content/public/test/mock_resource_context.h" |
| 22 #include "media/audio/audio_manager.h" | 21 #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" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 audio_manager_.reset(media::AudioManager::Create()); |
| 215 scoped_refptr<media_stream::AudioInputDeviceManager> | 214 media_stream_manager_.reset( |
| 216 audio_input_device_manager( | 215 new media_stream::MediaStreamManager(audio_manager_.get())); |
| 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 | 216 #ifndef TEST_REAL_CAPTURE_DEVICE |
| 224 media_stream_manager_->UseFakeDevice(); | 217 media_stream_manager_->UseFakeDevice(); |
| 225 #endif | 218 #endif |
| 226 | 219 |
| 227 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); | 220 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); |
| 228 | 221 |
| 229 // Simulate IPC channel connected. | 222 // Simulate IPC channel connected. |
| 230 host_->OnChannelConnected(base::GetCurrentProcId()); | 223 host_->OnChannelConnected(base::GetCurrentProcId()); |
| 231 } | 224 } |
| 232 | 225 |
| 233 virtual void TearDown() OVERRIDE { | 226 virtual void TearDown() OVERRIDE { |
| 234 // Verifies and removes the expectations on host_ and | 227 // Verifies and removes the expectations on host_ and |
| 235 // returns true iff successful. | 228 // returns true iff successful. |
| 236 Mock::VerifyAndClearExpectations(host_); | 229 Mock::VerifyAndClearExpectations(host_); |
| 237 | 230 |
| 238 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 231 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, |
| 239 video_capture::kStopped)) | 232 video_capture::kStopped)) |
| 240 .Times(AnyNumber()); | 233 .Times(AnyNumber()); |
| 241 | 234 |
| 242 // Simulate closing the IPC channel. | 235 // Simulate closing the IPC channel. |
| 243 host_->OnChannelClosing(); | 236 host_->OnChannelClosing(); |
| 244 | 237 |
| 245 // Release the reference to the mock object. The object will be destructed | 238 // Release the reference to the mock object. The object will be destructed |
| 246 // on message_loop_. | 239 // on message_loop_. |
| 247 host_ = NULL; | 240 host_ = NULL; |
| 248 | 241 |
| 249 // We need to continue running message_loop_ to complete all destructions. | 242 // We need to continue running message_loop_ to complete all destructions. |
| 250 message_loop_->RunAllPending(); | 243 message_loop_->RunAllPending(); |
| 251 | 244 |
| 252 // Delete the IO message loop to delete the device thread, | 245 // Delete the IO message loop. This will cause the MediaStreamManager to be |
| 253 // AudioInputDeviceManager and VideoCaptureManager. | 246 // notified so it will stop its device thread and device managers. |
| 254 message_loop_.reset(); | 247 message_loop_.reset(); |
| 255 } | 248 } |
| 256 | 249 |
| 257 void StartCapture() { | 250 void StartCapture() { |
| 258 InSequence s; | 251 InSequence s; |
| 259 // 1. First - get info about the new resolution | 252 // 1. First - get info about the new resolution |
| 260 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); | 253 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); |
| 261 | 254 |
| 262 // 2. Change state to started | 255 // 2. Change state to started |
| 263 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 256 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 380 } |
| 388 | 381 |
| 389 #ifdef DUMP_VIDEO | 382 #ifdef DUMP_VIDEO |
| 390 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 383 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
| 391 CaptureAndDumpVideo(640, 480, 30); | 384 CaptureAndDumpVideo(640, 480, 30); |
| 392 } | 385 } |
| 393 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 386 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
| 394 CaptureAndDumpVideo(1280, 720, 30); | 387 CaptureAndDumpVideo(1280, 720, 30); |
| 395 } | 388 } |
| 396 #endif | 389 #endif |
| OLD | NEW |