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

Side by Side Diff: webrtc/api/datachannel_unittest.cc

Issue 2472113002: Correct stats for RTCPeerConnectionStats.dataChannels[Opened/Closed]. (Closed)
Patch Set: Addressed deadbeef's comments Created 4 years, 1 month 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
« no previous file with comments | « webrtc/api/datachannel.cc ('k') | webrtc/api/peerconnection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2013 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
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 observer_.reset(new FakeDataChannelObserver()); 87 observer_.reset(new FakeDataChannelObserver());
88 webrtc_data_channel_->RegisterObserver(observer_.get()); 88 webrtc_data_channel_->RegisterObserver(observer_.get());
89 } 89 }
90 90
91 webrtc::InternalDataChannelInit init_; 91 webrtc::InternalDataChannelInit init_;
92 std::unique_ptr<FakeDataChannelProvider> provider_; 92 std::unique_ptr<FakeDataChannelProvider> provider_;
93 std::unique_ptr<FakeDataChannelObserver> observer_; 93 std::unique_ptr<FakeDataChannelObserver> observer_;
94 rtc::scoped_refptr<DataChannel> webrtc_data_channel_; 94 rtc::scoped_refptr<DataChannel> webrtc_data_channel_;
95 }; 95 };
96 96
97 class StateSignalsListener : public sigslot::has_slots<> {
98 public:
99 int opened_count() const { return opened_count_; }
100 int closed_count() const { return closed_count_; }
101
102 void OnSignalOpened(DataChannel* data_channel) {
103 ++opened_count_;
104 }
105
106 void OnSignalClosed(DataChannel* data_channel) {
107 ++closed_count_;
108 }
109
110 private:
111 int opened_count_ = 0;
112 int closed_count_ = 0;
113 };
114
97 // Verifies that the data channel is connected to the transport after creation. 115 // Verifies that the data channel is connected to the transport after creation.
98 TEST_F(SctpDataChannelTest, ConnectedToTransportOnCreated) { 116 TEST_F(SctpDataChannelTest, ConnectedToTransportOnCreated) {
99 provider_->set_transport_available(true); 117 provider_->set_transport_available(true);
100 rtc::scoped_refptr<DataChannel> dc = 118 rtc::scoped_refptr<DataChannel> dc =
101 DataChannel::Create(provider_.get(), cricket::DCT_SCTP, "test1", init_); 119 DataChannel::Create(provider_.get(), cricket::DCT_SCTP, "test1", init_);
102 120
103 EXPECT_TRUE(provider_->IsConnected(dc.get())); 121 EXPECT_TRUE(provider_->IsConnected(dc.get()));
104 // The sid is not set yet, so it should not have added the streams. 122 // The sid is not set yet, so it should not have added the streams.
105 EXPECT_FALSE(provider_->IsSendStreamAdded(dc->id())); 123 EXPECT_FALSE(provider_->IsSendStreamAdded(dc->id()));
106 EXPECT_FALSE(provider_->IsRecvStreamAdded(dc->id())); 124 EXPECT_FALSE(provider_->IsRecvStreamAdded(dc->id()));
107 125
108 dc->SetSctpSid(0); 126 dc->SetSctpSid(0);
109 EXPECT_TRUE(provider_->IsSendStreamAdded(dc->id())); 127 EXPECT_TRUE(provider_->IsSendStreamAdded(dc->id()));
110 EXPECT_TRUE(provider_->IsRecvStreamAdded(dc->id())); 128 EXPECT_TRUE(provider_->IsRecvStreamAdded(dc->id()));
111 } 129 }
112 130
113 // Verifies that the data channel is connected to the transport if the transport 131 // Verifies that the data channel is connected to the transport if the transport
114 // is not available initially and becomes available later. 132 // is not available initially and becomes available later.
115 TEST_F(SctpDataChannelTest, ConnectedAfterTransportBecomesAvailable) { 133 TEST_F(SctpDataChannelTest, ConnectedAfterTransportBecomesAvailable) {
116 EXPECT_FALSE(provider_->IsConnected(webrtc_data_channel_.get())); 134 EXPECT_FALSE(provider_->IsConnected(webrtc_data_channel_.get()));
117 135
118 provider_->set_transport_available(true); 136 provider_->set_transport_available(true);
119 webrtc_data_channel_->OnTransportChannelCreated(); 137 webrtc_data_channel_->OnTransportChannelCreated();
120 EXPECT_TRUE(provider_->IsConnected(webrtc_data_channel_.get())); 138 EXPECT_TRUE(provider_->IsConnected(webrtc_data_channel_.get()));
121 } 139 }
122 140
123 // Tests the state of the data channel. 141 // Tests the state of the data channel.
124 TEST_F(SctpDataChannelTest, StateTransition) { 142 TEST_F(SctpDataChannelTest, StateTransition) {
143 StateSignalsListener state_signals_listener;
144 webrtc_data_channel_->SignalOpened.connect(
145 &state_signals_listener, &StateSignalsListener::OnSignalOpened);
146 webrtc_data_channel_->SignalClosed.connect(
147 &state_signals_listener, &StateSignalsListener::OnSignalClosed);
125 EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, 148 EXPECT_EQ(webrtc::DataChannelInterface::kConnecting,
126 webrtc_data_channel_->state()); 149 webrtc_data_channel_->state());
150 EXPECT_EQ(state_signals_listener.opened_count(), 0);
151 EXPECT_EQ(state_signals_listener.closed_count(), 0);
127 SetChannelReady(); 152 SetChannelReady();
128 153
129 EXPECT_EQ(webrtc::DataChannelInterface::kOpen, webrtc_data_channel_->state()); 154 EXPECT_EQ(webrtc::DataChannelInterface::kOpen, webrtc_data_channel_->state());
155 EXPECT_EQ(state_signals_listener.opened_count(), 1);
156 EXPECT_EQ(state_signals_listener.closed_count(), 0);
130 webrtc_data_channel_->Close(); 157 webrtc_data_channel_->Close();
131 EXPECT_EQ(webrtc::DataChannelInterface::kClosed, 158 EXPECT_EQ(webrtc::DataChannelInterface::kClosed,
132 webrtc_data_channel_->state()); 159 webrtc_data_channel_->state());
160 EXPECT_EQ(state_signals_listener.opened_count(), 1);
161 EXPECT_EQ(state_signals_listener.closed_count(), 1);
133 // Verifies that it's disconnected from the transport. 162 // Verifies that it's disconnected from the transport.
134 EXPECT_FALSE(provider_->IsConnected(webrtc_data_channel_.get())); 163 EXPECT_FALSE(provider_->IsConnected(webrtc_data_channel_.get()));
135 } 164 }
136 165
137 // Tests that DataChannel::buffered_amount() is correct after the channel is 166 // Tests that DataChannel::buffered_amount() is correct after the channel is
138 // blocked. 167 // blocked.
139 TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) { 168 TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) {
140 AddObserver(); 169 AddObserver();
141 SetChannelReady(); 170 SetChannelReady();
142 webrtc::DataBuffer buffer("abcd"); 171 webrtc::DataBuffer buffer("abcd");
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); 705 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id));
677 EXPECT_EQ(even_id, allocated_id); 706 EXPECT_EQ(even_id, allocated_id);
678 707
679 // Verifies that used higher ids are not reused. 708 // Verifies that used higher ids are not reused.
680 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_SERVER, &allocated_id)); 709 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_SERVER, &allocated_id));
681 EXPECT_EQ(odd_id + 6, allocated_id); 710 EXPECT_EQ(odd_id + 6, allocated_id);
682 711
683 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id)); 712 EXPECT_TRUE(allocator_.AllocateSid(rtc::SSL_CLIENT, &allocated_id));
684 EXPECT_EQ(even_id + 6, allocated_id); 713 EXPECT_EQ(even_id + 6, allocated_id);
685 } 714 }
OLDNEW
« no previous file with comments | « webrtc/api/datachannel.cc ('k') | webrtc/api/peerconnection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698