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

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

Issue 22876027: Consolidate duplicated frame / capability structures in video_capture_types.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased: changed media::VideoCaptureCapability::kI420 -> media::PIXEL_FORMAT_I420 etc. Created 7 years, 3 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 "content/browser/renderer_host/media/web_contents_video_capture_device. h" 5 #include "content/browser/renderer_host/media/web_contents_video_capture_device. h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/debug/debugger.h" 8 #include "base/debug/debugger.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 base::AutoLock guard(lock_); 400 base::AutoLock guard(lock_);
401 error_encountered_ = true; 401 error_encountered_ = true;
402 } 402 }
403 PostColorOrError(kNothingYet); 403 PostColorOrError(kNothingYet);
404 } 404 }
405 405
406 virtual void OnFrameInfo(const media::VideoCaptureCapability& info) OVERRIDE { 406 virtual void OnFrameInfo(const media::VideoCaptureCapability& info) OVERRIDE {
407 EXPECT_EQ(kTestWidth, info.width); 407 EXPECT_EQ(kTestWidth, info.width);
408 EXPECT_EQ(kTestHeight, info.height); 408 EXPECT_EQ(kTestHeight, info.height);
409 EXPECT_EQ(kTestFramesPerSecond, info.frame_rate); 409 EXPECT_EQ(kTestFramesPerSecond, info.frame_rate);
410 EXPECT_EQ(media::VideoCaptureCapability::kI420, info.color); 410 EXPECT_EQ(media::PIXEL_FORMAT_I420, info.color);
411 } 411 }
412 412
413 private: 413 private:
414 base::Lock lock_; 414 base::Lock lock_;
415 bool error_encountered_; 415 bool error_encountered_;
416 SkColor wait_color_yuv_; 416 SkColor wait_color_yuv_;
417 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; 417 scoped_refptr<VideoCaptureBufferPool> buffer_pool_;
418 418
419 DISALLOW_COPY_AND_ASSIGN(StubConsumer); 419 DISALLOW_COPY_AND_ASSIGN(StubConsumer);
420 }; 420 };
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) { 540 TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) {
541 // Before the installs itself on the UI thread up to start capturing, we'll 541 // Before the installs itself on the UI thread up to start capturing, we'll
542 // delete the web contents. This should trigger an error which can happen in 542 // delete the web contents. This should trigger an error which can happen in
543 // practice; we should be able to recover gracefully. 543 // practice; we should be able to recover gracefully.
544 ResetWebContents(); 544 ResetWebContents();
545 545
546 media::VideoCaptureCapability capture_format( 546 media::VideoCaptureCapability capture_format(
547 kTestWidth, 547 kTestWidth,
548 kTestHeight, 548 kTestHeight,
549 kTestFramesPerSecond, 549 kTestFramesPerSecond,
550 media::VideoCaptureCapability::kI420, 550 media::PIXEL_FORMAT_I420,
551 0, 551 0,
552 false, 552 false,
553 media::ConstantResolutionVideoCaptureDevice); 553 media::ConstantResolutionVideoCaptureDevice);
554 device()->Allocate(capture_format, consumer()); 554 device()->Allocate(capture_format, consumer());
555 device()->Start(); 555 device()->Start();
556 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); 556 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError());
557 device()->DeAllocate(); 557 device()->DeAllocate();
558 } 558 }
559 559
560 TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) { 560 TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) {
561 // We'll simulate the tab being closed after the capture pipeline is up and 561 // We'll simulate the tab being closed after the capture pipeline is up and
562 // running. 562 // running.
563 media::VideoCaptureCapability capture_format( 563 media::VideoCaptureCapability capture_format(
564 kTestWidth, 564 kTestWidth,
565 kTestHeight, 565 kTestHeight,
566 kTestFramesPerSecond, 566 kTestFramesPerSecond,
567 media::VideoCaptureCapability::kI420, 567 media::PIXEL_FORMAT_I420,
568 0, 568 0,
569 false, 569 false,
570 media::ConstantResolutionVideoCaptureDevice); 570 media::ConstantResolutionVideoCaptureDevice);
571 device()->Allocate(capture_format, consumer()); 571 device()->Allocate(capture_format, consumer());
572 device()->Start(); 572 device()->Start();
573 573
574 // Do one capture to prove 574 // Do one capture to prove
575 source()->SetSolidColor(SK_ColorRED); 575 source()->SetSolidColor(SK_ColorRED);
576 SimulateDrawEvent(); 576 SimulateDrawEvent();
577 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); 577 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED));
578 578
579 base::RunLoop().RunUntilIdle(); 579 base::RunLoop().RunUntilIdle();
580 580
581 // Post a task to close the tab. We should see an error reported to the 581 // Post a task to close the tab. We should see an error reported to the
582 // consumer. 582 // consumer.
583 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 583 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
584 base::Bind(&WebContentsVideoCaptureDeviceTest::ResetWebContents, 584 base::Bind(&WebContentsVideoCaptureDeviceTest::ResetWebContents,
585 base::Unretained(this))); 585 base::Unretained(this)));
586 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); 586 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError());
587 device()->DeAllocate(); 587 device()->DeAllocate();
588 } 588 }
589 589
590 TEST_F(WebContentsVideoCaptureDeviceTest, 590 TEST_F(WebContentsVideoCaptureDeviceTest,
591 StopDeviceBeforeCaptureMachineCreation) { 591 StopDeviceBeforeCaptureMachineCreation) {
592 media::VideoCaptureCapability capture_format( 592 media::VideoCaptureCapability capture_format(
593 kTestWidth, 593 kTestWidth,
594 kTestHeight, 594 kTestHeight,
595 kTestFramesPerSecond, 595 kTestFramesPerSecond,
596 media::VideoCaptureCapability::kI420, 596 media::PIXEL_FORMAT_I420,
597 0, 597 0,
598 false, 598 false,
599 media::ConstantResolutionVideoCaptureDevice); 599 media::ConstantResolutionVideoCaptureDevice);
600 device()->Allocate(capture_format, consumer()); 600 device()->Allocate(capture_format, consumer());
601 device()->Start(); 601 device()->Start();
602 // Make a point of not running the UI messageloop here. 602 // Make a point of not running the UI messageloop here.
603 device()->Stop(); 603 device()->Stop();
604 device()->DeAllocate(); 604 device()->DeAllocate();
605 DestroyVideoCaptureDevice(); 605 DestroyVideoCaptureDevice();
606 606
607 // Currently, there should be CreateCaptureMachineOnUIThread() and 607 // Currently, there should be CreateCaptureMachineOnUIThread() and
608 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message 608 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message
609 // loop. These should both succeed without crashing, and the machine should 609 // loop. These should both succeed without crashing, and the machine should
610 // wind up in the idle state. 610 // wind up in the idle state.
611 base::RunLoop().RunUntilIdle(); 611 base::RunLoop().RunUntilIdle();
612 } 612 }
613 613
614 TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { 614 TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) {
615 // Set up the test to use RGB copies and an normal 615 // Set up the test to use RGB copies and an normal
616 source()->SetCanCopyToVideoFrame(false); 616 source()->SetCanCopyToVideoFrame(false);
617 source()->SetUseFrameSubscriber(false); 617 source()->SetUseFrameSubscriber(false);
618 media::VideoCaptureCapability capture_format( 618 media::VideoCaptureCapability capture_format(
619 kTestWidth, 619 kTestWidth,
620 kTestHeight, 620 kTestHeight,
621 kTestFramesPerSecond, 621 kTestFramesPerSecond,
622 media::VideoCaptureCapability::kI420, 622 media::PIXEL_FORMAT_I420,
623 0, 623 0,
624 false, 624 false,
625 media::ConstantResolutionVideoCaptureDevice); 625 media::ConstantResolutionVideoCaptureDevice);
626 device()->Allocate(capture_format, consumer()); 626 device()->Allocate(capture_format, consumer());
627 627
628 device()->Start(); 628 device()->Start();
629 // Make a point of not running the UI messageloop here. 629 // Make a point of not running the UI messageloop here.
630 // TODO(ajwong): Why do we care? 630 // TODO(ajwong): Why do we care?
631 base::RunLoop().RunUntilIdle(); 631 base::RunLoop().RunUntilIdle();
632 632
633 for (int i = 0; i < 10; ++i) 633 for (int i = 0; i < 10; ++i)
634 SimulateDrawEvent(); 634 SimulateDrawEvent();
635 635
636 device()->Stop(); 636 device()->Stop();
637 device()->DeAllocate(); 637 device()->DeAllocate();
638 // Currently, there should be CreateCaptureMachineOnUIThread() and 638 // Currently, there should be CreateCaptureMachineOnUIThread() and
639 // DestroyCaptureMachineOnUIThread() tasks pending on the current message 639 // DestroyCaptureMachineOnUIThread() tasks pending on the current message
640 // loop. These should both succeed without crashing, and the machine should 640 // loop. These should both succeed without crashing, and the machine should
641 // wind up in the idle state. 641 // wind up in the idle state.
642 ASSERT_FALSE(consumer()->HasError()); 642 ASSERT_FALSE(consumer()->HasError());
643 base::RunLoop().RunUntilIdle(); 643 base::RunLoop().RunUntilIdle();
644 ASSERT_FALSE(consumer()->HasError()); 644 ASSERT_FALSE(consumer()->HasError());
645 } 645 }
646 646
647 TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) { 647 TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) {
648 media::VideoCaptureCapability capture_format( 648 media::VideoCaptureCapability capture_format(
649 kTestWidth, 649 kTestWidth,
650 kTestHeight, 650 kTestHeight,
651 kTestFramesPerSecond, 651 kTestFramesPerSecond,
652 media::VideoCaptureCapability::kI420, 652 media::PIXEL_FORMAT_I420,
653 0, 653 0,
654 false, 654 false,
655 media::ConstantResolutionVideoCaptureDevice); 655 media::ConstantResolutionVideoCaptureDevice);
656 device()->Allocate(capture_format, consumer()); 656 device()->Allocate(capture_format, consumer());
657 device()->Start(); 657 device()->Start();
658 base::RunLoop().RunUntilIdle(); 658 base::RunLoop().RunUntilIdle();
659 source()->SetSolidColor(SK_ColorRED); 659 source()->SetSolidColor(SK_ColorRED);
660 SimulateDrawEvent(); 660 SimulateDrawEvent();
661 SimulateDrawEvent(); 661 SimulateDrawEvent();
662 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); 662 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED));
(...skipping 21 matching lines...) Expand all
684 684
685 // The "happy case" test. No scaling is needed, so we should be able to change 685 // The "happy case" test. No scaling is needed, so we should be able to change
686 // the picture emitted from the source and expect to see each delivered to the 686 // the picture emitted from the source and expect to see each delivered to the
687 // consumer. The test will alternate between the three capture paths, simulating 687 // consumer. The test will alternate between the three capture paths, simulating
688 // falling in and out of accelerated compositing. 688 // falling in and out of accelerated compositing.
689 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { 689 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) {
690 media::VideoCaptureCapability capture_format( 690 media::VideoCaptureCapability capture_format(
691 kTestWidth, 691 kTestWidth,
692 kTestHeight, 692 kTestHeight,
693 kTestFramesPerSecond, 693 kTestFramesPerSecond,
694 media::VideoCaptureCapability::kI420, 694 media::PIXEL_FORMAT_I420,
695 0, 695 0,
696 false, 696 false,
697 media::ConstantResolutionVideoCaptureDevice); 697 media::ConstantResolutionVideoCaptureDevice);
698 device()->Allocate(capture_format, consumer()); 698 device()->Allocate(capture_format, consumer());
699 699
700 device()->Start(); 700 device()->Start();
701 701
702 for (int i = 0; i < 6; i++) { 702 for (int i = 0; i < 6; i++) {
703 const char* name = NULL; 703 const char* name = NULL;
704 switch (i % 3) { 704 switch (i % 3) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorBLACK)); 740 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorBLACK));
741 } 741 }
742 device()->DeAllocate(); 742 device()->DeAllocate();
743 } 743 }
744 744
745 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) { 745 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) {
746 media::VideoCaptureCapability capture_format( 746 media::VideoCaptureCapability capture_format(
747 1280, 747 1280,
748 720, 748 720,
749 -2, 749 -2,
750 media::VideoCaptureCapability::kI420, 750 media::PIXEL_FORMAT_I420,
751 0, 751 0,
752 false, 752 false,
753 media::ConstantResolutionVideoCaptureDevice); 753 media::ConstantResolutionVideoCaptureDevice);
754 BrowserThread::PostTask(BrowserThread::UI, 754 BrowserThread::PostTask(BrowserThread::UI,
755 FROM_HERE, 755 FROM_HERE,
756 base::Bind(&media::VideoCaptureDevice::Allocate, 756 base::Bind(&media::VideoCaptureDevice::Allocate,
757 base::Unretained(device()), 757 base::Unretained(device()),
758 capture_format, 758 capture_format,
759 consumer())); 759 consumer()));
760 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError()); 760 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForError());
761 } 761 }
762 762
763 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) { 763 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) {
764 media::VideoCaptureCapability capture_format( 764 media::VideoCaptureCapability capture_format(
765 kTestWidth, 765 kTestWidth,
766 kTestHeight, 766 kTestHeight,
767 kTestFramesPerSecond, 767 kTestFramesPerSecond,
768 media::VideoCaptureCapability::kI420, 768 media::PIXEL_FORMAT_I420,
769 0, 769 0,
770 false, 770 false,
771 media::ConstantResolutionVideoCaptureDevice); 771 media::ConstantResolutionVideoCaptureDevice);
772 device()->Allocate(capture_format, consumer()); 772 device()->Allocate(capture_format, consumer());
773 773
774 // 1x1 is too small to process; we intend for this to result in an error. 774 // 1x1 is too small to process; we intend for this to result in an error.
775 source()->SetCopyResultSize(1, 1); 775 source()->SetCopyResultSize(1, 1);
776 source()->SetSolidColor(SK_ColorRED); 776 source()->SetSolidColor(SK_ColorRED);
777 device()->Start(); 777 device()->Start();
778 778
(...skipping 11 matching lines...) Expand all
790 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorGREEN)); 790 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorGREEN));
791 source()->SetSolidColor(SK_ColorRED); 791 source()->SetSolidColor(SK_ColorRED);
792 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); 792 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED));
793 793
794 device()->Stop(); 794 device()->Stop();
795 device()->DeAllocate(); 795 device()->DeAllocate();
796 } 796 }
797 797
798 } // namespace 798 } // namespace
799 } // namespace content 799 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/web_contents_video_capture_device.cc ('k') | content/common/media/media_param_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698