Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(965)

Unified Diff: third_party/WebKit/Source/modules/mediastream/MediaConstraintsTest.cpp

Issue 1977513004: Adds multiple forms of MediaStreamTrack constraints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Tommi's comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1d5724b858d44a743e3bf181a91f05cfbdfe7c75 100644
--- a/third_party/WebKit/Source/modules/mediastream/MediaConstraintsTest.cpp
+++ b/third_party/WebKit/Source/modules/mediastream/MediaConstraintsTest.cpp
@@ -2,21 +2,25 @@
// 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"
+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 +29,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 +64,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 +73,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 +97,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 +107,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>(&"foo", 1));
+ 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;
+
+ WebVector<WebString> buffer(static_cast<size_t>(2u));
+ buffer[0] = "foo";
+ buffer[1] = "bar";
+
+ WebMediaTrackConstraintSet basic;
+ std::vector<WebMediaTrackConstraintSet> advanced;
+ basic.facingMode.setIdeal(buffer);
+ 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

Powered by Google App Engine
This is Rietveld 408576698