Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1345)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 1136753002: Test alternate Job failing but request succeeding. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re: #3. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12000 matching lines...) Expand 10 before | Expand all | Expand 10 after
12011 request.url = GURL("https://origin.example.org:443"); 12011 request.url = GURL("https://origin.example.org:443");
12012 request.load_flags = 0; 12012 request.load_flags = 0;
12013 TestCompletionCallback callback; 12013 TestCompletionCallback callback;
12014 12014
12015 // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is 12015 // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is
12016 // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. 12016 // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED.
12017 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 12017 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12018 EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); 12018 EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv));
12019 } 12019 }
12020 12020
12021 // A request to a server with an alternative service fires two Jobs: one to the
12022 // origin, and an alternate one to the alternative server. If the former
12023 // succeeds, the request should succeed, even if the latter fails because
12024 // HTTP/1.1 is negotiated which is insufficient for alternative service.
12025 TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) {
12026 HostPortPair origin("origin.example.org", 443);
12027 HostPortPair alternative("alternative.example.org", 443);
12028
12029 // Negotiate HTTP/1.1 with alternative.
12030 SSLSocketDataProvider alternative_ssl(ASYNC, OK);
12031 alternative_ssl.SetNextProto(kProtoHTTP11);
12032 session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl);
12033
12034 // No data should be read from the alternative, because HTTP/1.1 is
12035 // negotiated.
12036 StaticSocketDataProvider data;
12037 session_deps_.socket_factory->AddSocketDataProvider(&data);
12038
12039 // Negotiate HTTP/1.1 with origin.
12040 SSLSocketDataProvider origin_ssl(ASYNC, OK);
12041 origin_ssl.SetNextProto(kProtoHTTP11);
12042 session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl);
12043
12044 MockWrite http_writes[] = {
12045 MockWrite(
12046 "GET / HTTP/1.1\r\n"
12047 "Host: origin.example.org\r\n"
12048 "Connection: keep-alive\r\n\r\n"),
12049 MockWrite(
12050 "GET /second HTTP/1.1\r\n"
12051 "Host: origin.example.org\r\n"
12052 "Connection: keep-alive\r\n\r\n"),
12053 };
12054
12055 MockRead http_reads[] = {
12056 MockRead("HTTP/1.1 200 OK\r\n"),
12057 MockRead("Content-Type: text/html\r\n"),
12058 MockRead("Content-Length: 6\r\n\r\n"),
12059 MockRead("foobar"),
12060 MockRead("HTTP/1.1 200 OK\r\n"),
12061 MockRead("Content-Type: text/html\r\n"),
12062 MockRead("Content-Length: 7\r\n\r\n"),
12063 MockRead("another"),
12064 };
12065 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
12066 http_writes, arraysize(http_writes));
12067 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
12068
12069 // Set up alternative service for origin.
12070 session_deps_.use_alternate_protocols = true;
12071 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12072 base::WeakPtr<HttpServerProperties> http_server_properties =
12073 session->http_server_properties();
12074 AlternativeService alternative_service(
12075 AlternateProtocolFromNextProto(GetParam()), alternative);
12076 http_server_properties->SetAlternativeService(origin, alternative_service,
12077 1.0);
12078
12079 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
12080 HttpRequestInfo request1;
12081 request1.method = "GET";
12082 request1.url = GURL("https://origin.example.org:443");
12083 request1.load_flags = 0;
12084 TestCompletionCallback callback1;
12085
12086 int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog());
12087 rv = callback1.GetResult(rv);
12088 EXPECT_EQ(OK, rv);
12089
12090 const HttpResponseInfo* response1 = trans1.GetResponseInfo();
12091 ASSERT_TRUE(response1 != nullptr);
12092 ASSERT_TRUE(response1->headers.get() != nullptr);
12093 EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine());
12094
12095 std::string response_data1;
12096 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1));
12097 EXPECT_EQ("foobar", response_data1);
12098
12099 // Alternative should be marked as broken, because HTTP/1.1 is not sufficient
12100 // for alternative service.
12101 EXPECT_TRUE(
12102 http_server_properties->IsAlternativeServiceBroken(alternative_service));
12103
12104 // Since |alternative_service| is broken, a second transaction to origin
12105 // should not start an alternate Job. It should pool to existing connection
12106 // to origin.
12107 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
12108 HttpRequestInfo request2;
12109 request2.method = "GET";
12110 request2.url = GURL("https://origin.example.org:443/second");
12111 request2.load_flags = 0;
12112 TestCompletionCallback callback2;
12113
12114 rv = trans2.Start(&request2, callback2.callback(), BoundNetLog());
12115 rv = callback2.GetResult(rv);
12116 EXPECT_EQ(OK, rv);
12117
12118 const HttpResponseInfo* response2 = trans2.GetResponseInfo();
12119 ASSERT_TRUE(response2 != nullptr);
12120 ASSERT_TRUE(response2->headers.get() != nullptr);
12121 EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine());
12122
12123 std::string response_data2;
12124 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2));
12125 EXPECT_EQ("another", response_data2);
12126 }
12127
12021 // Alternative service requires HTTP/2 (or SPDY), but there is already a 12128 // Alternative service requires HTTP/2 (or SPDY), but there is already a
12022 // HTTP/1.1 socket open to the alternative server. That socket should not be 12129 // HTTP/1.1 socket open to the alternative server. That socket should not be
12023 // used. 12130 // used.
12024 TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { 12131 TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) {
12025 HostPortPair origin("origin.example.org", 443); 12132 HostPortPair origin("origin.example.org", 443);
12026 HostPortPair alternative("alternative.example.org", 443); 12133 HostPortPair alternative("alternative.example.org", 443);
12027 std::string origin_url = "https://origin.example.org:443"; 12134 std::string origin_url = "https://origin.example.org:443";
12028 std::string alternative_url = "https://alternative.example.org:443"; 12135 std::string alternative_url = "https://alternative.example.org:443";
12029 12136
12030 // Negotiate HTTP/1.1 with alternative.example.org. 12137 // Negotiate HTTP/1.1 with alternative.example.org.
(...skipping 2141 matching lines...) Expand 10 before | Expand all | Expand 10 after
14172 ASSERT_TRUE(response); 14279 ASSERT_TRUE(response);
14173 ASSERT_TRUE(response->headers.get()); 14280 ASSERT_TRUE(response->headers.get());
14174 14281
14175 EXPECT_EQ(101, response->headers->response_code()); 14282 EXPECT_EQ(101, response->headers->response_code());
14176 14283
14177 trans.reset(); 14284 trans.reset();
14178 session->CloseAllConnections(); 14285 session->CloseAllConnections();
14179 } 14286 }
14180 14287
14181 } // namespace net 14288 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698