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