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" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 216 |
217 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); | 217 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); |
218 | 218 |
219 // Simulate IPC channel connected. | 219 // Simulate IPC channel connected. |
220 host_->OnChannelConnected(base::GetCurrentProcId()); | 220 host_->OnChannelConnected(base::GetCurrentProcId()); |
221 } | 221 } |
222 | 222 |
223 virtual void TearDown() OVERRIDE { | 223 virtual void TearDown() OVERRIDE { |
224 // Verifies and removes the expectations on host_ and | 224 // Verifies and removes the expectations on host_ and |
225 // returns true iff successful. | 225 // returns true iff successful. |
226 Mock::VerifyAndClearExpectations(host_); | 226 Mock::VerifyAndClearExpectations(host_.get()); |
227 | 227 |
228 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 228 EXPECT_CALL(*host_.get(), |
229 VIDEO_CAPTURE_STATE_STOPPED)) | 229 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)) |
230 .Times(AnyNumber()); | 230 .Times(AnyNumber()); |
231 | 231 |
232 // Simulate closing the IPC channel. | 232 // Simulate closing the IPC channel. |
233 host_->OnChannelClosing(); | 233 host_->OnChannelClosing(); |
234 | 234 |
235 // Release the reference to the mock object. The object will be destructed | 235 // Release the reference to the mock object. The object will be destructed |
236 // on message_loop_. | 236 // on message_loop_. |
237 host_ = NULL; | 237 host_ = NULL; |
238 | 238 |
239 // We need to continue running message_loop_ to complete all destructions. | 239 // We need to continue running message_loop_ to complete all destructions. |
240 message_loop_->RunUntilIdle(); | 240 message_loop_->RunUntilIdle(); |
241 | 241 |
242 // Delete the IO message loop. This will cause the MediaStreamManager to be | 242 // Delete the IO message loop. This will cause the MediaStreamManager to be |
243 // notified so it will stop its device thread and device managers. | 243 // notified so it will stop its device thread and device managers. |
244 message_loop_.reset(); | 244 message_loop_.reset(); |
245 } | 245 } |
246 | 246 |
247 void StartCapture() { | 247 void StartCapture() { |
248 InSequence s; | 248 InSequence s; |
249 // 1. First - get info about the new resolution | 249 // 1. First - get info about the new resolution |
250 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); | 250 EXPECT_CALL(*host_.get(), OnDeviceInfo(kDeviceId)); |
251 | 251 |
252 // 2. Change state to started | 252 // 2. Change state to started |
253 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 253 EXPECT_CALL(*host_.get(), |
254 VIDEO_CAPTURE_STATE_STARTED)); | 254 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STARTED)); |
255 | 255 |
256 // 3. Newly created buffers will arrive. | 256 // 3. Newly created buffers will arrive. |
257 EXPECT_CALL(*host_, OnNewBufferCreated(kDeviceId, _, _, _)) | 257 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) |
258 .Times(AnyNumber()) | 258 .Times(AnyNumber()).WillRepeatedly(Return()); |
259 .WillRepeatedly(Return()); | |
260 | 259 |
261 // 4. First filled buffer will arrive. | 260 // 4. First filled buffer will arrive. |
262 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _)) | 261 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _)) |
263 .Times(AnyNumber()) | 262 .Times(AnyNumber()).WillOnce(ExitMessageLoop(message_loop_.get())); |
264 .WillOnce(ExitMessageLoop(message_loop_.get())); | |
265 | 263 |
266 media::VideoCaptureParams params; | 264 media::VideoCaptureParams params; |
267 params.width = 352; | 265 params.width = 352; |
268 params.height = 288; | 266 params.height = 288; |
269 params.frame_per_second = 30; | 267 params.frame_per_second = 30; |
270 params.session_id = kTestFakeDeviceId; | 268 params.session_id = kTestFakeDeviceId; |
271 host_->OnStartCapture(kDeviceId, params); | 269 host_->OnStartCapture(kDeviceId, params); |
272 message_loop_->Run(); | 270 message_loop_->Run(); |
273 } | 271 } |
274 | 272 |
(...skipping 16 matching lines...) Expand all Loading... |
291 params.height = heigt; | 289 params.height = heigt; |
292 params.frame_per_second = frame_rate; | 290 params.frame_per_second = frame_rate; |
293 params.session_id = kTestFakeDeviceId; | 291 params.session_id = kTestFakeDeviceId; |
294 host_->SetDumpVideo(true); | 292 host_->SetDumpVideo(true); |
295 host_->OnStartCapture(kDeviceId, params); | 293 host_->OnStartCapture(kDeviceId, params); |
296 message_loop_->Run(); | 294 message_loop_->Run(); |
297 } | 295 } |
298 #endif | 296 #endif |
299 | 297 |
300 void StopCapture() { | 298 void StopCapture() { |
301 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 299 EXPECT_CALL(*host_.get(), |
302 VIDEO_CAPTURE_STATE_STOPPED)) | 300 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)) |
303 .WillOnce(ExitMessageLoop(message_loop_.get())); | 301 .WillOnce(ExitMessageLoop(message_loop_.get())); |
304 | 302 |
305 host_->OnStopCapture(kDeviceId); | 303 host_->OnStopCapture(kDeviceId); |
306 host_->SetReturnReceviedDibs(true); | 304 host_->SetReturnReceviedDibs(true); |
307 host_->ReturnReceivedDibs(kDeviceId); | 305 host_->ReturnReceivedDibs(kDeviceId); |
308 | 306 |
309 message_loop_->Run(); | 307 message_loop_->Run(); |
310 | 308 |
311 host_->SetReturnReceviedDibs(false); | 309 host_->SetReturnReceviedDibs(false); |
312 // Expect the VideoCaptureDevice has been stopped | 310 // Expect the VideoCaptureDevice has been stopped |
313 EXPECT_EQ(0u, host_->entries_.size()); | 311 EXPECT_EQ(0u, host_->entries_.size()); |
314 } | 312 } |
315 | 313 |
316 void NotifyPacketReady() { | 314 void NotifyPacketReady() { |
317 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _)) | 315 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _)) |
318 .Times(AnyNumber()) | 316 .Times(AnyNumber()).WillOnce(ExitMessageLoop(message_loop_.get())) |
319 .WillOnce(ExitMessageLoop(message_loop_.get())) | |
320 .RetiresOnSaturation(); | 317 .RetiresOnSaturation(); |
321 message_loop_->Run(); | 318 message_loop_->Run(); |
322 } | 319 } |
323 | 320 |
324 void ReturnReceivedPackets() { | 321 void ReturnReceivedPackets() { |
325 host_->ReturnReceivedDibs(kDeviceId); | 322 host_->ReturnReceivedDibs(kDeviceId); |
326 } | 323 } |
327 | 324 |
328 void SimulateError() { | 325 void SimulateError() { |
329 // Expect a change state to error state sent through IPC. | 326 // Expect a change state to error state sent through IPC. |
330 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_ERROR)) | 327 EXPECT_CALL(*host_.get(), |
331 .Times(1); | 328 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_ERROR)).Times(1); |
332 VideoCaptureControllerID id(kDeviceId); | 329 VideoCaptureControllerID id(kDeviceId); |
333 host_->OnError(id); | 330 host_->OnError(id); |
334 // Wait for the error callback. | 331 // Wait for the error callback. |
335 message_loop_->RunUntilIdle(); | 332 message_loop_->RunUntilIdle(); |
336 } | 333 } |
337 | 334 |
338 scoped_refptr<MockVideoCaptureHost> host_; | 335 scoped_refptr<MockVideoCaptureHost> host_; |
339 | 336 |
340 private: | 337 private: |
341 scoped_ptr<base::MessageLoop> message_loop_; | 338 scoped_ptr<base::MessageLoop> message_loop_; |
(...skipping 16 matching lines...) Expand all Loading... |
358 StopCapture(); | 355 StopCapture(); |
359 } | 356 } |
360 | 357 |
361 TEST_F(VideoCaptureHostTest, StartCaptureErrorStop) { | 358 TEST_F(VideoCaptureHostTest, StartCaptureErrorStop) { |
362 StartCapture(); | 359 StartCapture(); |
363 SimulateError(); | 360 SimulateError(); |
364 StopCapture(); | 361 StopCapture(); |
365 } | 362 } |
366 | 363 |
367 TEST_F(VideoCaptureHostTest, StartCaptureError) { | 364 TEST_F(VideoCaptureHostTest, StartCaptureError) { |
368 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 365 EXPECT_CALL(*host_.get(), |
369 VIDEO_CAPTURE_STATE_STOPPED)) | 366 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)).Times(0); |
370 .Times(0); | |
371 StartCapture(); | 367 StartCapture(); |
372 NotifyPacketReady(); | 368 NotifyPacketReady(); |
373 SimulateError(); | 369 SimulateError(); |
374 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); | 370 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); |
375 } | 371 } |
376 | 372 |
377 #ifdef DUMP_VIDEO | 373 #ifdef DUMP_VIDEO |
378 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 374 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
379 CaptureAndDumpVideo(640, 480, 30); | 375 CaptureAndDumpVideo(640, 480, 30); |
380 } | 376 } |
381 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 377 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
382 CaptureAndDumpVideo(1280, 720, 30); | 378 CaptureAndDumpVideo(1280, 720, 30); |
383 } | 379 } |
384 #endif | 380 #endif |
385 | 381 |
386 } // namespace content | 382 } // namespace content |
OLD | NEW |