| 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 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 set = ResolutionSet(1, 1, 1, 1, 0.5, 0.5); | 367 set = ResolutionSet(1, 1, 1, 1, 0.5, 0.5); |
| 368 EXPECT_TRUE(set.IsEmpty()); | 368 EXPECT_TRUE(set.IsEmpty()); |
| 369 EXPECT_TRUE(set.IsAspectRatioEmpty()); | 369 EXPECT_TRUE(set.IsAspectRatioEmpty()); |
| 370 EXPECT_FALSE(set.ContainsPoint(0, 0)); | 370 EXPECT_FALSE(set.ContainsPoint(0, 0)); |
| 371 EXPECT_FALSE(set.ContainsPoint(1, 1)); | 371 EXPECT_FALSE(set.ContainsPoint(1, 1)); |
| 372 EXPECT_FALSE(set.ContainsPoint(1, 0)); | 372 EXPECT_FALSE(set.ContainsPoint(1, 0)); |
| 373 EXPECT_FALSE(set.ContainsPoint(0, 1)); | 373 EXPECT_FALSE(set.ContainsPoint(0, 1)); |
| 374 } | 374 } |
| 375 | 375 |
| 376 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionBoxEmptiness) { | 376 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionBoxEmptiness) { |
| 377 int kMin = 100; | 377 const int kMin = 100; |
| 378 int kMax = 200; | 378 const int kMax = 200; |
| 379 // Max aspect ratio below box. | 379 // Max aspect ratio below box. |
| 380 ResolutionSet set(kMin, kMax, kMin, kMax, 0.4, 0.4); | 380 ResolutionSet set(kMin, kMax, kMin, kMax, 0.4, 0.4); |
| 381 EXPECT_TRUE(set.IsEmpty()); | 381 EXPECT_TRUE(set.IsEmpty()); |
| 382 EXPECT_TRUE(set.IsAspectRatioEmpty()); | 382 EXPECT_TRUE(set.IsAspectRatioEmpty()); |
| 383 | 383 |
| 384 // Min aspect ratio above box. | 384 // Min aspect ratio above box. |
| 385 set = ResolutionSet(kMin, kMax, kMin, kMax, 3.0, HUGE_VAL); | 385 set = ResolutionSet(kMin, kMax, kMin, kMax, 3.0, HUGE_VAL); |
| 386 EXPECT_TRUE(set.IsEmpty()); | 386 EXPECT_TRUE(set.IsEmpty()); |
| 387 EXPECT_TRUE(set.IsAspectRatioEmpty()); | 387 EXPECT_TRUE(set.IsAspectRatioEmpty()); |
| 388 | 388 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 EXPECT_EQ(P(20, 10), set.ClosestPointTo(P(20, 9))); | 567 EXPECT_EQ(P(20, 10), set.ClosestPointTo(P(20, 9))); |
| 568 EXPECT_EQ(P(100, 50), set.ClosestPointTo(P(101, 50))); | 568 EXPECT_EQ(P(100, 50), set.ClosestPointTo(P(101, 50))); |
| 569 EXPECT_EQ(P(100, 100), set.ClosestPointTo(P(101, 101))); | 569 EXPECT_EQ(P(100, 100), set.ClosestPointTo(P(101, 101))); |
| 570 EXPECT_EQ(P(100 / 1.5, 100), set.ClosestPointTo(P(100 / 1.5, 101))); | 570 EXPECT_EQ(P(100 / 1.5, 100), set.ClosestPointTo(P(100 / 1.5, 101))); |
| 571 EXPECT_EQ(P(10, 15), set.ClosestPointTo(P(9, 15))); | 571 EXPECT_EQ(P(10, 15), set.ClosestPointTo(P(9, 15))); |
| 572 } | 572 } |
| 573 | 573 |
| 574 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionIdealIntersects) { | 574 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionIdealIntersects) { |
| 575 ResolutionSet set(100, 1000, 100, 1000, 0.5, 2.0); | 575 ResolutionSet set(100, 1000, 100, 1000, 0.5, 2.0); |
| 576 | 576 |
| 577 int kIdealHeight = 500; | 577 const int kIdealHeight = 500; |
| 578 int kIdealWidth = 1000; | 578 const int kIdealWidth = 1000; |
| 579 double kIdealAspectRatio = 1.5; | 579 const double kIdealAspectRatio = 1.5; |
| 580 | 580 |
| 581 // Ideal height. | 581 // Ideal height. |
| 582 { | 582 { |
| 583 factory_.Reset(); | 583 factory_.Reset(); |
| 584 factory_.basic().height.setIdeal(kIdealHeight); | 584 factory_.basic().height.setIdeal(kIdealHeight); |
| 585 Point point = set.SelectClosestPointToIdeal( | 585 Point point = set.SelectClosestPointToIdeal( |
| 586 factory_.CreateWebMediaConstraints().basic()); | 586 factory_.CreateWebMediaConstraints().basic()); |
| 587 EXPECT_POINT_EQ( | 587 EXPECT_POINT_EQ( |
| 588 Point(kIdealHeight, | 588 Point(kIdealHeight, |
| 589 kIdealHeight * MediaStreamVideoSource::kDefaultAspectRatio), | 589 kIdealHeight * MediaStreamVideoSource::kDefaultAspectRatio), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 factory_.CreateWebMediaConstraints().basic()); | 654 factory_.CreateWebMediaConstraints().basic()); |
| 655 // Ideal aspect ratio should be ignored. | 655 // Ideal aspect ratio should be ignored. |
| 656 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealWidth), point); | 656 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealWidth), point); |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 | 659 |
| 660 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionIdealOutsideSinglePoint) { | 660 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionIdealOutsideSinglePoint) { |
| 661 // This set is a triangle with vertices (100,100), (1000,100) and (1000,1000). | 661 // 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); | 662 ResolutionSet set(100, 1000, 100, 1000, 0.0, 1.0); |
| 663 | 663 |
| 664 int kIdealHeight = 50; | 664 const int kIdealHeight = 50; |
| 665 int kIdealWidth = 1100; | 665 const int kIdealWidth = 1100; |
| 666 double kIdealAspectRatio = 0.09; | 666 const double kIdealAspectRatio = 0.09; |
| 667 Point kVertex1(100, 100); | 667 const Point kVertex1(100, 100); |
| 668 Point kVertex2(1000, 100); | 668 const Point kVertex2(1000, 100); |
| 669 Point kVertex3(1000, 1000); | 669 const Point kVertex3(1000, 1000); |
| 670 | 670 |
| 671 // Ideal height. | 671 // Ideal height. |
| 672 { | 672 { |
| 673 factory_.Reset(); | 673 factory_.Reset(); |
| 674 factory_.basic().height.setIdeal(kIdealHeight); | 674 factory_.basic().height.setIdeal(kIdealHeight); |
| 675 Point point = set.SelectClosestPointToIdeal( | 675 Point point = set.SelectClosestPointToIdeal( |
| 676 factory_.CreateWebMediaConstraints().basic()); | 676 factory_.CreateWebMediaConstraints().basic()); |
| 677 EXPECT_POINT_EQ(kVertex1, point); | 677 EXPECT_POINT_EQ(kVertex1, point); |
| 678 } | 678 } |
| 679 | 679 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 Point expected = set.ClosestPointTo(Point(kIdealHeight, kIdealWidth)); | 742 Point expected = set.ClosestPointTo(Point(kIdealHeight, kIdealWidth)); |
| 743 EXPECT_POINT_EQ(expected, point); | 743 EXPECT_POINT_EQ(expected, point); |
| 744 } | 744 } |
| 745 } | 745 } |
| 746 | 746 |
| 747 TEST_F(MediaStreamConstraintsUtilSetsTest, | 747 TEST_F(MediaStreamConstraintsUtilSetsTest, |
| 748 ResolutionIdealOutsideMultiplePoints) { | 748 ResolutionIdealOutsideMultiplePoints) { |
| 749 // This set is a triangle with vertices (100,100), (1000,100) and (1000,1000). | 749 // 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); | 750 ResolutionSet set(100, 1000, 100, 1000, 0.0, 1.0); |
| 751 | 751 |
| 752 int kIdealHeight = 1100; | 752 const int kIdealHeight = 1100; |
| 753 int kIdealWidth = 50; | 753 const int kIdealWidth = 50; |
| 754 double kIdealAspectRatio = 11.0; | 754 const double kIdealAspectRatio = 11.0; |
| 755 Point kVertex1(100, 100); | 755 const Point kVertex1(100, 100); |
| 756 Point kVertex2(1000, 100); | 756 const Point kVertex2(1000, 100); |
| 757 Point kVertex3(1000, 1000); | 757 const Point kVertex3(1000, 1000); |
| 758 | 758 |
| 759 // Ideal height. | 759 // Ideal height. |
| 760 { | 760 { |
| 761 factory_.Reset(); | 761 factory_.Reset(); |
| 762 factory_.basic().height.setIdeal(kIdealHeight); | 762 factory_.basic().height.setIdeal(kIdealHeight); |
| 763 Point point = set.SelectClosestPointToIdeal( | 763 Point point = set.SelectClosestPointToIdeal( |
| 764 factory_.CreateWebMediaConstraints().basic()); | 764 factory_.CreateWebMediaConstraints().basic()); |
| 765 // Parallel to the side between kVertex2 and kVertex3. Point closest to | 765 // Parallel to the side between kVertex2 and kVertex3. Point closest to |
| 766 // default aspect ratio is kVertex3. | 766 // default aspect ratio is kVertex3. |
| 767 EXPECT_POINT_EQ(kVertex3, point); | 767 EXPECT_POINT_EQ(kVertex3, point); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 EXPECT_TRUE(intersection.Contains(true)); | 1272 EXPECT_TRUE(intersection.Contains(true)); |
| 1273 EXPECT_TRUE(intersection.Contains(true)); | 1273 EXPECT_TRUE(intersection.Contains(true)); |
| 1274 | 1274 |
| 1275 // Empty intersection. | 1275 // Empty intersection. |
| 1276 set = BoolSet({true}); | 1276 set = BoolSet({true}); |
| 1277 intersection = set.Intersection(BoolSet({false})); | 1277 intersection = set.Intersection(BoolSet({false})); |
| 1278 EXPECT_TRUE(intersection.IsEmpty()); | 1278 EXPECT_TRUE(intersection.IsEmpty()); |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 } // namespace content | 1281 } // namespace content |
| OLD | NEW |