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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 const HttpResponseInfo* response = trans->GetResponseInfo(); | 272 const HttpResponseInfo* response = trans->GetResponseInfo(); |
273 ASSERT_TRUE(response != nullptr); | 273 ASSERT_TRUE(response != nullptr); |
274 ASSERT_TRUE(response->headers.get() != nullptr); | 274 ASSERT_TRUE(response->headers.get() != nullptr); |
275 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 275 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
276 EXPECT_FALSE(response->was_fetched_via_spdy); | 276 EXPECT_FALSE(response->was_fetched_via_spdy); |
277 EXPECT_FALSE(response->was_npn_negotiated); | 277 EXPECT_FALSE(response->was_npn_negotiated); |
278 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, | 278 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
279 response->connection_info); | 279 response->connection_info); |
280 } | 280 } |
281 | 281 |
282 void CheckResponseData(HttpNetworkTransaction* trans, | 282 void CheckResponseData(const scoped_ptr<HttpNetworkTransaction>& trans, |
283 const std::string& expected) { | 283 const std::string& expected) { |
284 std::string response_data; | 284 std::string response_data; |
285 ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); | 285 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
286 EXPECT_EQ(expected, response_data); | 286 EXPECT_EQ(expected, response_data); |
287 } | 287 } |
288 | 288 |
289 void RunTransaction(HttpNetworkTransaction* trans) { | 289 void RunTransaction(const scoped_ptr<HttpNetworkTransaction>& trans) { |
290 TestCompletionCallback callback; | 290 TestCompletionCallback callback; |
291 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 291 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
292 EXPECT_EQ(ERR_IO_PENDING, rv); | 292 EXPECT_EQ(ERR_IO_PENDING, rv); |
293 EXPECT_EQ(OK, callback.WaitForResult()); | 293 EXPECT_EQ(OK, callback.WaitForResult()); |
294 } | 294 } |
295 | 295 |
296 void SendRequestAndExpectHttpResponse(const std::string& expected) { | 296 void SendRequestAndExpectHttpResponse(const std::string& expected) { |
297 scoped_ptr<HttpNetworkTransaction> trans( | 297 scoped_ptr<HttpNetworkTransaction> trans( |
298 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 298 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
299 RunTransaction(trans.get()); | 299 RunTransaction(trans); |
300 CheckWasHttpResponse(trans); | 300 CheckWasHttpResponse(trans); |
301 CheckResponseData(trans.get(), expected); | 301 CheckResponseData(trans, expected); |
302 } | 302 } |
303 | 303 |
304 void SendRequestAndExpectQuicResponse(const std::string& expected) { | 304 void SendRequestAndExpectQuicResponse(const std::string& expected) { |
305 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, 80); | 305 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, 80); |
306 } | 306 } |
307 | 307 |
308 void SendRequestAndExpectQuicResponseOnPort(const std::string& expected, | 308 void SendRequestAndExpectQuicResponseOnPort(const std::string& expected, |
309 uint16 port) { | 309 uint16 port) { |
310 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, port); | 310 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, port); |
311 } | 311 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 void SendRequestAndExpectQuicResponseMaybeFromProxy( | 369 void SendRequestAndExpectQuicResponseMaybeFromProxy( |
370 const std::string& expected, | 370 const std::string& expected, |
371 bool used_proxy, | 371 bool used_proxy, |
372 uint16 port) { | 372 uint16 port) { |
373 scoped_ptr<HttpNetworkTransaction> trans( | 373 scoped_ptr<HttpNetworkTransaction> trans( |
374 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 374 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
375 ProxyHeadersHandler proxy_headers_handler; | 375 ProxyHeadersHandler proxy_headers_handler; |
376 trans->SetBeforeProxyHeadersSentCallback( | 376 trans->SetBeforeProxyHeadersSentCallback( |
377 base::Bind(&ProxyHeadersHandler::OnBeforeProxyHeadersSent, | 377 base::Bind(&ProxyHeadersHandler::OnBeforeProxyHeadersSent, |
378 base::Unretained(&proxy_headers_handler))); | 378 base::Unretained(&proxy_headers_handler))); |
379 RunTransaction(trans.get()); | 379 RunTransaction(trans); |
380 CheckWasQuicResponse(trans); | 380 CheckWasQuicResponse(trans); |
381 CheckResponsePort(trans, port); | 381 CheckResponsePort(trans, port); |
382 CheckResponseData(trans.get(), expected); | 382 CheckResponseData(trans, expected); |
383 EXPECT_EQ(used_proxy, proxy_headers_handler.was_called()); | 383 EXPECT_EQ(used_proxy, proxy_headers_handler.was_called()); |
384 } | 384 } |
385 }; | 385 }; |
386 | 386 |
387 INSTANTIATE_TEST_CASE_P(Version, QuicNetworkTransactionTest, | 387 INSTANTIATE_TEST_CASE_P(Version, QuicNetworkTransactionTest, |
388 ::testing::ValuesIn(QuicSupportedVersions())); | 388 ::testing::ValuesIn(QuicSupportedVersions())); |
389 | 389 |
390 TEST_P(QuicNetworkTransactionTest, ForceQuic) { | 390 TEST_P(QuicNetworkTransactionTest, ForceQuic) { |
391 params_.origin_to_force_quic_on = | 391 params_.origin_to_force_quic_on = |
392 HostPortPair::FromString("www.google.com:80"); | 392 HostPortPair::FromString("www.google.com:80"); |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 | 1251 |
1252 request_.url = GURL("https://www.google.com:443"); | 1252 request_.url = GURL("https://www.google.com:443"); |
1253 AddHangingNonAlternateProtocolSocketData(); | 1253 AddHangingNonAlternateProtocolSocketData(); |
1254 CreateSessionWithNextProtos(); | 1254 CreateSessionWithNextProtos(); |
1255 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); | 1255 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
1256 SendRequestAndExpectQuicResponse("hello!"); | 1256 SendRequestAndExpectQuicResponse("hello!"); |
1257 } | 1257 } |
1258 | 1258 |
1259 } // namespace test | 1259 } // namespace test |
1260 } // namespace net | 1260 } // namespace net |
OLD | NEW |