Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: webrtc/ortc/ortcfactory_unittest.cc

Issue 2675173003: Adding "adapter" ORTC objects on top of ChannelManager/BaseChannel/etc. (Closed)
Patch Set: More sender/receiver tests. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2017 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
11 #include <memory>
12
13 #include "webrtc/base/fakenetwork.h"
14 #include "webrtc/base/gunit.h"
15 #include "webrtc/base/physicalsocketserver.h"
16 #include "webrtc/base/virtualsocketserver.h"
17 #include "webrtc/media/base/fakemediaengine.h"
18 #include "webrtc/ortc/ortcfactory.h"
19 #include "webrtc/ortc/testrtpparameters.h"
20 #include "webrtc/p2p/base/fakepackettransport.h"
21
22 namespace webrtc {
23
24 // This test uses a virtual network and fake media engine, in order to test the
25 // OrtcFactory at only an API level. Any end-to-end test should go in
26 // ortcfactory_integrationtest.cc instead.
27 class OrtcFactoryTest : public testing::Test {
28 public:
29 OrtcFactoryTest()
30 : virtual_socket_server_(&physical_socket_server_),
31 socket_server_scope_(&virtual_socket_server_),
32 fake_packet_transport_("fake transport") {
33 ortc_factory_ = OrtcFactory::Create(
34 nullptr, nullptr, &fake_network_manager_, nullptr,
35 nullptr, std::unique_ptr<cricket::MediaEngineInterface>(
36 new cricket::FakeMediaEngine()))
37 .MoveValue();
38 }
39
40 protected:
41 // Uses a single premade FakePacketTransport, so shouldn't be called twice in
42 // the same test.
43 std::unique_ptr<RtpTransportInterface>
44 CreateRtpTransportWithFakePacketTransport() {
45 return ortc_factory_
46 ->CreateRtpTransport(MakeRtcpMuxParameters(), &fake_packet_transport_,
47 nullptr, nullptr)
48 .MoveValue();
49 }
50
51 rtc::PhysicalSocketServer physical_socket_server_;
52 rtc::VirtualSocketServer virtual_socket_server_;
53 rtc::SocketServerScope socket_server_scope_;
54 rtc::FakeNetworkManager fake_network_manager_;
55 rtc::FakePacketTransport fake_packet_transport_;
56 std::unique_ptr<OrtcFactoryInterface> ortc_factory_;
57 };
58
59 TEST_F(OrtcFactoryTest, CanCreateMultipleRtpTransportControllers) {
60 auto controller_result1 = ortc_factory_->CreateRtpTransportController();
61 EXPECT_TRUE(controller_result1.ok());
62 auto controller_result2 = ortc_factory_->CreateRtpTransportController();
63 EXPECT_TRUE(controller_result1.ok());
64 }
65
66 // Simple test for the successful cases of CreateRtpTransport.
67 TEST_F(OrtcFactoryTest, CreateRtpTransportWithAndWithoutMux) {
68 rtc::FakePacketTransport rtp("rtp");
69 rtc::FakePacketTransport rtcp("rtcp");
70 // With muxed RTCP.
71 RtcpParameters rtcp_parameters;
72 rtcp_parameters.mux = true;
73 auto result = ortc_factory_->CreateRtpTransport(rtcp_parameters, &rtp,
74 nullptr, nullptr);
75 EXPECT_TRUE(result.ok());
76 result.MoveValue().reset();
77 // With non-muxed RTCP.
78 rtcp_parameters.mux = false;
79 result =
80 ortc_factory_->CreateRtpTransport(rtcp_parameters, &rtp, &rtcp, nullptr);
81 EXPECT_TRUE(result.ok());
82 }
83
84 // If no CNAME is provided, one should be generated and returned by
85 // GetRtpParameters.
86 TEST_F(OrtcFactoryTest, CreateRtpTransportGeneratesCname) {
87 rtc::FakePacketTransport rtp("rtp");
88 RtcpParameters rtcp_parameters;
89 rtcp_parameters.mux = true;
90 auto result = ortc_factory_->CreateRtpTransport(rtcp_parameters, &rtp,
91 nullptr, nullptr);
92 ASSERT_TRUE(result.ok());
93 EXPECT_FALSE(result.value()->GetRtcpParameters().cname.empty());
94 }
95
96 TEST_F(OrtcFactoryTest, CreateRtpTransportWithNoPacketTransport) {
97 auto result = ortc_factory_->CreateRtpTransport(MakeRtcpMuxParameters(),
98 nullptr, nullptr, nullptr);
99 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, result.error().type());
100 }
101
102 // If the |mux| member of the RtcpParameters is false, both an RTP and RTCP
103 // packet transport are needed.
104 TEST_F(OrtcFactoryTest, CreateRtpTransportWithMissingRtcpTransport) {
105 rtc::FakePacketTransport rtp("rtp");
106 RtcpParameters rtcp_parameters;
107 rtcp_parameters.mux = false;
108 auto result = ortc_factory_->CreateRtpTransport(rtcp_parameters, &rtp,
109 nullptr, nullptr);
110 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, result.error().type());
111 }
112
113 // If the |mux| member of the RtcpParameters is true, only an RTP packet
114 // transport is necessary. So, passing in an RTCP transport is most likely
115 // an accident, and thus should be treated as an error.
116 TEST_F(OrtcFactoryTest, CreateRtpTransportWithExtraneousRtcpTransport) {
117 rtc::FakePacketTransport rtp("rtp");
118 rtc::FakePacketTransport rtcp("rtcp");
119 RtcpParameters rtcp_parameters;
120 rtcp_parameters.mux = true;
121 auto result =
122 ortc_factory_->CreateRtpTransport(rtcp_parameters, &rtp, &rtcp, nullptr);
123 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, result.error().type());
124 }
125
126 // Basic test that CreateUdpTransport works with AF_INET and AF_INET6.
127 TEST_F(OrtcFactoryTest, CreateUdpTransport) {
128 auto result = ortc_factory_->CreateUdpTransport(AF_INET);
129 EXPECT_TRUE(result.ok());
130 result = ortc_factory_->CreateUdpTransport(AF_INET6);
131 EXPECT_TRUE(result.ok());
132 }
133
134 // Test CreateUdpPort with the |min_port| and |max_port| arguments.
135 TEST_F(OrtcFactoryTest, CreateUdpTransportWithPortRange) {
136 auto socket_result1 = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002);
137 ASSERT_TRUE(socket_result1.ok());
138 EXPECT_EQ(2000, socket_result1.value()->GetLocalAddress().port());
139 auto socket_result2 = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002);
140 ASSERT_TRUE(socket_result2.ok());
141 EXPECT_EQ(2001, socket_result2.value()->GetLocalAddress().port());
142 auto socket_result3 = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002);
143 ASSERT_TRUE(socket_result3.ok());
144 EXPECT_EQ(2002, socket_result3.value()->GetLocalAddress().port());
145
146 // All sockets in the range have been exhausted, so the next call should
147 // fail.
148 auto failed_result = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002);
149 EXPECT_EQ(RTCErrorType::RESOURCE_EXHAUSTED, failed_result.error().type());
150
151 // If one socket is destroyed, that port should be freed up again.
152 socket_result2.MoveValue().reset();
153 auto socket_result4 = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002);
154 ASSERT_TRUE(socket_result4.ok());
155 EXPECT_EQ(2001, socket_result4.value()->GetLocalAddress().port());
156 }
157
158 // Just sanity check that each "GetCapabilities" method returns some codecs.
159 TEST_F(OrtcFactoryTest, GetSenderAndReceiverCapabilities) {
160 RtpCapabilities audio_send_caps =
161 ortc_factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_AUDIO);
162 EXPECT_GT(audio_send_caps.codecs.size(), 0u);
163 RtpCapabilities video_send_caps =
164 ortc_factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO);
165 EXPECT_GT(video_send_caps.codecs.size(), 0u);
166 RtpCapabilities audio_receive_caps =
167 ortc_factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_AUDIO);
168 EXPECT_GT(audio_receive_caps.codecs.size(), 0u);
169 RtpCapabilities video_receive_caps =
170 ortc_factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_VIDEO);
171 EXPECT_GT(video_receive_caps.codecs.size(), 0u);
172 }
173
174 // Calling CreateRtpSender with a null track should fail, since that makes it
175 // impossible to know whether to create an audio or video sender. The
176 // application should be using the method that takes a cricket::MediaType
177 // instead.
178 TEST_F(OrtcFactoryTest, CreateSenderWithNullTrack) {
179 auto rtp_transport = CreateRtpTransportWithFakePacketTransport();
180 auto result = ortc_factory_->CreateRtpSender(nullptr, rtp_transport.get());
181 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, result.error().type());
182 }
183
184 // Calling CreateRtpSender or CreateRtpReceiver with MEDIA_TYPE_DATA should
185 // fail.
186 TEST_F(OrtcFactoryTest, CreateSenderOrReceieverWithInvalidKind) {
187 auto rtp_transport = CreateRtpTransportWithFakePacketTransport();
188 auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_DATA,
189 rtp_transport.get());
190 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, sender_result.error().type());
191 auto receiver_result = ortc_factory_->CreateRtpReceiver(
192 cricket::MEDIA_TYPE_DATA, rtp_transport.get());
193 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, receiver_result.error().type());
194 }
195
196 TEST_F(OrtcFactoryTest, CreateSendersOrReceieversWithNullTransport) {
197 auto sender_result =
198 ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO, nullptr);
199 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, sender_result.error().type());
200 auto receiver_result =
201 ortc_factory_->CreateRtpReceiver(cricket::MEDIA_TYPE_AUDIO, nullptr);
202 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, receiver_result.error().type());
203 }
204
205 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698