hta | a2a49d9 | 2016-03-04 10:51:39 | [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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "api/media_constraints_interface.h" |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include "absl/types/optional.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 14 | #include "api/test/fake_constraints.h" |
| 15 | #include "media/base/media_config.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 16 | #include "test/gtest.h" |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | namespace { |
| 21 | |
nisse | c36b31b | 2016-04-12 06:25:29 | [diff] [blame] | 22 | // Checks all settings touched by CopyConstraintsIntoRtcConfiguration, |
| 23 | // plus audio_jitter_buffer_max_packets. |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 24 | bool Matches(const PeerConnectionInterface::RTCConfiguration& a, |
| 25 | const PeerConnectionInterface::RTCConfiguration& b) { |
nisse | c36b31b | 2016-04-12 06:25:29 | [diff] [blame] | 26 | return a.disable_ipv6 == b.disable_ipv6 && |
| 27 | a.audio_jitter_buffer_max_packets == |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 28 | b.audio_jitter_buffer_max_packets && |
nisse | c36b31b | 2016-04-12 06:25:29 | [diff] [blame] | 29 | a.enable_rtp_data_channel == b.enable_rtp_data_channel && |
| 30 | a.screencast_min_bitrate == b.screencast_min_bitrate && |
| 31 | a.combined_audio_video_bwe == b.combined_audio_video_bwe && |
| 32 | a.enable_dtls_srtp == b.enable_dtls_srtp && |
Niels Möller | 1d7ecd2 | 2018-01-18 14:25:12 | [diff] [blame] | 33 | a.media_config == b.media_config; |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | TEST(MediaConstraintsInterface, CopyConstraintsIntoRtcConfiguration) { |
| 37 | FakeConstraints constraints; |
| 38 | PeerConnectionInterface::RTCConfiguration old_configuration; |
| 39 | PeerConnectionInterface::RTCConfiguration configuration; |
| 40 | |
| 41 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 42 | EXPECT_TRUE(Matches(old_configuration, configuration)); |
| 43 | |
| 44 | constraints.SetMandatory(MediaConstraintsInterface::kEnableIPv6, "true"); |
| 45 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 46 | EXPECT_FALSE(configuration.disable_ipv6); |
| 47 | constraints.SetMandatory(MediaConstraintsInterface::kEnableIPv6, "false"); |
| 48 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 49 | EXPECT_TRUE(configuration.disable_ipv6); |
| 50 | |
| 51 | constraints.SetMandatory(MediaConstraintsInterface::kScreencastMinBitrate, |
| 52 | 27); |
| 53 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 54 | EXPECT_TRUE(configuration.screencast_min_bitrate); |
| 55 | EXPECT_EQ(27, *(configuration.screencast_min_bitrate)); |
| 56 | |
| 57 | // An empty set of constraints will not overwrite |
| 58 | // values that are already present. |
| 59 | constraints = FakeConstraints(); |
| 60 | configuration = old_configuration; |
Oskar Sundbom | 36f8f3e | 2017-11-16 09:54:27 | [diff] [blame] | 61 | configuration.enable_dtls_srtp = true; |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 62 | configuration.audio_jitter_buffer_max_packets = 34; |
| 63 | CopyConstraintsIntoRtcConfiguration(&constraints, &configuration); |
| 64 | EXPECT_EQ(34, configuration.audio_jitter_buffer_max_packets); |
| 65 | ASSERT_TRUE(configuration.enable_dtls_srtp); |
| 66 | EXPECT_TRUE(*(configuration.enable_dtls_srtp)); |
| 67 | } |
| 68 | |
| 69 | } // namespace |
| 70 | |
| 71 | } // namespace webrtc |