Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: content/browser/renderer_host/media/video_capture_host_unittest.cc

Issue 10662049: Move the device enumerate/open/close work to device thread from IO thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready for review. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/media_stream_manager.h" 16 #include "content/browser/renderer_host/media/media_stream_manager.h"
17 #include "content/browser/renderer_host/media/video_capture_host.h" 17 #include "content/browser/renderer_host/media/video_capture_host.h"
18 #include "content/browser/renderer_host/media/video_capture_manager.h" 18 #include "content/browser/renderer_host/media/video_capture_manager.h"
19 #include "content/common/media/video_capture_messages.h" 19 #include "content/common/media/video_capture_messages.h"
20 #include "content/public/test/mock_resource_context.h" 20 #include "content/public/test/mock_resource_context.h"
21 #include "media/audio/audio_manager.h"
22 #include "media/video/capture/video_capture_types.h" 21 #include "media/video/capture/video_capture_types.h"
23 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
24 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
26 25
27 using ::testing::_; 26 using ::testing::_;
28 using ::testing::AtLeast; 27 using ::testing::AtLeast;
29 using ::testing::AnyNumber; 28 using ::testing::AnyNumber;
30 using ::testing::DoAll; 29 using ::testing::DoAll;
31 using ::testing::InSequence; 30 using ::testing::InSequence;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 63 }
65 } 64 }
66 65
67 private: 66 private:
68 file_util::ScopedFILE file_; 67 file_util::ScopedFILE file_;
69 int expected_size_; 68 int expected_size_;
70 }; 69 };
71 70
72 class MockVideoCaptureHost : public VideoCaptureHost { 71 class MockVideoCaptureHost : public VideoCaptureHost {
73 public: 72 public:
74 MockVideoCaptureHost(content::ResourceContext* resource_context, 73 MockVideoCaptureHost(content::ResourceContext* resource_context)
75 media::AudioManager* audio_manager) 74 : VideoCaptureHost(resource_context),
76 : VideoCaptureHost(resource_context, audio_manager),
77 return_buffers_(false), 75 return_buffers_(false),
78 dump_video_(false) {} 76 dump_video_(false) {}
79 77
80 // A list of mock methods. 78 // A list of mock methods.
81 MOCK_METHOD4(OnNewBufferCreated, 79 MOCK_METHOD4(OnNewBufferCreated,
82 void(int device_id, base::SharedMemoryHandle handle, 80 void(int device_id, base::SharedMemoryHandle handle,
83 int length, int buffer_id)); 81 int length, int buffer_id));
84 MOCK_METHOD3(OnBufferFilled, 82 MOCK_METHOD3(OnBufferFilled,
85 void(int device_id, int buffer_id, base::Time timestamp)); 83 void(int device_id, int buffer_id, base::Time timestamp));
86 MOCK_METHOD2(OnStateChanged, 84 MOCK_METHOD2(OnStateChanged,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); 199 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
202 200
203 // ResourceContext must be created on the UI thread. 201 // ResourceContext must be created on the UI thread.
204 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, 202 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI,
205 message_loop_.get())); 203 message_loop_.get()));
206 204
207 // MediaStreamManager must be created on the IO thread. 205 // MediaStreamManager must be created on the IO thread.
208 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 206 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
209 message_loop_.get())); 207 message_loop_.get()));
210 208
211 audio_manager_.reset(media::AudioManager::Create());
212
213 #ifndef TEST_REAL_CAPTURE_DEVICE 209 #ifndef TEST_REAL_CAPTURE_DEVICE
214 media_stream::MediaStreamManager::GetForResourceContext( 210 media_stream::MediaStreamManager::GetForResourceContext(
215 &resource_context_, audio_manager_.get())->UseFakeDevice(); 211 &resource_context_)->UseFakeDevice();
216 #endif 212 #endif
217 213
218 host_ = new MockVideoCaptureHost(&resource_context_, audio_manager_.get()); 214 host_ = new MockVideoCaptureHost(&resource_context_);
219 215
220 // Simulate IPC channel connected. 216 // Simulate IPC channel connected.
221 host_->OnChannelConnected(base::GetCurrentProcId()); 217 host_->OnChannelConnected(base::GetCurrentProcId());
222 } 218 }
223 219
224 virtual void TearDown() { 220 virtual void TearDown() {
225 // Verifies and removes the expectations on host_ and 221 // Verifies and removes the expectations on host_ and
226 // returns true iff successful. 222 // returns true iff successful.
227 Mock::VerifyAndClearExpectations(host_); 223 Mock::VerifyAndClearExpectations(host_);
228 224
(...skipping 12 matching lines...) Expand all
241 SyncWithVideoCaptureManagerThread(); 237 SyncWithVideoCaptureManagerThread();
242 } 238 }
243 239
244 // Called on the VideoCaptureManager thread. 240 // Called on the VideoCaptureManager thread.
245 static void PostQuitMessageLoop(MessageLoop* message_loop) { 241 static void PostQuitMessageLoop(MessageLoop* message_loop) {
246 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 242 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
247 } 243 }
248 244
249 // Called on the main thread. 245 // Called on the main thread.
250 static void PostQuitOnVideoCaptureManagerThread( 246 static void PostQuitOnVideoCaptureManagerThread(
251 MessageLoop* message_loop, content::ResourceContext* resource_context, 247 MessageLoop* message_loop, content::ResourceContext* resource_context) {
252 media:: AudioManager* audio_manager) {
253 media_stream::MediaStreamManager* manager = 248 media_stream::MediaStreamManager* manager =
254 media_stream::MediaStreamManager::GetForResourceContext( 249 media_stream::MediaStreamManager::GetForResourceContext(
255 resource_context, audio_manager); 250 resource_context);
256 manager->video_capture_manager()->GetMessageLoop()->PostTask( 251 manager->GetMessageLoop()->PostTask(
257 FROM_HERE, base::Bind(&PostQuitMessageLoop, message_loop)); 252 FROM_HERE, base::Bind(&PostQuitMessageLoop, message_loop));
258 } 253 }
259 254
260 // SyncWithVideoCaptureManagerThread() waits until all pending tasks on the 255 // SyncWithVideoCaptureManagerThread() waits until all pending tasks on the
261 // video_capture_manager thread are executed while also processing pending 256 // video_capture_manager thread are executed while also processing pending
262 // task in message_loop_ on the current thread. It is used to synchronize 257 // task in message_loop_ on the current thread. It is used to synchronize
263 // with the video capture manager thread when we are stopping a video 258 // with the video capture manager thread when we are stopping a video
264 // capture device. 259 // capture device.
265 void SyncWithVideoCaptureManagerThread() { 260 void SyncWithVideoCaptureManagerThread() {
266 message_loop_->PostTask( 261 message_loop_->PostTask(
267 FROM_HERE, 262 FROM_HERE,
268 base::Bind(&PostQuitOnVideoCaptureManagerThread, message_loop_.get(), 263 base::Bind(&PostQuitOnVideoCaptureManagerThread, message_loop_.get(),
269 &resource_context_, audio_manager_.get())); 264 &resource_context_));
270 message_loop_->Run(); 265 message_loop_->Run();
271 } 266 }
272 267
273 void StartCapture() { 268 void StartCapture() {
274 InSequence s; 269 InSequence s;
275 // 1. First - get info about the new resolution 270 // 1. First - get info about the new resolution
276 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); 271 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId));
277 272
278 // 2. Change state to started 273 // 2. Change state to started
279 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, 274 EXPECT_CALL(*host_, OnStateChanged(kDeviceId,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 host_->OnError(id); 353 host_->OnError(id);
359 SyncWithVideoCaptureManagerThread(); 354 SyncWithVideoCaptureManagerThread();
360 } 355 }
361 356
362 scoped_refptr<MockVideoCaptureHost> host_; 357 scoped_refptr<MockVideoCaptureHost> host_;
363 358
364 private: 359 private:
365 scoped_ptr<MessageLoop> message_loop_; 360 scoped_ptr<MessageLoop> message_loop_;
366 scoped_ptr<BrowserThreadImpl> ui_thread_; 361 scoped_ptr<BrowserThreadImpl> ui_thread_;
367 scoped_ptr<BrowserThreadImpl> io_thread_; 362 scoped_ptr<BrowserThreadImpl> io_thread_;
368 scoped_ptr<media::AudioManager> audio_manager_;
369 content::MockResourceContext resource_context_; 363 content::MockResourceContext resource_context_;
370 364
371 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); 365 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest);
372 }; 366 };
373 367
374 TEST_F(VideoCaptureHostTest, StartCapture) { 368 TEST_F(VideoCaptureHostTest, StartCapture) {
375 StartCapture(); 369 StartCapture();
376 } 370 }
377 371
378 TEST_F(VideoCaptureHostTest, StartCapturePlayStop) { 372 TEST_F(VideoCaptureHostTest, StartCapturePlayStop) {
(...skipping 21 matching lines...) Expand all
400 } 394 }
401 395
402 #ifdef DUMP_VIDEO 396 #ifdef DUMP_VIDEO
403 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { 397 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) {
404 CaptureAndDumpVideo(640, 480, 30); 398 CaptureAndDumpVideo(640, 480, 30);
405 } 399 }
406 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { 400 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) {
407 CaptureAndDumpVideo(1280, 720, 30); 401 CaptureAndDumpVideo(1280, 720, 30);
408 } 402 }
409 #endif 403 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698