Chromium Code Reviews| Index: third_party/WebKit/Source/modules/mediastream/MediaConstraintsTest.cpp |
| diff --git a/third_party/WebKit/Source/modules/mediastream/MediaConstraintsTest.cpp b/third_party/WebKit/Source/modules/mediastream/MediaConstraintsTest.cpp |
| index adc955480005b7e7b117f000057c87d81fa87f34..ae4b574df1fdd169a0888ff6bdd2bb8293846e4c 100644 |
| --- a/third_party/WebKit/Source/modules/mediastream/MediaConstraintsTest.cpp |
| +++ b/third_party/WebKit/Source/modules/mediastream/MediaConstraintsTest.cpp |
| @@ -2,21 +2,27 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "modules/mediastream/MediaConstraintsImpl.h" |
| +#include "modules/mediastream/MediaTrackConstraints.h" |
| #include "public/platform/WebMediaConstraints.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "wtf/Vector.h" |
| +#include "wtf/text/WTFString.h" |
| + |
| +namespace blink { |
| // The MediaTrackConstraintsTest group tests the types declared in |
| // WebKit/public/platform/WebMediaConstraints.h |
| TEST(MediaTrackConstraintsTest, LongConstraint) |
| { |
| - blink::LongConstraint rangeConstraint(nullptr); |
| + LongConstraint rangeConstraint(nullptr); |
| rangeConstraint.setMin(5); |
| rangeConstraint.setMax(6); |
| EXPECT_TRUE(rangeConstraint.matches(5)); |
| EXPECT_TRUE(rangeConstraint.matches(6)); |
| EXPECT_FALSE(rangeConstraint.matches(4)); |
| EXPECT_FALSE(rangeConstraint.matches(7)); |
| - blink::LongConstraint exactConstraint(nullptr); |
| + LongConstraint exactConstraint(nullptr); |
| exactConstraint.setExact(5); |
| EXPECT_FALSE(exactConstraint.matches(4)); |
| EXPECT_TRUE(exactConstraint.matches(5)); |
| @@ -25,27 +31,27 @@ TEST(MediaTrackConstraintsTest, LongConstraint) |
| TEST(MediaTrackConstraintsTest, DoubleConstraint) |
| { |
| - blink::DoubleConstraint rangeConstraint(nullptr); |
| + DoubleConstraint rangeConstraint(nullptr); |
| EXPECT_TRUE(rangeConstraint.isEmpty()); |
| rangeConstraint.setMin(5.0); |
| rangeConstraint.setMax(6.5); |
| EXPECT_FALSE(rangeConstraint.isEmpty()); |
| // Matching within epsilon |
| - EXPECT_TRUE(rangeConstraint.matches(5.0 - blink::DoubleConstraint::kConstraintEpsilon / 2)); |
| - EXPECT_TRUE(rangeConstraint.matches(6.5 + blink::DoubleConstraint::kConstraintEpsilon / 2)); |
| - blink::DoubleConstraint exactConstraint(nullptr); |
| + EXPECT_TRUE(rangeConstraint.matches(5.0 - DoubleConstraint::kConstraintEpsilon / 2)); |
| + EXPECT_TRUE(rangeConstraint.matches(6.5 + DoubleConstraint::kConstraintEpsilon / 2)); |
| + DoubleConstraint exactConstraint(nullptr); |
| exactConstraint.setExact(5.0); |
| EXPECT_FALSE(rangeConstraint.isEmpty()); |
| EXPECT_FALSE(exactConstraint.matches(4.9)); |
| EXPECT_TRUE(exactConstraint.matches(5.0)); |
| - EXPECT_TRUE(exactConstraint.matches(5.0 - blink::DoubleConstraint::kConstraintEpsilon / 2)); |
| - EXPECT_TRUE(exactConstraint.matches(5.0 + blink::DoubleConstraint::kConstraintEpsilon / 2)); |
| + EXPECT_TRUE(exactConstraint.matches(5.0 - DoubleConstraint::kConstraintEpsilon / 2)); |
| + EXPECT_TRUE(exactConstraint.matches(5.0 + DoubleConstraint::kConstraintEpsilon / 2)); |
| EXPECT_FALSE(exactConstraint.matches(5.1)); |
| } |
| TEST(MediaTrackConstraintsTest, BooleanConstraint) |
| { |
| - blink::BooleanConstraint boolConstraint(nullptr); |
| + BooleanConstraint boolConstraint(nullptr); |
| EXPECT_TRUE(boolConstraint.isEmpty()); |
| EXPECT_TRUE(boolConstraint.matches(false)); |
| EXPECT_TRUE(boolConstraint.matches(true)); |
| @@ -60,7 +66,7 @@ TEST(MediaTrackConstraintsTest, BooleanConstraint) |
| TEST(MediaTrackConstraintsTest, ConstraintSetEmpty) |
| { |
| - blink::WebMediaTrackConstraintSet theSet; |
| + WebMediaTrackConstraintSet theSet; |
| EXPECT_TRUE(theSet.isEmpty()); |
| theSet.echoCancellation.setExact(false); |
| EXPECT_FALSE(theSet.isEmpty()); |
| @@ -69,13 +75,13 @@ TEST(MediaTrackConstraintsTest, ConstraintSetEmpty) |
| TEST(MediaTrackConstraintsTest, ConstraintName) |
| { |
| const char* theName = "name"; |
| - blink::BooleanConstraint boolConstraint(theName); |
| + BooleanConstraint boolConstraint(theName); |
| EXPECT_EQ(theName, boolConstraint.name()); |
| } |
| TEST(MediaTrackConstraintsTest, MandatoryChecks) |
| { |
| - blink::WebMediaTrackConstraintSet theSet; |
| + WebMediaTrackConstraintSet theSet; |
| std::string foundName; |
| EXPECT_FALSE(theSet.hasMandatory()); |
| EXPECT_FALSE(theSet.hasMandatoryOutsideSet({ "width" }, foundName)); |
| @@ -93,7 +99,7 @@ TEST(MediaTrackConstraintsTest, MandatoryChecks) |
| TEST(MediaTrackConstraintsTest, SetToString) |
| { |
| - blink::WebMediaTrackConstraintSet theSet; |
| + WebMediaTrackConstraintSet theSet; |
| EXPECT_EQ("", theSet.toString()); |
| theSet.width.setMax(240); |
| EXPECT_EQ("width: {max: 240}", theSet.toString().utf8()); |
| @@ -103,14 +109,98 @@ TEST(MediaTrackConstraintsTest, SetToString) |
| TEST(MediaTrackConstraintsTest, ConstraintsToString) |
| { |
| - blink::WebMediaConstraints theConstraints; |
| - blink::WebMediaTrackConstraintSet basic; |
| - blink::WebVector<blink::WebMediaTrackConstraintSet> advanced(static_cast<size_t>(1)); |
| + WebMediaConstraints theConstraints; |
| + WebMediaTrackConstraintSet basic; |
| + WebVector<WebMediaTrackConstraintSet> advanced(static_cast<size_t>(1)); |
| basic.width.setMax(240); |
| advanced[0].echoCancellation.setExact(true); |
| theConstraints.initialize(basic, advanced); |
| EXPECT_EQ("{width: {max: 240}, advanced: [{echoCancellation: {exact: true}}]}", theConstraints.toString().utf8()); |
| - blink::WebMediaConstraints nullConstraints; |
| + WebMediaConstraints nullConstraints; |
| EXPECT_EQ("", nullConstraints.toString().utf8()); |
| } |
| + |
| +TEST(MediaTrackConstraintsTest, ConvertWebConstraintsBasic) |
| +{ |
| + WebMediaConstraints input; |
| + MediaTrackConstraints output; |
| + |
| + MediaConstraintsImpl::convertConstraints(input, output); |
| +} |
| + |
| +TEST(MediaTrackConstraintsTest, ConvertWebSingleStringConstraint) |
| +{ |
| + WebMediaConstraints input; |
| + MediaTrackConstraints output; |
| + |
| + WebMediaTrackConstraintSet basic; |
| + WebVector<WebMediaTrackConstraintSet> advanced; |
| + |
| + 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
|
| + input.initialize(basic, advanced); |
| + MediaConstraintsImpl::convertConstraints(input, output); |
| + ASSERT_TRUE(output.hasFacingMode()); |
| + ASSERT_TRUE(output.facingMode().isString()); |
| + EXPECT_EQ("foo", output.facingMode().getAsString()); |
| +} |
| + |
| +TEST(MediaTrackConstraintsTest, ConvertWebDoubleStringConstraint) |
| +{ |
| + WebMediaConstraints input; |
| + MediaTrackConstraints output; |
| + |
| + WebMediaTrackConstraintSet basic; |
| + 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
|
| + Vector<String> buffer; |
| + buffer.append(String("foo")); |
| + buffer.append(String("bar")); |
| + |
| + 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
|
| + input.initialize(basic, advanced); |
| + MediaConstraintsImpl::convertConstraints(input, output); |
| + ASSERT_TRUE(output.hasFacingMode()); |
| + ASSERT_TRUE(output.facingMode().isStringSequence()); |
| + auto outBuffer = output.facingMode().getAsStringSequence(); |
| + EXPECT_EQ("foo", outBuffer[0]); |
| + EXPECT_EQ("bar", outBuffer[1]); |
| +} |
| + |
| +TEST(MediaTrackConstraintsTest, ConvertBlinkStringConstraint) |
| +{ |
| + MediaTrackConstraints input; |
| + WebMediaConstraints output; |
| + StringOrStringSequenceOrConstrainDOMStringParameters parameter; |
| + parameter.setString("foo"); |
| + input.setFacingMode(parameter); |
| + output = MediaConstraintsImpl::convertConstraintsToWeb(input); |
| + ASSERT_TRUE(output.basic().facingMode.hasIdeal()); |
| + ASSERT_EQ(1U, output.basic().facingMode.ideal().size()); |
| + ASSERT_EQ("foo", output.basic().facingMode.ideal()[0]); |
| +} |
| + |
| +TEST(MediaTrackConstraintsTest, ConvertBlinkComplexStringConstraint) |
| +{ |
| + MediaTrackConstraints input; |
| + WebMediaConstraints output; |
| + StringOrStringSequenceOrConstrainDOMStringParameters parameter; |
| + ConstrainDOMStringParameters subparameter; |
| + StringOrStringSequence innerString; |
| + innerString.setString("foo"); |
| + subparameter.setIdeal(innerString); |
| + parameter.setConstrainDOMStringParameters(subparameter); |
| + input.setFacingMode(parameter); |
| + output = MediaConstraintsImpl::convertConstraintsToWeb(input); |
| + ASSERT_TRUE(output.basic().facingMode.hasIdeal()); |
| + ASSERT_EQ(1U, output.basic().facingMode.ideal().size()); |
| + ASSERT_EQ("foo", output.basic().facingMode.ideal()[0]); |
| + |
| + // Convert this back, and see that it appears as a single string. |
| + MediaTrackConstraints recycled; |
| + MediaConstraintsImpl::convertConstraints(output, recycled); |
| + ASSERT_TRUE(recycled.hasFacingMode()); |
| + ASSERT_TRUE(recycled.facingMode().isString()); |
| + ASSERT_EQ("foo", recycled.facingMode().getAsString()); |
| +} |
| + |
| +} // namespace blink |