blob: dcacf587f562b4f9a5267b4ac275add788e2731b [file] [log] [blame]
Johannes Kron9ac3c912018-10-12 08:54:261/*
2 * Copyright 2018 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#include "pc/sessiondescription.h"
11#include "rtc_base/gunit.h"
12
13namespace cricket {
14
15TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) {
16 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 08:17:3917 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2618}
19
20TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) {
21 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 08:17:3922 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
23 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
24 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:2625 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:3926 video_desc.extmap_allow_mixed_enum());
27 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
Johannes Kron9ac3c912018-10-12 08:54:2628 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3929 video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2630
31 // Not allowed to downgrade from kSession to kMedia.
Johannes Kron9581bc42018-10-23 08:17:3932 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:2633 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3934 video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2635
36 // Always okay to set not supported.
Johannes Kron9581bc42018-10-23 08:17:3937 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
38 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
39 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:2640 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:3941 video_desc.extmap_allow_mixed_enum());
42 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
43 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2644}
45
46TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) {
47 VideoContentDescription video_desc;
Johannes Kron9581bc42018-10-23 08:17:3948 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
49 EXPECT_FALSE(video_desc.extmap_allow_mixed());
50 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
51 EXPECT_TRUE(video_desc.extmap_allow_mixed());
52 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
53 EXPECT_TRUE(video_desc.extmap_allow_mixed());
Johannes Kron9ac3c912018-10-12 08:54:2654}
55
56TEST(SessionDescriptionTest, SetExtmapAllowMixed) {
57 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 08:17:3958 session_desc.set_extmap_allow_mixed(true);
59 EXPECT_TRUE(session_desc.extmap_allow_mixed());
60 session_desc.set_extmap_allow_mixed(false);
61 EXPECT_FALSE(session_desc.extmap_allow_mixed());
Johannes Kron9ac3c912018-10-12 08:54:2662}
63
64TEST(SessionDescriptionTest, SetExtmapAllowMixedPropagatesToMediaLevel) {
65 SessionDescription session_desc;
66 MediaContentDescription* video_desc = new VideoContentDescription();
67 session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
68
69 // Setting true on session level propagates to media level.
Johannes Kron9581bc42018-10-23 08:17:3970 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 08:54:2671 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3972 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2673
74 // Don't downgrade from session level to media level
Johannes Kron9581bc42018-10-23 08:17:3975 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:2676 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3977 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2678
79 // Setting false on session level propagates to media level if the current
80 // state is kSession.
Johannes Kron9581bc42018-10-23 08:17:3981 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 08:54:2682 EXPECT_EQ(MediaContentDescription::kNo,
Johannes Kron9581bc42018-10-23 08:17:3983 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2684
85 // Now possible to set at media level.
Johannes Kron9581bc42018-10-23 08:17:3986 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:2687 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:3988 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2689
90 // Setting false on session level does not override on media level if current
91 // state is kMedia.
Johannes Kron9581bc42018-10-23 08:17:3992 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 08:54:2693 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:3994 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:2695
96 // Setting true on session level overrides setting on media level.
Johannes Kron9581bc42018-10-23 08:17:3997 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 08:54:2698 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:3999 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26100}
101
102TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) {
103 SessionDescription session_desc;
Johannes Kron9581bc42018-10-23 08:17:39104 session_desc.set_extmap_allow_mixed(false);
Johannes Kron9ac3c912018-10-12 08:54:26105 MediaContentDescription* audio_desc = new AudioContentDescription();
Johannes Kron9581bc42018-10-23 08:17:39106 audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:26107
108 // If session setting is false, media level setting is preserved when new
109 // content is added.
110 session_desc.AddContent("audio", MediaProtocolType::kRtp, audio_desc);
111 EXPECT_EQ(MediaContentDescription::kMedia,
Johannes Kron9581bc42018-10-23 08:17:39112 audio_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26113
114 // If session setting is true, it's transferred to media level when new
115 // content is added.
Johannes Kron9581bc42018-10-23 08:17:39116 session_desc.set_extmap_allow_mixed(true);
Johannes Kron9ac3c912018-10-12 08:54:26117 MediaContentDescription* video_desc = new VideoContentDescription();
118 session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
119 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:39120 video_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26121
122 // Session level setting overrides media level when new content is added.
123 MediaContentDescription* data_desc = new DataContentDescription;
Johannes Kron9581bc42018-10-23 08:17:39124 data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
Johannes Kron9ac3c912018-10-12 08:54:26125 session_desc.AddContent("data", MediaProtocolType::kRtp, data_desc);
126 EXPECT_EQ(MediaContentDescription::kSession,
Johannes Kron9581bc42018-10-23 08:17:39127 data_desc->extmap_allow_mixed_enum());
Johannes Kron9ac3c912018-10-12 08:54:26128}
129
130} // namespace cricket