| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/renderer/media/media_stream_constraints_util_sets.h" | 5 #include "content/renderer/media/media_stream_constraints_util_sets.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "content/renderer/media/media_stream_video_source.h" | |
| 12 #include "content/renderer/media/mock_constraint_factory.h" | 11 #include "content/renderer/media/mock_constraint_factory.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| 15 namespace content { | 14 namespace content { |
| 16 | 15 |
| 17 using Point = ResolutionSet::Point; | 16 using Point = ResolutionSet::Point; |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 20 const int kDefaultWidth = 640; |
| 21 const int kDefaultHeight = 480; |
| 22 constexpr double kDefaultAspectRatio = |
| 23 static_cast<double>(kDefaultWidth) / static_cast<double>(kDefaultHeight); |
| 24 |
| 21 // Defined as macro in order to get more informative line-number information | 25 // Defined as macro in order to get more informative line-number information |
| 22 // when a test fails. | 26 // when a test fails. |
| 23 #define EXPECT_POINT_EQ(p1, p2) \ | 27 #define EXPECT_POINT_EQ(p1, p2) \ |
| 24 do { \ | 28 do { \ |
| 25 EXPECT_DOUBLE_EQ((p1).height(), (p2).height()); \ | 29 EXPECT_DOUBLE_EQ((p1).height(), (p2).height()); \ |
| 26 EXPECT_DOUBLE_EQ((p1).width(), (p2).width()); \ | 30 EXPECT_DOUBLE_EQ((p1).width(), (p2).width()); \ |
| 27 } while (0) | 31 } while (0) |
| 28 | 32 |
| 29 // Checks if |point| is an element of |vertices| using | 33 // Checks if |point| is an element of |vertices| using |
| 30 // Point::IsApproximatelyEqualTo() to test for equality. | 34 // Point::IsApproximatelyEqualTo() to test for equality. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 double projection_height = projection_length * std::cos(segment_angle); | 111 double projection_height = projection_length * std::cos(segment_angle); |
| 108 double projection_width = projection_length * std::sin(segment_angle); | 112 double projection_width = projection_length * std::sin(segment_angle); |
| 109 return Point(projection_height, projection_width); | 113 return Point(projection_height, projection_width); |
| 110 } | 114 } |
| 111 | 115 |
| 112 } // namespace | 116 } // namespace |
| 113 | 117 |
| 114 class MediaStreamConstraintsUtilSetsTest : public testing::Test { | 118 class MediaStreamConstraintsUtilSetsTest : public testing::Test { |
| 115 protected: | 119 protected: |
| 116 using P = Point; | 120 using P = Point; |
| 121 |
| 122 Point SelectClosestPointToIdeal(const ResolutionSet& set) { |
| 123 return set.SelectClosestPointToIdeal( |
| 124 factory_.CreateWebMediaConstraints().basic(), kDefaultHeight, |
| 125 kDefaultWidth); |
| 126 } |
| 127 |
| 117 MockConstraintFactory factory_; | 128 MockConstraintFactory factory_; |
| 118 }; | 129 }; |
| 119 | 130 |
| 120 // This test tests the test-harness function AreValidVertices. | 131 // This test tests the test-harness function AreValidVertices. |
| 121 TEST_F(MediaStreamConstraintsUtilSetsTest, VertexListValidity) { | 132 TEST_F(MediaStreamConstraintsUtilSetsTest, VertexListValidity) { |
| 122 EXPECT_TRUE(AreCounterclockwise({P(1, 1)})); | 133 EXPECT_TRUE(AreCounterclockwise({P(1, 1)})); |
| 123 EXPECT_TRUE(AreCounterclockwise({P(1, 1)})); | 134 EXPECT_TRUE(AreCounterclockwise({P(1, 1)})); |
| 124 EXPECT_TRUE(AreCounterclockwise({P(1, 0), P(0, 1)})); | 135 EXPECT_TRUE(AreCounterclockwise({P(1, 0), P(0, 1)})); |
| 125 EXPECT_TRUE(AreCounterclockwise({P(1, 1), P(0, 0), P(1, 0)})); | 136 EXPECT_TRUE(AreCounterclockwise({P(1, 1), P(0, 0), P(1, 0)})); |
| 126 | 137 |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 ResolutionSet set(100, 1000, 100, 1000, 0.5, 2.0); | 586 ResolutionSet set(100, 1000, 100, 1000, 0.5, 2.0); |
| 576 | 587 |
| 577 int kIdealHeight = 500; | 588 int kIdealHeight = 500; |
| 578 int kIdealWidth = 1000; | 589 int kIdealWidth = 1000; |
| 579 double kIdealAspectRatio = 1.5; | 590 double kIdealAspectRatio = 1.5; |
| 580 | 591 |
| 581 // Ideal height. | 592 // Ideal height. |
| 582 { | 593 { |
| 583 factory_.Reset(); | 594 factory_.Reset(); |
| 584 factory_.basic().height.setIdeal(kIdealHeight); | 595 factory_.basic().height.setIdeal(kIdealHeight); |
| 585 Point point = set.SelectClosestPointToIdeal( | 596 Point point = SelectClosestPointToIdeal(set); |
| 586 factory_.CreateWebMediaConstraints().basic()); | 597 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealHeight * kDefaultAspectRatio), |
| 587 EXPECT_POINT_EQ( | 598 point); |
| 588 Point(kIdealHeight, | |
| 589 kIdealHeight * MediaStreamVideoSource::kDefaultAspectRatio), | |
| 590 point); | |
| 591 } | 599 } |
| 592 | 600 |
| 593 // Ideal width. | 601 // Ideal width. |
| 594 { | 602 { |
| 595 factory_.Reset(); | 603 factory_.Reset(); |
| 596 factory_.basic().width.setIdeal(kIdealWidth); | 604 factory_.basic().width.setIdeal(kIdealWidth); |
| 597 Point point = set.SelectClosestPointToIdeal( | 605 Point point = SelectClosestPointToIdeal(set); |
| 598 factory_.CreateWebMediaConstraints().basic()); | 606 EXPECT_POINT_EQ(Point(kIdealWidth / kDefaultAspectRatio, kIdealWidth), |
| 599 EXPECT_POINT_EQ( | 607 point); |
| 600 Point(kIdealWidth / MediaStreamVideoSource::kDefaultAspectRatio, | |
| 601 kIdealWidth), | |
| 602 point); | |
| 603 } | 608 } |
| 604 | 609 |
| 605 // Ideal aspect ratio. | 610 // Ideal aspect ratio. |
| 606 { | 611 { |
| 607 factory_.Reset(); | 612 factory_.Reset(); |
| 608 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 613 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 609 Point point = set.SelectClosestPointToIdeal( | 614 Point point = SelectClosestPointToIdeal(set); |
| 610 factory_.CreateWebMediaConstraints().basic()); | 615 EXPECT_DOUBLE_EQ(kDefaultHeight, point.height()); |
| 611 EXPECT_DOUBLE_EQ(MediaStreamVideoSource::kDefaultHeight, point.height()); | 616 EXPECT_DOUBLE_EQ(kDefaultHeight * kIdealAspectRatio, point.width()); |
| 612 EXPECT_DOUBLE_EQ(MediaStreamVideoSource::kDefaultHeight * kIdealAspectRatio, | |
| 613 point.width()); | |
| 614 } | 617 } |
| 615 | 618 |
| 616 // Ideal height and width. | 619 // Ideal height and width. |
| 617 { | 620 { |
| 618 factory_.Reset(); | 621 factory_.Reset(); |
| 619 factory_.basic().height.setIdeal(kIdealHeight); | 622 factory_.basic().height.setIdeal(kIdealHeight); |
| 620 factory_.basic().width.setIdeal(kIdealWidth); | 623 factory_.basic().width.setIdeal(kIdealWidth); |
| 621 Point point = set.SelectClosestPointToIdeal( | 624 Point point = SelectClosestPointToIdeal(set); |
| 622 factory_.CreateWebMediaConstraints().basic()); | |
| 623 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealWidth), point); | 625 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealWidth), point); |
| 624 } | 626 } |
| 625 | 627 |
| 626 // Ideal height and aspect-ratio. | 628 // Ideal height and aspect-ratio. |
| 627 { | 629 { |
| 628 factory_.Reset(); | 630 factory_.Reset(); |
| 629 factory_.basic().height.setIdeal(kIdealHeight); | 631 factory_.basic().height.setIdeal(kIdealHeight); |
| 630 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 632 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 631 Point point = set.SelectClosestPointToIdeal( | 633 Point point = SelectClosestPointToIdeal(set); |
| 632 factory_.CreateWebMediaConstraints().basic()); | |
| 633 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealHeight * kIdealAspectRatio), | 634 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealHeight * kIdealAspectRatio), |
| 634 point); | 635 point); |
| 635 } | 636 } |
| 636 | 637 |
| 637 // Ideal width and aspect-ratio. | 638 // Ideal width and aspect-ratio. |
| 638 { | 639 { |
| 639 factory_.Reset(); | 640 factory_.Reset(); |
| 640 factory_.basic().width.setIdeal(kIdealWidth); | 641 factory_.basic().width.setIdeal(kIdealWidth); |
| 641 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 642 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 642 Point point = set.SelectClosestPointToIdeal( | 643 Point point = SelectClosestPointToIdeal(set); |
| 643 factory_.CreateWebMediaConstraints().basic()); | |
| 644 EXPECT_POINT_EQ(Point(kIdealWidth / kIdealAspectRatio, kIdealWidth), point); | 644 EXPECT_POINT_EQ(Point(kIdealWidth / kIdealAspectRatio, kIdealWidth), point); |
| 645 } | 645 } |
| 646 | 646 |
| 647 // Ideal height, width and aspect-ratio. | 647 // Ideal height, width and aspect-ratio. |
| 648 { | 648 { |
| 649 factory_.Reset(); | 649 factory_.Reset(); |
| 650 factory_.basic().height.setIdeal(kIdealHeight); | 650 factory_.basic().height.setIdeal(kIdealHeight); |
| 651 factory_.basic().width.setIdeal(kIdealWidth); | 651 factory_.basic().width.setIdeal(kIdealWidth); |
| 652 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 652 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 653 Point point = set.SelectClosestPointToIdeal( | 653 Point point = SelectClosestPointToIdeal(set); |
| 654 factory_.CreateWebMediaConstraints().basic()); | |
| 655 // Ideal aspect ratio should be ignored. | 654 // Ideal aspect ratio should be ignored. |
| 656 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealWidth), point); | 655 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealWidth), point); |
| 657 } | 656 } |
| 658 } | 657 } |
| 659 | 658 |
| 660 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionIdealOutsideSinglePoint) { | 659 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionIdealOutsideSinglePoint) { |
| 661 // This set is a triangle with vertices (100,100), (1000,100) and (1000,1000). | 660 // This set is a triangle with vertices (100,100), (1000,100) and (1000,1000). |
| 662 ResolutionSet set(100, 1000, 100, 1000, 0.0, 1.0); | 661 ResolutionSet set(100, 1000, 100, 1000, 0.0, 1.0); |
| 663 | 662 |
| 664 int kIdealHeight = 50; | 663 int kIdealHeight = 50; |
| 665 int kIdealWidth = 1100; | 664 int kIdealWidth = 1100; |
| 666 double kIdealAspectRatio = 0.09; | 665 double kIdealAspectRatio = 0.09; |
| 667 Point kVertex1(100, 100); | 666 Point kVertex1(100, 100); |
| 668 Point kVertex2(1000, 100); | 667 Point kVertex2(1000, 100); |
| 669 Point kVertex3(1000, 1000); | 668 Point kVertex3(1000, 1000); |
| 670 | 669 |
| 671 // Ideal height. | 670 // Ideal height. |
| 672 { | 671 { |
| 673 factory_.Reset(); | 672 factory_.Reset(); |
| 674 factory_.basic().height.setIdeal(kIdealHeight); | 673 factory_.basic().height.setIdeal(kIdealHeight); |
| 675 Point point = set.SelectClosestPointToIdeal( | 674 Point point = SelectClosestPointToIdeal(set); |
| 676 factory_.CreateWebMediaConstraints().basic()); | |
| 677 EXPECT_POINT_EQ(kVertex1, point); | 675 EXPECT_POINT_EQ(kVertex1, point); |
| 678 } | 676 } |
| 679 | 677 |
| 680 // Ideal width. | 678 // Ideal width. |
| 681 { | 679 { |
| 682 factory_.Reset(); | 680 factory_.Reset(); |
| 683 factory_.basic().width.setIdeal(kIdealWidth); | 681 factory_.basic().width.setIdeal(kIdealWidth); |
| 684 Point point = set.SelectClosestPointToIdeal( | 682 Point point = SelectClosestPointToIdeal(set); |
| 685 factory_.CreateWebMediaConstraints().basic()); | |
| 686 EXPECT_POINT_EQ(kVertex3, point); | 683 EXPECT_POINT_EQ(kVertex3, point); |
| 687 } | 684 } |
| 688 | 685 |
| 689 // Ideal aspect ratio. | 686 // Ideal aspect ratio. |
| 690 { | 687 { |
| 691 factory_.Reset(); | 688 factory_.Reset(); |
| 692 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 689 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 693 Point point = set.SelectClosestPointToIdeal( | 690 Point point = SelectClosestPointToIdeal(set); |
| 694 factory_.CreateWebMediaConstraints().basic()); | |
| 695 EXPECT_POINT_EQ(kVertex2, point); | 691 EXPECT_POINT_EQ(kVertex2, point); |
| 696 } | 692 } |
| 697 | 693 |
| 698 // Ideal height and width. | 694 // Ideal height and width. |
| 699 { | 695 { |
| 700 factory_.Reset(); | 696 factory_.Reset(); |
| 701 factory_.basic().height.setIdeal(kIdealHeight); | 697 factory_.basic().height.setIdeal(kIdealHeight); |
| 702 factory_.basic().width.setIdeal(kIdealWidth); | 698 factory_.basic().width.setIdeal(kIdealWidth); |
| 703 Point point = set.SelectClosestPointToIdeal( | 699 Point point = SelectClosestPointToIdeal(set); |
| 704 factory_.CreateWebMediaConstraints().basic()); | |
| 705 Point expected = set.ClosestPointTo(Point(kIdealHeight, kIdealWidth)); | 700 Point expected = set.ClosestPointTo(Point(kIdealHeight, kIdealWidth)); |
| 706 EXPECT_POINT_EQ(expected, point); | 701 EXPECT_POINT_EQ(expected, point); |
| 707 } | 702 } |
| 708 | 703 |
| 709 // Ideal height and aspect-ratio. | 704 // Ideal height and aspect-ratio. |
| 710 { | 705 { |
| 711 factory_.Reset(); | 706 factory_.Reset(); |
| 712 factory_.basic().height.setIdeal(kIdealHeight); | 707 factory_.basic().height.setIdeal(kIdealHeight); |
| 713 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 708 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 714 Point point = set.SelectClosestPointToIdeal( | 709 Point point = SelectClosestPointToIdeal(set); |
| 715 factory_.CreateWebMediaConstraints().basic()); | |
| 716 Point expected = set.ClosestPointTo( | 710 Point expected = set.ClosestPointTo( |
| 717 Point(kIdealHeight, kIdealHeight * kIdealAspectRatio)); | 711 Point(kIdealHeight, kIdealHeight * kIdealAspectRatio)); |
| 718 EXPECT_POINT_EQ(expected, point); | 712 EXPECT_POINT_EQ(expected, point); |
| 719 } | 713 } |
| 720 | 714 |
| 721 // Ideal width and aspect-ratio. | 715 // Ideal width and aspect-ratio. |
| 722 { | 716 { |
| 723 factory_.Reset(); | 717 factory_.Reset(); |
| 724 factory_.basic().width.setIdeal(kIdealWidth); | 718 factory_.basic().width.setIdeal(kIdealWidth); |
| 725 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 719 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 726 Point point = set.SelectClosestPointToIdeal( | 720 Point point = SelectClosestPointToIdeal(set); |
| 727 factory_.CreateWebMediaConstraints().basic()); | |
| 728 Point expected = | 721 Point expected = |
| 729 set.ClosestPointTo(Point(kIdealWidth / kIdealAspectRatio, kIdealWidth)); | 722 set.ClosestPointTo(Point(kIdealWidth / kIdealAspectRatio, kIdealWidth)); |
| 730 EXPECT_POINT_EQ(expected, point); | 723 EXPECT_POINT_EQ(expected, point); |
| 731 } | 724 } |
| 732 | 725 |
| 733 // Ideal height, width and aspect-ratio. | 726 // Ideal height, width and aspect-ratio. |
| 734 { | 727 { |
| 735 factory_.Reset(); | 728 factory_.Reset(); |
| 736 factory_.basic().height.setIdeal(kIdealHeight); | 729 factory_.basic().height.setIdeal(kIdealHeight); |
| 737 factory_.basic().width.setIdeal(kIdealWidth); | 730 factory_.basic().width.setIdeal(kIdealWidth); |
| 738 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 731 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 739 Point point = set.SelectClosestPointToIdeal( | 732 Point point = SelectClosestPointToIdeal(set); |
| 740 factory_.CreateWebMediaConstraints().basic()); | |
| 741 // kIdealAspectRatio is ignored if all three ideals are given. | 733 // kIdealAspectRatio is ignored if all three ideals are given. |
| 742 Point expected = set.ClosestPointTo(Point(kIdealHeight, kIdealWidth)); | 734 Point expected = set.ClosestPointTo(Point(kIdealHeight, kIdealWidth)); |
| 743 EXPECT_POINT_EQ(expected, point); | 735 EXPECT_POINT_EQ(expected, point); |
| 744 } | 736 } |
| 745 } | 737 } |
| 746 | 738 |
| 747 TEST_F(MediaStreamConstraintsUtilSetsTest, | 739 TEST_F(MediaStreamConstraintsUtilSetsTest, |
| 748 ResolutionIdealOutsideMultiplePoints) { | 740 ResolutionIdealOutsideMultiplePoints) { |
| 749 // This set is a triangle with vertices (100,100), (1000,100) and (1000,1000). | 741 // This set is a triangle with vertices (100,100), (1000,100) and (1000,1000). |
| 750 ResolutionSet set(100, 1000, 100, 1000, 0.0, 1.0); | 742 ResolutionSet set(100, 1000, 100, 1000, 0.0, 1.0); |
| 751 | 743 |
| 752 int kIdealHeight = 1100; | 744 int kIdealHeight = 1100; |
| 753 int kIdealWidth = 50; | 745 int kIdealWidth = 50; |
| 754 double kIdealAspectRatio = 11.0; | 746 double kIdealAspectRatio = 11.0; |
| 755 Point kVertex1(100, 100); | 747 Point kVertex1(100, 100); |
| 756 Point kVertex2(1000, 100); | 748 Point kVertex2(1000, 100); |
| 757 Point kVertex3(1000, 1000); | 749 Point kVertex3(1000, 1000); |
| 758 | 750 |
| 759 // Ideal height. | 751 // Ideal height. |
| 760 { | 752 { |
| 761 factory_.Reset(); | 753 factory_.Reset(); |
| 762 factory_.basic().height.setIdeal(kIdealHeight); | 754 factory_.basic().height.setIdeal(kIdealHeight); |
| 763 Point point = set.SelectClosestPointToIdeal( | 755 Point point = SelectClosestPointToIdeal(set); |
| 764 factory_.CreateWebMediaConstraints().basic()); | |
| 765 // Parallel to the side between kVertex2 and kVertex3. Point closest to | 756 // Parallel to the side between kVertex2 and kVertex3. Point closest to |
| 766 // default aspect ratio is kVertex3. | 757 // default aspect ratio is kVertex3. |
| 767 EXPECT_POINT_EQ(kVertex3, point); | 758 EXPECT_POINT_EQ(kVertex3, point); |
| 768 } | 759 } |
| 769 | 760 |
| 770 // Ideal width. | 761 // Ideal width. |
| 771 { | 762 { |
| 772 factory_.Reset(); | 763 factory_.Reset(); |
| 773 factory_.basic().width.setIdeal(kIdealWidth); | 764 factory_.basic().width.setIdeal(kIdealWidth); |
| 774 Point point = set.SelectClosestPointToIdeal( | 765 Point point = SelectClosestPointToIdeal(set); |
| 775 factory_.CreateWebMediaConstraints().basic()); | |
| 776 // Parallel to the side between kVertex1 and kVertex2. Point closest to | 766 // Parallel to the side between kVertex1 and kVertex2. Point closest to |
| 777 // default aspect ratio is kVertex1. | 767 // default aspect ratio is kVertex1. |
| 778 EXPECT_POINT_EQ(kVertex1, point); | 768 EXPECT_POINT_EQ(kVertex1, point); |
| 779 } | 769 } |
| 780 | 770 |
| 781 // Ideal aspect ratio. | 771 // Ideal aspect ratio. |
| 782 { | 772 { |
| 783 factory_.Reset(); | 773 factory_.Reset(); |
| 784 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | 774 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
| 785 Point point = set.SelectClosestPointToIdeal( | 775 Point point = SelectClosestPointToIdeal(set); |
| 786 factory_.CreateWebMediaConstraints().basic()); | |
| 787 // The side between kVertex1 and kVertex3 is closest. The points closest to | 776 // The side between kVertex1 and kVertex3 is closest. The points closest to |
| 788 // default dimensions are (kDefaultHeight, kDefaultHeight * AR) | 777 // default dimensions are (kDefaultHeight, kDefaultHeight * AR) |
| 789 // and (kDefaultWidth / AR, kDefaultWidth). Since the aspect ratio of the | 778 // and (kDefaultWidth / AR, kDefaultWidth). Since the aspect ratio of the |
| 790 // polygon side is less than the default, the algorithm preserves the | 779 // polygon side is less than the default, the algorithm preserves the |
| 791 // default width. | 780 // default width. |
| 792 Point expected( | 781 Point expected(kDefaultWidth / kVertex1.AspectRatio(), kDefaultWidth); |
| 793 MediaStreamVideoSource::kDefaultWidth / kVertex1.AspectRatio(), | |
| 794 MediaStreamVideoSource::kDefaultWidth); | |
| 795 EXPECT_POINT_EQ(expected, point); | 782 EXPECT_POINT_EQ(expected, point); |
| 796 EXPECT_TRUE(set.ContainsPoint(expected)); | 783 EXPECT_TRUE(set.ContainsPoint(expected)); |
| 797 } | 784 } |
| 798 } | 785 } |
| 799 | 786 |
| 800 TEST_F(MediaStreamConstraintsUtilSetsTest, | 787 TEST_F(MediaStreamConstraintsUtilSetsTest, |
| 801 ResolutionUnconstrainedExtremeIdeal) { | 788 ResolutionUnconstrainedExtremeIdeal) { |
| 802 ResolutionSet set; | 789 ResolutionSet set; |
| 803 | 790 |
| 804 // Ideal height. | 791 // Ideal height. |
| 805 { | 792 { |
| 806 factory_.Reset(); | 793 factory_.Reset(); |
| 807 factory_.basic().height.setIdeal(std::numeric_limits<long>::max()); | 794 factory_.basic().height.setIdeal(std::numeric_limits<long>::max()); |
| 808 Point point = set.SelectClosestPointToIdeal( | 795 Point point = SelectClosestPointToIdeal(set); |
| 809 factory_.CreateWebMediaConstraints().basic()); | |
| 810 EXPECT_POINT_EQ( | 796 EXPECT_POINT_EQ( |
| 811 Point(ResolutionSet::kMaxDimension, ResolutionSet::kMaxDimension), | 797 Point(ResolutionSet::kMaxDimension, ResolutionSet::kMaxDimension), |
| 812 point); | 798 point); |
| 813 factory_.basic().height.setIdeal(0); | 799 factory_.basic().height.setIdeal(0); |
| 814 point = set.SelectClosestPointToIdeal( | 800 point = SelectClosestPointToIdeal(set); |
| 815 factory_.CreateWebMediaConstraints().basic()); | |
| 816 EXPECT_POINT_EQ(Point(0, 0), point); | 801 EXPECT_POINT_EQ(Point(0, 0), point); |
| 817 } | 802 } |
| 818 | 803 |
| 819 // Ideal width. | 804 // Ideal width. |
| 820 { | 805 { |
| 821 factory_.Reset(); | 806 factory_.Reset(); |
| 822 factory_.basic().width.setIdeal(std::numeric_limits<long>::max()); | 807 factory_.basic().width.setIdeal(std::numeric_limits<long>::max()); |
| 823 Point point = set.SelectClosestPointToIdeal( | 808 Point point = SelectClosestPointToIdeal(set); |
| 824 factory_.CreateWebMediaConstraints().basic()); | 809 EXPECT_POINT_EQ(Point(ResolutionSet::kMaxDimension / kDefaultAspectRatio, |
| 825 EXPECT_POINT_EQ(Point(ResolutionSet::kMaxDimension / | |
| 826 MediaStreamVideoSource::kDefaultAspectRatio, | |
| 827 ResolutionSet::kMaxDimension), | 810 ResolutionSet::kMaxDimension), |
| 828 point); | 811 point); |
| 829 factory_.basic().width.setIdeal(0); | 812 factory_.basic().width.setIdeal(0); |
| 830 point = set.SelectClosestPointToIdeal( | 813 point = SelectClosestPointToIdeal(set); |
| 831 factory_.CreateWebMediaConstraints().basic()); | |
| 832 EXPECT_POINT_EQ(Point(0, 0), point); | 814 EXPECT_POINT_EQ(Point(0, 0), point); |
| 833 } | 815 } |
| 834 | 816 |
| 835 // Ideal Aspect Ratio. | 817 // Ideal Aspect Ratio. |
| 836 { | 818 { |
| 837 factory_.Reset(); | 819 factory_.Reset(); |
| 838 factory_.basic().aspectRatio.setIdeal(HUGE_VAL); | 820 factory_.basic().aspectRatio.setIdeal(HUGE_VAL); |
| 839 Point point = set.SelectClosestPointToIdeal( | 821 Point point = SelectClosestPointToIdeal(set); |
| 840 factory_.CreateWebMediaConstraints().basic()); | |
| 841 EXPECT_POINT_EQ(Point(0, ResolutionSet::kMaxDimension), point); | 822 EXPECT_POINT_EQ(Point(0, ResolutionSet::kMaxDimension), point); |
| 842 factory_.basic().aspectRatio.setIdeal(0.0); | 823 factory_.basic().aspectRatio.setIdeal(0.0); |
| 843 point = set.SelectClosestPointToIdeal( | 824 point = SelectClosestPointToIdeal(set); |
| 844 factory_.CreateWebMediaConstraints().basic()); | |
| 845 EXPECT_POINT_EQ(Point(ResolutionSet::kMaxDimension, 0), point); | 825 EXPECT_POINT_EQ(Point(ResolutionSet::kMaxDimension, 0), point); |
| 846 } | 826 } |
| 847 } | 827 } |
| 848 | 828 |
| 849 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionVertices) { | 829 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionVertices) { |
| 850 // Empty set. | 830 // Empty set. |
| 851 { | 831 { |
| 852 ResolutionSet set(1000, 100, 1000, 100, 0.5, 1.5); | 832 ResolutionSet set(1000, 100, 1000, 100, 0.5, 1.5); |
| 853 ASSERT_TRUE(set.IsEmpty()); | 833 ASSERT_TRUE(set.IsEmpty()); |
| 854 auto vertices = set.ComputeVertices(); | 834 auto vertices = set.ComputeVertices(); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 EXPECT_TRUE(intersection.Contains(true)); | 1252 EXPECT_TRUE(intersection.Contains(true)); |
| 1273 EXPECT_TRUE(intersection.Contains(true)); | 1253 EXPECT_TRUE(intersection.Contains(true)); |
| 1274 | 1254 |
| 1275 // Empty intersection. | 1255 // Empty intersection. |
| 1276 set = BoolSet({true}); | 1256 set = BoolSet({true}); |
| 1277 intersection = set.Intersection(BoolSet({false})); | 1257 intersection = set.Intersection(BoolSet({false})); |
| 1278 EXPECT_TRUE(intersection.IsEmpty()); | 1258 EXPECT_TRUE(intersection.IsEmpty()); |
| 1279 } | 1259 } |
| 1280 | 1260 |
| 1281 } // namespace content | 1261 } // namespace content |
| OLD | NEW |