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

Side by Side Diff: media/capture/video/video_capture_device_unittest.cc

Issue 2673373003: getUserMeida: report device starting states (Closed)
Patch Set: address comments on PS#8 Created 3 years, 9 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
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 "media/capture/video/video_capture_device.h" 5 #include "media/capture/video/video_capture_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 class MockVideoCaptureClient : public VideoCaptureDevice::Client { 94 class MockVideoCaptureClient : public VideoCaptureDevice::Client {
95 public: 95 public:
96 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); 96 MOCK_METHOD0(DoReserveOutputBuffer, void(void));
97 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); 97 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void));
98 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); 98 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void));
99 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); 99 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void));
100 MOCK_METHOD2(OnError, 100 MOCK_METHOD2(OnError,
101 void(const tracked_objects::Location& from_here, 101 void(const tracked_objects::Location& from_here,
102 const std::string& reason)); 102 const std::string& reason));
103 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); 103 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void));
104 MOCK_METHOD0(OnStarted, void(void));
104 105
105 explicit MockVideoCaptureClient( 106 explicit MockVideoCaptureClient(
106 base::Callback<void(const VideoCaptureFormat&)> frame_cb) 107 base::Callback<void(const VideoCaptureFormat&)> frame_cb)
107 : main_thread_(base::ThreadTaskRunnerHandle::Get()), frame_cb_(frame_cb) { 108 : main_thread_(base::ThreadTaskRunnerHandle::Get()), frame_cb_(frame_cb) {
108 ON_CALL(*this, OnError(_, _)).WillByDefault(Invoke(DumpError)); 109 ON_CALL(*this, OnError(_, _)).WillByDefault(Invoke(DumpError));
109 } 110 }
110 111
111 void OnIncomingCapturedData(const uint8_t* data, 112 void OnIncomingCapturedData(const uint8_t* data,
112 int length, 113 int length,
113 const VideoCaptureFormat& format, 114 const VideoCaptureFormat& format,
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 return; 400 return;
400 const int width = size.width(); 401 const int width = size.width();
401 const int height = size.height(); 402 const int height = size.height();
402 403
403 std::unique_ptr<VideoCaptureDevice> device( 404 std::unique_ptr<VideoCaptureDevice> device(
404 video_capture_device_factory_->CreateDevice( 405 video_capture_device_factory_->CreateDevice(
405 device_descriptors_->front())); 406 device_descriptors_->front()));
406 ASSERT_TRUE(device); 407 ASSERT_TRUE(device);
407 408
408 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 409 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
410 EXPECT_CALL(*video_capture_client_, OnStarted());
409 411
410 VideoCaptureParams capture_params; 412 VideoCaptureParams capture_params;
411 capture_params.requested_format.frame_size.SetSize(width, height); 413 capture_params.requested_format.frame_size.SetSize(width, height);
412 capture_params.requested_format.frame_rate = 30.0f; 414 capture_params.requested_format.frame_rate = 30.0f;
413 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 415 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
414 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 416 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
415 417
416 WaitForCapturedFrame(); 418 WaitForCapturedFrame();
417 EXPECT_EQ(last_format().frame_size.width(), width); 419 EXPECT_EQ(last_format().frame_size.width(), width);
418 EXPECT_EQ(last_format().frame_size.height(), height); 420 EXPECT_EQ(last_format().frame_size.height(), height);
(...skipping 14 matching lines...) Expand all
433 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 435 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
434 if (!EnumerateAndFindUsableDevices()) 436 if (!EnumerateAndFindUsableDevices())
435 return; 437 return;
436 438
437 std::unique_ptr<VideoCaptureDevice> device( 439 std::unique_ptr<VideoCaptureDevice> device(
438 video_capture_device_factory_->CreateDevice( 440 video_capture_device_factory_->CreateDevice(
439 device_descriptors_->front())); 441 device_descriptors_->front()));
440 ASSERT_TRUE(device); 442 ASSERT_TRUE(device);
441 443
442 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 444 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
445 EXPECT_CALL(*video_capture_client_, OnStarted());
443 446
444 const gfx::Size input_size(640, 480); 447 const gfx::Size input_size(640, 480);
445 VideoCaptureParams capture_params; 448 VideoCaptureParams capture_params;
446 capture_params.requested_format.frame_size.SetSize(637, 472); 449 capture_params.requested_format.frame_size.SetSize(637, 472);
447 capture_params.requested_format.frame_rate = 35; 450 capture_params.requested_format.frame_rate = 35;
448 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 451 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
449 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 452 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
450 WaitForCapturedFrame(); 453 WaitForCapturedFrame();
451 device->StopAndDeAllocate(); 454 device->StopAndDeAllocate();
452 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); 455 EXPECT_EQ(last_format().frame_size.width(), input_size.width());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 VLOG(1) << "Skipped on Win10: http://crbug.com/570604, current: " 516 VLOG(1) << "Skipped on Win10: http://crbug.com/570604, current: "
514 << static_cast<int>(version); 517 << static_cast<int>(version);
515 return; 518 return;
516 } 519 }
517 #endif 520 #endif
518 std::unique_ptr<VideoCaptureDevice> device( 521 std::unique_ptr<VideoCaptureDevice> device(
519 video_capture_device_factory_->CreateDevice(*device_descriptor)); 522 video_capture_device_factory_->CreateDevice(*device_descriptor));
520 ASSERT_TRUE(device); 523 ASSERT_TRUE(device);
521 524
522 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 525 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
526 EXPECT_CALL(*video_capture_client_, OnStarted());
523 527
524 VideoCaptureParams capture_params; 528 VideoCaptureParams capture_params;
525 capture_params.requested_format.frame_size.SetSize(1280, 720); 529 capture_params.requested_format.frame_size.SetSize(1280, 720);
526 capture_params.requested_format.frame_rate = 30; 530 capture_params.requested_format.frame_rate = 30;
527 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 531 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
528 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 532 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
529 533
530 WaitForCapturedFrame(); 534 WaitForCapturedFrame();
531 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 535 // Verify we get MJPEG from the device. Not all devices can capture 1280x720
532 // @ 30 fps, so we don't care about the exact resolution we get. 536 // @ 30 fps, so we don't care about the exact resolution we get.
(...skipping 26 matching lines...) Expand all
559 return; 563 return;
560 } 564 }
561 #endif 565 #endif
562 566
563 std::unique_ptr<VideoCaptureDevice> device( 567 std::unique_ptr<VideoCaptureDevice> device(
564 video_capture_device_factory_->CreateDevice( 568 video_capture_device_factory_->CreateDevice(
565 device_descriptors_->front())); 569 device_descriptors_->front()));
566 ASSERT_TRUE(device); 570 ASSERT_TRUE(device);
567 571
568 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 572 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
573 EXPECT_CALL(*video_capture_client_, OnStarted());
569 574
570 VideoCaptureParams capture_params; 575 VideoCaptureParams capture_params;
571 capture_params.requested_format.frame_size.SetSize(320, 240); 576 capture_params.requested_format.frame_size.SetSize(320, 240);
572 capture_params.requested_format.frame_rate = 30; 577 capture_params.requested_format.frame_rate = 30;
573 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 578 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
574 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 579 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
575 580
576 VideoCaptureDevice::TakePhotoCallback scoped_callback( 581 VideoCaptureDevice::TakePhotoCallback scoped_callback(
577 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken, 582 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken,
578 image_capture_client_), 583 image_capture_client_),
(...skipping 24 matching lines...) Expand all
603 return; 608 return;
604 } 609 }
605 #endif 610 #endif
606 611
607 std::unique_ptr<VideoCaptureDevice> device( 612 std::unique_ptr<VideoCaptureDevice> device(
608 video_capture_device_factory_->CreateDevice( 613 video_capture_device_factory_->CreateDevice(
609 device_descriptors_->front())); 614 device_descriptors_->front()));
610 ASSERT_TRUE(device); 615 ASSERT_TRUE(device);
611 616
612 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 617 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
618 EXPECT_CALL(*video_capture_client_, OnStarted());
613 619
614 VideoCaptureParams capture_params; 620 VideoCaptureParams capture_params;
615 capture_params.requested_format.frame_size.SetSize(320, 240); 621 capture_params.requested_format.frame_size.SetSize(320, 240);
616 capture_params.requested_format.frame_rate = 30; 622 capture_params.requested_format.frame_rate = 30;
617 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 623 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
618 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 624 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
619 625
620 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback( 626 VideoCaptureDevice::GetPhotoCapabilitiesCallback scoped_get_callback(
621 base::Bind(&MockImageCaptureClient::DoOnGetPhotoCapabilities, 627 base::Bind(&MockImageCaptureClient::DoOnGetPhotoCapabilities,
622 image_capture_client_), 628 image_capture_client_),
623 media::BindToCurrentLoop( 629 media::BindToCurrentLoop(
624 base::Bind(&MockImageCaptureClient::OnGetPhotoCapabilitiesFailure, 630 base::Bind(&MockImageCaptureClient::OnGetPhotoCapabilitiesFailure,
625 image_capture_client_))); 631 image_capture_client_)));
626 632
627 base::RunLoop run_loop; 633 base::RunLoop run_loop;
628 base::Closure quit_closure = media::BindToCurrentLoop(run_loop.QuitClosure()); 634 base::Closure quit_closure = media::BindToCurrentLoop(run_loop.QuitClosure());
629 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities()) 635 EXPECT_CALL(*image_capture_client_.get(), OnCorrectGetPhotoCapabilities())
630 .Times(1) 636 .Times(1)
631 .WillOnce(RunClosure(quit_closure)); 637 .WillOnce(RunClosure(quit_closure));
632 638
633 device->GetPhotoCapabilities(std::move(scoped_get_callback)); 639 device->GetPhotoCapabilities(std::move(scoped_get_callback));
634 run_loop.Run(); 640 run_loop.Run();
635 641
636 ASSERT_TRUE(image_capture_client_->capabilities()); 642 ASSERT_TRUE(image_capture_client_->capabilities());
637 643
638 device->StopAndDeAllocate(); 644 device->StopAndDeAllocate();
639 } 645 }
640 646
641 }; // namespace media 647 }; // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/video_capture_device_client_unittest.cc ('k') | media/capture/video/video_frame_receiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698