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

Side by Side Diff: talk/app/webrtc/datachannel_unittest.cc

Issue 1207613006: Support for onbufferedamountlow (Closed) Base URL: https://chromium.googlesource.com/external/webrtc/trunk/talk.git@master
Patch Set: Fix path problems Created 5 years, 5 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
« no previous file with comments | « talk/app/webrtc/datachannel.cc ('k') | talk/app/webrtc/datachannelinterface.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 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 17 matching lines...) Expand all
28 #include "talk/app/webrtc/datachannel.h" 28 #include "talk/app/webrtc/datachannel.h"
29 #include "talk/app/webrtc/sctputils.h" 29 #include "talk/app/webrtc/sctputils.h"
30 #include "talk/app/webrtc/test/fakedatachannelprovider.h" 30 #include "talk/app/webrtc/test/fakedatachannelprovider.h"
31 #include "webrtc/base/gunit.h" 31 #include "webrtc/base/gunit.h"
32 32
33 using webrtc::DataChannel; 33 using webrtc::DataChannel;
34 34
35 class FakeDataChannelObserver : public webrtc::DataChannelObserver { 35 class FakeDataChannelObserver : public webrtc::DataChannelObserver {
36 public: 36 public:
37 FakeDataChannelObserver() 37 FakeDataChannelObserver()
38 : messages_received_(0), on_state_change_count_(0) {} 38 : messages_received_(0), on_state_change_count_(0),
39 on_buffered_amount_change_count_(0) {}
juberti1 2015/06/25 18:56:22 fix indent - 1 initializer per line
bemasc2 2015/06/25 19:56:08 Done.
39 40
40 void OnStateChange() { 41 void OnStateChange() {
41 ++on_state_change_count_; 42 ++on_state_change_count_;
42 } 43 }
43 44
45 void OnBufferedAmountChange(uint64 previous_amount) {
46 ++on_buffered_amount_change_count_;
47 }
48
44 void OnMessage(const webrtc::DataBuffer& buffer) { 49 void OnMessage(const webrtc::DataBuffer& buffer) {
45 ++messages_received_; 50 ++messages_received_;
46 } 51 }
47 52
48 size_t messages_received() const { 53 size_t messages_received() const {
49 return messages_received_; 54 return messages_received_;
50 } 55 }
51 56
52 void ResetOnStateChangeCount() { 57 void ResetOnStateChangeCount() {
53 on_state_change_count_ = 0; 58 on_state_change_count_ = 0;
54 } 59 }
55 60
61 void ResetOnBufferedAmountChangeCount() {
62 on_buffered_amount_change_count_ = 0;
63 }
64
56 size_t on_state_change_count() const { 65 size_t on_state_change_count() const {
57 return on_state_change_count_; 66 return on_state_change_count_;
58 } 67 }
59 68
69 size_t on_buffered_amount_change_count() const {
70 return on_buffered_amount_change_count_;
71 }
72
60 private: 73 private:
61 size_t messages_received_; 74 size_t messages_received_;
62 size_t on_state_change_count_; 75 size_t on_state_change_count_;
76 size_t on_buffered_amount_change_count_;
63 }; 77 };
64 78
65 class SctpDataChannelTest : public testing::Test { 79 class SctpDataChannelTest : public testing::Test {
66 protected: 80 protected:
67 SctpDataChannelTest() 81 SctpDataChannelTest()
68 : webrtc_data_channel_( 82 : webrtc_data_channel_(
69 DataChannel::Create( 83 DataChannel::Create(
70 &provider_, cricket::DCT_SCTP, "test", init_)) { 84 &provider_, cricket::DCT_SCTP, "test", init_)) {
71 } 85 }
72 86
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 webrtc_data_channel_->Close(); 140 webrtc_data_channel_->Close();
127 EXPECT_EQ(webrtc::DataChannelInterface::kClosed, 141 EXPECT_EQ(webrtc::DataChannelInterface::kClosed,
128 webrtc_data_channel_->state()); 142 webrtc_data_channel_->state());
129 // Verifies that it's disconnected from the transport. 143 // Verifies that it's disconnected from the transport.
130 EXPECT_FALSE(provider_.IsConnected(webrtc_data_channel_.get())); 144 EXPECT_FALSE(provider_.IsConnected(webrtc_data_channel_.get()));
131 } 145 }
132 146
133 // Tests that DataChannel::buffered_amount() is correct after the channel is 147 // Tests that DataChannel::buffered_amount() is correct after the channel is
134 // blocked. 148 // blocked.
135 TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) { 149 TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) {
150 AddObserver();
136 SetChannelReady(); 151 SetChannelReady();
137 webrtc::DataBuffer buffer("abcd"); 152 webrtc::DataBuffer buffer("abcd");
138 EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); 153 EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
139 154
140 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); 155 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount());
156 EXPECT_EQ(0U, observer_->on_buffered_amount_change_count());
141 157
142 provider_.set_send_blocked(true); 158 provider_.set_send_blocked(true);
143 159
144 const int number_of_packets = 3; 160 const int number_of_packets = 3;
145 for (int i = 0; i < number_of_packets; ++i) { 161 for (int i = 0; i < number_of_packets; ++i) {
146 EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); 162 EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
147 } 163 }
148 EXPECT_EQ(buffer.data.size() * number_of_packets, 164 EXPECT_EQ(buffer.data.size() * number_of_packets,
149 webrtc_data_channel_->buffered_amount()); 165 webrtc_data_channel_->buffered_amount());
166 EXPECT_EQ(number_of_packets, observer_->on_buffered_amount_change_count());
150 } 167 }
151 168
152 // Tests that the queued data are sent when the channel transitions from blocked 169 // Tests that the queued data are sent when the channel transitions from blocked
153 // to unblocked. 170 // to unblocked.
154 TEST_F(SctpDataChannelTest, QueuedDataSentWhenUnblocked) { 171 TEST_F(SctpDataChannelTest, QueuedDataSentWhenUnblocked) {
172 AddObserver();
155 SetChannelReady(); 173 SetChannelReady();
156 webrtc::DataBuffer buffer("abcd"); 174 webrtc::DataBuffer buffer("abcd");
157 provider_.set_send_blocked(true); 175 provider_.set_send_blocked(true);
158 EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); 176 EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
159 177
178 EXPECT_EQ(1U, observer_->on_buffered_amount_change_count());
179
160 provider_.set_send_blocked(false); 180 provider_.set_send_blocked(false);
161 SetChannelReady(); 181 SetChannelReady();
162 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); 182 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount());
183 EXPECT_EQ(2U, observer_->on_buffered_amount_change_count());
163 } 184 }
164 185
165 // Tests that no crash when the channel is blocked right away while trying to 186 // Tests that no crash when the channel is blocked right away while trying to
166 // send queued data. 187 // send queued data.
167 TEST_F(SctpDataChannelTest, BlockedWhenSendQueuedDataNoCrash) { 188 TEST_F(SctpDataChannelTest, BlockedWhenSendQueuedDataNoCrash) {
189 AddObserver();
168 SetChannelReady(); 190 SetChannelReady();
169 webrtc::DataBuffer buffer("abcd"); 191 webrtc::DataBuffer buffer("abcd");
170 provider_.set_send_blocked(true); 192 provider_.set_send_blocked(true);
171 EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); 193 EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
194 EXPECT_EQ(1U, observer_->on_buffered_amount_change_count());
172 195
173 // Set channel ready while it is still blocked. 196 // Set channel ready while it is still blocked.
174 SetChannelReady(); 197 SetChannelReady();
175 EXPECT_EQ(buffer.size(), webrtc_data_channel_->buffered_amount()); 198 EXPECT_EQ(buffer.size(), webrtc_data_channel_->buffered_amount());
199 EXPECT_EQ(1U, observer_->on_buffered_amount_change_count());
176 200
177 // Unblock the channel to send queued data again, there should be no crash. 201 // Unblock the channel to send queued data again, there should be no crash.
178 provider_.set_send_blocked(false); 202 provider_.set_send_blocked(false);
179 SetChannelReady(); 203 SetChannelReady();
180 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); 204 EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount());
205 EXPECT_EQ(2U, observer_->on_buffered_amount_change_count());
181 } 206 }
182 207
183 // Tests that the queued control message is sent when channel is ready. 208 // Tests that the queued control message is sent when channel is ready.
184 TEST_F(SctpDataChannelTest, OpenMessageSent) { 209 TEST_F(SctpDataChannelTest, OpenMessageSent) {
185 // Initially the id is unassigned. 210 // Initially the id is unassigned.
186 EXPECT_EQ(-1, webrtc_data_channel_->id()); 211 EXPECT_EQ(-1, webrtc_data_channel_->id());
187 212
188 SetChannelReady(); 213 SetChannelReady();
189 EXPECT_GE(webrtc_data_channel_->id(), 0); 214 EXPECT_GE(webrtc_data_channel_->id(), 0);
190 EXPECT_EQ(cricket::DMT_CONTROL, provider_.last_send_data_params().type); 215 EXPECT_EQ(cricket::DMT_CONTROL, provider_.last_send_data_params().type);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 EXPECT_EQ(webrtc::DataChannelInterface::kOpen, 498 EXPECT_EQ(webrtc::DataChannelInterface::kOpen,
474 webrtc_data_channel_->state()); 499 webrtc_data_channel_->state());
475 } 500 }
476 501
477 // Tests that a channel can be closed without being opened or assigned an sid. 502 // Tests that a channel can be closed without being opened or assigned an sid.
478 TEST_F(SctpDataChannelTest, NeverOpened) { 503 TEST_F(SctpDataChannelTest, NeverOpened) {
479 provider_.set_transport_available(true); 504 provider_.set_transport_available(true);
480 webrtc_data_channel_->OnTransportChannelCreated(); 505 webrtc_data_channel_->OnTransportChannelCreated();
481 webrtc_data_channel_->Close(); 506 webrtc_data_channel_->Close();
482 } 507 }
OLDNEW
« no previous file with comments | « talk/app/webrtc/datachannel.cc ('k') | talk/app/webrtc/datachannelinterface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698