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

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

Issue 848006: Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up RequestTracker into ConnectJobTracker+RequestTracker+RequestTrackerBase, address comments Created 10 years, 9 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 | « net/socket/ssl_client_socket_nss.cc ('k') | net/socket/ssl_client_socket_win.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 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/host_resolver.h" 8 #include "net/base/host_resolver.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/load_log.h" 10 #include "net/base/net_log.h"
11 #include "net/base/load_log_unittest.h" 11 #include "net/base/net_log_unittest.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/ssl_config_service.h" 13 #include "net/base/ssl_config_service.h"
14 #include "net/base/test_completion_callback.h" 14 #include "net/base/test_completion_callback.h"
15 #include "net/socket/client_socket_factory.h" 15 #include "net/socket/client_socket_factory.h"
16 #include "net/socket/ssl_test_util.h" 16 #include "net/socket/ssl_test_util.h"
17 #include "net/socket/tcp_client_socket.h" 17 #include "net/socket/tcp_client_socket.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h" 19 #include "testing/platform_test.h"
20 20
21 //----------------------------------------------------------------------------- 21 //-----------------------------------------------------------------------------
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 if (rv == net::ERR_IO_PENDING) 73 if (rv == net::ERR_IO_PENDING)
74 rv = callback.WaitForResult(); 74 rv = callback.WaitForResult();
75 EXPECT_EQ(net::OK, rv); 75 EXPECT_EQ(net::OK, rv);
76 76
77 scoped_ptr<net::SSLClientSocket> sock( 77 scoped_ptr<net::SSLClientSocket> sock(
78 socket_factory_->CreateSSLClientSocket(transport, 78 socket_factory_->CreateSSLClientSocket(transport,
79 server_.kHostName, kDefaultSSLConfig)); 79 server_.kHostName, kDefaultSSLConfig));
80 80
81 EXPECT_FALSE(sock->IsConnected()); 81 EXPECT_FALSE(sock->IsConnected());
82 82
83 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); 83 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
84 rv = sock->Connect(&callback, log); 84 rv = sock->Connect(&callback, log.bound());
85 EXPECT_TRUE(net::LogContainsBeginEvent( 85 EXPECT_TRUE(net::LogContainsBeginEvent(
86 *log, 0, net::LoadLog::TYPE_SSL_CONNECT)); 86 log.entries(), 0, net::NetLog::TYPE_SSL_CONNECT));
87 if (rv != net::OK) { 87 if (rv != net::OK) {
88 ASSERT_EQ(net::ERR_IO_PENDING, rv); 88 ASSERT_EQ(net::ERR_IO_PENDING, rv);
89 EXPECT_FALSE(sock->IsConnected()); 89 EXPECT_FALSE(sock->IsConnected());
90 EXPECT_FALSE(net::LogContainsEndEvent( 90 EXPECT_FALSE(net::LogContainsEndEvent(
91 *log, -1, net::LoadLog::TYPE_SSL_CONNECT)); 91 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT));
92 92
93 rv = callback.WaitForResult(); 93 rv = callback.WaitForResult();
94 EXPECT_EQ(net::OK, rv); 94 EXPECT_EQ(net::OK, rv);
95 } 95 }
96 96
97 EXPECT_TRUE(sock->IsConnected()); 97 EXPECT_TRUE(sock->IsConnected());
98 EXPECT_TRUE(net::LogContainsEndEvent( 98 EXPECT_TRUE(net::LogContainsEndEvent(
99 *log, -1, net::LoadLog::TYPE_SSL_CONNECT)); 99 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT));
100 100
101 sock->Disconnect(); 101 sock->Disconnect();
102 EXPECT_FALSE(sock->IsConnected()); 102 EXPECT_FALSE(sock->IsConnected());
103 } 103 }
104 104
105 TEST_F(SSLClientSocketTest, ConnectExpired) { 105 TEST_F(SSLClientSocketTest, ConnectExpired) {
106 StartExpiredServer(); 106 StartExpiredServer();
107 107
108 net::AddressList addr; 108 net::AddressList addr;
109 TestCompletionCallback callback; 109 TestCompletionCallback callback;
110 110
111 net::HostResolver::RequestInfo info(server_.kHostName, server_.kBadHTTPSPort); 111 net::HostResolver::RequestInfo info(server_.kHostName, server_.kBadHTTPSPort);
112 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); 112 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL);
113 EXPECT_EQ(net::OK, rv); 113 EXPECT_EQ(net::OK, rv);
114 114
115 net::ClientSocket *transport = new net::TCPClientSocket(addr); 115 net::ClientSocket *transport = new net::TCPClientSocket(addr);
116 rv = transport->Connect(&callback, NULL); 116 rv = transport->Connect(&callback, NULL);
117 if (rv == net::ERR_IO_PENDING) 117 if (rv == net::ERR_IO_PENDING)
118 rv = callback.WaitForResult(); 118 rv = callback.WaitForResult();
119 EXPECT_EQ(net::OK, rv); 119 EXPECT_EQ(net::OK, rv);
120 120
121 scoped_ptr<net::SSLClientSocket> sock( 121 scoped_ptr<net::SSLClientSocket> sock(
122 socket_factory_->CreateSSLClientSocket(transport, 122 socket_factory_->CreateSSLClientSocket(transport,
123 server_.kHostName, kDefaultSSLConfig)); 123 server_.kHostName, kDefaultSSLConfig));
124 124
125 EXPECT_FALSE(sock->IsConnected()); 125 EXPECT_FALSE(sock->IsConnected());
126 126
127 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); 127 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
128 rv = sock->Connect(&callback, log); 128 rv = sock->Connect(&callback, log.bound());
129 EXPECT_TRUE(net::LogContainsBeginEvent( 129 EXPECT_TRUE(net::LogContainsBeginEvent(
130 *log, 0, net::LoadLog::TYPE_SSL_CONNECT)); 130 log.entries(), 0, net::NetLog::TYPE_SSL_CONNECT));
131 if (rv != net::OK) { 131 if (rv != net::OK) {
132 ASSERT_EQ(net::ERR_IO_PENDING, rv); 132 ASSERT_EQ(net::ERR_IO_PENDING, rv);
133 EXPECT_FALSE(sock->IsConnected()); 133 EXPECT_FALSE(sock->IsConnected());
134 EXPECT_FALSE(net::LogContainsEndEvent( 134 EXPECT_FALSE(net::LogContainsEndEvent(
135 *log, -1, net::LoadLog::TYPE_SSL_CONNECT)); 135 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT));
136 136
137 rv = callback.WaitForResult(); 137 rv = callback.WaitForResult();
138 EXPECT_EQ(net::ERR_CERT_DATE_INVALID, rv); 138 EXPECT_EQ(net::ERR_CERT_DATE_INVALID, rv);
139 } 139 }
140 140
141 // We cannot test sock->IsConnected(), as the NSS implementation disconnects 141 // We cannot test sock->IsConnected(), as the NSS implementation disconnects
142 // the socket when it encounters an error, whereas other implementations 142 // the socket when it encounters an error, whereas other implementations
143 // leave it connected. 143 // leave it connected.
144 144
145 EXPECT_TRUE(net::LogContainsEndEvent( 145 EXPECT_TRUE(net::LogContainsEndEvent(
146 *log, -1, net::LoadLog::TYPE_SSL_CONNECT)); 146 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT));
147 } 147 }
148 148
149 TEST_F(SSLClientSocketTest, ConnectMismatched) { 149 TEST_F(SSLClientSocketTest, ConnectMismatched) {
150 StartMismatchedServer(); 150 StartMismatchedServer();
151 151
152 net::AddressList addr; 152 net::AddressList addr;
153 TestCompletionCallback callback; 153 TestCompletionCallback callback;
154 154
155 net::HostResolver::RequestInfo info(server_.kMismatchedHostName, 155 net::HostResolver::RequestInfo info(server_.kMismatchedHostName,
156 server_.kOKHTTPSPort); 156 server_.kOKHTTPSPort);
157 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL); 157 int rv = resolver_->Resolve(info, &addr, NULL, NULL, NULL);
158 EXPECT_EQ(net::OK, rv); 158 EXPECT_EQ(net::OK, rv);
159 159
160 net::ClientSocket *transport = new net::TCPClientSocket(addr); 160 net::ClientSocket *transport = new net::TCPClientSocket(addr);
161 rv = transport->Connect(&callback, NULL); 161 rv = transport->Connect(&callback, NULL);
162 if (rv == net::ERR_IO_PENDING) 162 if (rv == net::ERR_IO_PENDING)
163 rv = callback.WaitForResult(); 163 rv = callback.WaitForResult();
164 EXPECT_EQ(net::OK, rv); 164 EXPECT_EQ(net::OK, rv);
165 165
166 scoped_ptr<net::SSLClientSocket> sock( 166 scoped_ptr<net::SSLClientSocket> sock(
167 socket_factory_->CreateSSLClientSocket(transport, 167 socket_factory_->CreateSSLClientSocket(transport,
168 server_.kMismatchedHostName, kDefaultSSLConfig)); 168 server_.kMismatchedHostName, kDefaultSSLConfig));
169 169
170 EXPECT_FALSE(sock->IsConnected()); 170 EXPECT_FALSE(sock->IsConnected());
171 171
172 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); 172 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
173 rv = sock->Connect(&callback, log); 173 rv = sock->Connect(&callback, log.bound());
174 EXPECT_TRUE(net::LogContainsBeginEvent( 174 EXPECT_TRUE(net::LogContainsBeginEvent(
175 *log, 0, net::LoadLog::TYPE_SSL_CONNECT)); 175 log.entries(), 0, net::NetLog::TYPE_SSL_CONNECT));
176 if (rv != net::ERR_CERT_COMMON_NAME_INVALID) { 176 if (rv != net::ERR_CERT_COMMON_NAME_INVALID) {
177 ASSERT_EQ(net::ERR_IO_PENDING, rv); 177 ASSERT_EQ(net::ERR_IO_PENDING, rv);
178 EXPECT_FALSE(sock->IsConnected()); 178 EXPECT_FALSE(sock->IsConnected());
179 EXPECT_FALSE(net::LogContainsEndEvent( 179 EXPECT_FALSE(net::LogContainsEndEvent(
180 *log, -1, net::LoadLog::TYPE_SSL_CONNECT)); 180 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT));
181 181
182 rv = callback.WaitForResult(); 182 rv = callback.WaitForResult();
183 EXPECT_EQ(net::ERR_CERT_COMMON_NAME_INVALID, rv); 183 EXPECT_EQ(net::ERR_CERT_COMMON_NAME_INVALID, rv);
184 } 184 }
185 185
186 // We cannot test sock->IsConnected(), as the NSS implementation disconnects 186 // We cannot test sock->IsConnected(), as the NSS implementation disconnects
187 // the socket when it encounters an error, whereas other implementations 187 // the socket when it encounters an error, whereas other implementations
188 // leave it connected. 188 // leave it connected.
189 189
190 EXPECT_TRUE(net::LogContainsEndEvent( 190 EXPECT_TRUE(net::LogContainsEndEvent(
191 *log, -1, net::LoadLog::TYPE_SSL_CONNECT)); 191 log.entries(), -1, net::NetLog::TYPE_SSL_CONNECT));
192 } 192 }
193 193
194 // TODO(wtc): Add unit tests for IsConnectedAndIdle: 194 // TODO(wtc): Add unit tests for IsConnectedAndIdle:
195 // - Server closes an SSL connection (with a close_notify alert message). 195 // - Server closes an SSL connection (with a close_notify alert message).
196 // - Server closes the underlying TCP connection directly. 196 // - Server closes the underlying TCP connection directly.
197 // - Server sends data unexpectedly. 197 // - Server sends data unexpectedly.
198 198
199 TEST_F(SSLClientSocketTest, Read) { 199 TEST_F(SSLClientSocketTest, Read) {
200 StartOKServer(); 200 StartOKServer();
201 201
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // Do a partial read and then exit. This test should not crash! 417 // Do a partial read and then exit. This test should not crash!
418 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(512); 418 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(512);
419 rv = sock->Read(buf, 512, &callback); 419 rv = sock->Read(buf, 512, &callback);
420 EXPECT_TRUE(rv > 0 || rv == net::ERR_IO_PENDING); 420 EXPECT_TRUE(rv > 0 || rv == net::ERR_IO_PENDING);
421 421
422 if (rv == net::ERR_IO_PENDING) 422 if (rv == net::ERR_IO_PENDING)
423 rv = callback.WaitForResult(); 423 rv = callback.WaitForResult();
424 424
425 EXPECT_GT(rv, 0); 425 EXPECT_GT(rv, 0);
426 } 426 }
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_nss.cc ('k') | net/socket/ssl_client_socket_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698