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

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

Issue 9433006: Remove GetAudioManager and GetMediaStreamManager from ResourceContext. The reason is the content mo… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head Created 8 years, 10 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"
(...skipping 13 matching lines...) Expand all
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 using ::testing::_; 26 using ::testing::_;
27 using ::testing::AtLeast; 27 using ::testing::AtLeast;
28 using ::testing::AnyNumber; 28 using ::testing::AnyNumber;
29 using ::testing::DoAll; 29 using ::testing::DoAll;
30 using ::testing::InSequence; 30 using ::testing::InSequence;
31 using ::testing::Mock; 31 using ::testing::Mock;
32 using ::testing::Return; 32 using ::testing::Return;
33 using content::BrowserThread; 33 using content::BrowserThread;
34
35 using content::BrowserThreadImpl; 34 using content::BrowserThreadImpl;
36 35
37 // Id used to identify the capture session between renderer and 36 // Id used to identify the capture session between renderer and
38 // video_capture_host. 37 // video_capture_host.
39 static const int kDeviceId = 1; 38 static const int kDeviceId = 1;
40 // Id of a video capture device 39 // Id of a video capture device
41 static const media::VideoCaptureSessionId kTestFakeDeviceId = 40 static const media::VideoCaptureSessionId kTestFakeDeviceId =
42 media_stream::VideoCaptureManager::kStartOpenSessionId; 41 media_stream::VideoCaptureManager::kStartOpenSessionId;
43 42
44 // Define to enable test where video is dumped to file. 43 // Define to enable test where video is dumped to file.
(...skipping 19 matching lines...) Expand all
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 explicit MockVideoCaptureHost(content::ResourceContext* resource_context) 73 explicit MockVideoCaptureHost(content::ResourceContext* resource_context,
tommi (sloooow) - chröme 2012/02/23 07:50:59 no need for explicit anymore
jam 2012/02/23 08:05:09 Done.
75 : VideoCaptureHost(resource_context), 74 AudioManager* audio_manager)
75 : VideoCaptureHost(resource_context, audio_manager),
76 return_buffers_(false), 76 return_buffers_(false),
77 dump_video_(false) {} 77 dump_video_(false) {}
78 virtual ~MockVideoCaptureHost() { 78 virtual ~MockVideoCaptureHost() {
79 STLDeleteContainerPairSecondPointers(filled_dib_.begin(), 79 STLDeleteContainerPairSecondPointers(filled_dib_.begin(),
80 filled_dib_.end()); 80 filled_dib_.end());
81 } 81 }
82 82
83 // A list of mock methods. 83 // A list of mock methods.
84 MOCK_METHOD4(OnNewBufferCreated, 84 MOCK_METHOD4(OnNewBufferCreated,
85 void(int device_id, base::SharedMemoryHandle handle, 85 void(int device_id, base::SharedMemoryHandle handle,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // ResourceContext must be created on the UI thread. 199 // ResourceContext must be created on the UI thread.
200 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, 200 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI,
201 message_loop_.get())); 201 message_loop_.get()));
202 202
203 // MediaStreamManager must be created on the IO thread. 203 // MediaStreamManager must be created on the IO thread.
204 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 204 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
205 message_loop_.get())); 205 message_loop_.get()));
206 206
207 audio_manager_.reset(AudioManager::Create()); 207 audio_manager_.reset(AudioManager::Create());
208 208
209 // Create a MediaStreamManager instance and hand over pointer to
210 // ResourceContext.
211 media_stream_manager_.reset(new media_stream::MediaStreamManager(
212 audio_manager_.get()));
213
214 #ifndef TEST_REAL_CAPTURE_DEVICE 209 #ifndef TEST_REAL_CAPTURE_DEVICE
215 media_stream_manager_->UseFakeDevice(); 210 media_stream::MediaStreamManager::GetForResourceContext(
211 &resource_context_, audio_manager_.get())->UseFakeDevice();
216 #endif 212 #endif
217 213
218 resource_context_.set_media_stream_manager(media_stream_manager_.get()); 214 host_ = new MockVideoCaptureHost(&resource_context_, audio_manager_.get());
219 host_ = new MockVideoCaptureHost(&resource_context_);
220 215
221 // Simulate IPC channel connected. 216 // Simulate IPC channel connected.
222 host_->OnChannelConnected(base::GetCurrentProcId()); 217 host_->OnChannelConnected(base::GetCurrentProcId());
223 } 218 }
224 219
225 virtual void TearDown() { 220 virtual void TearDown() {
226 // Verifies and removes the expectations on host_ and 221 // Verifies and removes the expectations on host_ and
227 // returns true iff successful. 222 // returns true iff successful.
228 Mock::VerifyAndClearExpectations(host_); 223 Mock::VerifyAndClearExpectations(host_);
229 224
(...skipping 12 matching lines...) Expand all
242 SyncWithVideoCaptureManagerThread(); 237 SyncWithVideoCaptureManagerThread();
243 } 238 }
244 239
245 // Called on the VideoCaptureManager thread. 240 // Called on the VideoCaptureManager thread.
246 static void PostQuitMessageLoop(MessageLoop* message_loop) { 241 static void PostQuitMessageLoop(MessageLoop* message_loop) {
247 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 242 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
248 } 243 }
249 244
250 // Called on the main thread. 245 // Called on the main thread.
251 static void PostQuitOnVideoCaptureManagerThread( 246 static void PostQuitOnVideoCaptureManagerThread(
252 MessageLoop* message_loop, content::ResourceContext* resource_context) { 247 MessageLoop* message_loop, content::ResourceContext* resource_context,
253 resource_context->GetMediaStreamManager()->video_capture_manager()-> 248 AudioManager* audio_manager) {
254 GetMessageLoop()->PostTask(FROM_HERE, 249 media_stream::MediaStreamManager* manager =
255 base::Bind(&PostQuitMessageLoop, 250 media_stream::MediaStreamManager::GetForResourceContext(
256 message_loop)); 251 resource_context, audio_manager);
252 manager->video_capture_manager()->GetMessageLoop()->PostTask(
253 FROM_HERE, base::Bind(&PostQuitMessageLoop, message_loop));
257 } 254 }
258 255
259 // SyncWithVideoCaptureManagerThread() waits until all pending tasks on the 256 // SyncWithVideoCaptureManagerThread() waits until all pending tasks on the
260 // video_capture_manager thread are executed while also processing pending 257 // video_capture_manager thread are executed while also processing pending
261 // task in message_loop_ on the current thread. It is used to synchronize 258 // task in message_loop_ on the current thread. It is used to synchronize
262 // with the video capture manager thread when we are stopping a video 259 // with the video capture manager thread when we are stopping a video
263 // capture device. 260 // capture device.
264 void SyncWithVideoCaptureManagerThread() { 261 void SyncWithVideoCaptureManagerThread() {
265 message_loop_->PostTask( 262 message_loop_->PostTask(
266 FROM_HERE, 263 FROM_HERE,
267 base::Bind(&PostQuitOnVideoCaptureManagerThread, 264 base::Bind(&PostQuitOnVideoCaptureManagerThread, message_loop_.get(),
268 message_loop_.get(), &resource_context_)); 265 &resource_context_, audio_manager_.get()));
269 message_loop_->Run(); 266 message_loop_->Run();
270 } 267 }
271 268
272 void StartCapture() { 269 void StartCapture() {
273 InSequence s; 270 InSequence s;
274 // 1. First - get info about the new resolution 271 // 1. First - get info about the new resolution
275 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); 272 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId));
276 273
277 // 2. Change state to started 274 // 2. Change state to started
278 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, 275 EXPECT_CALL(*host_, OnStateChanged(kDeviceId,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 host_->OnError(id); 354 host_->OnError(id);
358 SyncWithVideoCaptureManagerThread(); 355 SyncWithVideoCaptureManagerThread();
359 } 356 }
360 357
361 scoped_refptr<MockVideoCaptureHost> host_; 358 scoped_refptr<MockVideoCaptureHost> host_;
362 359
363 private: 360 private:
364 scoped_ptr<MessageLoop> message_loop_; 361 scoped_ptr<MessageLoop> message_loop_;
365 scoped_ptr<BrowserThreadImpl> ui_thread_; 362 scoped_ptr<BrowserThreadImpl> ui_thread_;
366 scoped_ptr<BrowserThreadImpl> io_thread_; 363 scoped_ptr<BrowserThreadImpl> io_thread_;
367 scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_;
368 scoped_ptr<AudioManager> audio_manager_; 364 scoped_ptr<AudioManager> audio_manager_;
369 content::MockResourceContext resource_context_; 365 content::MockResourceContext resource_context_;
370 366
371 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); 367 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest);
372 }; 368 };
373 369
374 TEST_F(VideoCaptureHostTest, StartCapture) { 370 TEST_F(VideoCaptureHostTest, StartCapture) {
375 StartCapture(); 371 StartCapture();
376 } 372 }
377 373
(...skipping 22 matching lines...) Expand all
400 } 396 }
401 397
402 #ifdef DUMP_VIDEO 398 #ifdef DUMP_VIDEO
403 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { 399 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) {
404 CaptureAndDumpVideo(640, 480, 30); 400 CaptureAndDumpVideo(640, 480, 30);
405 } 401 }
406 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { 402 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) {
407 CaptureAndDumpVideo(1280, 720, 30); 403 CaptureAndDumpVideo(1280, 720, 30);
408 } 404 }
409 #endif 405 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698