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

Side by Side Diff: ppapi/tests/test_transport.cc

Issue 7713021: Add SetProperty() in the PPB_Transport_Dev interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/tests/test_transport.h" 5 #include "ppapi/tests/test_transport.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } // namespace 96 } // namespace
97 97
98 bool TestTransport::Init() { 98 bool TestTransport::Init() {
99 transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>( 99 transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>(
100 pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE)); 100 pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE));
101 return transport_interface_ && InitTestingInterface(); 101 return transport_interface_ && InitTestingInterface();
102 } 102 }
103 103
104 void TestTransport::RunTest() { 104 void TestTransport::RunTest() {
105 RUN_TEST(Create); 105 RUN_TEST(Create);
106 RUN_TEST(Connect); 106 RUN_TEST_FORCEASYNC_AND_NOT(Connect);
107 RUN_TEST_FORCEASYNC(SendDataUdp); 107 RUN_TEST(SetConfig);
108 RUN_TEST(SendDataTcp); 108 RUN_TEST_FORCEASYNC_AND_NOT(SendDataUdp);
109 RUN_TEST(ConnectAndCloseUdp); 109 RUN_TEST_FORCEASYNC_AND_NOT(SendDataTcp);
110 RUN_TEST(ConnectAndCloseTcp); 110 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndCloseUdp);
111 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndCloseTcp);
111 } 112 }
112 113
113 std::string TestTransport::InitTargets(const char* proto) { 114 std::string TestTransport::InitTargets(const char* proto) {
114 transport1_.reset(new pp::Transport_Dev(instance_, kTestChannelName, proto)); 115 transport1_.reset(new pp::Transport_Dev(instance_, kTestChannelName, proto));
115 transport2_.reset(new pp::Transport_Dev(instance_, kTestChannelName, proto)); 116 transport2_.reset(new pp::Transport_Dev(instance_, kTestChannelName, proto));
116 117
117 ASSERT_TRUE(transport1_.get() != NULL); 118 ASSERT_TRUE(transport1_.get() != NULL);
118 ASSERT_TRUE(transport2_.get() != NULL); 119 ASSERT_TRUE(transport2_.get() != NULL);
119 120
120 PASS(); 121 PASS();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 160 }
160 161
161 std::string TestTransport::TestCreate() { 162 std::string TestTransport::TestCreate() {
162 RUN_SUBTEST(InitTargets("udp")); 163 RUN_SUBTEST(InitTargets("udp"));
163 164
164 Clean(); 165 Clean();
165 166
166 PASS(); 167 PASS();
167 } 168 }
168 169
170 std::string TestTransport::TestSetConfig() {
171 RUN_SUBTEST(InitTargets("udp"));
172
173 const char kEmptyConfig[] = "{}";
174 ASSERT_EQ(transport1_->SetConfig(kEmptyConfig), PP_OK);
175
176 const char kTestConfig1[] =
177 "{\"stunServer\": [\"stun1.a.com:31323\", \"stun2.a.com:54324\"],"
178 "\"relayServer\": [\"relay.google.com\", \"relay.google.com\"],"
179 "\"relayToken\": \"34t34f234f12\","
180 "\"tcpReceiveWindow\": 32768,"
181 "\"tcpSendWindow\": 32768,}";
182 ASSERT_EQ(transport1_->SetConfig(kTestConfig1), PP_OK);
183
184 const char kTestConfig2[] =
185 "{\"stunServer\": \"stun1.a.com:31323\","
186 "\"relayServer\": \"relay.google.com\","
187 "\"relayToken\": \"34t34f234f12\"}";
188 ASSERT_EQ(transport1_->SetConfig(kTestConfig2), PP_OK);
189
190 const char kInvalidConfig[] =
191 "{\"stunServer\": \"stun1.a.com:31323\","
192 "\"relayServer\": 44,"
193 "\"relayToken\": \"34t34f234f12\"}";
194 ASSERT_EQ(transport1_->SetConfig(kInvalidConfig), PP_ERROR_BADARGUMENT);
195
196 RUN_SUBTEST(Connect());
197
198 // SetConfig() should fail after we've connected.
199 ASSERT_EQ(transport1_->SetConfig(kEmptyConfig), PP_ERROR_FAILED);
200
201 Clean();
202
203 PASS();
204 }
205
169 std::string TestTransport::TestConnect() { 206 std::string TestTransport::TestConnect() {
170 RUN_SUBTEST(InitTargets("udp")); 207 RUN_SUBTEST(InitTargets("udp"));
171 RUN_SUBTEST(Connect()); 208 RUN_SUBTEST(Connect());
172 209
173 Clean(); 210 Clean();
174 211
175 PASS(); 212 PASS();
176 } 213 }
177 214
178 // Creating datagram connection and try sending data over it. Verify 215 // Creating datagram connection and try sending data over it. Verify
(...skipping 25 matching lines...) Expand all
204 if (force_async_) { 241 if (force_async_) {
205 ASSERT_EQ(result, PP_OK_COMPLETIONPENDING); 242 ASSERT_EQ(result, PP_OK_COMPLETIONPENDING);
206 ASSERT_EQ(send_cb.WaitForResult(), static_cast<int>(send_buffer.size())); 243 ASSERT_EQ(send_cb.WaitForResult(), static_cast<int>(send_buffer.size()));
207 } else { 244 } else {
208 ASSERT_EQ(result, static_cast<int>(send_buffer.size())); 245 ASSERT_EQ(result, static_cast<int>(send_buffer.size()));
209 } 246 }
210 sent_packets[i] = send_buffer; 247 sent_packets[i] = send_buffer;
211 } 248 }
212 249
213 // Limit waiting time. 250 // Limit waiting time.
214 pp::Module::Get()->core()->CallOnMainThread(kUdpWaitTimeMs, done_cb); 251 TestCompletionCallback timeout_cb(instance_->pp_instance());
215 ASSERT_EQ(done_cb.WaitForResult(), PP_OK); 252 pp::Module::Get()->core()->CallOnMainThread(kUdpWaitTimeMs, timeout_cb);
Sergey Ulanov 2011/08/22 23:25:10 I changed this code and removed timeout in TestSen
253 ASSERT_EQ(timeout_cb.WaitForResult(), PP_OK);
216 254
217 ASSERT_TRUE(reader.errors().size() == 0); 255 ASSERT_TRUE(reader.errors().size() == 0);
218 ASSERT_TRUE(reader.received().size() > 0); 256 ASSERT_TRUE(reader.received().size() > 0);
219 for (std::list<std::vector<char> >::const_iterator it = 257 for (std::list<std::vector<char> >::const_iterator it =
220 reader.received().begin(); it != reader.received().end(); ++it) { 258 reader.received().begin(); it != reader.received().end(); ++it) {
221 int index; 259 int index;
222 memcpy(&index, &(*it)[0], sizeof(index)); 260 memcpy(&index, &(*it)[0], sizeof(index));
223 ASSERT_TRUE(sent_packets[index] == *it); 261 ASSERT_TRUE(sent_packets[index] == *it);
224 } 262 }
225 263
226 Clean(); 264 Clean();
227 265
228 PASS(); 266 PASS();
229 } 267 }
230 268
231 // Creating reliable (TCP-like) connection and try sending data over 269 // Creating reliable (TCP-like) connection and try sending data over
232 // it. Verify that all data is received correctly. 270 // it. Verify that all data is received correctly.
233 std::string TestTransport::TestSendDataTcp() { 271 std::string TestTransport::TestSendDataTcp() {
234 RUN_SUBTEST(InitTargets("tcp")); 272 RUN_SUBTEST(InitTargets("tcp"));
235 RUN_SUBTEST(Connect()); 273 RUN_SUBTEST(Connect());
236 274
237 const int kTcpSendSize = 100000; 275 const int kTcpSendSize = 100000;
238 const int kTimeoutMs = 20000; // 20 seconds.
239 276
240 TestCompletionCallback done_cb(instance_->pp_instance()); 277 TestCompletionCallback done_cb(instance_->pp_instance());
241 StreamReader reader(transport1_.get(), kTcpSendSize, 278 StreamReader reader(transport1_.get(), kTcpSendSize,
242 done_cb); 279 done_cb);
243 280
244 std::vector<char> send_buffer(kTcpSendSize); 281 std::vector<char> send_buffer(kTcpSendSize);
245 for (size_t j = 0; j < send_buffer.size(); ++j) { 282 for (size_t j = 0; j < send_buffer.size(); ++j) {
246 send_buffer[j] = rand() % 256; 283 send_buffer[j] = rand() % 256;
247 } 284 }
248 285
249 int pos = 0; 286 int pos = 0;
250 while (pos < static_cast<int>(send_buffer.size())) { 287 while (pos < static_cast<int>(send_buffer.size())) {
251 TestCompletionCallback send_cb(instance_->pp_instance(), force_async_); 288 TestCompletionCallback send_cb(instance_->pp_instance(), force_async_);
252 int result = transport2_->Send( 289 int result = transport2_->Send(
253 &send_buffer[0] + pos, send_buffer.size() - pos, send_cb); 290 &send_buffer[0] + pos, send_buffer.size() - pos, send_cb);
254 if (force_async_) 291 if (force_async_)
255 ASSERT_EQ(result, PP_OK_COMPLETIONPENDING); 292 ASSERT_EQ(result, PP_OK_COMPLETIONPENDING);
256 if (result == PP_OK_COMPLETIONPENDING) 293 if (result == PP_OK_COMPLETIONPENDING)
257 result = send_cb.WaitForResult(); 294 result = send_cb.WaitForResult();
258 ASSERT_TRUE(result > 0); 295 ASSERT_TRUE(result > 0);
259 pos += result; 296 pos += result;
260 } 297 }
261 298
262 // Limit waiting time.
263 pp::Module::Get()->core()->CallOnMainThread(kTimeoutMs, done_cb);
264 ASSERT_EQ(done_cb.WaitForResult(), PP_OK); 299 ASSERT_EQ(done_cb.WaitForResult(), PP_OK);
265 300
266 ASSERT_TRUE(reader.errors().size() == 0); 301 ASSERT_TRUE(reader.errors().size() == 0);
267 302
268 std::vector<char> received_data; 303 std::vector<char> received_data;
269 for (std::list<std::vector<char> >::const_iterator it = 304 for (std::list<std::vector<char> >::const_iterator it =
270 reader.received().begin(); it != reader.received().end(); ++it) { 305 reader.received().begin(); it != reader.received().end(); ++it) {
271 received_data.insert(received_data.end(), it->begin(), it->end()); 306 received_data.insert(received_data.end(), it->begin(), it->end());
272 } 307 }
273 ASSERT_EQ(send_buffer, received_data); 308 ASSERT_EQ(send_buffer, received_data);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // Close the transport and verify that callback is aborted. 346 // Close the transport and verify that callback is aborted.
312 ASSERT_EQ(transport1_->Close(), PP_OK); 347 ASSERT_EQ(transport1_->Close(), PP_OK);
313 348
314 ASSERT_EQ(recv_cb.run_count(), 1); 349 ASSERT_EQ(recv_cb.run_count(), 1);
315 ASSERT_EQ(recv_cb.result(), PP_ERROR_ABORTED); 350 ASSERT_EQ(recv_cb.result(), PP_ERROR_ABORTED);
316 351
317 Clean(); 352 Clean();
318 353
319 PASS(); 354 PASS();
320 } 355 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698