| OLD | NEW |
| 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 <arpa/inet.h> | 5 #include <arpa/inet.h> |
| 6 #include <netinet/tcp.h> | 6 #include <netinet/tcp.h> |
| 7 #include <stdarg.h> | 7 #include <stdarg.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 | 10 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 scoped_refptr<IOBuffer> reply_buffer = new IOBuffer(8); | 219 scoped_refptr<IOBuffer> reply_buffer = new IOBuffer(8); |
| 220 rv = sock->Read(reply_buffer, 8, &callback); | 220 rv = sock->Read(reply_buffer, 8, &callback); |
| 221 if (rv < 0) { | 221 if (rv < 0) { |
| 222 ASSERT_EQ(ERR_IO_PENDING, rv); | 222 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 223 rv = callback.WaitForResult(); | 223 rv = callback.WaitForResult(); |
| 224 } | 224 } |
| 225 EXPECT_EQ(8, rv); | 225 EXPECT_EQ(8, rv); |
| 226 EXPECT_TRUE(memcmp(reply_buffer->data(), "goodbye!", 8) == 0); | 226 EXPECT_TRUE(memcmp(reply_buffer->data(), "goodbye!", 8) == 0); |
| 227 | 227 |
| 228 next_proto_status_ = sock->GetNextProto(&next_proto_); |
| 229 |
| 228 sock->Disconnect(); | 230 sock->Disconnect(); |
| 229 } | 231 } |
| 230 | 232 |
| 231 // SnapStartEventType extracts the type of Snap Start from the NetLog. See | 233 // SnapStartEventType extracts the type of Snap Start from the NetLog. See |
| 232 // the SSL_SNAP_START_* defines in sslt.h | 234 // the SSL_SNAP_START_* defines in sslt.h |
| 233 int SnapStartEventType() { | 235 int SnapStartEventType() { |
| 234 const std::vector<CapturingNetLog::Entry>& entries = log_.entries(); | 236 const std::vector<CapturingNetLog::Entry>& entries = log_.entries(); |
| 235 for (std::vector<CapturingNetLog::Entry>::const_iterator | 237 for (std::vector<CapturingNetLog::Entry>::const_iterator |
| 236 i = entries.begin(); i != entries.end(); i++) { | 238 i = entries.begin(); i != entries.end(); i++) { |
| 237 if (i->type == NetLog::TYPE_SSL_SNAP_START) { | 239 if (i->type == NetLog::TYPE_SSL_SNAP_START) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 258 } | 260 } |
| 259 return false; | 261 return false; |
| 260 } | 262 } |
| 261 | 263 |
| 262 base::ProcessHandle child_; | 264 base::ProcessHandle child_; |
| 263 ClientSocketFactory* const socket_factory_; | 265 ClientSocketFactory* const socket_factory_; |
| 264 struct sockaddr_in remote_; | 266 struct sockaddr_in remote_; |
| 265 int client_; | 267 int client_; |
| 266 SSLConfig ssl_config_; | 268 SSLConfig ssl_config_; |
| 267 CapturingNetLog log_; | 269 CapturingNetLog log_; |
| 270 SSLClientSocket::NextProtoStatus next_proto_status_; |
| 271 std::string next_proto_; |
| 268 }; | 272 }; |
| 269 | 273 |
| 270 TEST_F(SSLClientSocketSnapStartTest, Basic) { | 274 TEST_F(SSLClientSocketSnapStartTest, Basic) { |
| 271 // Not a Snap Start connection. | 275 // Not a Snap Start connection. |
| 272 StartSnapStartServer(NULL); | 276 StartSnapStartServer(NULL); |
| 273 PerformConnection(); | 277 PerformConnection(); |
| 274 EXPECT_EQ(SSL_SNAP_START_NONE, SnapStartEventType()); | 278 EXPECT_EQ(SSL_SNAP_START_NONE, SnapStartEventType()); |
| 275 EXPECT_FALSE(DidMerge()); | 279 EXPECT_FALSE(DidMerge()); |
| 276 } | 280 } |
| 277 | 281 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 TEST_F(SSLClientSocketSnapStartTest, SnapStartResumeRecovery) { | 314 TEST_F(SSLClientSocketSnapStartTest, SnapStartResumeRecovery) { |
| 311 StartSnapStartServer("snap-start-recovery", NULL); | 315 StartSnapStartServer("snap-start-recovery", NULL); |
| 312 PerformConnection(); | 316 PerformConnection(); |
| 313 EXPECT_EQ(SSL_SNAP_START_NONE, SnapStartEventType()); | 317 EXPECT_EQ(SSL_SNAP_START_NONE, SnapStartEventType()); |
| 314 EXPECT_FALSE(DidMerge()); | 318 EXPECT_FALSE(DidMerge()); |
| 315 PerformConnection(); | 319 PerformConnection(); |
| 316 EXPECT_EQ(SSL_SNAP_START_RESUME_RECOVERY, SnapStartEventType()); | 320 EXPECT_EQ(SSL_SNAP_START_RESUME_RECOVERY, SnapStartEventType()); |
| 317 EXPECT_TRUE(DidMerge()); | 321 EXPECT_TRUE(DidMerge()); |
| 318 } | 322 } |
| 319 | 323 |
| 324 TEST_F(SSLClientSocketSnapStartTest, SnapStartWithNPN) { |
| 325 ssl_config_.next_protos.assign("\003foo\003bar"); |
| 326 StartSnapStartServer("snap-start", "npn", NULL); |
| 327 PerformConnection(); |
| 328 EXPECT_EQ(SSLClientSocket::kNextProtoNegotiated, next_proto_status_); |
| 329 EXPECT_EQ("foo", next_proto_); |
| 330 EXPECT_EQ(SSL_SNAP_START_NONE, SnapStartEventType()); |
| 331 EXPECT_FALSE(DidMerge()); |
| 332 SSLClientSocketNSS::ClearSessionCache(); |
| 333 PerformConnection(); |
| 334 EXPECT_EQ(SSL_SNAP_START_FULL, SnapStartEventType()); |
| 335 EXPECT_EQ(SSLClientSocket::kNextProtoNegotiated, next_proto_status_); |
| 336 EXPECT_EQ("foo", next_proto_); |
| 337 EXPECT_TRUE(DidMerge()); |
| 338 } |
| 339 |
| 340 TEST_F(SSLClientSocketSnapStartTest, SnapStartWithNPNMispredict) { |
| 341 // This tests that we recover in the event of a misprediction. |
| 342 ssl_config_.next_protos.assign("\003foo\003baz"); |
| 343 StartSnapStartServer("snap-start", "npn-mispredict", NULL); |
| 344 PerformConnection(); |
| 345 EXPECT_EQ(SSLClientSocket::kNextProtoNegotiated, next_proto_status_); |
| 346 EXPECT_EQ("foo", next_proto_); |
| 347 EXPECT_EQ(SSL_SNAP_START_NONE, SnapStartEventType()); |
| 348 EXPECT_FALSE(DidMerge()); |
| 349 |
| 350 SSLClientSocketNSS::ClearSessionCache(); |
| 351 PerformConnection(); |
| 352 EXPECT_EQ(SSL_SNAP_START_RECOVERY, SnapStartEventType()); |
| 353 EXPECT_EQ(SSLClientSocket::kNextProtoNegotiated, next_proto_status_); |
| 354 EXPECT_EQ("baz", next_proto_); |
| 355 EXPECT_TRUE(DidMerge()); |
| 356 |
| 357 SSLClientSocketNSS::ClearSessionCache(); |
| 358 PerformConnection(); |
| 359 EXPECT_EQ(SSL_SNAP_START_FULL, SnapStartEventType()); |
| 360 EXPECT_EQ(SSLClientSocket::kNextProtoNegotiated, next_proto_status_); |
| 361 EXPECT_EQ("baz", next_proto_); |
| 362 EXPECT_TRUE(DidMerge()); |
| 363 } |
| 364 |
| 320 } // namespace net | 365 } // namespace net |
| OLD | NEW |