Chromium Code Reviews| 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 9310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9321 ASSERT_TRUE(response != NULL); | 9321 ASSERT_TRUE(response != NULL); |
| 9322 ASSERT_TRUE(response->headers.get() != NULL); | 9322 ASSERT_TRUE(response->headers.get() != NULL); |
| 9323 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 9323 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9324 EXPECT_TRUE(response->was_fetched_via_spdy); | 9324 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9325 EXPECT_TRUE(response->was_npn_negotiated); | 9325 EXPECT_TRUE(response->was_npn_negotiated); |
| 9326 | 9326 |
| 9327 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 9327 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9328 EXPECT_EQ("hello!", response_data); | 9328 EXPECT_EQ("hello!", response_data); |
| 9329 } | 9329 } |
| 9330 | 9330 |
| 9331 // A request to a server with an alternative service fires two Jobs: one to the | |
| 9332 // origin, and an alternate one to the alternative server. If the former | |
| 9333 // succeeds but the latter fails, the request should succeed. | |
| 9334 TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { | |
| 9335 HostPortPair origin("origin.example.org", 443); | |
| 9336 HostPortPair alternative("alternative.example.org", 443); | |
| 9337 | |
| 9338 // Connection to alternative server fails. | |
| 9339 StaticSocketDataProvider refused_data; | |
| 9340 refused_data.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); | |
|
Ryan Hamilton
2015/05/08 21:20:26
I was thinking that this would be testing the "don
Bence
2015/05/11 16:11:29
Oh okay. Sorry it wasn't clear to me from https:/
| |
| 9341 session_deps_.socket_factory->AddSocketDataProvider(&refused_data); | |
| 9342 | |
| 9343 // Connection to origin server succeeds. | |
| 9344 SSLSocketDataProvider ssl(ASYNC, OK); | |
| 9345 ssl.SetNextProto(kProtoHTTP11); | |
| 9346 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 9347 | |
| 9348 MockWrite http_writes[] = { | |
| 9349 MockWrite( | |
| 9350 "GET / HTTP/1.1\r\n" | |
| 9351 "Host: origin.example.org\r\n" | |
| 9352 "Connection: keep-alive\r\n\r\n"), | |
| 9353 }; | |
| 9354 | |
| 9355 MockRead http_reads[] = { | |
| 9356 MockRead("HTTP/1.1 200 OK\r\n"), | |
| 9357 MockRead("Content-Type: text/html\r\n"), | |
| 9358 MockRead("Content-Length: 6\r\n\r\n"), | |
| 9359 MockRead("foobar"), | |
| 9360 }; | |
| 9361 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | |
| 9362 http_writes, arraysize(http_writes)); | |
| 9363 session_deps_.socket_factory->AddSocketDataProvider(&http_data); | |
| 9364 | |
| 9365 // Set up alternative service for origin. | |
| 9366 session_deps_.use_alternate_protocols = true; | |
| 9367 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
| 9368 base::WeakPtr<HttpServerProperties> http_server_properties = | |
| 9369 session->http_server_properties(); | |
| 9370 AlternativeService alternative_service( | |
| 9371 AlternateProtocolFromNextProto(GetParam()), alternative); | |
| 9372 http_server_properties->SetAlternativeService(origin, alternative_service, | |
| 9373 1.0); | |
| 9374 | |
| 9375 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | |
| 9376 HttpRequestInfo request; | |
| 9377 request.method = "GET"; | |
| 9378 request.url = GURL("https://origin.example.org:443"); | |
| 9379 request.load_flags = 0; | |
| 9380 TestCompletionCallback callback; | |
| 9381 | |
| 9382 int rv = trans.Start(&request, callback.callback(), BoundNetLog()); | |
| 9383 rv = callback.GetResult(rv); | |
| 9384 EXPECT_EQ(OK, rv); | |
| 9385 | |
| 9386 const HttpResponseInfo* response = trans.GetResponseInfo(); | |
| 9387 ASSERT_TRUE(response != nullptr); | |
| 9388 ASSERT_TRUE(response->headers.get() != nullptr); | |
| 9389 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
| 9390 | |
| 9391 std::string response_data; | |
| 9392 ASSERT_EQ(OK, ReadTransaction(&trans, &response_data)); | |
| 9393 EXPECT_EQ("foobar", response_data); | |
| 9394 | |
| 9395 // Failure to alternative server should be recorded in HttpServerProperties. | |
| 9396 EXPECT_TRUE( | |
| 9397 http_server_properties->IsAlternativeServiceBroken(alternative_service)); | |
| 9398 } | |
|
Ryan Hamilton
2015/05/08 21:20:26
Looks great. Can you add a second transaction and
Bence
2015/05/11 16:11:29
Done.
| |
| 9399 | |
| 9331 TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { | 9400 TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
| 9332 session_deps_.use_alternate_protocols = true; | 9401 session_deps_.use_alternate_protocols = true; |
| 9333 session_deps_.next_protos = SpdyNextProtos(); | 9402 session_deps_.next_protos = SpdyNextProtos(); |
| 9334 | 9403 |
| 9335 HttpRequestInfo request; | 9404 HttpRequestInfo request; |
| 9336 request.method = "GET"; | 9405 request.method = "GET"; |
| 9337 request.url = GURL("http://www.example.org/"); | 9406 request.url = GURL("http://www.example.org/"); |
| 9338 request.load_flags = 0; | 9407 request.load_flags = 0; |
| 9339 | 9408 |
| 9340 std::string alternate_protocol_http_header = | 9409 std::string alternate_protocol_http_header = |
| (...skipping 4665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14006 ASSERT_TRUE(response); | 14075 ASSERT_TRUE(response); |
| 14007 ASSERT_TRUE(response->headers.get()); | 14076 ASSERT_TRUE(response->headers.get()); |
| 14008 | 14077 |
| 14009 EXPECT_EQ(101, response->headers->response_code()); | 14078 EXPECT_EQ(101, response->headers->response_code()); |
| 14010 | 14079 |
| 14011 trans.reset(); | 14080 trans.reset(); |
| 14012 session->CloseAllConnections(); | 14081 session->CloseAllConnections(); |
| 14013 } | 14082 } |
| 14014 | 14083 |
| 14015 } // namespace net | 14084 } // namespace net |
| OLD | NEW |