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
3 // found in the LICENSE file.
7 #include "content/renderer/media/media_stream_audio_processor_options.h"
8 #include "content/renderer/media/media_stream_constraints_util.h"
9 #include "content/renderer/media/media_stream_video_source.h"
10 #include "content/renderer/media/mock_media_constraint_factory.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 class MediaStreamConstraintsUtilTest
: public testing::Test
{
18 TEST_F(MediaStreamConstraintsUtilTest
, BooleanConstraints
) {
19 static const std::string kValueTrue
= "true";
20 static const std::string kValueFalse
= "false";
22 MockMediaConstraintFactory constraint_factory
;
23 // Mandatory constraints.
24 constraint_factory
.AddMandatory(MediaAudioConstraints::kEchoCancellation
,
26 constraint_factory
.AddMandatory(MediaAudioConstraints::kGoogEchoCancellation
,
28 blink::WebMediaConstraints constraints
=
29 constraint_factory
.CreateWebMediaConstraints();
30 bool value_true
= false;
31 bool value_false
= false;
32 EXPECT_TRUE(GetMandatoryConstraintValueAsBoolean(
33 constraints
, MediaAudioConstraints::kEchoCancellation
, &value_true
));
34 EXPECT_TRUE(GetMandatoryConstraintValueAsBoolean(
35 constraints
, MediaAudioConstraints::kGoogEchoCancellation
, &value_false
));
36 EXPECT_TRUE(value_true
);
37 EXPECT_FALSE(value_false
);
39 // Optional constraints.
40 constraint_factory
.AddOptional(MediaAudioConstraints::kEchoCancellation
,
42 constraint_factory
.AddOptional(MediaAudioConstraints::kGoogEchoCancellation
,
44 constraints
= constraint_factory
.CreateWebMediaConstraints();
45 EXPECT_TRUE(GetOptionalConstraintValueAsBoolean(
46 constraints
, MediaAudioConstraints::kEchoCancellation
, &value_false
));
47 EXPECT_TRUE(GetOptionalConstraintValueAsBoolean(
48 constraints
, MediaAudioConstraints::kGoogEchoCancellation
,
50 EXPECT_TRUE(value_true
);
51 EXPECT_FALSE(value_false
);
54 TEST_F(MediaStreamConstraintsUtilTest
, IntConstraints
) {
55 MockMediaConstraintFactory constraint_factory
;
58 constraint_factory
.AddMandatory(MediaStreamVideoSource::kMaxWidth
, width
);
59 constraint_factory
.AddMandatory(MediaStreamVideoSource::kMaxHeight
, height
);
60 blink::WebMediaConstraints constraints
=
61 constraint_factory
.CreateWebMediaConstraints();
64 EXPECT_TRUE(GetMandatoryConstraintValueAsInteger(
65 constraints
, MediaStreamVideoSource::kMaxWidth
, &value_width
));
66 EXPECT_TRUE(GetMandatoryConstraintValueAsInteger(
67 constraints
, MediaStreamVideoSource::kMaxHeight
, &value_height
));
68 EXPECT_EQ(width
, value_width
);
69 EXPECT_EQ(height
, value_height
);
73 constraint_factory
.AddOptional(MediaStreamVideoSource::kMaxWidth
, width
);
74 constraint_factory
.AddOptional(MediaStreamVideoSource::kMaxHeight
, height
);
75 constraints
= constraint_factory
.CreateWebMediaConstraints();
76 EXPECT_TRUE(GetOptionalConstraintValueAsInteger(
77 constraints
, MediaStreamVideoSource::kMaxWidth
, &value_width
));
78 EXPECT_TRUE(GetOptionalConstraintValueAsInteger(
79 constraints
, MediaStreamVideoSource::kMaxHeight
, &value_height
));
80 EXPECT_EQ(width
, value_width
);
81 EXPECT_EQ(height
, value_height
);
84 TEST_F(MediaStreamConstraintsUtilTest
, WrongBooleanConstraints
) {
85 static const std::string kWrongValueTrue
= "True";
86 static const std::string kWrongValueFalse
= "False";
87 MockMediaConstraintFactory constraint_factory
;
88 constraint_factory
.AddMandatory(MediaAudioConstraints::kEchoCancellation
,
90 constraint_factory
.AddMandatory(MediaAudioConstraints::kGoogEchoCancellation
,
92 blink::WebMediaConstraints constraints
=
93 constraint_factory
.CreateWebMediaConstraints();
94 bool value_false
= false;
95 EXPECT_FALSE(GetMandatoryConstraintValueAsBoolean(
96 constraints
, MediaAudioConstraints::kEchoCancellation
, &value_false
));
97 EXPECT_FALSE(value_false
);
98 EXPECT_FALSE(GetMandatoryConstraintValueAsBoolean(
99 constraints
, MediaAudioConstraints::kGoogEchoCancellation
, &value_false
));
100 EXPECT_FALSE(value_false
);
103 } // namespace content