blob: dab85eb971874e5e58eb6080d26727498126a681 [file] [log] [blame]
htaa2a49d92016-03-04 02:51:39 -08001/*
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
Niels Möllerdac03d92019-02-13 08:52:27 +010011#include "sdk/media_constraints.h"
htaa2a49d92016-03-04 02:51:39 -080012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include "test/gtest.h"
htaa2a49d92016-03-04 02:51:39 -080014
15namespace webrtc {
16
17namespace {
18
nissec36b31b2016-04-11 23:25:29 -070019// Checks all settings touched by CopyConstraintsIntoRtcConfiguration,
20// plus audio_jitter_buffer_max_packets.
htaa2a49d92016-03-04 02:51:39 -080021bool Matches(const PeerConnectionInterface::RTCConfiguration& a,
22 const PeerConnectionInterface::RTCConfiguration& b) {
nissec36b31b2016-04-11 23:25:29 -070023 return a.disable_ipv6 == b.disable_ipv6 &&
24 a.audio_jitter_buffer_max_packets ==
htaa2a49d92016-03-04 02:51:39 -080025 b.audio_jitter_buffer_max_packets &&
nissec36b31b2016-04-11 23:25:29 -070026 a.screencast_min_bitrate == b.screencast_min_bitrate &&
27 a.combined_audio_video_bwe == b.combined_audio_video_bwe &&
28 a.enable_dtls_srtp == b.enable_dtls_srtp &&
Niels Möller1d7ecd22018-01-18 15:25:12 +010029 a.media_config == b.media_config;
htaa2a49d92016-03-04 02:51:39 -080030}
31
Niels Möllerdac03d92019-02-13 08:52:27 +010032TEST(MediaConstraints, CopyConstraintsIntoRtcConfiguration) {
33 const MediaConstraints constraints_empty;
htaa2a49d92016-03-04 02:51:39 -080034 PeerConnectionInterface::RTCConfiguration old_configuration;
35 PeerConnectionInterface::RTCConfiguration configuration;
36
Niels Möllerdac03d92019-02-13 08:52:27 +010037 CopyConstraintsIntoRtcConfiguration(&constraints_empty, &configuration);
htaa2a49d92016-03-04 02:51:39 -080038 EXPECT_TRUE(Matches(old_configuration, configuration));
39
Niels Möllerdac03d92019-02-13 08:52:27 +010040 const MediaConstraints constraits_enable_ipv6(
41 {MediaConstraints::Constraint(MediaConstraints::kEnableIPv6, "true")},
42 {});
43 CopyConstraintsIntoRtcConfiguration(&constraits_enable_ipv6, &configuration);
htaa2a49d92016-03-04 02:51:39 -080044 EXPECT_FALSE(configuration.disable_ipv6);
Niels Möllerdac03d92019-02-13 08:52:27 +010045 const MediaConstraints constraints_disable_ipv6(
46 {MediaConstraints::Constraint(MediaConstraints::kEnableIPv6, "false")},
47 {});
48 CopyConstraintsIntoRtcConfiguration(&constraints_disable_ipv6,
49 &configuration);
htaa2a49d92016-03-04 02:51:39 -080050 EXPECT_TRUE(configuration.disable_ipv6);
51
Niels Möllerdac03d92019-02-13 08:52:27 +010052 const MediaConstraints constraints_screencast(
53 {MediaConstraints::Constraint(MediaConstraints::kScreencastMinBitrate,
54 "27")},
55 {});
56 CopyConstraintsIntoRtcConfiguration(&constraints_screencast, &configuration);
htaa2a49d92016-03-04 02:51:39 -080057 EXPECT_TRUE(configuration.screencast_min_bitrate);
58 EXPECT_EQ(27, *(configuration.screencast_min_bitrate));
59
60 // An empty set of constraints will not overwrite
61 // values that are already present.
htaa2a49d92016-03-04 02:51:39 -080062 configuration = old_configuration;
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +010063 configuration.enable_dtls_srtp = true;
htaa2a49d92016-03-04 02:51:39 -080064 configuration.audio_jitter_buffer_max_packets = 34;
Niels Möllerdac03d92019-02-13 08:52:27 +010065 CopyConstraintsIntoRtcConfiguration(&constraints_empty, &configuration);
htaa2a49d92016-03-04 02:51:39 -080066 EXPECT_EQ(34, configuration.audio_jitter_buffer_max_packets);
67 ASSERT_TRUE(configuration.enable_dtls_srtp);
68 EXPECT_TRUE(*(configuration.enable_dtls_srtp));
69}
70
71} // namespace
72
73} // namespace webrtc