| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
| 8 #include <stdarg.h> | 8 #include <stdarg.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 10114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10125 } | 10125 } |
| 10126 | 10126 |
| 10127 HttpRequestInfo request; | 10127 HttpRequestInfo request; |
| 10128 request.method = "GET"; | 10128 request.method = "GET"; |
| 10129 request.url = GURL(test_config.server_url); | 10129 request.url = GURL(test_config.server_url); |
| 10130 request.load_flags = 0; | 10130 request.load_flags = 0; |
| 10131 | 10131 |
| 10132 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 10132 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10133 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | 10133 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10134 | 10134 |
| 10135 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 10136 |
| 10137 std::vector<std::vector<MockRead>> mock_reads(1); |
| 10138 std::vector<std::vector<MockWrite>> mock_writes(1); |
| 10135 for (int round = 0; round < test_config.num_auth_rounds; ++round) { | 10139 for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10136 const TestRound& read_write_round = test_config.rounds[round]; | 10140 const TestRound& read_write_round = test_config.rounds[round]; |
| 10137 | 10141 |
| 10138 // Set up expected reads and writes. | 10142 // Set up expected reads and writes. |
| 10139 MockRead reads[2]; | 10143 mock_reads.back().push_back(read_write_round.read); |
| 10140 reads[0] = read_write_round.read; | 10144 mock_writes.back().push_back(read_write_round.write); |
| 10141 size_t length_reads = 1; | 10145 |
| 10142 if (read_write_round.extra_read) { | 10146 // kProxyChallenge uses Proxy-Connection: close which means that the |
| 10143 reads[1] = *read_write_round.extra_read; | 10147 // socket is closed and a new one will be created for the next request. |
| 10144 length_reads = 2; | 10148 if (read_write_round.read.data == kProxyChallenge.data && |
| 10149 read_write_round.write.data != kConnect.data) { |
| 10150 mock_reads.push_back(std::vector<MockRead>()); |
| 10151 mock_writes.push_back(std::vector<MockWrite>()); |
| 10145 } | 10152 } |
| 10146 | 10153 |
| 10147 MockWrite writes[2]; | 10154 if (read_write_round.extra_read) { |
| 10148 writes[0] = read_write_round.write; | 10155 mock_reads.back().push_back(*read_write_round.extra_read); |
| 10149 size_t length_writes = 1; | 10156 } |
| 10150 if (read_write_round.extra_write) { | 10157 if (read_write_round.extra_write) { |
| 10151 writes[1] = *read_write_round.extra_write; | 10158 mock_writes.back().push_back(*read_write_round.extra_write); |
| 10152 length_writes = 2; | |
| 10153 } | 10159 } |
| 10154 StaticSocketDataProvider data_provider( | |
| 10155 reads, length_reads, writes, length_writes); | |
| 10156 session_deps_.socket_factory->AddSocketDataProvider(&data_provider); | |
| 10157 | 10160 |
| 10158 // Add an SSL sequence if necessary. | 10161 // Add an SSL sequence if necessary. |
| 10159 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); | |
| 10160 if (round >= test_config.first_ssl_round) | 10162 if (round >= test_config.first_ssl_round) |
| 10161 session_deps_.socket_factory->AddSSLSocketDataProvider( | 10163 session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 10162 &ssl_socket_data_provider); | 10164 &ssl_socket_data_provider); |
| 10165 } |
| 10163 | 10166 |
| 10167 ScopedVector<StaticSocketDataProvider> data_providers; |
| 10168 for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 10169 data_providers.push_back(new StaticSocketDataProvider( |
| 10170 vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 10171 vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 10172 session_deps_.socket_factory->AddSocketDataProvider( |
| 10173 data_providers.back()); |
| 10174 } |
| 10175 |
| 10176 for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10177 const TestRound& read_write_round = test_config.rounds[round]; |
| 10164 // Start or restart the transaction. | 10178 // Start or restart the transaction. |
| 10165 TestCompletionCallback callback; | 10179 TestCompletionCallback callback; |
| 10166 int rv; | 10180 int rv; |
| 10167 if (round == 0) { | 10181 if (round == 0) { |
| 10168 rv = trans.Start(&request, callback.callback(), BoundNetLog()); | 10182 rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10169 } else { | 10183 } else { |
| 10170 rv = trans.RestartWithAuth( | 10184 rv = trans.RestartWithAuth( |
| 10171 AuthCredentials(kFoo, kBar), callback.callback()); | 10185 AuthCredentials(kFoo, kBar), callback.callback()); |
| 10172 } | 10186 } |
| 10173 if (rv == ERR_IO_PENDING) | 10187 if (rv == ERR_IO_PENDING) |
| (...skipping 4065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14239 ASSERT_TRUE(response); | 14253 ASSERT_TRUE(response); |
| 14240 ASSERT_TRUE(response->headers.get()); | 14254 ASSERT_TRUE(response->headers.get()); |
| 14241 | 14255 |
| 14242 EXPECT_EQ(101, response->headers->response_code()); | 14256 EXPECT_EQ(101, response->headers->response_code()); |
| 14243 | 14257 |
| 14244 trans.reset(); | 14258 trans.reset(); |
| 14245 session->CloseAllConnections(); | 14259 session->CloseAllConnections(); |
| 14246 } | 14260 } |
| 14247 | 14261 |
| 14248 } // namespace net | 14262 } // namespace net |
| OLD | NEW |