Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 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/sessiondescription.h" |
| 11 | #include "rtc_base/gunit.h" |
| 12 | |
| 13 | namespace cricket { |
| 14 | |
| 15 | TEST(MediaContentDescriptionTest, ExtmapAllowMixedDefaultValue) { |
| 16 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 17 | EXPECT_EQ(MediaContentDescription::kNo, video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | TEST(MediaContentDescriptionTest, SetExtmapAllowMixed) { |
| 21 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 22 | 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 Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 25 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 26 | video_desc.extmap_allow_mixed_enum()); |
| 27 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kSession); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 28 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 29 | video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 30 | |
| 31 | // Not allowed to downgrade from kSession to kMedia. |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 32 | video_desc.set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 33 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 34 | video_desc.extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 35 | |
| 36 | // Always okay to set not supported. |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 37 | 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 Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 40 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 41 | 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 Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | TEST(MediaContentDescriptionTest, MixedOneTwoByteHeaderSupported) { |
| 47 | VideoContentDescription video_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 48 | 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 Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | TEST(SessionDescriptionTest, SetExtmapAllowMixed) { |
| 57 | SessionDescription session_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 58 | 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 Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | TEST(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 Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 70 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 71 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 72 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 73 | |
| 74 | // Don't downgrade from session level to media level |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 75 | video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 76 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 77 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 78 | |
| 79 | // Setting false on session level propagates to media level if the current |
| 80 | // state is kSession. |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 81 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 82 | EXPECT_EQ(MediaContentDescription::kNo, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 83 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 84 | |
| 85 | // Now possible to set at media level. |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 86 | video_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 87 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 88 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 89 | |
| 90 | // Setting false on session level does not override on media level if current |
| 91 | // state is kMedia. |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 92 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 93 | EXPECT_EQ(MediaContentDescription::kMedia, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 94 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 95 | |
| 96 | // Setting true on session level overrides setting on media level. |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 97 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 98 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 99 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | TEST(SessionDescriptionTest, AddContentTransfersExtmapAllowMixedSetting) { |
| 103 | SessionDescription session_desc; |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 104 | session_desc.set_extmap_allow_mixed(false); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 105 | MediaContentDescription* audio_desc = new AudioContentDescription(); |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 106 | audio_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 107 | |
| 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 Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 112 | audio_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 113 | |
| 114 | // If session setting is true, it's transferred to media level when new |
| 115 | // content is added. |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 116 | session_desc.set_extmap_allow_mixed(true); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 117 | MediaContentDescription* video_desc = new VideoContentDescription(); |
| 118 | session_desc.AddContent("video", MediaProtocolType::kRtp, video_desc); |
| 119 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 120 | video_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 121 | |
| 122 | // Session level setting overrides media level when new content is added. |
| 123 | MediaContentDescription* data_desc = new DataContentDescription; |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 124 | data_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 125 | session_desc.AddContent("data", MediaProtocolType::kRtp, data_desc); |
| 126 | EXPECT_EQ(MediaContentDescription::kSession, |
Johannes Kron | 9581bc4 | 2018-10-23 08:17:39 | [diff] [blame] | 127 | data_desc->extmap_allow_mixed_enum()); |
Johannes Kron | 9ac3c91 | 2018-10-12 08:54:26 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | } // namespace cricket |