| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "content/renderer/media/media_stream_audio_processor_options.h" | 7 #include "content/renderer/media/media_stream_audio_processor_options.h" |
| 8 #include "content/renderer/media/media_stream_constraints_util.h" | 8 #include "content/renderer/media/media_stream_constraints_util.h" |
| 9 #include "content/renderer/media/media_stream_video_source.h" | 9 #include "content/renderer/media/media_stream_video_source.h" |
| 10 #include "content/renderer/media/mock_media_constraint_factory.h" | 10 #include "content/renderer/media/mock_constraint_factory.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class MediaStreamConstraintsUtilTest : public testing::Test { | 15 class MediaStreamConstraintsUtilTest : public testing::Test { |
| 16 }; | 16 }; |
| 17 | 17 |
| 18 TEST_F(MediaStreamConstraintsUtilTest, BooleanConstraints) { | 18 TEST_F(MediaStreamConstraintsUtilTest, BooleanConstraints) { |
| 19 static const std::string kValueTrue = "true"; | 19 static const std::string kValueTrue = "true"; |
| 20 static const std::string kValueFalse = "false"; | 20 static const std::string kValueFalse = "false"; |
| 21 | 21 |
| 22 MockMediaConstraintFactory constraint_factory; | 22 MockConstraintFactory constraint_factory; |
| 23 // Mandatory constraints. | 23 // Mandatory constraints. |
| 24 constraint_factory.AddMandatory(MediaAudioConstraints::kEchoCancellation, | 24 constraint_factory.basic().echoCancellation.setExact(true); |
| 25 kValueTrue); | 25 constraint_factory.basic().googEchoCancellation.setExact(false); |
| 26 constraint_factory.AddMandatory(MediaAudioConstraints::kGoogEchoCancellation, | |
| 27 kValueFalse); | |
| 28 blink::WebMediaConstraints constraints = | 26 blink::WebMediaConstraints constraints = |
| 29 constraint_factory.CreateWebMediaConstraints(); | 27 constraint_factory.CreateWebMediaConstraints(); |
| 30 bool value_true = false; | 28 bool value_true = false; |
| 31 bool value_false = false; | 29 bool value_false = false; |
| 32 EXPECT_TRUE(GetMandatoryConstraintValueAsBoolean( | 30 EXPECT_TRUE(GetConstraintValueAsBoolean( |
| 33 constraints, MediaAudioConstraints::kEchoCancellation, &value_true)); | 31 constraints, &blink::WebMediaTrackConstraintSet::echoCancellation, |
| 34 EXPECT_TRUE(GetMandatoryConstraintValueAsBoolean( | 32 &value_true)); |
| 35 constraints, MediaAudioConstraints::kGoogEchoCancellation, &value_false)); | 33 EXPECT_TRUE(GetConstraintValueAsBoolean( |
| 34 constraints, &blink::WebMediaTrackConstraintSet::googEchoCancellation, |
| 35 &value_false)); |
| 36 EXPECT_TRUE(value_true); | 36 EXPECT_TRUE(value_true); |
| 37 EXPECT_FALSE(value_false); | 37 EXPECT_FALSE(value_false); |
| 38 | 38 |
| 39 // Optional constraints. | 39 // Optional constraints, represented as "advanced" |
| 40 constraint_factory.AddOptional(MediaAudioConstraints::kEchoCancellation, | 40 constraint_factory.Reset(); |
| 41 kValueFalse); | 41 constraint_factory.AddAdvanced().echoCancellation.setExact(false); |
| 42 constraint_factory.AddOptional(MediaAudioConstraints::kGoogEchoCancellation, | 42 constraint_factory.AddAdvanced().googEchoCancellation.setExact(true); |
| 43 kValueTrue); | |
| 44 constraints = constraint_factory.CreateWebMediaConstraints(); | 43 constraints = constraint_factory.CreateWebMediaConstraints(); |
| 45 EXPECT_TRUE(GetOptionalConstraintValueAsBoolean( | 44 EXPECT_TRUE(GetConstraintValueAsBoolean( |
| 46 constraints, MediaAudioConstraints::kEchoCancellation, &value_false)); | 45 constraints, &blink::WebMediaTrackConstraintSet::echoCancellation, |
| 47 EXPECT_TRUE(GetOptionalConstraintValueAsBoolean( | 46 &value_false)); |
| 48 constraints, MediaAudioConstraints::kGoogEchoCancellation, | 47 EXPECT_TRUE(GetConstraintValueAsBoolean( |
| 48 constraints, &blink::WebMediaTrackConstraintSet::googEchoCancellation, |
| 49 &value_true)); | 49 &value_true)); |
| 50 EXPECT_TRUE(value_true); | 50 EXPECT_TRUE(value_true); |
| 51 EXPECT_FALSE(value_false); | 51 EXPECT_FALSE(value_false); |
| 52 |
| 53 // A mandatory constraint should override an optional one. |
| 54 constraint_factory.Reset(); |
| 55 constraint_factory.AddAdvanced().echoCancellation.setExact(false); |
| 56 constraint_factory.basic().echoCancellation.setExact(true); |
| 57 constraints = constraint_factory.CreateWebMediaConstraints(); |
| 58 EXPECT_TRUE(GetConstraintValueAsBoolean( |
| 59 constraints, &blink::WebMediaTrackConstraintSet::echoCancellation, |
| 60 &value_true)); |
| 61 EXPECT_TRUE(value_true); |
| 52 } | 62 } |
| 53 | 63 |
| 54 TEST_F(MediaStreamConstraintsUtilTest, MandatoryDoubleConstraints) { | 64 TEST_F(MediaStreamConstraintsUtilTest, DoubleConstraints) { |
| 55 MockMediaConstraintFactory constraint_factory; | 65 MockConstraintFactory constraint_factory; |
| 56 const std::string test_key = "test key"; | |
| 57 const double test_value= 0.01f; | 66 const double test_value= 0.01f; |
| 58 | 67 |
| 59 constraint_factory.AddMandatory(test_key, test_value); | 68 constraint_factory.basic().aspectRatio.setExact(test_value); |
| 60 blink::WebMediaConstraints constraints = | 69 blink::WebMediaConstraints constraints = |
| 61 constraint_factory.CreateWebMediaConstraints(); | 70 constraint_factory.CreateWebMediaConstraints(); |
| 62 | 71 |
| 63 double value; | 72 double value; |
| 64 EXPECT_FALSE(GetOptionalConstraintValueAsDouble(constraints, test_key, | 73 EXPECT_FALSE(GetConstraintValueAsDouble( |
| 65 &value)); | 74 constraints, &blink::WebMediaTrackConstraintSet::frameRate, &value)); |
| 66 EXPECT_TRUE(GetMandatoryConstraintValueAsDouble(constraints, test_key, | 75 EXPECT_TRUE(GetConstraintValueAsDouble( |
| 67 &value)); | 76 constraints, &blink::WebMediaTrackConstraintSet::aspectRatio, &value)); |
| 68 EXPECT_EQ(test_value, value); | |
| 69 | |
| 70 value = 0; | |
| 71 EXPECT_TRUE(GetConstraintValueAsDouble(constraints, test_key, &value)); | |
| 72 EXPECT_EQ(test_value, value); | |
| 73 } | |
| 74 | |
| 75 TEST_F(MediaStreamConstraintsUtilTest, OptionalDoubleConstraints) { | |
| 76 MockMediaConstraintFactory constraint_factory; | |
| 77 const std::string test_key = "test key"; | |
| 78 const double test_value= 0.01f; | |
| 79 | |
| 80 constraint_factory.AddOptional(test_key, test_value); | |
| 81 blink::WebMediaConstraints constraints = | |
| 82 constraint_factory.CreateWebMediaConstraints(); | |
| 83 | |
| 84 double value; | |
| 85 EXPECT_FALSE(GetMandatoryConstraintValueAsDouble(constraints, test_key, | |
| 86 &value)); | |
| 87 EXPECT_TRUE(GetOptionalConstraintValueAsDouble(constraints, test_key, | |
| 88 &value)); | |
| 89 EXPECT_EQ(test_value, value); | |
| 90 | |
| 91 value = 0; | |
| 92 EXPECT_TRUE(GetConstraintValueAsDouble(constraints, test_key, &value)); | |
| 93 EXPECT_EQ(test_value, value); | 77 EXPECT_EQ(test_value, value); |
| 94 } | 78 } |
| 95 | 79 |
| 96 TEST_F(MediaStreamConstraintsUtilTest, IntConstraints) { | 80 TEST_F(MediaStreamConstraintsUtilTest, IntConstraints) { |
| 97 MockMediaConstraintFactory constraint_factory; | 81 MockConstraintFactory constraint_factory; |
| 98 int width = 600; | 82 const int test_value = 327; |
| 99 int height = 480; | 83 |
| 100 constraint_factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, width); | 84 constraint_factory.basic().width.setExact(test_value); |
| 101 constraint_factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, height); | |
| 102 blink::WebMediaConstraints constraints = | 85 blink::WebMediaConstraints constraints = |
| 103 constraint_factory.CreateWebMediaConstraints(); | 86 constraint_factory.CreateWebMediaConstraints(); |
| 104 int value_width = 0; | |
| 105 int value_height = 0; | |
| 106 EXPECT_TRUE(GetMandatoryConstraintValueAsInteger( | |
| 107 constraints, MediaStreamVideoSource::kMaxWidth, &value_width)); | |
| 108 EXPECT_TRUE(GetMandatoryConstraintValueAsInteger( | |
| 109 constraints, MediaStreamVideoSource::kMaxHeight, &value_height)); | |
| 110 EXPECT_EQ(width, value_width); | |
| 111 EXPECT_EQ(height, value_height); | |
| 112 | 87 |
| 113 width = 720; | 88 int value; |
| 114 height = 600; | 89 EXPECT_TRUE(GetConstraintValueAsInteger( |
| 115 constraint_factory.AddOptional(MediaStreamVideoSource::kMaxWidth, width); | 90 constraints, &blink::WebMediaTrackConstraintSet::width, &value)); |
| 116 constraint_factory.AddOptional(MediaStreamVideoSource::kMaxHeight, height); | 91 EXPECT_EQ(test_value, value); |
| 117 constraints = constraint_factory.CreateWebMediaConstraints(); | |
| 118 EXPECT_TRUE(GetOptionalConstraintValueAsInteger( | |
| 119 constraints, MediaStreamVideoSource::kMaxWidth, &value_width)); | |
| 120 EXPECT_TRUE(GetOptionalConstraintValueAsInteger( | |
| 121 constraints, MediaStreamVideoSource::kMaxHeight, &value_height)); | |
| 122 EXPECT_EQ(width, value_width); | |
| 123 EXPECT_EQ(height, value_height); | |
| 124 } | |
| 125 | |
| 126 TEST_F(MediaStreamConstraintsUtilTest, WrongBooleanConstraints) { | |
| 127 static const std::string kWrongValueTrue = "True"; | |
| 128 static const std::string kWrongValueFalse = "False"; | |
| 129 MockMediaConstraintFactory constraint_factory; | |
| 130 constraint_factory.AddMandatory(MediaAudioConstraints::kEchoCancellation, | |
| 131 kWrongValueTrue); | |
| 132 constraint_factory.AddMandatory(MediaAudioConstraints::kGoogEchoCancellation, | |
| 133 kWrongValueFalse); | |
| 134 blink::WebMediaConstraints constraints = | |
| 135 constraint_factory.CreateWebMediaConstraints(); | |
| 136 bool value_false = false; | |
| 137 EXPECT_FALSE(GetMandatoryConstraintValueAsBoolean( | |
| 138 constraints, MediaAudioConstraints::kEchoCancellation, &value_false)); | |
| 139 EXPECT_FALSE(value_false); | |
| 140 EXPECT_FALSE(GetMandatoryConstraintValueAsBoolean( | |
| 141 constraints, MediaAudioConstraints::kGoogEchoCancellation, &value_false)); | |
| 142 EXPECT_FALSE(value_false); | |
| 143 } | 92 } |
| 144 | 93 |
| 145 } // namespace content | 94 } // namespace content |
| OLD | NEW |