OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/mediastream/MediaConstraintsImpl.h" |
| 6 #include "modules/mediastream/MediaTrackConstraints.h" |
5 #include "public/platform/WebMediaConstraints.h" | 7 #include "public/platform/WebMediaConstraints.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
7 | 9 |
| 10 namespace blink { |
| 11 |
8 // The MediaTrackConstraintsTest group tests the types declared in | 12 // The MediaTrackConstraintsTest group tests the types declared in |
9 // WebKit/public/platform/WebMediaConstraints.h | 13 // WebKit/public/platform/WebMediaConstraints.h |
10 TEST(MediaTrackConstraintsTest, LongConstraint) | 14 TEST(MediaTrackConstraintsTest, LongConstraint) |
11 { | 15 { |
12 blink::LongConstraint rangeConstraint(nullptr); | 16 LongConstraint rangeConstraint(nullptr); |
13 rangeConstraint.setMin(5); | 17 rangeConstraint.setMin(5); |
14 rangeConstraint.setMax(6); | 18 rangeConstraint.setMax(6); |
15 EXPECT_TRUE(rangeConstraint.matches(5)); | 19 EXPECT_TRUE(rangeConstraint.matches(5)); |
16 EXPECT_TRUE(rangeConstraint.matches(6)); | 20 EXPECT_TRUE(rangeConstraint.matches(6)); |
17 EXPECT_FALSE(rangeConstraint.matches(4)); | 21 EXPECT_FALSE(rangeConstraint.matches(4)); |
18 EXPECT_FALSE(rangeConstraint.matches(7)); | 22 EXPECT_FALSE(rangeConstraint.matches(7)); |
19 blink::LongConstraint exactConstraint(nullptr); | 23 LongConstraint exactConstraint(nullptr); |
20 exactConstraint.setExact(5); | 24 exactConstraint.setExact(5); |
21 EXPECT_FALSE(exactConstraint.matches(4)); | 25 EXPECT_FALSE(exactConstraint.matches(4)); |
22 EXPECT_TRUE(exactConstraint.matches(5)); | 26 EXPECT_TRUE(exactConstraint.matches(5)); |
23 EXPECT_FALSE(exactConstraint.matches(6)); | 27 EXPECT_FALSE(exactConstraint.matches(6)); |
24 } | 28 } |
25 | 29 |
26 TEST(MediaTrackConstraintsTest, DoubleConstraint) | 30 TEST(MediaTrackConstraintsTest, DoubleConstraint) |
27 { | 31 { |
28 blink::DoubleConstraint rangeConstraint(nullptr); | 32 DoubleConstraint rangeConstraint(nullptr); |
29 EXPECT_TRUE(rangeConstraint.isEmpty()); | 33 EXPECT_TRUE(rangeConstraint.isEmpty()); |
30 rangeConstraint.setMin(5.0); | 34 rangeConstraint.setMin(5.0); |
31 rangeConstraint.setMax(6.5); | 35 rangeConstraint.setMax(6.5); |
32 EXPECT_FALSE(rangeConstraint.isEmpty()); | 36 EXPECT_FALSE(rangeConstraint.isEmpty()); |
33 // Matching within epsilon | 37 // Matching within epsilon |
34 EXPECT_TRUE(rangeConstraint.matches(5.0 - blink::DoubleConstraint::kConstrai
ntEpsilon / 2)); | 38 EXPECT_TRUE(rangeConstraint.matches(5.0 - DoubleConstraint::kConstraintEpsil
on / 2)); |
35 EXPECT_TRUE(rangeConstraint.matches(6.5 + blink::DoubleConstraint::kConstrai
ntEpsilon / 2)); | 39 EXPECT_TRUE(rangeConstraint.matches(6.5 + DoubleConstraint::kConstraintEpsil
on / 2)); |
36 blink::DoubleConstraint exactConstraint(nullptr); | 40 DoubleConstraint exactConstraint(nullptr); |
37 exactConstraint.setExact(5.0); | 41 exactConstraint.setExact(5.0); |
38 EXPECT_FALSE(rangeConstraint.isEmpty()); | 42 EXPECT_FALSE(rangeConstraint.isEmpty()); |
39 EXPECT_FALSE(exactConstraint.matches(4.9)); | 43 EXPECT_FALSE(exactConstraint.matches(4.9)); |
40 EXPECT_TRUE(exactConstraint.matches(5.0)); | 44 EXPECT_TRUE(exactConstraint.matches(5.0)); |
41 EXPECT_TRUE(exactConstraint.matches(5.0 - blink::DoubleConstraint::kConstrai
ntEpsilon / 2)); | 45 EXPECT_TRUE(exactConstraint.matches(5.0 - DoubleConstraint::kConstraintEpsil
on / 2)); |
42 EXPECT_TRUE(exactConstraint.matches(5.0 + blink::DoubleConstraint::kConstrai
ntEpsilon / 2)); | 46 EXPECT_TRUE(exactConstraint.matches(5.0 + DoubleConstraint::kConstraintEpsil
on / 2)); |
43 EXPECT_FALSE(exactConstraint.matches(5.1)); | 47 EXPECT_FALSE(exactConstraint.matches(5.1)); |
44 } | 48 } |
45 | 49 |
46 TEST(MediaTrackConstraintsTest, BooleanConstraint) | 50 TEST(MediaTrackConstraintsTest, BooleanConstraint) |
47 { | 51 { |
48 blink::BooleanConstraint boolConstraint(nullptr); | 52 BooleanConstraint boolConstraint(nullptr); |
49 EXPECT_TRUE(boolConstraint.isEmpty()); | 53 EXPECT_TRUE(boolConstraint.isEmpty()); |
50 EXPECT_TRUE(boolConstraint.matches(false)); | 54 EXPECT_TRUE(boolConstraint.matches(false)); |
51 EXPECT_TRUE(boolConstraint.matches(true)); | 55 EXPECT_TRUE(boolConstraint.matches(true)); |
52 boolConstraint.setExact(false); | 56 boolConstraint.setExact(false); |
53 EXPECT_FALSE(boolConstraint.isEmpty()); | 57 EXPECT_FALSE(boolConstraint.isEmpty()); |
54 EXPECT_FALSE(boolConstraint.matches(true)); | 58 EXPECT_FALSE(boolConstraint.matches(true)); |
55 EXPECT_TRUE(boolConstraint.matches(false)); | 59 EXPECT_TRUE(boolConstraint.matches(false)); |
56 boolConstraint.setExact(true); | 60 boolConstraint.setExact(true); |
57 EXPECT_FALSE(boolConstraint.matches(false)); | 61 EXPECT_FALSE(boolConstraint.matches(false)); |
58 EXPECT_TRUE(boolConstraint.matches(true)); | 62 EXPECT_TRUE(boolConstraint.matches(true)); |
59 } | 63 } |
60 | 64 |
61 TEST(MediaTrackConstraintsTest, ConstraintSetEmpty) | 65 TEST(MediaTrackConstraintsTest, ConstraintSetEmpty) |
62 { | 66 { |
63 blink::WebMediaTrackConstraintSet theSet; | 67 WebMediaTrackConstraintSet theSet; |
64 EXPECT_TRUE(theSet.isEmpty()); | 68 EXPECT_TRUE(theSet.isEmpty()); |
65 theSet.echoCancellation.setExact(false); | 69 theSet.echoCancellation.setExact(false); |
66 EXPECT_FALSE(theSet.isEmpty()); | 70 EXPECT_FALSE(theSet.isEmpty()); |
67 } | 71 } |
68 | 72 |
69 TEST(MediaTrackConstraintsTest, ConstraintName) | 73 TEST(MediaTrackConstraintsTest, ConstraintName) |
70 { | 74 { |
71 const char* theName = "name"; | 75 const char* theName = "name"; |
72 blink::BooleanConstraint boolConstraint(theName); | 76 BooleanConstraint boolConstraint(theName); |
73 EXPECT_EQ(theName, boolConstraint.name()); | 77 EXPECT_EQ(theName, boolConstraint.name()); |
74 } | 78 } |
75 | 79 |
76 TEST(MediaTrackConstraintsTest, MandatoryChecks) | 80 TEST(MediaTrackConstraintsTest, MandatoryChecks) |
77 { | 81 { |
78 blink::WebMediaTrackConstraintSet theSet; | 82 WebMediaTrackConstraintSet theSet; |
79 std::string foundName; | 83 std::string foundName; |
80 EXPECT_FALSE(theSet.hasMandatory()); | 84 EXPECT_FALSE(theSet.hasMandatory()); |
81 EXPECT_FALSE(theSet.hasMandatoryOutsideSet({ "width" }, foundName)); | 85 EXPECT_FALSE(theSet.hasMandatoryOutsideSet({ "width" }, foundName)); |
82 EXPECT_FALSE(theSet.width.hasMandatory()); | 86 EXPECT_FALSE(theSet.width.hasMandatory()); |
83 theSet.width.setMax(240); | 87 theSet.width.setMax(240); |
84 EXPECT_TRUE(theSet.width.hasMandatory()); | 88 EXPECT_TRUE(theSet.width.hasMandatory()); |
85 EXPECT_TRUE(theSet.hasMandatory()); | 89 EXPECT_TRUE(theSet.hasMandatory()); |
86 EXPECT_FALSE(theSet.hasMandatoryOutsideSet({ "width" }, foundName)); | 90 EXPECT_FALSE(theSet.hasMandatoryOutsideSet({ "width" }, foundName)); |
87 EXPECT_TRUE(theSet.hasMandatoryOutsideSet({ "height" }, foundName)); | 91 EXPECT_TRUE(theSet.hasMandatoryOutsideSet({ "height" }, foundName)); |
88 EXPECT_EQ("width", foundName); | 92 EXPECT_EQ("width", foundName); |
89 theSet.googPayloadPadding.setExact(true); | 93 theSet.googPayloadPadding.setExact(true); |
90 EXPECT_TRUE(theSet.hasMandatoryOutsideSet({ "width" }, foundName)); | 94 EXPECT_TRUE(theSet.hasMandatoryOutsideSet({ "width" }, foundName)); |
91 EXPECT_EQ("googPayloadPadding", foundName); | 95 EXPECT_EQ("googPayloadPadding", foundName); |
92 } | 96 } |
93 | 97 |
94 TEST(MediaTrackConstraintsTest, SetToString) | 98 TEST(MediaTrackConstraintsTest, SetToString) |
95 { | 99 { |
96 blink::WebMediaTrackConstraintSet theSet; | 100 WebMediaTrackConstraintSet theSet; |
97 EXPECT_EQ("", theSet.toString()); | 101 EXPECT_EQ("", theSet.toString()); |
98 theSet.width.setMax(240); | 102 theSet.width.setMax(240); |
99 EXPECT_EQ("width: {max: 240}", theSet.toString().utf8()); | 103 EXPECT_EQ("width: {max: 240}", theSet.toString().utf8()); |
100 theSet.echoCancellation.setIdeal(true); | 104 theSet.echoCancellation.setIdeal(true); |
101 EXPECT_EQ("width: {max: 240}, echoCancellation: {ideal: true}", theSet.toStr
ing().utf8()); | 105 EXPECT_EQ("width: {max: 240}, echoCancellation: {ideal: true}", theSet.toStr
ing().utf8()); |
102 } | 106 } |
103 | 107 |
104 TEST(MediaTrackConstraintsTest, ConstraintsToString) | 108 TEST(MediaTrackConstraintsTest, ConstraintsToString) |
105 { | 109 { |
106 blink::WebMediaConstraints theConstraints; | 110 WebMediaConstraints theConstraints; |
107 blink::WebMediaTrackConstraintSet basic; | 111 WebMediaTrackConstraintSet basic; |
108 blink::WebVector<blink::WebMediaTrackConstraintSet> advanced(static_cast<siz
e_t>(1)); | 112 WebVector<WebMediaTrackConstraintSet> advanced(static_cast<size_t>(1)); |
109 basic.width.setMax(240); | 113 basic.width.setMax(240); |
110 advanced[0].echoCancellation.setExact(true); | 114 advanced[0].echoCancellation.setExact(true); |
111 theConstraints.initialize(basic, advanced); | 115 theConstraints.initialize(basic, advanced); |
112 EXPECT_EQ("{width: {max: 240}, advanced: [{echoCancellation: {exact: true}}]
}", theConstraints.toString().utf8()); | 116 EXPECT_EQ("{width: {max: 240}, advanced: [{echoCancellation: {exact: true}}]
}", theConstraints.toString().utf8()); |
113 | 117 |
114 blink::WebMediaConstraints nullConstraints; | 118 WebMediaConstraints nullConstraints; |
115 EXPECT_EQ("", nullConstraints.toString().utf8()); | 119 EXPECT_EQ("", nullConstraints.toString().utf8()); |
116 } | 120 } |
| 121 |
| 122 TEST(MediaTrackConstraintsTest, ConvertWebConstraintsBasic) |
| 123 { |
| 124 WebMediaConstraints input; |
| 125 MediaTrackConstraints output; |
| 126 |
| 127 MediaConstraintsImpl::convertConstraints(input, output); |
| 128 } |
| 129 |
| 130 TEST(MediaTrackConstraintsTest, ConvertWebSingleStringConstraint) |
| 131 { |
| 132 WebMediaConstraints input; |
| 133 MediaTrackConstraints output; |
| 134 |
| 135 WebMediaTrackConstraintSet basic; |
| 136 WebVector<WebMediaTrackConstraintSet> advanced; |
| 137 |
| 138 basic.facingMode.setIdeal(WebVector<WebString>(&"foo", 1)); |
| 139 input.initialize(basic, advanced); |
| 140 MediaConstraintsImpl::convertConstraints(input, output); |
| 141 ASSERT_TRUE(output.hasFacingMode()); |
| 142 ASSERT_TRUE(output.facingMode().isString()); |
| 143 EXPECT_EQ("foo", output.facingMode().getAsString()); |
| 144 } |
| 145 |
| 146 TEST(MediaTrackConstraintsTest, ConvertWebDoubleStringConstraint) |
| 147 { |
| 148 WebMediaConstraints input; |
| 149 MediaTrackConstraints output; |
| 150 |
| 151 WebVector<WebString> buffer(static_cast<size_t>(2u)); |
| 152 buffer[0] = "foo"; |
| 153 buffer[1] = "bar"; |
| 154 |
| 155 WebMediaTrackConstraintSet basic; |
| 156 std::vector<WebMediaTrackConstraintSet> advanced; |
| 157 basic.facingMode.setIdeal(buffer); |
| 158 input.initialize(basic, advanced); |
| 159 MediaConstraintsImpl::convertConstraints(input, output); |
| 160 ASSERT_TRUE(output.hasFacingMode()); |
| 161 ASSERT_TRUE(output.facingMode().isStringSequence()); |
| 162 auto outBuffer = output.facingMode().getAsStringSequence(); |
| 163 EXPECT_EQ("foo", outBuffer[0]); |
| 164 EXPECT_EQ("bar", outBuffer[1]); |
| 165 } |
| 166 |
| 167 TEST(MediaTrackConstraintsTest, ConvertBlinkStringConstraint) |
| 168 { |
| 169 MediaTrackConstraints input; |
| 170 WebMediaConstraints output; |
| 171 StringOrStringSequenceOrConstrainDOMStringParameters parameter; |
| 172 parameter.setString("foo"); |
| 173 input.setFacingMode(parameter); |
| 174 output = MediaConstraintsImpl::convertConstraintsToWeb(input); |
| 175 ASSERT_TRUE(output.basic().facingMode.hasIdeal()); |
| 176 ASSERT_EQ(1U, output.basic().facingMode.ideal().size()); |
| 177 ASSERT_EQ("foo", output.basic().facingMode.ideal()[0]); |
| 178 } |
| 179 |
| 180 TEST(MediaTrackConstraintsTest, ConvertBlinkComplexStringConstraint) |
| 181 { |
| 182 MediaTrackConstraints input; |
| 183 WebMediaConstraints output; |
| 184 StringOrStringSequenceOrConstrainDOMStringParameters parameter; |
| 185 ConstrainDOMStringParameters subparameter; |
| 186 StringOrStringSequence innerString; |
| 187 innerString.setString("foo"); |
| 188 subparameter.setIdeal(innerString); |
| 189 parameter.setConstrainDOMStringParameters(subparameter); |
| 190 input.setFacingMode(parameter); |
| 191 output = MediaConstraintsImpl::convertConstraintsToWeb(input); |
| 192 ASSERT_TRUE(output.basic().facingMode.hasIdeal()); |
| 193 ASSERT_EQ(1U, output.basic().facingMode.ideal().size()); |
| 194 ASSERT_EQ("foo", output.basic().facingMode.ideal()[0]); |
| 195 |
| 196 // Convert this back, and see that it appears as a single string. |
| 197 MediaTrackConstraints recycled; |
| 198 MediaConstraintsImpl::convertConstraints(output, recycled); |
| 199 ASSERT_TRUE(recycled.hasFacingMode()); |
| 200 ASSERT_TRUE(recycled.facingMode().isString()); |
| 201 ASSERT_EQ("foo", recycled.facingMode().getAsString()); |
| 202 } |
| 203 |
| 204 } // namespace blink |
OLD | NEW |