hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "api/mediaconstraintsinterface.h" |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "api/test/fakeconstraints.h" |
| 14 | #include "rtc_base/gunit.h" |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | namespace { |
| 19 | |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 20 | // Checks all settings touched by CopyConstraintsIntoRtcConfiguration, |
| 21 | // plus audio_jitter_buffer_max_packets. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 22 | bool Matches(const PeerConnectionInterface::RTCConfiguration& a, |
| 23 | const PeerConnectionInterface::RTCConfiguration& b) { |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 24 | return a.disable_ipv6 == b.disable_ipv6 && |
| 25 | a.audio_jitter_buffer_max_packets == |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 26 | b.audio_jitter_buffer_max_packets && |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 27 | a.enable_rtp_data_channel == b.enable_rtp_data_channel && |
| 28 | a.screencast_min_bitrate == b.screencast_min_bitrate && |
| 29 | a.combined_audio_video_bwe == b.combined_audio_video_bwe && |
| 30 | a.enable_dtls_srtp == b.enable_dtls_srtp && |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 31 | a.media_config == b.media_config; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | TEST(MediaConstraintsInterface, CopyConstraintsIntoRtcConfiguration) { |
| 35 | FakeConstraints constraints; |
| 36 | PeerConnectionInterface::RTCConfiguration old_configuration; |
| 37 | PeerConnectionInterface::RTCConfiguration configuration; |
| 38 | |
| 39 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 40 | EXPECT_TRUE(Matches(old_configuration, configuration)); |
| 41 | |
| 42 | constraints.SetMandatory(MediaConstraintsInterface::kEnableIPv6, "true"); |
| 43 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 44 | EXPECT_FALSE(configuration.disable_ipv6); |
| 45 | constraints.SetMandatory(MediaConstraintsInterface::kEnableIPv6, "false"); |
| 46 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 47 | EXPECT_TRUE(configuration.disable_ipv6); |
| 48 | |
| 49 | constraints.SetMandatory(MediaConstraintsInterface::kScreencastMinBitrate, |
| 50 | 27); |
| 51 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 52 | EXPECT_TRUE(configuration.screencast_min_bitrate); |
| 53 | EXPECT_EQ(27, *(configuration.screencast_min_bitrate)); |
| 54 | |
| 55 | // An empty set of constraints will not overwrite |
| 56 | // values that are already present. |
| 57 | constraints = FakeConstraints(); |
| 58 | configuration = old_configuration; |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 59 | configuration.enable_dtls_srtp = true; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 60 | configuration.audio_jitter_buffer_max_packets = 34; |
| 61 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 62 | EXPECT_EQ(34, configuration.audio_jitter_buffer_max_packets); |
| 63 | ASSERT_TRUE(configuration.enable_dtls_srtp); |
| 64 | EXPECT_TRUE(*(configuration.enable_dtls_srtp)); |
| 65 | } |
| 66 | |
| 67 | } // namespace |
| 68 | |
| 69 | } // namespace webrtc |