Chromium Code Reviews| 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 #include "jingle/notifier/base/fake_ssl_client_socket.h" | 5 #include "jingle/notifier/base/fake_ssl_client_socket.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 // (sliced up according to the parameters) and makes sure the | 124 // (sliced up according to the parameters) and makes sure the |
| 125 // FakeSSLClientSocket behaves as expected. | 125 // FakeSSLClientSocket behaves as expected. |
| 126 void RunSuccessfulHandshakeTest( | 126 void RunSuccessfulHandshakeTest( |
| 127 bool async, size_t read_chunk_size, size_t write_chunk_size, | 127 bool async, size_t read_chunk_size, size_t write_chunk_size, |
| 128 int num_resets) { | 128 int num_resets) { |
| 129 base::StringPiece ssl_client_hello = | 129 base::StringPiece ssl_client_hello = |
| 130 FakeSSLClientSocket::GetSslClientHello(); | 130 FakeSSLClientSocket::GetSslClientHello(); |
| 131 base::StringPiece ssl_server_hello = | 131 base::StringPiece ssl_server_hello = |
| 132 FakeSSLClientSocket::GetSslServerHello(); | 132 FakeSSLClientSocket::GetSslServerHello(); |
| 133 | 133 |
| 134 net::MockConnect mock_connect(async, net::OK); | 134 net::MockConnect mock_connect(async ? net::ASYNC : net::SYNCHRONOUS, |
|
akalin
2012/02/17 19:46:49
ideally you'd propagate the enum up, but that's no
Ryan Hamilton
2012/02/17 19:58:09
Yup, I intend to do that in a subsequent CL, comin
| |
| 135 net::OK); | |
| 135 std::vector<net::MockRead> reads; | 136 std::vector<net::MockRead> reads; |
| 136 std::vector<net::MockWrite> writes; | 137 std::vector<net::MockWrite> writes; |
| 137 static const char kReadTestData[] = "read test data"; | 138 static const char kReadTestData[] = "read test data"; |
| 138 static const char kWriteTestData[] = "write test data"; | 139 static const char kWriteTestData[] = "write test data"; |
| 139 for (int i = 0; i < num_resets + 1; ++i) { | 140 for (int i = 0; i < num_resets + 1; ++i) { |
| 140 SCOPED_TRACE(i); | 141 SCOPED_TRACE(i); |
| 141 AddChunkedOps(ssl_server_hello, read_chunk_size, async, &reads); | 142 AddChunkedOps(ssl_server_hello, read_chunk_size, async, &reads); |
| 142 AddChunkedOps(ssl_client_hello, write_chunk_size, async, &writes); | 143 AddChunkedOps(ssl_client_hello, write_chunk_size, async, &writes); |
| 143 reads.push_back( | 144 reads.push_back( |
| 144 net::MockRead(async, kReadTestData, arraysize(kReadTestData))); | 145 net::MockRead(async, kReadTestData, arraysize(kReadTestData))); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 // Sets up the mock socket to generate an unsuccessful handshake | 186 // Sets up the mock socket to generate an unsuccessful handshake |
| 186 // FakeSSLClientSocket fails as expected. | 187 // FakeSSLClientSocket fails as expected. |
| 187 void RunUnsuccessfulHandshakeTestHelper( | 188 void RunUnsuccessfulHandshakeTestHelper( |
| 188 bool async, int error, HandshakeErrorLocation location) { | 189 bool async, int error, HandshakeErrorLocation location) { |
| 189 DCHECK_NE(error, net::OK); | 190 DCHECK_NE(error, net::OK); |
| 190 base::StringPiece ssl_client_hello = | 191 base::StringPiece ssl_client_hello = |
| 191 FakeSSLClientSocket::GetSslClientHello(); | 192 FakeSSLClientSocket::GetSslClientHello(); |
| 192 base::StringPiece ssl_server_hello = | 193 base::StringPiece ssl_server_hello = |
| 193 FakeSSLClientSocket::GetSslServerHello(); | 194 FakeSSLClientSocket::GetSslServerHello(); |
| 194 | 195 |
| 195 net::MockConnect mock_connect(async, net::OK); | 196 net::MockConnect mock_connect(async ? net::ASYNC : net::SYNCHRONOUS, |
| 197 net::OK); | |
| 196 std::vector<net::MockRead> reads; | 198 std::vector<net::MockRead> reads; |
| 197 std::vector<net::MockWrite> writes; | 199 std::vector<net::MockWrite> writes; |
| 198 const size_t kChunkSize = 1; | 200 const size_t kChunkSize = 1; |
| 199 AddChunkedOps(ssl_server_hello, kChunkSize, async, &reads); | 201 AddChunkedOps(ssl_server_hello, kChunkSize, async, &reads); |
| 200 AddChunkedOps(ssl_client_hello, kChunkSize, async, &writes); | 202 AddChunkedOps(ssl_client_hello, kChunkSize, async, &writes); |
| 201 switch (location) { | 203 switch (location) { |
| 202 case CONNECT_ERROR: | 204 case CONNECT_ERROR: |
| 203 mock_connect.result = error; | 205 mock_connect.result = error; |
| 204 writes.clear(); | 206 writes.clear(); |
| 205 reads.clear(); | 207 reads.clear(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 } | 341 } |
| 340 | 342 |
| 341 TEST_F(FakeSSLClientSocketTest, MalformedServerHello) { | 343 TEST_F(FakeSSLClientSocketTest, MalformedServerHello) { |
| 342 RunUnsuccessfulHandshakeTest(ERR_MALFORMED_SERVER_HELLO, | 344 RunUnsuccessfulHandshakeTest(ERR_MALFORMED_SERVER_HELLO, |
| 343 VERIFY_SERVER_HELLO_ERROR); | 345 VERIFY_SERVER_HELLO_ERROR); |
| 344 } | 346 } |
| 345 | 347 |
| 346 } // namespace | 348 } // namespace |
| 347 | 349 |
| 348 } // namespace notifier | 350 } // namespace notifier |
| OLD | NEW |