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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_network_transaction_unittest.cc
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 9cb8ea905367b8a61b3658c44d02ea9ec179f29c..8d4e7cfb0377ec366c690a17705d66cbedfe8e31 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -9328,6 +9328,75 @@ TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) {
EXPECT_EQ("hello!", response_data);
}
+// A request to a server with an alternative service fires two Jobs: one to the
+// origin, and an alternate one to the alternative server. If the former
+// succeeds but the latter fails, the request should succeed.
+TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) {
+ HostPortPair origin("origin.example.org", 443);
+ HostPortPair alternative("alternative.example.org", 443);
+
+ // Connection to alternative server fails.
+ StaticSocketDataProvider refused_data;
+ 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:/
+ session_deps_.socket_factory->AddSocketDataProvider(&refused_data);
+
+ // Connection to origin server succeeds.
+ SSLSocketDataProvider ssl(ASYNC, OK);
+ ssl.SetNextProto(kProtoHTTP11);
+ session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
+
+ MockWrite http_writes[] = {
+ MockWrite(
+ "GET / HTTP/1.1\r\n"
+ "Host: origin.example.org\r\n"
+ "Connection: keep-alive\r\n\r\n"),
+ };
+
+ MockRead http_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n"),
+ MockRead("Content-Type: text/html\r\n"),
+ MockRead("Content-Length: 6\r\n\r\n"),
+ MockRead("foobar"),
+ };
+ StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
+ http_writes, arraysize(http_writes));
+ session_deps_.socket_factory->AddSocketDataProvider(&http_data);
+
+ // Set up alternative service for origin.
+ session_deps_.use_alternate_protocols = true;
+ scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+ base::WeakPtr<HttpServerProperties> http_server_properties =
+ session->http_server_properties();
+ AlternativeService alternative_service(
+ AlternateProtocolFromNextProto(GetParam()), alternative);
+ http_server_properties->SetAlternativeService(origin, alternative_service,
+ 1.0);
+
+ HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("https://origin.example.org:443");
+ request.load_flags = 0;
+ TestCompletionCallback callback;
+
+ int rv = trans.Start(&request, callback.callback(), BoundNetLog());
+ rv = callback.GetResult(rv);
+ EXPECT_EQ(OK, rv);
+
+ const HttpResponseInfo* response = trans.GetResponseInfo();
+ ASSERT_TRUE(response != nullptr);
+ ASSERT_TRUE(response->headers.get() != nullptr);
+ EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
+
+ std::string response_data;
+ ASSERT_EQ(OK, ReadTransaction(&trans, &response_data));
+ EXPECT_EQ("foobar", response_data);
+
+ // Failure to alternative server should be recorded in HttpServerProperties.
+ EXPECT_TRUE(
+ http_server_properties->IsAlternativeServiceBroken(alternative_service));
+}
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.
+
TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) {
session_deps_.use_alternate_protocols = true;
session_deps_.next_protos = SpdyNextProtos();
« 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