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

Side by Side Diff: webrtc/p2p/base/transportcontroller_unittest.cc

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: minor cleanup Created 5 years, 4 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
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/gunit.h" 11 #include "webrtc/base/gunit.h"
12 #include "webrtc/base/helpers.h" 12 #include "webrtc/base/helpers.h"
13 #include "webrtc/base/scoped_ptr.h" 13 #include "webrtc/base/scoped_ptr.h"
14 #include "webrtc/base/thread.h" 14 #include "webrtc/base/thread.h"
15 #include "webrtc/p2p/base/dtlstransportchannel.h" 15 #include "webrtc/p2p/base/dtlstransportchannel.h"
16 #include "webrtc/p2p/base/p2ptransportchannel.h" 16 #include "webrtc/p2p/base/p2ptransportchannel.h"
17 #include "webrtc/p2p/base/portallocator.h" 17 #include "webrtc/p2p/base/portallocator.h"
18 #include "webrtc/p2p/base/session.h" 18 #include "webrtc/p2p/base/transportcontroller.h"
19 #include "webrtc/p2p/base/transportchannelproxy.h" 19 #include "webrtc/p2p/base/transportchannelproxy.h"
20 #include "webrtc/p2p/client/fakeportallocator.h" 20 #include "webrtc/p2p/client/fakeportallocator.h"
21 21
22 using cricket::BaseSession; 22 using cricket::TransportController;
23 using cricket::TransportChannel;
23 using cricket::DtlsTransportChannelWrapper; 24 using cricket::DtlsTransportChannelWrapper;
24 using cricket::FakePortAllocator; 25 using cricket::FakePortAllocator;
25 using cricket::P2PTransportChannel; 26 using cricket::P2PTransportChannel;
26 using cricket::PortAllocator; 27 using cricket::PortAllocator;
27 using cricket::TransportChannelProxy; 28 using cricket::TransportChannelProxy;
28 using cricket::TransportProxy;
29 29
30 class BaseSessionForTest : public BaseSession { 30 class TransportControllerForTest : public TransportController {
31 public: 31 public:
32 BaseSessionForTest(rtc::Thread* signaling_thread, 32 TransportControllerForTest(rtc::Thread* signaling_thread,
33 rtc::Thread* worker_thread, 33 rtc::Thread* worker_thread,
34 PortAllocator* port_allocator, 34 PortAllocator* port_allocator,
35 const std::string& sid, 35 bool initiator)
36 const std::string& content_type, 36 : TransportController(signaling_thread,
37 bool initiator) 37 worker_thread,
38 : BaseSession(signaling_thread, 38 port_allocator) {
39 worker_thread, 39 SetIceRole(initiator ? cricket::ICEROLE_CONTROLLING
40 port_allocator, 40 : cricket::ICEROLE_CONTROLLED);
41 sid, 41 }
42 content_type,
43 initiator) {}
44 using BaseSession::GetOrCreateTransportProxy;
45 }; 42 };
46 43
47 class BaseSessionTest : public testing::Test { 44 class TransportControllerTest : public testing::Test {
48 public: 45 public:
49 BaseSessionTest() 46 TransportControllerTest()
50 : port_allocator_(new FakePortAllocator(rtc::Thread::Current(), nullptr)), 47 : port_allocator_(new FakePortAllocator(rtc::Thread::Current(), nullptr)),
51 session_(new BaseSessionForTest(rtc::Thread::Current(), 48 transport_controller_(
52 rtc::Thread::Current(), 49 new TransportControllerForTest(rtc::Thread::Current(),
53 port_allocator_.get(), 50 rtc::Thread::Current(),
54 "123", 51 port_allocator_.get(),
55 cricket::NS_JINGLE_RTP, 52 false)) {}
56 false)) {} 53
57 P2PTransportChannel* CreateChannel(const std::string& content, 54 P2PTransportChannel* CreateChannel(const std::string& content,
58 int component) { 55 int component) {
59 TransportProxy* transport_proxy = 56 TransportChannel* channel =
60 session_->GetOrCreateTransportProxy(content); 57 transport_controller_->CreateTransportChannel_w(content, component);
61 // This hacking is needed in order that the p2p transport channel
62 // will be created in the following.
63 transport_proxy->CompleteNegotiation();
64
65 TransportChannelProxy* channel_proxy = static_cast<TransportChannelProxy*>(
66 session_->CreateChannel(content, component));
67 DtlsTransportChannelWrapper* dtls_channel = 58 DtlsTransportChannelWrapper* dtls_channel =
68 static_cast<DtlsTransportChannelWrapper*>(channel_proxy->impl()); 59 static_cast<DtlsTransportChannelWrapper*>(channel);
69 return static_cast<P2PTransportChannel*>(dtls_channel->channel()); 60 return static_cast<P2PTransportChannel*>(dtls_channel->channel());
70 } 61 }
71 62
72 rtc::scoped_ptr<PortAllocator> port_allocator_; 63 rtc::scoped_ptr<PortAllocator> port_allocator_;
73 rtc::scoped_ptr<BaseSessionForTest> session_; 64 rtc::scoped_ptr<TransportControllerForTest> transport_controller_;
74 }; 65 };
75 66
76 TEST_F(BaseSessionTest, TestSetIceReceivingTimeout) { 67 TEST_F(TransportControllerTest, TestSetIceReceivingTimeout) {
77 P2PTransportChannel* channel1 = CreateChannel("audio", 1); 68 P2PTransportChannel* channel1 = CreateChannel("audio", 1);
78 ASSERT_NE(channel1, nullptr); 69 ASSERT_NE(channel1, nullptr);
79 // These are the default values. 70 // These are the default values.
80 EXPECT_EQ(2500, channel1->receiving_timeout()); 71 EXPECT_EQ(2500, channel1->receiving_timeout());
81 EXPECT_EQ(250, channel1->check_receiving_delay()); 72 EXPECT_EQ(250, channel1->check_receiving_delay());
82 // Set the timeout to a different value. 73 // Set the timeout to a different value.
83 session_->SetIceConnectionReceivingTimeout(1000); 74 transport_controller_->SetIceConnectionReceivingTimeout(1000);
84 EXPECT_EQ(1000, channel1->receiving_timeout()); 75 EXPECT_EQ(1000, channel1->receiving_timeout());
85 EXPECT_EQ(100, channel1->check_receiving_delay()); 76 EXPECT_EQ(100, channel1->check_receiving_delay());
86 77
87 // Even if a channel is created after setting the receiving timeout, 78 // Even if a channel is created after setting the receiving timeout,
88 // the set timeout value is applied to the new channel. 79 // the set timeout value is applied to the new channel.
89 P2PTransportChannel* channel2 = CreateChannel("video", 2); 80 P2PTransportChannel* channel2 = CreateChannel("video", 2);
90 ASSERT_NE(channel2, nullptr); 81 ASSERT_NE(channel2, nullptr);
91 EXPECT_EQ(1000, channel2->receiving_timeout()); 82 EXPECT_EQ(1000, channel2->receiving_timeout());
92 EXPECT_EQ(100, channel2->check_receiving_delay()); 83 EXPECT_EQ(100, channel2->check_receiving_delay());
93 84
94 // Test minimum checking delay. 85 // Test minimum checking delay.
95 session_->SetIceConnectionReceivingTimeout(200); 86 transport_controller_->SetIceConnectionReceivingTimeout(200);
96 EXPECT_EQ(200, channel1->receiving_timeout()); 87 EXPECT_EQ(200, channel1->receiving_timeout());
97 EXPECT_EQ(50, channel1->check_receiving_delay()); 88 EXPECT_EQ(50, channel1->check_receiving_delay());
98 EXPECT_EQ(200, channel2->receiving_timeout()); 89 EXPECT_EQ(200, channel2->receiving_timeout());
99 EXPECT_EQ(50, channel2->check_receiving_delay()); 90 EXPECT_EQ(50, channel2->check_receiving_delay());
100 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698