blob: b539524bc3b253efc139cef51bdf6c9af839ee36 [file] [log] [blame]
Johannes Kron9ac3c912018-10-12 10:54:26 +02001/*
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;
17 EXPECT_EQ(MediaContentDescription::kNo,
18 video_desc.extmap_allow_mixed_headers());
19}
20
21TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) {
22 VideoContentDescription video_desc;
23 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kNo);
24 EXPECT_EQ(MediaContentDescription::kNo,
25 video_desc.extmap_allow_mixed_headers());
26 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kMedia);
27 EXPECT_EQ(MediaContentDescription::kMedia,
28 video_desc.extmap_allow_mixed_headers());
29 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kSession);
30 EXPECT_EQ(MediaContentDescription::kSession,
31 video_desc.extmap_allow_mixed_headers());
32
33 // Not allowed to downgrade from kSession to kMedia.
34 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kMedia);
35 EXPECT_EQ(MediaContentDescription::kSession,
36 video_desc.extmap_allow_mixed_headers());
37
38 // Always okay to set not supported.
39 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kNo);
40 EXPECT_EQ(MediaContentDescription::kNo,
41 video_desc.extmap_allow_mixed_headers());
42 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kMedia);
43 EXPECT_EQ(MediaContentDescription::kMedia,
44 video_desc.extmap_allow_mixed_headers());
45 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kNo);
46 EXPECT_EQ(MediaContentDescription::kNo,
47 video_desc.extmap_allow_mixed_headers());
48}
49
50TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) {
51 VideoContentDescription video_desc;
52 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kNo);
53 EXPECT_FALSE(video_desc.mixed_one_two_byte_header_extensions_supported());
54 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kMedia);
55 EXPECT_TRUE(video_desc.mixed_one_two_byte_header_extensions_supported());
56 video_desc.set_extmap_allow_mixed_headers(MediaContentDescription::kSession);
57 EXPECT_TRUE(video_desc.mixed_one_two_byte_header_extensions_supported());
58}
59
60TEST(SessionDescriptionTest, SetExtmapAllowMixed) {
61 SessionDescription session_desc;
62 session_desc.set_extmap_allow_mixed_headers(true);
63 EXPECT_TRUE(session_desc.extmap_allow_mixed_headers());
64 session_desc.set_extmap_allow_mixed_headers(false);
65 EXPECT_FALSE(session_desc.extmap_allow_mixed_headers());
66}
67
68TEST(SessionDescriptionTest, SetExtmapAllowMixedPropagatesToMediaLevel) {
69 SessionDescription session_desc;
70 MediaContentDescription* video_desc = new VideoContentDescription();
71 session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
72
73 // Setting true on session level propagates to media level.
74 session_desc.set_extmap_allow_mixed_headers(true);
75 EXPECT_EQ(MediaContentDescription::kSession,
76 video_desc->extmap_allow_mixed_headers());
77
78 // Don't downgrade from session level to media level
79 video_desc->set_extmap_allow_mixed_headers(MediaContentDescription::kMedia);
80 EXPECT_EQ(MediaContentDescription::kSession,
81 video_desc->extmap_allow_mixed_headers());
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_headers(false);
86 EXPECT_EQ(MediaContentDescription::kNo,
87 video_desc->extmap_allow_mixed_headers());
88
89 // Now possible to set at media level.
90 video_desc->set_extmap_allow_mixed_headers(MediaContentDescription::kMedia);
91 EXPECT_EQ(MediaContentDescription::kMedia,
92 video_desc->extmap_allow_mixed_headers());
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_headers(false);
97 EXPECT_EQ(MediaContentDescription::kMedia,
98 video_desc->extmap_allow_mixed_headers());
99
100 // Setting true on session level overrides setting on media level.
101 session_desc.set_extmap_allow_mixed_headers(true);
102 EXPECT_EQ(MediaContentDescription::kSession,
103 video_desc->extmap_allow_mixed_headers());
104}
105
106TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) {
107 SessionDescription session_desc;
108 session_desc.set_extmap_allow_mixed_headers(false);
109 MediaContentDescription* audio_desc = new AudioContentDescription();
110 audio_desc->set_extmap_allow_mixed_headers(MediaContentDescription::kMedia);
111
112 // If session setting is false, media level setting is preserved when new
113 // content is added.
114 session_desc.AddContent("audio", MediaProtocolType::kRtp, audio_desc);
115 EXPECT_EQ(MediaContentDescription::kMedia,
116 audio_desc->extmap_allow_mixed_headers());
117
118 // If session setting is true, it's transferred to media level when new
119 // content is added.
120 session_desc.set_extmap_allow_mixed_headers(true);
121 MediaContentDescription* video_desc = new VideoContentDescription();
122 session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc);
123 EXPECT_EQ(MediaContentDescription::kSession,
124 video_desc->extmap_allow_mixed_headers());
125
126 // Session level setting overrides media level when new content is added.
127 MediaContentDescription* data_desc = new DataContentDescription;
128 data_desc->set_extmap_allow_mixed_headers(MediaContentDescription::kMedia);
129 session_desc.AddContent("data", MediaProtocolType::kRtp, data_desc);
130 EXPECT_EQ(MediaContentDescription::kSession,
131 data_desc->extmap_allow_mixed_headers());
132}
133
134} // namespace cricket