| OLD | NEW |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "testing/platform_test.h" | 45 #include "testing/platform_test.h" |
| 46 | 46 |
| 47 namespace net { | 47 namespace net { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 class FakeDataChannel { | 51 class FakeDataChannel { |
| 52 public: | 52 public: |
| 53 FakeDataChannel() | 53 FakeDataChannel() |
| 54 : old_read_callback_(NULL), | 54 : read_buf_len_(0), |
| 55 read_buf_len_(0), | 55 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 56 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | |
| 57 } | 56 } |
| 58 | 57 |
| 59 virtual int Read(IOBuffer* buf, int buf_len, | 58 virtual int Read(IOBuffer* buf, int buf_len, |
| 60 OldCompletionCallback* callback) { | |
| 61 if (data_.empty()) { | |
| 62 old_read_callback_ = callback; | |
| 63 read_buf_ = buf; | |
| 64 read_buf_len_ = buf_len; | |
| 65 return net::ERR_IO_PENDING; | |
| 66 } | |
| 67 return PropogateData(buf, buf_len); | |
| 68 } | |
| 69 virtual int Read(IOBuffer* buf, int buf_len, | |
| 70 const CompletionCallback& callback) { | 59 const CompletionCallback& callback) { |
| 71 if (data_.empty()) { | 60 if (data_.empty()) { |
| 72 read_callback_ = callback; | 61 read_callback_ = callback; |
| 73 read_buf_ = buf; | 62 read_buf_ = buf; |
| 74 read_buf_len_ = buf_len; | 63 read_buf_len_ = buf_len; |
| 75 return net::ERR_IO_PENDING; | 64 return net::ERR_IO_PENDING; |
| 76 } | 65 } |
| 77 return PropogateData(buf, buf_len); | 66 return PropogateData(buf, buf_len); |
| 78 } | 67 } |
| 79 | 68 |
| 80 virtual int Write(IOBuffer* buf, int buf_len, | 69 virtual int Write(IOBuffer* buf, int buf_len, |
| 81 OldCompletionCallback* callback) { | 70 const CompletionCallback& callback) { |
| 82 data_.push(new net::DrainableIOBuffer(buf, buf_len)); | 71 data_.push(new net::DrainableIOBuffer(buf, buf_len)); |
| 83 MessageLoop::current()->PostTask( | 72 MessageLoop::current()->PostTask( |
| 84 FROM_HERE, task_factory_.NewRunnableMethod( | 73 FROM_HERE, base::Bind(&FakeDataChannel::DoReadCallback, |
| 85 &FakeDataChannel::DoReadCallback)); | 74 weak_factory_.GetWeakPtr())); |
| 86 return buf_len; | 75 return buf_len; |
| 87 } | 76 } |
| 88 | 77 |
| 89 private: | 78 private: |
| 90 void DoReadCallback() { | 79 void DoReadCallback() { |
| 91 if ((!old_read_callback_ && read_callback_.is_null()) || data_.empty()) | 80 if (read_callback_.is_null() || data_.empty()) |
| 92 return; | 81 return; |
| 93 | 82 |
| 94 int copied = PropogateData(read_buf_, read_buf_len_); | 83 int copied = PropogateData(read_buf_, read_buf_len_); |
| 95 if (old_read_callback_) { | 84 CompletionCallback callback = read_callback_; |
| 96 net::OldCompletionCallback* callback = old_read_callback_; | 85 read_callback_.Reset(); |
| 97 old_read_callback_ = NULL; | 86 read_buf_ = NULL; |
| 98 read_buf_ = NULL; | 87 read_buf_len_ = 0; |
| 99 read_buf_len_ = 0; | 88 callback.Run(copied); |
| 100 callback->Run(copied); | |
| 101 } else { | |
| 102 net::CompletionCallback callback = read_callback_; | |
| 103 read_callback_.Reset(); | |
| 104 read_buf_ = NULL; | |
| 105 read_buf_len_ = 0; | |
| 106 callback.Run(copied); | |
| 107 } | |
| 108 } | 89 } |
| 109 | 90 |
| 110 int PropogateData(scoped_refptr<net::IOBuffer> read_buf, int read_buf_len) { | 91 int PropogateData(scoped_refptr<net::IOBuffer> read_buf, int read_buf_len) { |
| 111 scoped_refptr<net::DrainableIOBuffer> buf = data_.front(); | 92 scoped_refptr<net::DrainableIOBuffer> buf = data_.front(); |
| 112 int copied = std::min(buf->BytesRemaining(), read_buf_len); | 93 int copied = std::min(buf->BytesRemaining(), read_buf_len); |
| 113 memcpy(read_buf->data(), buf->data(), copied); | 94 memcpy(read_buf->data(), buf->data(), copied); |
| 114 buf->DidConsume(copied); | 95 buf->DidConsume(copied); |
| 115 | 96 |
| 116 if (!buf->BytesRemaining()) | 97 if (!buf->BytesRemaining()) |
| 117 data_.pop(); | 98 data_.pop(); |
| 118 return copied; | 99 return copied; |
| 119 } | 100 } |
| 120 | 101 |
| 121 net::OldCompletionCallback* old_read_callback_; | 102 CompletionCallback read_callback_; |
| 122 net::CompletionCallback read_callback_; | |
| 123 scoped_refptr<net::IOBuffer> read_buf_; | 103 scoped_refptr<net::IOBuffer> read_buf_; |
| 124 int read_buf_len_; | 104 int read_buf_len_; |
| 125 | 105 |
| 126 std::queue<scoped_refptr<net::DrainableIOBuffer> > data_; | 106 std::queue<scoped_refptr<net::DrainableIOBuffer> > data_; |
| 127 | 107 |
| 128 ScopedRunnableMethodFactory<FakeDataChannel> task_factory_; | 108 base::WeakPtrFactory<FakeDataChannel> weak_factory_; |
| 129 | 109 |
| 130 DISALLOW_COPY_AND_ASSIGN(FakeDataChannel); | 110 DISALLOW_COPY_AND_ASSIGN(FakeDataChannel); |
| 131 }; | 111 }; |
| 132 | 112 |
| 133 class FakeSocket : public StreamSocket { | 113 class FakeSocket : public StreamSocket { |
| 134 public: | 114 public: |
| 135 FakeSocket(FakeDataChannel* incoming_channel, | 115 FakeSocket(FakeDataChannel* incoming_channel, |
| 136 FakeDataChannel* outgoing_channel) | 116 FakeDataChannel* outgoing_channel) |
| 137 : incoming_(incoming_channel), | 117 : incoming_(incoming_channel), |
| 138 outgoing_(outgoing_channel) { | 118 outgoing_(outgoing_channel) { |
| 139 } | 119 } |
| 140 | 120 |
| 141 virtual ~FakeSocket() { | 121 virtual ~FakeSocket() { |
| 142 } | 122 } |
| 143 | 123 |
| 144 virtual int Read(IOBuffer* buf, int buf_len, | 124 virtual int Read(IOBuffer* buf, int buf_len, |
| 145 OldCompletionCallback* callback) { | 125 const CompletionCallback& callback) OVERRIDE { |
| 146 // Read random number of bytes. | |
| 147 buf_len = rand() % buf_len + 1; | |
| 148 return incoming_->Read(buf, buf_len, callback); | |
| 149 } | |
| 150 virtual int Read(IOBuffer* buf, int buf_len, | |
| 151 const CompletionCallback& callback) { | |
| 152 // Read random number of bytes. | 126 // Read random number of bytes. |
| 153 buf_len = rand() % buf_len + 1; | 127 buf_len = rand() % buf_len + 1; |
| 154 return incoming_->Read(buf, buf_len, callback); | 128 return incoming_->Read(buf, buf_len, callback); |
| 155 } | 129 } |
| 156 | 130 |
| 157 virtual int Write(IOBuffer* buf, int buf_len, | 131 virtual int Write(IOBuffer* buf, int buf_len, |
| 158 OldCompletionCallback* callback) { | 132 const CompletionCallback& callback) OVERRIDE { |
| 159 // Write random number of bytes. | 133 // Write random number of bytes. |
| 160 buf_len = rand() % buf_len + 1; | 134 buf_len = rand() % buf_len + 1; |
| 161 return outgoing_->Write(buf, buf_len, callback); | 135 return outgoing_->Write(buf, buf_len, callback); |
| 162 } | 136 } |
| 163 | 137 |
| 164 virtual bool SetReceiveBufferSize(int32 size) { | 138 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE { |
| 165 return true; | 139 return true; |
| 166 } | 140 } |
| 167 | 141 |
| 168 virtual bool SetSendBufferSize(int32 size) { | 142 virtual bool SetSendBufferSize(int32 size) OVERRIDE { |
| 169 return true; | 143 return true; |
| 170 } | 144 } |
| 171 | 145 |
| 172 virtual int Connect(OldCompletionCallback* callback) { | 146 virtual int Connect(const CompletionCallback& callback) OVERRIDE { |
| 173 return net::OK; | |
| 174 } | |
| 175 virtual int Connect(const CompletionCallback& callback) { | |
| 176 return net::OK; | 147 return net::OK; |
| 177 } | 148 } |
| 178 | 149 |
| 179 virtual void Disconnect() {} | 150 virtual void Disconnect() OVERRIDE {} |
| 180 | 151 |
| 181 virtual bool IsConnected() const { | 152 virtual bool IsConnected() const OVERRIDE { |
| 182 return true; | 153 return true; |
| 183 } | 154 } |
| 184 | 155 |
| 185 virtual bool IsConnectedAndIdle() const { | 156 virtual bool IsConnectedAndIdle() const OVERRIDE { |
| 186 return true; | 157 return true; |
| 187 } | 158 } |
| 188 | 159 |
| 189 virtual int GetPeerAddress(AddressList* address) const { | 160 virtual int GetPeerAddress(AddressList* address) const OVERRIDE { |
| 190 net::IPAddressNumber ip_address(4); | 161 net::IPAddressNumber ip_address(4); |
| 191 *address = net::AddressList::CreateFromIPAddress(ip_address, 0 /*port*/); | 162 *address = net::AddressList::CreateFromIPAddress(ip_address, 0 /*port*/); |
| 192 return net::OK; | 163 return net::OK; |
| 193 } | 164 } |
| 194 | 165 |
| 195 virtual int GetLocalAddress(IPEndPoint* address) const { | 166 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { |
| 196 net::IPAddressNumber ip_address(4); | 167 net::IPAddressNumber ip_address(4); |
| 197 *address = net::IPEndPoint(ip_address, 0); | 168 *address = net::IPEndPoint(ip_address, 0); |
| 198 return net::OK; | 169 return net::OK; |
| 199 } | 170 } |
| 200 | 171 |
| 201 virtual const BoundNetLog& NetLog() const { | 172 virtual const BoundNetLog& NetLog() const OVERRIDE { |
| 202 return net_log_; | 173 return net_log_; |
| 203 } | 174 } |
| 204 | 175 |
| 205 virtual void SetSubresourceSpeculation() {} | 176 virtual void SetSubresourceSpeculation() OVERRIDE {} |
| 206 virtual void SetOmniboxSpeculation() {} | 177 virtual void SetOmniboxSpeculation() OVERRIDE {} |
| 207 | 178 |
| 208 virtual bool WasEverUsed() const { | 179 virtual bool WasEverUsed() const OVERRIDE { |
| 209 return true; | 180 return true; |
| 210 } | 181 } |
| 211 | 182 |
| 212 virtual bool UsingTCPFastOpen() const { | 183 virtual bool UsingTCPFastOpen() const OVERRIDE { |
| 213 return false; | 184 return false; |
| 214 } | 185 } |
| 215 | 186 |
| 216 virtual int64 NumBytesRead() const { | 187 virtual int64 NumBytesRead() const OVERRIDE { |
| 217 return -1; | 188 return -1; |
| 218 } | 189 } |
| 219 | 190 |
| 220 virtual base::TimeDelta GetConnectTimeMicros() const { | 191 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE { |
| 221 return base::TimeDelta::FromMicroseconds(-1); | 192 return base::TimeDelta::FromMicroseconds(-1); |
| 222 } | 193 } |
| 223 | 194 |
| 224 private: | 195 private: |
| 225 net::BoundNetLog net_log_; | 196 net::BoundNetLog net_log_; |
| 226 FakeDataChannel* incoming_; | 197 FakeDataChannel* incoming_; |
| 227 FakeDataChannel* outgoing_; | 198 FakeDataChannel* outgoing_; |
| 228 | 199 |
| 229 DISALLOW_COPY_AND_ASSIGN(FakeSocket); | 200 DISALLOW_COPY_AND_ASSIGN(FakeSocket); |
| 230 }; | 201 }; |
| 231 | 202 |
| 232 } // namespace | 203 } // namespace |
| 233 | 204 |
| 234 // Verify the correctness of the test helper classes first. | 205 // Verify the correctness of the test helper classes first. |
| 235 TEST(FakeSocketTest, DataTransfer) { | 206 TEST(FakeSocketTest, DataTransfer) { |
| 236 // Establish channels between two sockets. | 207 // Establish channels between two sockets. |
| 237 FakeDataChannel channel_1; | 208 FakeDataChannel channel_1; |
| 238 FakeDataChannel channel_2; | 209 FakeDataChannel channel_2; |
| 239 FakeSocket client(&channel_1, &channel_2); | 210 FakeSocket client(&channel_1, &channel_2); |
| 240 FakeSocket server(&channel_2, &channel_1); | 211 FakeSocket server(&channel_2, &channel_1); |
| 241 | 212 |
| 242 const char kTestData[] = "testing123"; | 213 const char kTestData[] = "testing123"; |
| 243 const int kTestDataSize = strlen(kTestData); | 214 const int kTestDataSize = strlen(kTestData); |
| 244 const int kReadBufSize = 1024; | 215 const int kReadBufSize = 1024; |
| 245 scoped_refptr<net::IOBuffer> write_buf = new net::StringIOBuffer(kTestData); | 216 scoped_refptr<net::IOBuffer> write_buf = new net::StringIOBuffer(kTestData); |
| 246 scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(kReadBufSize); | 217 scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(kReadBufSize); |
| 247 | 218 |
| 248 // Write then read. | 219 // Write then read. |
| 249 int written = server.Write(write_buf, kTestDataSize, NULL); | 220 int written = server.Write(write_buf, kTestDataSize, CompletionCallback()); |
| 250 EXPECT_GT(written, 0); | 221 EXPECT_GT(written, 0); |
| 251 EXPECT_LE(written, kTestDataSize); | 222 EXPECT_LE(written, kTestDataSize); |
| 252 | 223 |
| 253 int read = client.Read(read_buf, kReadBufSize, NULL); | 224 int read = client.Read(read_buf, kReadBufSize, CompletionCallback()); |
| 254 EXPECT_GT(read, 0); | 225 EXPECT_GT(read, 0); |
| 255 EXPECT_LE(read, written); | 226 EXPECT_LE(read, written); |
| 256 EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read)); | 227 EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read)); |
| 257 | 228 |
| 258 // Read then write. | 229 // Read then write. |
| 259 TestOldCompletionCallback callback; | 230 TestCompletionCallback callback; |
| 260 EXPECT_EQ(net::ERR_IO_PENDING, | 231 EXPECT_EQ(net::ERR_IO_PENDING, |
| 261 server.Read(read_buf, kReadBufSize, &callback)); | 232 server.Read(read_buf, kReadBufSize, callback.callback())); |
| 262 | 233 |
| 263 written = client.Write(write_buf, kTestDataSize, NULL); | 234 written = client.Write(write_buf, kTestDataSize, CompletionCallback()); |
| 264 EXPECT_GT(written, 0); | 235 EXPECT_GT(written, 0); |
| 265 EXPECT_LE(written, kTestDataSize); | 236 EXPECT_LE(written, kTestDataSize); |
| 266 | 237 |
| 267 read = callback.WaitForResult(); | 238 read = callback.WaitForResult(); |
| 268 EXPECT_GT(read, 0); | 239 EXPECT_GT(read, 0); |
| 269 EXPECT_LE(read, written); | 240 EXPECT_LE(read, written); |
| 270 EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read)); | 241 EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read)); |
| 271 } | 242 } |
| 272 | 243 |
| 273 class SSLServerSocketTest : public PlatformTest { | 244 class SSLServerSocketTest : public PlatformTest { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 TEST_F(SSLServerSocketTest, Initialize) { | 318 TEST_F(SSLServerSocketTest, Initialize) { |
| 348 Initialize(); | 319 Initialize(); |
| 349 } | 320 } |
| 350 | 321 |
| 351 // This test executes Connect() on SSLClientSocket and Handshake() on | 322 // This test executes Connect() on SSLClientSocket and Handshake() on |
| 352 // SSLServerSocket to make sure handshaking between the two sockets is | 323 // SSLServerSocket to make sure handshaking between the two sockets is |
| 353 // completed successfully. | 324 // completed successfully. |
| 354 TEST_F(SSLServerSocketTest, Handshake) { | 325 TEST_F(SSLServerSocketTest, Handshake) { |
| 355 Initialize(); | 326 Initialize(); |
| 356 | 327 |
| 357 TestOldCompletionCallback connect_callback; | 328 TestCompletionCallback connect_callback; |
| 358 TestOldCompletionCallback handshake_callback; | 329 TestOldCompletionCallback handshake_callback; |
| 359 | 330 |
| 360 int server_ret = server_socket_->Handshake(&handshake_callback); | 331 int server_ret = server_socket_->Handshake(&handshake_callback); |
| 361 EXPECT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); | 332 EXPECT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); |
| 362 | 333 |
| 363 int client_ret = client_socket_->Connect(&connect_callback); | 334 int client_ret = client_socket_->Connect(connect_callback.callback()); |
| 364 EXPECT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); | 335 EXPECT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); |
| 365 | 336 |
| 366 if (client_ret == net::ERR_IO_PENDING) { | 337 if (client_ret == net::ERR_IO_PENDING) { |
| 367 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); | 338 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); |
| 368 } | 339 } |
| 369 if (server_ret == net::ERR_IO_PENDING) { | 340 if (server_ret == net::ERR_IO_PENDING) { |
| 370 EXPECT_EQ(net::OK, handshake_callback.WaitForResult()); | 341 EXPECT_EQ(net::OK, handshake_callback.WaitForResult()); |
| 371 } | 342 } |
| 372 | 343 |
| 373 // Make sure the cert status is expected. | 344 // Make sure the cert status is expected. |
| 374 SSLInfo ssl_info; | 345 SSLInfo ssl_info; |
| 375 client_socket_->GetSSLInfo(&ssl_info); | 346 client_socket_->GetSSLInfo(&ssl_info); |
| 376 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, ssl_info.cert_status); | 347 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, ssl_info.cert_status); |
| 377 } | 348 } |
| 378 | 349 |
| 379 TEST_F(SSLServerSocketTest, DataTransfer) { | 350 TEST_F(SSLServerSocketTest, DataTransfer) { |
| 380 Initialize(); | 351 Initialize(); |
| 381 | 352 |
| 382 TestOldCompletionCallback connect_callback; | 353 TestCompletionCallback connect_callback; |
| 383 TestOldCompletionCallback handshake_callback; | 354 TestOldCompletionCallback handshake_callback; |
| 384 | 355 |
| 385 // Establish connection. | 356 // Establish connection. |
| 386 int client_ret = client_socket_->Connect(&connect_callback); | 357 int client_ret = client_socket_->Connect(connect_callback.callback()); |
| 387 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); | 358 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); |
| 388 | 359 |
| 389 int server_ret = server_socket_->Handshake(&handshake_callback); | 360 int server_ret = server_socket_->Handshake(&handshake_callback); |
| 390 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); | 361 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); |
| 391 | 362 |
| 392 client_ret = connect_callback.GetResult(client_ret); | 363 client_ret = connect_callback.GetResult(client_ret); |
| 393 ASSERT_EQ(net::OK, client_ret); | 364 ASSERT_EQ(net::OK, client_ret); |
| 394 server_ret = handshake_callback.GetResult(server_ret); | 365 server_ret = handshake_callback.GetResult(server_ret); |
| 395 ASSERT_EQ(net::OK, server_ret); | 366 ASSERT_EQ(net::OK, server_ret); |
| 396 | 367 |
| 397 const int kReadBufSize = 1024; | 368 const int kReadBufSize = 1024; |
| 398 scoped_refptr<net::StringIOBuffer> write_buf = | 369 scoped_refptr<net::StringIOBuffer> write_buf = |
| 399 new net::StringIOBuffer("testing123"); | 370 new net::StringIOBuffer("testing123"); |
| 400 scoped_refptr<net::DrainableIOBuffer> read_buf = | 371 scoped_refptr<net::DrainableIOBuffer> read_buf = |
| 401 new net::DrainableIOBuffer(new net::IOBuffer(kReadBufSize), | 372 new net::DrainableIOBuffer(new net::IOBuffer(kReadBufSize), |
| 402 kReadBufSize); | 373 kReadBufSize); |
| 403 | 374 |
| 404 // Write then read. | 375 // Write then read. |
| 405 TestOldCompletionCallback write_callback; | 376 TestCompletionCallback write_callback; |
| 406 TestOldCompletionCallback read_callback; | 377 TestCompletionCallback read_callback; |
| 407 server_ret = server_socket_->Write(write_buf, write_buf->size(), | 378 server_ret = server_socket_->Write(write_buf, write_buf->size(), |
| 408 &write_callback); | 379 write_callback.callback()); |
| 409 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); | 380 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); |
| 410 client_ret = client_socket_->Read(read_buf, read_buf->BytesRemaining(), | 381 client_ret = client_socket_->Read(read_buf, read_buf->BytesRemaining(), |
| 411 &read_callback); | 382 read_callback.callback()); |
| 412 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); | 383 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); |
| 413 | 384 |
| 414 server_ret = write_callback.GetResult(server_ret); | 385 server_ret = write_callback.GetResult(server_ret); |
| 415 EXPECT_GT(server_ret, 0); | 386 EXPECT_GT(server_ret, 0); |
| 416 client_ret = read_callback.GetResult(client_ret); | 387 client_ret = read_callback.GetResult(client_ret); |
| 417 ASSERT_GT(client_ret, 0); | 388 ASSERT_GT(client_ret, 0); |
| 418 | 389 |
| 419 read_buf->DidConsume(client_ret); | 390 read_buf->DidConsume(client_ret); |
| 420 while (read_buf->BytesConsumed() < write_buf->size()) { | 391 while (read_buf->BytesConsumed() < write_buf->size()) { |
| 421 client_ret = client_socket_->Read(read_buf, read_buf->BytesRemaining(), | 392 client_ret = client_socket_->Read(read_buf, read_buf->BytesRemaining(), |
| 422 &read_callback); | 393 read_callback.callback()); |
| 423 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); | 394 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); |
| 424 client_ret = read_callback.GetResult(client_ret); | 395 client_ret = read_callback.GetResult(client_ret); |
| 425 ASSERT_GT(client_ret, 0); | 396 ASSERT_GT(client_ret, 0); |
| 426 read_buf->DidConsume(client_ret); | 397 read_buf->DidConsume(client_ret); |
| 427 } | 398 } |
| 428 EXPECT_EQ(write_buf->size(), read_buf->BytesConsumed()); | 399 EXPECT_EQ(write_buf->size(), read_buf->BytesConsumed()); |
| 429 read_buf->SetOffset(0); | 400 read_buf->SetOffset(0); |
| 430 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); | 401 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); |
| 431 | 402 |
| 432 // Read then write. | 403 // Read then write. |
| 433 write_buf = new net::StringIOBuffer("hello123"); | 404 write_buf = new net::StringIOBuffer("hello123"); |
| 434 server_ret = server_socket_->Read(read_buf, read_buf->BytesRemaining(), | 405 server_ret = server_socket_->Read(read_buf, read_buf->BytesRemaining(), |
| 435 &read_callback); | 406 read_callback.callback()); |
| 436 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); | 407 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); |
| 437 client_ret = client_socket_->Write(write_buf, write_buf->size(), | 408 client_ret = client_socket_->Write(write_buf, write_buf->size(), |
| 438 &write_callback); | 409 write_callback.callback()); |
| 439 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); | 410 EXPECT_TRUE(client_ret > 0 || client_ret == net::ERR_IO_PENDING); |
| 440 | 411 |
| 441 server_ret = read_callback.GetResult(server_ret); | 412 server_ret = read_callback.GetResult(server_ret); |
| 442 ASSERT_GT(server_ret, 0); | 413 ASSERT_GT(server_ret, 0); |
| 443 client_ret = write_callback.GetResult(client_ret); | 414 client_ret = write_callback.GetResult(client_ret); |
| 444 EXPECT_GT(client_ret, 0); | 415 EXPECT_GT(client_ret, 0); |
| 445 | 416 |
| 446 read_buf->DidConsume(server_ret); | 417 read_buf->DidConsume(server_ret); |
| 447 while (read_buf->BytesConsumed() < write_buf->size()) { | 418 while (read_buf->BytesConsumed() < write_buf->size()) { |
| 448 server_ret = server_socket_->Read(read_buf, read_buf->BytesRemaining(), | 419 server_ret = server_socket_->Read(read_buf, read_buf->BytesRemaining(), |
| 449 &read_callback); | 420 read_callback.callback()); |
| 450 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); | 421 EXPECT_TRUE(server_ret > 0 || server_ret == net::ERR_IO_PENDING); |
| 451 server_ret = read_callback.GetResult(server_ret); | 422 server_ret = read_callback.GetResult(server_ret); |
| 452 ASSERT_GT(server_ret, 0); | 423 ASSERT_GT(server_ret, 0); |
| 453 read_buf->DidConsume(server_ret); | 424 read_buf->DidConsume(server_ret); |
| 454 } | 425 } |
| 455 EXPECT_EQ(write_buf->size(), read_buf->BytesConsumed()); | 426 EXPECT_EQ(write_buf->size(), read_buf->BytesConsumed()); |
| 456 read_buf->SetOffset(0); | 427 read_buf->SetOffset(0); |
| 457 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); | 428 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); |
| 458 } | 429 } |
| 459 | 430 |
| 460 // This test executes ExportKeyingMaterial() on the client and server sockets, | 431 // This test executes ExportKeyingMaterial() on the client and server sockets, |
| 461 // after connecting them, and verifies that the results match. | 432 // after connecting them, and verifies that the results match. |
| 462 // This test will fail if False Start is enabled (see crbug.com/90208). | 433 // This test will fail if False Start is enabled (see crbug.com/90208). |
| 463 TEST_F(SSLServerSocketTest, ExportKeyingMaterial) { | 434 TEST_F(SSLServerSocketTest, ExportKeyingMaterial) { |
| 464 Initialize(); | 435 Initialize(); |
| 465 | 436 |
| 466 TestOldCompletionCallback connect_callback; | 437 TestCompletionCallback connect_callback; |
| 467 TestOldCompletionCallback handshake_callback; | 438 TestOldCompletionCallback handshake_callback; |
| 468 | 439 |
| 469 int client_ret = client_socket_->Connect(&connect_callback); | 440 int client_ret = client_socket_->Connect(connect_callback.callback()); |
| 470 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); | 441 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); |
| 471 | 442 |
| 472 int server_ret = server_socket_->Handshake(&handshake_callback); | 443 int server_ret = server_socket_->Handshake(&handshake_callback); |
| 473 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); | 444 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); |
| 474 | 445 |
| 475 if (client_ret == net::ERR_IO_PENDING) { | 446 if (client_ret == net::ERR_IO_PENDING) { |
| 476 ASSERT_EQ(net::OK, connect_callback.WaitForResult()); | 447 ASSERT_EQ(net::OK, connect_callback.WaitForResult()); |
| 477 } | 448 } |
| 478 if (server_ret == net::ERR_IO_PENDING) { | 449 if (server_ret == net::ERR_IO_PENDING) { |
| 479 ASSERT_EQ(net::OK, handshake_callback.WaitForResult()); | 450 ASSERT_EQ(net::OK, handshake_callback.WaitForResult()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 496 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; | 467 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; |
| 497 unsigned char client_bad[kKeyingMaterialSize]; | 468 unsigned char client_bad[kKeyingMaterialSize]; |
| 498 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, kKeyingContext, | 469 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, kKeyingContext, |
| 499 client_bad, sizeof(client_bad)); | 470 client_bad, sizeof(client_bad)); |
| 500 ASSERT_EQ(rv, net::OK); | 471 ASSERT_EQ(rv, net::OK); |
| 501 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0); | 472 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0); |
| 502 } | 473 } |
| 503 #endif | 474 #endif |
| 504 | 475 |
| 505 } // namespace net | 476 } // namespace net |
| OLD | NEW |