OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 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 "webrtc/base/gunit.h" | |
12 #include "webrtc/base/helpers.h" | |
13 #include "webrtc/base/scoped_ptr.h" | |
14 #include "webrtc/base/thread.h" | |
15 #include "webrtc/p2p/base/dtlstransportchannel.h" | |
16 #include "webrtc/p2p/base/p2ptransportchannel.h" | |
17 #include "webrtc/p2p/base/portallocator.h" | |
18 #include "webrtc/p2p/base/session.h" | |
19 #include "webrtc/p2p/base/transportchannelproxy.h" | |
20 #include "webrtc/p2p/client/fakeportallocator.h" | |
21 | |
22 using cricket::BaseSession; | |
23 using cricket::DtlsTransportChannelWrapper; | |
24 using cricket::FakePortAllocator; | |
25 using cricket::P2PTransportChannel; | |
26 using cricket::PortAllocator; | |
27 using cricket::TransportChannelProxy; | |
28 using cricket::TransportProxy; | |
29 | |
30 class BaseSessionForTest : public BaseSession { | |
31 public: | |
32 BaseSessionForTest(rtc::Thread* signaling_thread, | |
33 rtc::Thread* worker_thread, | |
34 PortAllocator* port_allocator, | |
35 const std::string& sid, | |
36 const std::string& content_type, | |
37 bool initiator) | |
38 : BaseSession(signaling_thread, | |
39 worker_thread, | |
40 port_allocator, | |
41 sid, | |
42 content_type, | |
43 initiator) {} | |
44 using BaseSession::GetOrCreateTransportProxy; | |
45 }; | |
46 | |
47 class BaseSessionTest : public testing::Test { | |
48 public: | |
49 BaseSessionTest() | |
50 : port_allocator_( | |
51 new FakePortAllocator(rtc::Thread::Current(), nullptr)), | |
52 session_(new BaseSessionForTest( | |
53 rtc::Thread::Current(), | |
54 rtc::Thread::Current(), | |
55 port_allocator_.get(), | |
56 "123", | |
57 cricket::NS_JINGLE_RTP, | |
58 false)) {} | |
pthatcher1
2015/07/11 00:24:54
Can you run "git cl format"? This format looks ki
honghaiz3
2015/08/05 23:57:39
Done. This also fixed the formatting of a few othe
| |
59 P2PTransportChannel* CreateChannel(const std::string& content, | |
60 int component) { | |
61 TransportProxy* transport_proxy = | |
62 session_->GetOrCreateTransportProxy(content); | |
63 // This hacking is needed in order that the p2p transport channel | |
64 // will be created in the following. | |
65 transport_proxy->CompleteNegotiation(); | |
66 | |
67 TransportChannelProxy* channel_proxy = static_cast<TransportChannelProxy*>( | |
68 session_->CreateChannel(content, component)); | |
69 DtlsTransportChannelWrapper* dtls_channel = | |
70 static_cast<DtlsTransportChannelWrapper*>(channel_proxy->impl()); | |
71 return static_cast<P2PTransportChannel*> (dtls_channel->channel()); | |
72 } | |
73 | |
74 rtc::scoped_ptr<PortAllocator> port_allocator_; | |
75 rtc::scoped_ptr<BaseSessionForTest> session_; | |
76 }; | |
77 | |
78 | |
79 TEST_F(BaseSessionTest, TestSetIceReceivingTimeout) { | |
80 P2PTransportChannel* channel1 = CreateChannel("audio", 1); | |
81 ASSERT_NE(channel1, nullptr); | |
82 // These are the default values. | |
83 EXPECT_EQ(2500, channel1->receiving_timeout()); | |
84 EXPECT_EQ(250, channel1->check_receiving_delay()); | |
85 // Set the timeout to a different value. | |
86 session_->SetIceConnectionReceivingTimeout(1000); | |
87 EXPECT_EQ(1000, channel1->receiving_timeout()); | |
88 EXPECT_EQ(100, channel1->check_receiving_delay()); | |
89 | |
90 // Even if a channel is created after setting the receiving timeout, | |
91 // the set timeout value is applied to the new channel. | |
92 P2PTransportChannel* channel2 = CreateChannel("video", 2); | |
93 ASSERT_NE(channel2, nullptr); | |
94 EXPECT_EQ(1000, channel2->receiving_timeout()); | |
95 EXPECT_EQ(100, channel2->check_receiving_delay()); | |
96 | |
97 // Test minimum checking delay. | |
98 session_->SetIceConnectionReceivingTimeout(200); | |
99 EXPECT_EQ(200, channel1->receiving_timeout()); | |
100 EXPECT_EQ(50, channel1->check_receiving_delay()); | |
101 EXPECT_EQ(200, channel2->receiving_timeout()); | |
102 EXPECT_EQ(50, channel2->check_receiving_delay()); | |
103 } | |
OLD | NEW |