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

Side by Side Diff: chrome/browser/sync/tools/chrome_async_socket_unittest.cc

Issue 2966011: Fixed some minor bugs with ChromeAsyncSocket. (Closed)
Patch Set: Created 10 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 | « chrome/browser/sync/tools/chrome_async_socket.cc ('k') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/sync/tools/chrome_async_socket.h" 5 #include "chrome/browser/sync/tools/chrome_async_socket.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 std::deque<net::MockWrite> writes_; 91 std::deque<net::MockWrite> writes_;
92 92
93 DISALLOW_COPY_AND_ASSIGN(AsyncSocketDataProvider); 93 DISALLOW_COPY_AND_ASSIGN(AsyncSocketDataProvider);
94 }; 94 };
95 95
96 class ChromeAsyncSocketTest 96 class ChromeAsyncSocketTest
97 : public testing::Test, 97 : public testing::Test,
98 public sigslot::has_slots<> { 98 public sigslot::has_slots<> {
99 protected: 99 protected:
100 // TODO(akalin): test SSL states other than connection success.
101 ChromeAsyncSocketTest() 100 ChromeAsyncSocketTest()
102 : ssl_socket_data_provider_(true, net::OK), 101 : ssl_socket_data_provider_(true, net::OK),
103 capturing_net_log_(net::CapturingNetLog::kUnbounded), 102 capturing_net_log_(net::CapturingNetLog::kUnbounded),
104 chrome_async_socket_(&mock_client_socket_factory_, 103 chrome_async_socket_(&mock_client_socket_factory_,
105 ssl_config_, 14, 20, &capturing_net_log_), 104 ssl_config_, 14, 20, &capturing_net_log_),
106 addr_(0xaabbccdd, 35) {} 105 addr_(0xaabbccdd, 35) {}
107 106
108 virtual ~ChromeAsyncSocketTest() {} 107 virtual ~ChromeAsyncSocketTest() {}
109 108
110 virtual void SetUp() { 109 virtual void SetUp() {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 char buf[4096]; 521 char buf[4096];
523 size_t len_read = 10000; 522 size_t len_read = 10000;
524 EXPECT_TRUE(chrome_async_socket_.Read(buf, sizeof(buf), &len_read)); 523 EXPECT_TRUE(chrome_async_socket_.Read(buf, sizeof(buf), &len_read));
525 EXPECT_EQ(0, len_read); 524 EXPECT_EQ(0, len_read);
526 525
527 DoCloseOpenedNoError(); 526 DoCloseOpenedNoError();
528 } 527 }
529 528
530 TEST_F(ChromeAsyncSocketTest, WrongRead) { 529 TEST_F(ChromeAsyncSocketTest, WrongRead) {
531 EXPECT_DEBUG_DEATH({ 530 EXPECT_DEBUG_DEATH({
531 async_socket_data_provider_.set_connect_data(
532 net::MockConnect(true, net::OK));
533 EXPECT_TRUE(chrome_async_socket_.Connect(addr_));
534 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING);
535 ExpectNoSignal();
536
532 char buf[4096]; 537 char buf[4096];
533 size_t len_read; 538 size_t len_read;
534 EXPECT_FALSE(chrome_async_socket_.Read(buf, sizeof(buf), &len_read)); 539 EXPECT_FALSE(chrome_async_socket_.Read(buf, sizeof(buf), &len_read));
535 ExpectErrorState(ChromeAsyncSocket::STATE_CLOSED, 540 ExpectErrorState(ChromeAsyncSocket::STATE_CLOSED,
536 ChromeAsyncSocket::ERROR_WRONGSTATE); 541 ChromeAsyncSocket::ERROR_WRONGSTATE);
537 EXPECT_TRUE(chrome_async_socket_.Close()); 542 EXPECT_TRUE(chrome_async_socket_.Close());
538 }, "non-open"); 543 }, "non-open");
539 } 544 }
540 545
546 TEST_F(ChromeAsyncSocketTest, WrongReadClosed) {
547 char buf[4096];
548 size_t len_read;
549 EXPECT_FALSE(chrome_async_socket_.Read(buf, sizeof(buf), &len_read));
550 ExpectErrorState(ChromeAsyncSocket::STATE_CLOSED,
551 ChromeAsyncSocket::ERROR_WRONGSTATE);
552 EXPECT_TRUE(chrome_async_socket_.Close());
553 }
554
541 const char kReadData[] = "mydatatoread"; 555 const char kReadData[] = "mydatatoread";
542 556
543 TEST_F(ChromeAsyncSocketTest, Read) { 557 TEST_F(ChromeAsyncSocketTest, Read) {
544 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); 558 async_socket_data_provider_.AddRead(net::MockRead(kReadData));
545 DoOpenClosed(); 559 DoOpenClosed();
546 560
547 ExpectReadSignal(); 561 ExpectReadSignal();
548 ExpectNoSignal(); 562 ExpectNoSignal();
549 563
550 EXPECT_EQ(kReadData, DrainRead(1)); 564 EXPECT_EQ(kReadData, DrainRead(1));
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 EXPECT_FALSE(chrome_async_socket_.StartTls("fakedomain.com")); 830 EXPECT_FALSE(chrome_async_socket_.StartTls("fakedomain.com"));
817 831
818 DoSSLCloseOpened( 832 DoSSLCloseOpened(
819 SignalSocketState(SIGNAL_CLOSE, 833 SignalSocketState(SIGNAL_CLOSE,
820 ChromeAsyncSocket::STATE_CLOSED, 834 ChromeAsyncSocket::STATE_CLOSED,
821 ChromeAsyncSocket::ERROR_WRONGSTATE, 835 ChromeAsyncSocket::ERROR_WRONGSTATE,
822 net::OK)); 836 net::OK));
823 }, "wrong state"); 837 }, "wrong state");
824 } 838 }
825 839
840 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) {
841 ssl_socket_data_provider_.connect =
842 net::MockConnect(true, net::ERR_CERT_COMMON_NAME_INVALID),
843
844 async_socket_data_provider_.AddRead(net::MockRead(kReadData));
845 DoOpenClosed();
846 ExpectReadSignal();
847
848 EXPECT_TRUE(chrome_async_socket_.StartTls("fakedomain.com"));
849 message_loop_.RunAllPending();
850 ExpectSignalSocketState(
851 SignalSocketState(
852 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED,
853 ChromeAsyncSocket::ERROR_WINSOCK,
854 net::ERR_CERT_COMMON_NAME_INVALID));
855
856 EXPECT_TRUE(chrome_async_socket_.Close());
857 ExpectClosed();
858 }
859
826 TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) { 860 TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) {
827 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); 861 async_socket_data_provider_.AddRead(net::MockRead(kReadData));
828 DoOpenClosed(); 862 DoOpenClosed();
829 ExpectReadSignal(); 863 ExpectReadSignal();
830 EXPECT_EQ(kReadData, DrainRead(1)); 864 EXPECT_EQ(kReadData, DrainRead(1));
831 865
832 EXPECT_TRUE(chrome_async_socket_.StartTls("fakedomain.com")); 866 EXPECT_TRUE(chrome_async_socket_.StartTls("fakedomain.com"));
833 ExpectNoSignal(); 867 ExpectNoSignal();
834 868
835 // Shouldn't do anything. 869 // Shouldn't do anything.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 message_loop_.RunAllPending(); 1006 message_loop_.RunAllPending();
973 1007
974 ExpectNoSignal(); 1008 ExpectNoSignal();
975 1009
976 DoSSLCloseOpenedNoError(); 1010 DoSSLCloseOpenedNoError();
977 } 1011 }
978 1012
979 } // namespace 1013 } // namespace
980 1014
981 } // namespace sync_tools 1015 } // namespace sync_tools
OLDNEW
« no previous file with comments | « chrome/browser/sync/tools/chrome_async_socket.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698