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

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

Issue 9430050: Remove usage of a deprecated TestServer constructor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Disentangle test refactoring from TestServer refactoring. Created 8 years, 10 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
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 "net/socket/ssl_client_socket.h" 5 #include "net/socket/ssl_client_socket.h"
6 6
7 #include "net/base/address_list.h" 7 #include "net/base/address_list.h"
8 #include "net/base/cert_verifier.h" 8 #include "net/base/cert_verifier.h"
9 #include "net/base/host_resolver.h" 9 #include "net/base/host_resolver.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // timeout. This means that an SSL connect end event may appear as a socket 60 // timeout. This means that an SSL connect end event may appear as a socket
61 // write. 61 // write.
62 static bool LogContainsSSLConnectEndEvent( 62 static bool LogContainsSSLConnectEndEvent(
63 const net::CapturingNetLog::EntryList& log, int i) { 63 const net::CapturingNetLog::EntryList& log, int i) {
64 return net::LogContainsEndEvent(log, i, net::NetLog::TYPE_SSL_CONNECT) || 64 return net::LogContainsEndEvent(log, i, net::NetLog::TYPE_SSL_CONNECT) ||
65 net::LogContainsEvent(log, i, net::NetLog::TYPE_SOCKET_BYTES_SENT, 65 net::LogContainsEvent(log, i, net::NetLog::TYPE_SOCKET_BYTES_SENT,
66 net::NetLog::PHASE_NONE); 66 net::NetLog::PHASE_NONE);
67 }; 67 };
68 68
69 TEST_F(SSLClientSocketTest, Connect) { 69 TEST_F(SSLClientSocketTest, Connect) {
70 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); 70 net::TestServer test_server(net::TestServer::TYPE_HTTPS,
71 net::TestServer::kLocalhost,
72 FilePath());
71 ASSERT_TRUE(test_server.Start()); 73 ASSERT_TRUE(test_server.Start());
72 74
73 net::AddressList addr; 75 net::AddressList addr;
74 ASSERT_TRUE(test_server.GetAddressList(&addr)); 76 ASSERT_TRUE(test_server.GetAddressList(&addr));
75 77
76 net::TestCompletionCallback callback; 78 net::TestCompletionCallback callback;
77 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); 79 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded);
78 net::StreamSocket* transport = new net::TCPClientSocket( 80 net::StreamSocket* transport = new net::TCPClientSocket(
79 addr, &log, net::NetLog::Source()); 81 addr, &log, net::NetLog::Source());
80 int rv = transport->Connect(callback.callback()); 82 int rv = transport->Connect(callback.callback());
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 sock->Disconnect(); 312 sock->Disconnect();
311 EXPECT_FALSE(sock->IsConnected()); 313 EXPECT_FALSE(sock->IsConnected());
312 } 314 }
313 315
314 // TODO(wtc): Add unit tests for IsConnectedAndIdle: 316 // TODO(wtc): Add unit tests for IsConnectedAndIdle:
315 // - Server closes an SSL connection (with a close_notify alert message). 317 // - Server closes an SSL connection (with a close_notify alert message).
316 // - Server closes the underlying TCP connection directly. 318 // - Server closes the underlying TCP connection directly.
317 // - Server sends data unexpectedly. 319 // - Server sends data unexpectedly.
318 320
319 TEST_F(SSLClientSocketTest, Read) { 321 TEST_F(SSLClientSocketTest, Read) {
320 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); 322 net::TestServer test_server(net::TestServer::TYPE_HTTPS,
323 net::TestServer::kLocalhost,
324 FilePath());
321 ASSERT_TRUE(test_server.Start()); 325 ASSERT_TRUE(test_server.Start());
322 326
323 net::AddressList addr; 327 net::AddressList addr;
324 ASSERT_TRUE(test_server.GetAddressList(&addr)); 328 ASSERT_TRUE(test_server.GetAddressList(&addr));
325 329
326 net::TestCompletionCallback callback; 330 net::TestCompletionCallback callback;
327 net::StreamSocket* transport = new net::TCPClientSocket( 331 net::StreamSocket* transport = new net::TCPClientSocket(
328 addr, NULL, net::NetLog::Source()); 332 addr, NULL, net::NetLog::Source());
329 int rv = transport->Connect(callback.callback()); 333 int rv = transport->Connect(callback.callback());
330 if (rv == net::ERR_IO_PENDING) 334 if (rv == net::ERR_IO_PENDING)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 368
365 EXPECT_GE(rv, 0); 369 EXPECT_GE(rv, 0);
366 if (rv <= 0) 370 if (rv <= 0)
367 break; 371 break;
368 } 372 }
369 } 373 }
370 374
371 // Test the full duplex mode, with Read and Write pending at the same time. 375 // Test the full duplex mode, with Read and Write pending at the same time.
372 // This test also serves as a regression test for http://crbug.com/29815. 376 // This test also serves as a regression test for http://crbug.com/29815.
373 TEST_F(SSLClientSocketTest, Read_FullDuplex) { 377 TEST_F(SSLClientSocketTest, Read_FullDuplex) {
374 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); 378 net::TestServer test_server(net::TestServer::TYPE_HTTPS,
379 net::TestServer::kLocalhost,
380 FilePath());
375 ASSERT_TRUE(test_server.Start()); 381 ASSERT_TRUE(test_server.Start());
376 382
377 net::AddressList addr; 383 net::AddressList addr;
378 ASSERT_TRUE(test_server.GetAddressList(&addr)); 384 ASSERT_TRUE(test_server.GetAddressList(&addr));
379 385
380 net::TestCompletionCallback callback; // Used for everything except Write. 386 net::TestCompletionCallback callback; // Used for everything except Write.
381 387
382 net::StreamSocket* transport = new net::TCPClientSocket( 388 net::StreamSocket* transport = new net::TCPClientSocket(
383 addr, NULL, net::NetLog::Source()); 389 addr, NULL, net::NetLog::Source());
384 int rv = transport->Connect(callback.callback()); 390 int rv = transport->Connect(callback.callback());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 if (rv == net::ERR_IO_PENDING) 429 if (rv == net::ERR_IO_PENDING)
424 rv = callback2.WaitForResult(); 430 rv = callback2.WaitForResult();
425 EXPECT_EQ(static_cast<int>(request_text.size()), rv); 431 EXPECT_EQ(static_cast<int>(request_text.size()), rv);
426 432
427 // Now get the Read result. 433 // Now get the Read result.
428 rv = callback.WaitForResult(); 434 rv = callback.WaitForResult();
429 EXPECT_GT(rv, 0); 435 EXPECT_GT(rv, 0);
430 } 436 }
431 437
432 TEST_F(SSLClientSocketTest, Read_SmallChunks) { 438 TEST_F(SSLClientSocketTest, Read_SmallChunks) {
433 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); 439 net::TestServer test_server(net::TestServer::TYPE_HTTPS,
440 net::TestServer::kLocalhost,
441 FilePath());
434 ASSERT_TRUE(test_server.Start()); 442 ASSERT_TRUE(test_server.Start());
435 443
436 net::AddressList addr; 444 net::AddressList addr;
437 ASSERT_TRUE(test_server.GetAddressList(&addr)); 445 ASSERT_TRUE(test_server.GetAddressList(&addr));
438 446
439 net::TestCompletionCallback callback; 447 net::TestCompletionCallback callback;
440 net::StreamSocket* transport = new net::TCPClientSocket( 448 net::StreamSocket* transport = new net::TCPClientSocket(
441 addr, NULL, net::NetLog::Source()); 449 addr, NULL, net::NetLog::Source());
442 int rv = transport->Connect(callback.callback()); 450 int rv = transport->Connect(callback.callback());
443 if (rv == net::ERR_IO_PENDING) 451 if (rv == net::ERR_IO_PENDING)
(...skipping 30 matching lines...) Expand all
474 if (rv == net::ERR_IO_PENDING) 482 if (rv == net::ERR_IO_PENDING)
475 rv = callback.WaitForResult(); 483 rv = callback.WaitForResult();
476 484
477 EXPECT_GE(rv, 0); 485 EXPECT_GE(rv, 0);
478 if (rv <= 0) 486 if (rv <= 0)
479 break; 487 break;
480 } 488 }
481 } 489 }
482 490
483 TEST_F(SSLClientSocketTest, Read_Interrupted) { 491 TEST_F(SSLClientSocketTest, Read_Interrupted) {
484 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); 492 net::TestServer test_server(net::TestServer::TYPE_HTTPS,
493 net::TestServer::kLocalhost,
494 FilePath());
485 ASSERT_TRUE(test_server.Start()); 495 ASSERT_TRUE(test_server.Start());
486 496
487 net::AddressList addr; 497 net::AddressList addr;
488 ASSERT_TRUE(test_server.GetAddressList(&addr)); 498 ASSERT_TRUE(test_server.GetAddressList(&addr));
489 499
490 net::TestCompletionCallback callback; 500 net::TestCompletionCallback callback;
491 net::StreamSocket* transport = new net::TCPClientSocket( 501 net::StreamSocket* transport = new net::TCPClientSocket(
492 addr, NULL, net::NetLog::Source()); 502 addr, NULL, net::NetLog::Source());
493 int rv = transport->Connect(callback.callback()); 503 int rv = transport->Connect(callback.callback());
494 if (rv == net::ERR_IO_PENDING) 504 if (rv == net::ERR_IO_PENDING)
(...skipping 27 matching lines...) Expand all
522 rv = sock->Read(buf, 512, callback.callback()); 532 rv = sock->Read(buf, 512, callback.callback());
523 EXPECT_TRUE(rv > 0 || rv == net::ERR_IO_PENDING); 533 EXPECT_TRUE(rv > 0 || rv == net::ERR_IO_PENDING);
524 534
525 if (rv == net::ERR_IO_PENDING) 535 if (rv == net::ERR_IO_PENDING)
526 rv = callback.WaitForResult(); 536 rv = callback.WaitForResult();
527 537
528 EXPECT_GT(rv, 0); 538 EXPECT_GT(rv, 0);
529 } 539 }
530 540
531 TEST_F(SSLClientSocketTest, Read_FullLogging) { 541 TEST_F(SSLClientSocketTest, Read_FullLogging) {
532 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); 542 net::TestServer test_server(net::TestServer::TYPE_HTTPS,
543 net::TestServer::kLocalhost,
544 FilePath());
533 ASSERT_TRUE(test_server.Start()); 545 ASSERT_TRUE(test_server.Start());
534 546
535 net::AddressList addr; 547 net::AddressList addr;
536 ASSERT_TRUE(test_server.GetAddressList(&addr)); 548 ASSERT_TRUE(test_server.GetAddressList(&addr));
537 549
538 net::TestCompletionCallback callback; 550 net::TestCompletionCallback callback;
539 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); 551 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded);
540 log.SetLogLevel(net::NetLog::LOG_ALL); 552 log.SetLogLevel(net::NetLog::LOG_ALL);
541 net::StreamSocket* transport = new net::TCPClientSocket( 553 net::StreamSocket* transport = new net::TCPClientSocket(
542 addr, &log, net::NetLog::Source()); 554 addr, &log, net::NetLog::Source());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 600
589 log.GetEntries(&entries); 601 log.GetEntries(&entries);
590 last_index = net::ExpectLogContainsSomewhereAfter( 602 last_index = net::ExpectLogContainsSomewhereAfter(
591 entries, last_index + 1, net::NetLog::TYPE_SSL_SOCKET_BYTES_RECEIVED, 603 entries, last_index + 1, net::NetLog::TYPE_SSL_SOCKET_BYTES_RECEIVED,
592 net::NetLog::PHASE_NONE); 604 net::NetLog::PHASE_NONE);
593 } 605 }
594 } 606 }
595 607
596 // Regression test for http://crbug.com/42538 608 // Regression test for http://crbug.com/42538
597 TEST_F(SSLClientSocketTest, PrematureApplicationData) { 609 TEST_F(SSLClientSocketTest, PrematureApplicationData) {
598 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); 610 net::TestServer test_server(net::TestServer::TYPE_HTTPS,
611 net::TestServer::kLocalhost,
612 FilePath());
599 ASSERT_TRUE(test_server.Start()); 613 ASSERT_TRUE(test_server.Start());
600 614
601 net::AddressList addr; 615 net::AddressList addr;
602 net::TestCompletionCallback callback; 616 net::TestCompletionCallback callback;
603 617
604 static const unsigned char application_data[] = { 618 static const unsigned char application_data[] = {
605 0x17, 0x03, 0x01, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x46, 0x03, 0x01, 0x4b, 619 0x17, 0x03, 0x01, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x46, 0x03, 0x01, 0x4b,
606 0xc2, 0xf8, 0xb2, 0xc1, 0x56, 0x42, 0xb9, 0x57, 0x7f, 0xde, 0x87, 0x46, 620 0xc2, 0xf8, 0xb2, 0xc1, 0x56, 0x42, 0xb9, 0x57, 0x7f, 0xde, 0x87, 0x46,
607 0xf7, 0xa3, 0x52, 0x42, 0x21, 0xf0, 0x13, 0x1c, 0x9c, 0x83, 0x88, 0xd6, 621 0xf7, 0xa3, 0x52, 0x42, 0x21, 0xf0, 0x13, 0x1c, 0x9c, 0x83, 0x88, 0xd6,
608 0x93, 0x0c, 0xf6, 0x36, 0x30, 0x05, 0x7e, 0x20, 0xb5, 0xb5, 0x73, 0x36, 622 0x93, 0x0c, 0xf6, 0x36, 0x30, 0x05, 0x7e, 0x20, 0xb5, 0xb5, 0x73, 0x36,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 // rather than the last entry. 730 // rather than the last entry.
717 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1) || 731 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1) ||
718 LogContainsSSLConnectEndEvent(entries, -2)); 732 LogContainsSSLConnectEndEvent(entries, -2));
719 } 733 }
720 734
721 // When creating an SSLClientSocket, it is allowed to pass in a 735 // When creating an SSLClientSocket, it is allowed to pass in a
722 // ClientSocketHandle that is not obtained from a client socket pool. 736 // ClientSocketHandle that is not obtained from a client socket pool.
723 // Here we verify that such a simple ClientSocketHandle, not associated with any 737 // Here we verify that such a simple ClientSocketHandle, not associated with any
724 // client socket pool, can be destroyed safely. 738 // client socket pool, can be destroyed safely.
725 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { 739 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) {
726 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); 740 net::TestServer test_server(net::TestServer::TYPE_HTTPS,
741 net::TestServer::kLocalhost,
742 FilePath());
727 ASSERT_TRUE(test_server.Start()); 743 ASSERT_TRUE(test_server.Start());
728 744
729 net::AddressList addr; 745 net::AddressList addr;
730 ASSERT_TRUE(test_server.GetAddressList(&addr)); 746 ASSERT_TRUE(test_server.GetAddressList(&addr));
731 747
732 net::TestCompletionCallback callback; 748 net::TestCompletionCallback callback;
733 net::StreamSocket* transport = new net::TCPClientSocket( 749 net::StreamSocket* transport = new net::TCPClientSocket(
734 addr, NULL, net::NetLog::Source()); 750 addr, NULL, net::NetLog::Source());
735 int rv = transport->Connect(callback.callback()); 751 int rv = transport->Connect(callback.callback());
736 if (rv == net::ERR_IO_PENDING) 752 if (rv == net::ERR_IO_PENDING)
(...skipping 15 matching lines...) Expand all
752 if (rv == net::ERR_IO_PENDING) 768 if (rv == net::ERR_IO_PENDING)
753 rv = callback.WaitForResult(); 769 rv = callback.WaitForResult();
754 EXPECT_EQ(net::OK, rv); 770 EXPECT_EQ(net::OK, rv);
755 } 771 }
756 772
757 // Verifies that SSLClientSocket::ClearSessionCache can be called without 773 // Verifies that SSLClientSocket::ClearSessionCache can be called without
758 // explicit NSS initialization. 774 // explicit NSS initialization.
759 TEST(SSLClientSocket, ClearSessionCache) { 775 TEST(SSLClientSocket, ClearSessionCache) {
760 net::SSLClientSocket::ClearSessionCache(); 776 net::SSLClientSocket::ClearSessionCache();
761 } 777 }
OLDNEW
« no previous file with comments | « net/proxy/proxy_script_fetcher_impl_unittest.cc ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698