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

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: Set media engine on voice channel 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, worker_thread, port_allocator) {
37 bool initiator) 37 SetIceRole(initiator ? cricket::ICEROLE_CONTROLLING
38 : BaseSession(signaling_thread, 38 : cricket::ICEROLE_CONTROLLED);
39 worker_thread, 39 }
40 port_allocator,
41 sid,
42 content_type,
43 initiator) {}
44 using BaseSession::GetOrCreateTransportProxy;
45 }; 40 };
46 41
47 class BaseSessionTest : public testing::Test { 42 class TransportControllerTest : public testing::Test {
48 public: 43 public:
49 BaseSessionTest() 44 TransportControllerTest()
50 : port_allocator_(new FakePortAllocator(rtc::Thread::Current(), nullptr)), 45 : port_allocator_(new FakePortAllocator(rtc::Thread::Current(), nullptr)),
51 session_(new BaseSessionForTest(rtc::Thread::Current(), 46 transport_controller_(
52 rtc::Thread::Current(), 47 new TransportControllerForTest(rtc::Thread::Current(),
53 port_allocator_.get(), 48 rtc::Thread::Current(),
54 "123", 49 port_allocator_.get(),
55 cricket::NS_JINGLE_RTP, 50 false)) {}
56 false)) {} 51
57 P2PTransportChannel* CreateChannel(const std::string& content, 52 P2PTransportChannel* CreateChannel(const std::string& content,
58 int component) { 53 int component) {
59 TransportProxy* transport_proxy = 54 TransportChannel* channel =
60 session_->GetOrCreateTransportProxy(content); 55 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 = 56 DtlsTransportChannelWrapper* dtls_channel =
68 static_cast<DtlsTransportChannelWrapper*>(channel_proxy->impl()); 57 static_cast<DtlsTransportChannelWrapper*>(channel);
69 return static_cast<P2PTransportChannel*>(dtls_channel->channel()); 58 return static_cast<P2PTransportChannel*>(dtls_channel->channel());
70 } 59 }
71 60
72 rtc::scoped_ptr<PortAllocator> port_allocator_; 61 rtc::scoped_ptr<PortAllocator> port_allocator_;
73 rtc::scoped_ptr<BaseSessionForTest> session_; 62 rtc::scoped_ptr<TransportControllerForTest> transport_controller_;
74 }; 63 };
75 64
76 TEST_F(BaseSessionTest, TestSetIceReceivingTimeout) { 65 TEST_F(TransportControllerTest, TestSetIceReceivingTimeout) {
77 P2PTransportChannel* channel1 = CreateChannel("audio", 1); 66 P2PTransportChannel* channel1 = CreateChannel("audio", 1);
78 ASSERT_NE(channel1, nullptr); 67 ASSERT_NE(channel1, nullptr);
79 // These are the default values. 68 // These are the default values.
80 EXPECT_EQ(2500, channel1->receiving_timeout()); 69 EXPECT_EQ(2500, channel1->receiving_timeout());
81 EXPECT_EQ(250, channel1->check_receiving_delay()); 70 EXPECT_EQ(250, channel1->check_receiving_delay());
82 // Set the timeout to a different value. 71 // Set the timeout to a different value.
83 session_->SetIceConnectionReceivingTimeout(1000); 72 transport_controller_->SetIceConnectionReceivingTimeout(1000);
84 EXPECT_EQ(1000, channel1->receiving_timeout()); 73 EXPECT_EQ(1000, channel1->receiving_timeout());
85 EXPECT_EQ(100, channel1->check_receiving_delay()); 74 EXPECT_EQ(100, channel1->check_receiving_delay());
86 75
87 // Even if a channel is created after setting the receiving timeout, 76 // Even if a channel is created after setting the receiving timeout,
88 // the set timeout value is applied to the new channel. 77 // the set timeout value is applied to the new channel.
89 P2PTransportChannel* channel2 = CreateChannel("video", 2); 78 P2PTransportChannel* channel2 = CreateChannel("video", 2);
90 ASSERT_NE(channel2, nullptr); 79 ASSERT_NE(channel2, nullptr);
91 EXPECT_EQ(1000, channel2->receiving_timeout()); 80 EXPECT_EQ(1000, channel2->receiving_timeout());
92 EXPECT_EQ(100, channel2->check_receiving_delay()); 81 EXPECT_EQ(100, channel2->check_receiving_delay());
93 82
94 // Test minimum checking delay. 83 // Test minimum checking delay.
95 session_->SetIceConnectionReceivingTimeout(200); 84 transport_controller_->SetIceConnectionReceivingTimeout(200);
96 EXPECT_EQ(200, channel1->receiving_timeout()); 85 EXPECT_EQ(200, channel1->receiving_timeout());
97 EXPECT_EQ(50, channel1->check_receiving_delay()); 86 EXPECT_EQ(50, channel1->check_receiving_delay());
98 EXPECT_EQ(200, channel2->receiving_timeout()); 87 EXPECT_EQ(200, channel2->receiving_timeout());
99 EXPECT_EQ(50, channel2->check_receiving_delay()); 88 EXPECT_EQ(50, channel2->check_receiving_delay());
100 } 89 }
pthatcher2 2015/08/19 18:32:16 I think we need to add a lot more tests. Sorry, w
Taylor Brandstetter 2015/08/27 22:15:57 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698