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

Side by Side Diff: net/socket/ssl_server_socket_unittest.cc

Issue 7648010: SSLServerSocketTest.DataTransfer should keep reading until it has read (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Change back to patch set 2 for checkin. 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This test suite uses SSLClientSocket to test the implementation of 5 // This test suite uses SSLClientSocket to test the implementation of
6 // SSLServerSocket. In order to establish connections between the sockets 6 // SSLServerSocket. In order to establish connections between the sockets
7 // we need two additional classes: 7 // we need two additional classes:
8 // 1. FakeSocket 8 // 1. FakeSocket
9 // Connects SSL socket to FakeDataChannel. This class is just a stub. 9 // Connects SSL socket to FakeDataChannel. This class is just a stub.
10 // 10 //
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 TestCompletionCallback connect_callback; 354 TestCompletionCallback connect_callback;
355 TestCompletionCallback handshake_callback; 355 TestCompletionCallback handshake_callback;
356 356
357 // Establish connection. 357 // Establish connection.
358 int client_ret = client_socket_->Connect(&connect_callback); 358 int client_ret = client_socket_->Connect(&connect_callback);
359 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); 359 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING);
360 360
361 int server_ret = server_socket_->Handshake(&handshake_callback); 361 int server_ret = server_socket_->Handshake(&handshake_callback);
362 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); 362 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING);
363 363
364 if (client_ret == net::ERR_IO_PENDING) { 364 client_ret = connect_callback.GetResult(client_ret);
365 ASSERT_EQ(net::OK, connect_callback.WaitForResult()); 365 ASSERT_EQ(net::OK, client_ret);
366 } 366 server_ret = handshake_callback.GetResult(server_ret);
367 if (server_ret == net::ERR_IO_PENDING) { 367 ASSERT_EQ(net::OK, server_ret);
368 ASSERT_EQ(net::OK, handshake_callback.WaitForResult());
369 }
370 368
371 const int kReadBufSize = 1024; 369 const int kReadBufSize = 1024;
372 scoped_refptr<net::StringIOBuffer> write_buf = 370 scoped_refptr<net::StringIOBuffer> write_buf =
373 new net::StringIOBuffer("testing123"); 371 new net::StringIOBuffer("testing123");
374 scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(kReadBufSize); 372 scoped_refptr<net::DrainableIOBuffer> read_buf =
373 new net::DrainableIOBuffer(new net::IOBuffer(kReadBufSize),
374 kReadBufSize);
375 375
376 // Write then read. 376 // Write then read.
377 TestCompletionCallback write_callback; 377 TestCompletionCallback write_callback;
378 TestCompletionCallback read_callback; 378 TestCompletionCallback read_callback;
379 server_ret = server_socket_->Write(write_buf, write_buf->size(), 379 server_ret = server_socket_->Write(write_buf, write_buf->size(),
380 &write_callback); 380 &write_callback);
381 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); 381 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING);
382 client_ret = client_socket_->Read(read_buf, kReadBufSize, &read_callback); 382 client_ret = client_socket_->Read(read_buf, read_buf->BytesRemaining(),
383 &read_callback);
383 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); 384 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING);
384 385
385 if (server_ret == net::ERR_IO_PENDING) { 386 server_ret = write_callback.GetResult(server_ret);
386 EXPECT_GT(write_callback.WaitForResult(), 0); 387 EXPECT_GT(server_ret, 0);
388 client_ret = read_callback.GetResult(client_ret);
389 ASSERT_GT(client_ret, 0);
390
391 read_buf->DidConsume(client_ret);
392 while (read_buf->BytesConsumed() < write_buf->size()) {
393 client_ret = client_socket_->Read(read_buf, read_buf->BytesRemaining(),
394 &read_callback);
395 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING);
396 client_ret = read_callback.GetResult(client_ret);
397 ASSERT_GT(client_ret, 0);
398 read_buf->DidConsume(client_ret);
387 } 399 }
388 if (client_ret == net::ERR_IO_PENDING) { 400 EXPECT_EQ(write_buf->size(), read_buf->BytesConsumed());
389 EXPECT_GT(read_callback.WaitForResult(), 0); 401 read_buf->SetOffset(0);
390 }
391 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); 402 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size()));
392 403
393 // Read then write. 404 // Read then write.
394 write_buf = new net::StringIOBuffer("hello123"); 405 write_buf = new net::StringIOBuffer("hello123");
395 server_ret = server_socket_->Read(read_buf, kReadBufSize, &read_callback); 406 server_ret = server_socket_->Read(read_buf, read_buf->BytesRemaining(),
407 &read_callback);
396 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); 408 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING);
397 client_ret = client_socket_->Write(write_buf, write_buf->size(), 409 client_ret = client_socket_->Write(write_buf, write_buf->size(),
398 &write_callback); 410 &write_callback);
399 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); 411 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING);
400 412
401 if (server_ret == net::ERR_IO_PENDING) { 413 server_ret = read_callback.GetResult(server_ret);
402 EXPECT_GT(read_callback.WaitForResult(), 0); 414 ASSERT_GT(server_ret, 0);
415 client_ret = write_callback.GetResult(client_ret);
416 EXPECT_GT(client_ret, 0);
417
418 read_buf->DidConsume(server_ret);
419 while (read_buf->BytesConsumed() < write_buf->size()) {
420 server_ret = server_socket_->Read(read_buf, read_buf->BytesRemaining(),
421 &read_callback);
422 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING);
423 server_ret = read_callback.GetResult(server_ret);
424 ASSERT_GT(server_ret, 0);
425 read_buf->DidConsume(server_ret);
403 } 426 }
404 if (client_ret == net::ERR_IO_PENDING) { 427 EXPECT_EQ(write_buf->size(), read_buf->BytesConsumed());
405 EXPECT_GT(write_callback.WaitForResult(), 0); 428 read_buf->SetOffset(0);
406 }
407 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); 429 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size()));
408 } 430 }
409 431
410 // This test executes ExportKeyingMaterial() on the client and server sockets, 432 // This test executes ExportKeyingMaterial() on the client and server sockets,
411 // after connecting them, and verifies that the results match. 433 // after connecting them, and verifies that the results match.
412 // This test will fail if False Start is enabled (see crbug.com/90208). 434 // This test will fail if False Start is enabled (see crbug.com/90208).
413 TEST_F(SSLServerSocketTest, ExportKeyingMaterial) { 435 TEST_F(SSLServerSocketTest, ExportKeyingMaterial) {
414 Initialize(); 436 Initialize();
415 437
416 TestCompletionCallback connect_callback; 438 TestCompletionCallback connect_callback;
(...skipping 29 matching lines...) Expand all
446 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; 468 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad";
447 unsigned char client_bad[kKeyingMaterialSize]; 469 unsigned char client_bad[kKeyingMaterialSize];
448 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, kKeyingContext, 470 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, kKeyingContext,
449 client_bad, sizeof(client_bad)); 471 client_bad, sizeof(client_bad));
450 ASSERT_EQ(rv, net::OK); 472 ASSERT_EQ(rv, net::OK);
451 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0); 473 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0);
452 } 474 }
453 #endif 475 #endif
454 476
455 } // namespace net 477 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698