1 /*
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/session_description.h"
11
12 #include "test/gtest.h"
13
14 namespace cricket {
15
TEST(MediaContentDescriptionTest,ExtmapAllowMixedDefaultValue)16 TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) {
17 VideoContentDescription video_desc;
18 EXPECT_EQ(MediaContentDescription::kMedia,
19 video_desc.extmap_allow_mixed_enum());
20 }
21
TEST(MediaContentDescriptionTest,SetExtmapAllowMixed)22 TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) {
23 VideoContentDescription video_desc;
24 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
25 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
26 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
27 EXPECT_EQ(MediaContentDescription::kMedia,
28 video_desc.extmap_allow_mixed_enum());
29 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
30 EXPECT_EQ(MediaContentDescription::kSession,
31 video_desc.extmap_allow_mixed_enum());
32
33 // Not allowed to downgrade from kSession to kMedia.
34 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
35 EXPECT_EQ(MediaContentDescription::kSession,
36 video_desc.extmap_allow_mixed_enum());
37
38 // Always okay to set not supported.
39 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
40 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
41 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
42 EXPECT_EQ(MediaContentDescription::kMedia,
43 video_desc.extmap_allow_mixed_enum());
44 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
45 EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum());
46 }
47
TEST(MediaContentDescriptionTest,MixedOneTwoByteHeaderSupported)48 TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) {
49 VideoContentDescription video_desc;
50 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
51 EXPECT_FALSE(video_desc.extmap_allow_mixed());
52 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
53 EXPECT_TRUE(video_desc.extmap_allow_mixed());
54 video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession);
55 EXPECT_TRUE(video_desc.extmap_allow_mixed());
56 }
57
TEST(SessionDescriptionTest,SetExtmapAllowMixed)58 TEST(SessionDescriptionTest, SetExtmapAllowMixed) {
59 SessionDescription session_desc;
60 session_desc.set_extmap_allow_mixed(true);
61 EXPECT_TRUE(session_desc.extmap_allow_mixed());
62 session_desc.set_extmap_allow_mixed(false);
63 EXPECT_FALSE(session_desc.extmap_allow_mixed());
64 }
65
TEST(SessionDescriptionTest,SetExtmapAllowMixedPropagatesToMediaLevel)66 TEST(SessionDescriptionTest, SetExtmapAllowMixedPropagatesToMediaLevel) {
67 SessionDescription session_desc;
68 session_desc.AddContent("video", MediaProtocolType::kRtp,
69 std::make_unique<VideoContentDescription>());
70 MediaContentDescription* video_desc =
71 session_desc.GetContentDescriptionByName("video");
72
73 // Setting true on session level propagates to media level.
74 session_desc.set_extmap_allow_mixed(true);
75 EXPECT_EQ(MediaContentDescription::kSession,
76 video_desc->extmap_allow_mixed_enum());
77
78 // Don't downgrade from session level to media level
79 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
80 EXPECT_EQ(MediaContentDescription::kSession,
81 video_desc->extmap_allow_mixed_enum());
82
83 // Setting false on session level propagates to media level if the current
84 // state is kSession.
85 session_desc.set_extmap_allow_mixed(false);
86 EXPECT_EQ(MediaContentDescription::kNo,
87 video_desc->extmap_allow_mixed_enum());
88
89 // Now possible to set at media level.
90 video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
91 EXPECT_EQ(MediaContentDescription::kMedia,
92 video_desc->extmap_allow_mixed_enum());
93
94 // Setting false on session level does not override on media level if current
95 // state is kMedia.
96 session_desc.set_extmap_allow_mixed(false);
97 EXPECT_EQ(MediaContentDescription::kMedia,
98 video_desc->extmap_allow_mixed_enum());
99
100 // Setting true on session level overrides setting on media level.
101 session_desc.set_extmap_allow_mixed(true);
102 EXPECT_EQ(MediaContentDescription::kSession,
103 video_desc->extmap_allow_mixed_enum());
104 }
105
TEST(SessionDescriptionTest,AddContentTransfersExtmapAllowMixedSetting)106 TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) {
107 SessionDescription session_desc;
108 session_desc.set_extmap_allow_mixed(false);
109 std::unique_ptr<MediaContentDescription> audio_desc =
110 std::make_unique<AudioContentDescription>();
111 audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia);
112
113 // If session setting is false, media level setting is preserved when new
114 // content is added.
115 session_desc.AddContent("audio", MediaProtocolType::kRtp,
116 std::move(audio_desc));
117 EXPECT_EQ(MediaContentDescription::kMedia,
118 session_desc.GetContentDescriptionByName("audio")
119 ->extmap_allow_mixed_enum());
120
121 // If session setting is true, it's transferred to media level when new
122 // content is added.
123 session_desc.set_extmap_allow_mixed(true);
124 std::unique_ptr<MediaContentDescription> video_desc =
125 std::make_unique<VideoContentDescription>();
126 session_desc.AddContent("video", MediaProtocolType::kRtp,
127 std::move(video_desc));
128 EXPECT_EQ(MediaContentDescription::kSession,
129 session_desc.GetContentDescriptionByName("video")
130 ->extmap_allow_mixed_enum());
131 }
132
133 } // namespace cricket
134