OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_manager.h" |
15 #include "content/browser/renderer_host/media/video_capture_host.h" | 16 #include "content/browser/renderer_host/media/video_capture_host.h" |
16 #include "content/browser/renderer_host/media/video_capture_manager.h" | 17 #include "content/browser/renderer_host/media/video_capture_manager.h" |
17 #include "content/common/media/video_capture_messages.h" | 18 #include "content/common/media/video_capture_messages.h" |
18 #include "media/video/capture/video_capture_types.h" | 19 #include "media/video/capture/video_capture_types.h" |
19 | 20 |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using ::testing::_; | 24 using ::testing::_; |
24 using ::testing::AtLeast; | 25 using ::testing::AtLeast; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 ACTION_P(ExitMessageLoop, message_loop) { | 181 ACTION_P(ExitMessageLoop, message_loop) { |
181 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 182 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
182 } | 183 } |
183 | 184 |
184 class VideoCaptureHostTest : public testing::Test { | 185 class VideoCaptureHostTest : public testing::Test { |
185 public: | 186 public: |
186 VideoCaptureHostTest() {} | 187 VideoCaptureHostTest() {} |
187 | 188 |
188 protected: | 189 protected: |
189 virtual void SetUp() { | 190 virtual void SetUp() { |
| 191 // Create a message loop so VideoCaptureHostTest can use it. |
| 192 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
| 193 io_thread_.reset(new BrowserThread(BrowserThread::IO, message_loop_.get())); |
190 // Setup the VideoCaptureManager to use fake video capture device. | 194 // Setup the VideoCaptureManager to use fake video capture device. |
191 #ifndef TEST_REAL_CAPTURE_DEVICE | 195 #ifndef TEST_REAL_CAPTURE_DEVICE |
192 media_stream::VideoCaptureManager* manager = | 196 media_stream::VideoCaptureManager* manager = |
193 media_stream::VideoCaptureManager::Get(); | 197 media_stream::MediaStreamManager::Get()->video_capture_manager(); |
194 manager->UseFakeDevice(); | 198 manager->UseFakeDevice(); |
195 #endif | 199 #endif |
196 // Create a message loop so VideoCaptureHostTest can use it. | |
197 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | |
198 io_thread_.reset(new BrowserThread(BrowserThread::IO, message_loop_.get())); | |
199 host_ = new MockVideoCaptureHost(); | 200 host_ = new MockVideoCaptureHost(); |
200 | 201 |
201 // Simulate IPC channel connected. | 202 // Simulate IPC channel connected. |
202 host_->OnChannelConnected(base::GetCurrentProcId()); | 203 host_->OnChannelConnected(base::GetCurrentProcId()); |
203 } | 204 } |
204 | 205 |
205 virtual void TearDown() { | 206 virtual void TearDown() { |
206 // Verifies and removes the expectations on host_ and | 207 // Verifies and removes the expectations on host_ and |
207 // returns true iff successful. | 208 // returns true iff successful. |
208 Mock::VerifyAndClearExpectations(host_); | 209 Mock::VerifyAndClearExpectations(host_); |
(...skipping 15 matching lines...) Expand all Loading... |
224 io_thread_.reset(); | 225 io_thread_.reset(); |
225 } | 226 } |
226 | 227 |
227 // Called on the VideoCaptureManager thread. | 228 // Called on the VideoCaptureManager thread. |
228 static void PostQuitMessageLoop(MessageLoop* message_loop) { | 229 static void PostQuitMessageLoop(MessageLoop* message_loop) { |
229 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 230 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
230 } | 231 } |
231 | 232 |
232 // Called on the main thread. | 233 // Called on the main thread. |
233 static void PostQuitOnVideoCaptureManagerThread(MessageLoop* message_loop) { | 234 static void PostQuitOnVideoCaptureManagerThread(MessageLoop* message_loop) { |
234 media_stream::VideoCaptureManager::Get()->GetMessageLoop()->PostTask( | 235 media_stream::MediaStreamManager::Get()->video_capture_manager()-> |
235 FROM_HERE, NewRunnableFunction(&PostQuitMessageLoop, message_loop)); | 236 GetMessageLoop()->PostTask(FROM_HERE, |
| 237 NewRunnableFunction( |
| 238 &PostQuitMessageLoop, message_loop)); |
236 } | 239 } |
237 | 240 |
238 // SyncWithVideoCaptureManagerThread() waits until all pending tasks on the | 241 // SyncWithVideoCaptureManagerThread() waits until all pending tasks on the |
239 // video_capture_manager thread are executed while also processing pending | 242 // video_capture_manager thread are executed while also processing pending |
240 // task in message_loop_ on the current thread. It is used to synchronize | 243 // task in message_loop_ on the current thread. It is used to synchronize |
241 // with the video capture manager thread when we are stopping a video | 244 // with the video capture manager thread when we are stopping a video |
242 // capture device. | 245 // capture device. |
243 void SyncWithVideoCaptureManagerThread() { | 246 void SyncWithVideoCaptureManagerThread() { |
244 message_loop_->PostTask( | 247 message_loop_->PostTask( |
245 FROM_HERE, NewRunnableFunction(&PostQuitOnVideoCaptureManagerThread, | 248 FROM_HERE, NewRunnableFunction(&PostQuitOnVideoCaptureManagerThread, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 376 } |
374 | 377 |
375 #ifdef DUMP_VIDEO | 378 #ifdef DUMP_VIDEO |
376 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 379 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
377 CaptureAndDumpVideo(640, 480, 30); | 380 CaptureAndDumpVideo(640, 480, 30); |
378 } | 381 } |
379 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 382 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
380 CaptureAndDumpVideo(1280, 720, 30); | 383 CaptureAndDumpVideo(1280, 720, 30); |
381 } | 384 } |
382 #endif | 385 #endif |
OLD | NEW |