OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "net/base/capturing_net_log.h" | 9 #include "net/base/capturing_net_log.h" |
10 #include "net/base/net_log_unittest.h" | 10 #include "net/base/net_log_unittest.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 params_.ssl_config_service = ssl_config_service_.get(); | 229 params_.ssl_config_service = ssl_config_service_.get(); |
230 params_.http_auth_handler_factory = auth_handler_factory_.get(); | 230 params_.http_auth_handler_factory = auth_handler_factory_.get(); |
231 params_.http_server_properties = &http_server_properties; | 231 params_.http_server_properties = &http_server_properties; |
232 | 232 |
233 session_ = new HttpNetworkSession(params_); | 233 session_ = new HttpNetworkSession(params_); |
234 } | 234 } |
235 | 235 |
236 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { | 236 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
237 const HttpResponseInfo* response = trans->GetResponseInfo(); | 237 const HttpResponseInfo* response = trans->GetResponseInfo(); |
238 ASSERT_TRUE(response != NULL); | 238 ASSERT_TRUE(response != NULL); |
239 ASSERT_TRUE(response->headers != NULL); | 239 ASSERT_TRUE(response->headers.get() != NULL); |
240 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 240 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
241 EXPECT_TRUE(response->was_fetched_via_spdy); | 241 EXPECT_TRUE(response->was_fetched_via_spdy); |
242 EXPECT_TRUE(response->was_npn_negotiated); | 242 EXPECT_TRUE(response->was_npn_negotiated); |
243 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, | 243 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, |
244 response->connection_info); | 244 response->connection_info); |
245 } | 245 } |
246 | 246 |
247 void CheckWasHttpResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { | 247 void CheckWasHttpResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
248 const HttpResponseInfo* response = trans->GetResponseInfo(); | 248 const HttpResponseInfo* response = trans->GetResponseInfo(); |
249 ASSERT_TRUE(response != NULL); | 249 ASSERT_TRUE(response != NULL); |
250 ASSERT_TRUE(response->headers != NULL); | 250 ASSERT_TRUE(response->headers.get() != NULL); |
251 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 251 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
252 EXPECT_FALSE(response->was_fetched_via_spdy); | 252 EXPECT_FALSE(response->was_fetched_via_spdy); |
253 EXPECT_FALSE(response->was_npn_negotiated); | 253 EXPECT_FALSE(response->was_npn_negotiated); |
254 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, | 254 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
255 response->connection_info); | 255 response->connection_info); |
256 } | 256 } |
257 | 257 |
258 void CheckResponseData(HttpNetworkTransaction* trans, | 258 void CheckResponseData(HttpNetworkTransaction* trans, |
259 const std::string& expected) { | 259 const std::string& expected) { |
260 std::string response_data; | 260 std::string response_data; |
261 ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); | 261 ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); |
262 EXPECT_EQ(expected, response_data); | 262 EXPECT_EQ(expected, response_data); |
263 } | 263 } |
264 | 264 |
265 void RunTransaction(HttpNetworkTransaction* trans) { | 265 void RunTransaction(HttpNetworkTransaction* trans) { |
266 TestCompletionCallback callback; | 266 TestCompletionCallback callback; |
267 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 267 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
268 EXPECT_EQ(ERR_IO_PENDING, rv); | 268 EXPECT_EQ(ERR_IO_PENDING, rv); |
269 EXPECT_EQ(OK, callback.WaitForResult()); | 269 EXPECT_EQ(OK, callback.WaitForResult()); |
270 } | 270 } |
271 | 271 |
272 void SendRequestAndExpectHttpResponse(const std::string& expected) { | 272 void SendRequestAndExpectHttpResponse(const std::string& expected) { |
273 scoped_ptr<HttpNetworkTransaction> trans( | 273 scoped_ptr<HttpNetworkTransaction> trans( |
274 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_)); | 274 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
275 RunTransaction(trans.get()); | 275 RunTransaction(trans.get()); |
276 CheckWasHttpResponse(trans); | 276 CheckWasHttpResponse(trans); |
277 CheckResponseData(trans.get(), expected); | 277 CheckResponseData(trans.get(), expected); |
278 } | 278 } |
279 | 279 |
280 void SendRequestAndExpectQuicResponse(const std::string& expected) { | 280 void SendRequestAndExpectQuicResponse(const std::string& expected) { |
281 scoped_ptr<HttpNetworkTransaction> trans( | 281 scoped_ptr<HttpNetworkTransaction> trans( |
282 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_)); | 282 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
283 RunTransaction(trans.get()); | 283 RunTransaction(trans.get()); |
284 CheckWasQuicResponse(trans); | 284 CheckWasQuicResponse(trans); |
285 CheckResponseData(trans.get(), expected); | 285 CheckResponseData(trans.get(), expected); |
286 } | 286 } |
287 | 287 |
288 void AddQuicAlternateProtocolMapping( | 288 void AddQuicAlternateProtocolMapping( |
289 MockCryptoClientStream::HandshakeMode handshake_mode) { | 289 MockCryptoClientStream::HandshakeMode handshake_mode) { |
290 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); | 290 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
291 session_->http_server_properties()->SetAlternateProtocol( | 291 session_->http_server_properties()->SetAlternateProtocol( |
292 HostPortPair::FromURL(request_.url), 80, QUIC); | 292 HostPortPair::FromURL(request_.url), 80, QUIC); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 MockRead quic_reads[] = { | 405 MockRead quic_reads[] = { |
406 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), | 406 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
407 }; | 407 }; |
408 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 408 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
409 NULL, 0); | 409 NULL, 0); |
410 socket_factory_.AddSocketDataProvider(&quic_data); | 410 socket_factory_.AddSocketDataProvider(&quic_data); |
411 | 411 |
412 CreateSession(); | 412 CreateSession(); |
413 | 413 |
414 scoped_ptr<HttpNetworkTransaction> trans( | 414 scoped_ptr<HttpNetworkTransaction> trans( |
415 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_)); | 415 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
416 TestCompletionCallback callback; | 416 TestCompletionCallback callback; |
417 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 417 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
418 EXPECT_EQ(ERR_IO_PENDING, rv); | 418 EXPECT_EQ(ERR_IO_PENDING, rv); |
419 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, callback.WaitForResult()); | 419 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, callback.WaitForResult()); |
420 } | 420 } |
421 | 421 |
422 TEST_F(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { | 422 TEST_F(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
423 // Attempt to "force" quic on 443, which will not be honored. | 423 // Attempt to "force" quic on 443, which will not be honored. |
424 params_.origin_port_to_force_quic_on = 443; | 424 params_.origin_port_to_force_quic_on = 443; |
425 | 425 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 610 |
611 CreateSession(); | 611 CreateSession(); |
612 | 612 |
613 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); | 613 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
614 SendRequestAndExpectHttpResponse("hello from http"); | 614 SendRequestAndExpectHttpResponse("hello from http"); |
615 ExpectBrokenAlternateProtocolMapping(); | 615 ExpectBrokenAlternateProtocolMapping(); |
616 } | 616 } |
617 | 617 |
618 } // namespace test | 618 } // namespace test |
619 } // namespace net | 619 } // namespace net |
OLD | NEW |