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

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

Issue 1151843002: DO NOT LAND Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More. 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
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "net/spdy/spdy_test_util_common.h" 73 #include "net/spdy/spdy_test_util_common.h"
74 #include "net/ssl/ssl_cert_request_info.h" 74 #include "net/ssl/ssl_cert_request_info.h"
75 #include "net/ssl/ssl_config_service.h" 75 #include "net/ssl/ssl_config_service.h"
76 #include "net/ssl/ssl_config_service_defaults.h" 76 #include "net/ssl/ssl_config_service_defaults.h"
77 #include "net/ssl/ssl_info.h" 77 #include "net/ssl/ssl_info.h"
78 #include "net/test/cert_test_util.h" 78 #include "net/test/cert_test_util.h"
79 #include "net/websockets/websocket_handshake_stream_base.h" 79 #include "net/websockets/websocket_handshake_stream_base.h"
80 #include "testing/gtest/include/gtest/gtest.h" 80 #include "testing/gtest/include/gtest/gtest.h"
81 #include "testing/platform_test.h" 81 #include "testing/platform_test.h"
82 #include "url/gurl.h" 82 #include "url/gurl.h"
83 #include "url/origin.h"
83 84
84 using base::ASCIIToUTF16; 85 using base::ASCIIToUTF16;
85 86
86 //----------------------------------------------------------------------------- 87 //-----------------------------------------------------------------------------
87 88
88 namespace net { 89 namespace net {
89 90
90 namespace { 91 namespace {
91 92
92 const base::string16 kBar(ASCIIToUTF16("bar")); 93 const base::string16 kBar(ASCIIToUTF16("bar"));
(...skipping 9993 matching lines...) Expand 10 before | Expand all | Expand 10 after
10086 HttpAuthHandlerMock::Factory* auth_factory( 10087 HttpAuthHandlerMock::Factory* auth_factory(
10087 new HttpAuthHandlerMock::Factory()); 10088 new HttpAuthHandlerMock::Factory());
10088 session_deps_.http_auth_handler_factory.reset(auth_factory); 10089 session_deps_.http_auth_handler_factory.reset(auth_factory);
10089 const TestConfig& test_config = test_configs[i]; 10090 const TestConfig& test_config = test_configs[i];
10090 10091
10091 // Set up authentication handlers as necessary. 10092 // Set up authentication handlers as necessary.
10092 if (test_config.proxy_auth_timing != AUTH_NONE) { 10093 if (test_config.proxy_auth_timing != AUTH_NONE) {
10093 for (int n = 0; n < 2; n++) { 10094 for (int n = 0; n < 2; n++) {
10094 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); 10095 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
10095 std::string auth_challenge = "Mock realm=proxy"; 10096 std::string auth_challenge = "Mock realm=proxy";
10096 GURL origin(test_config.proxy_url); 10097 url::Origin origin(test_config.proxy_url);
10097 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), 10098 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
10098 auth_challenge.end()); 10099 auth_challenge.end());
10099 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, 10100 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY,
10100 origin, BoundNetLog()); 10101 origin, BoundNetLog());
10101 auth_handler->SetGenerateExpectation( 10102 auth_handler->SetGenerateExpectation(
10102 test_config.proxy_auth_timing == AUTH_ASYNC, 10103 test_config.proxy_auth_timing == AUTH_ASYNC,
10103 test_config.proxy_auth_rv); 10104 test_config.proxy_auth_rv);
10104 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); 10105 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
10105 } 10106 }
10106 } 10107 }
10107 if (test_config.server_auth_timing != AUTH_NONE) { 10108 if (test_config.server_auth_timing != AUTH_NONE) {
10108 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); 10109 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
10109 std::string auth_challenge = "Mock realm=server"; 10110 std::string auth_challenge = "Mock realm=server";
10110 GURL origin(test_config.server_url); 10111 url::Origin origin(test_config.server_url);
10111 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), 10112 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
10112 auth_challenge.end()); 10113 auth_challenge.end());
10113 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, 10114 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
10114 origin, BoundNetLog()); 10115 origin, BoundNetLog());
10115 auth_handler->SetGenerateExpectation( 10116 auth_handler->SetGenerateExpectation(
10116 test_config.server_auth_timing == AUTH_ASYNC, 10117 test_config.server_auth_timing == AUTH_ASYNC,
10117 test_config.server_auth_rv); 10118 test_config.server_auth_rv);
10118 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); 10119 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
10119 } 10120 }
10120 if (test_config.proxy_url) { 10121 if (test_config.proxy_url) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
10194 HttpAuthHandlerMock::Factory* auth_factory( 10195 HttpAuthHandlerMock::Factory* auth_factory(
10195 new HttpAuthHandlerMock::Factory()); 10196 new HttpAuthHandlerMock::Factory());
10196 session_deps_.http_auth_handler_factory.reset(auth_factory); 10197 session_deps_.http_auth_handler_factory.reset(auth_factory);
10197 session_deps_.proxy_service.reset(ProxyService::CreateDirect()); 10198 session_deps_.proxy_service.reset(ProxyService::CreateDirect());
10198 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); 10199 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1");
10199 session_deps_.host_resolver->set_synchronous_mode(true); 10200 session_deps_.host_resolver->set_synchronous_mode(true);
10200 10201
10201 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); 10202 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
10202 auth_handler->set_connection_based(true); 10203 auth_handler->set_connection_based(true);
10203 std::string auth_challenge = "Mock realm=server"; 10204 std::string auth_challenge = "Mock realm=server";
10204 GURL origin("http://www.example.com"); 10205 url::Origin origin("http://www.example.com");
10205 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), 10206 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
10206 auth_challenge.end()); 10207 auth_challenge.end());
10207 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, 10208 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
10208 origin, BoundNetLog()); 10209 origin, BoundNetLog());
10209 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); 10210 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
10210 10211
10211 int rv = OK; 10212 int rv = OK;
10212 const HttpResponseInfo* response = NULL; 10213 const HttpResponseInfo* response = NULL;
10213 HttpRequestInfo request; 10214 HttpRequestInfo request;
10214 request.method = "GET"; 10215 request.method = "GET";
10215 request.url = origin; 10216 request.url = GURL(origin.string());
10216 request.load_flags = 0; 10217 request.load_flags = 0;
10217 10218
10218 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 10219 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
10219 10220
10220 // Use a TCP Socket Pool with only one connection per group. This is used 10221 // Use a TCP Socket Pool with only one connection per group. This is used
10221 // to validate that the TCP socket is not released to the pool between 10222 // to validate that the TCP socket is not released to the pool between
10222 // each round of multi-round authentication. 10223 // each round of multi-round authentication.
10223 HttpNetworkSessionPeer session_peer(session); 10224 HttpNetworkSessionPeer session_peer(session);
10224 TransportClientSocketPool* transport_pool = new TransportClientSocketPool( 10225 TransportClientSocketPool* transport_pool = new TransportClientSocketPool(
10225 50, // Max sockets for pool 10226 50, // Max sockets for pool
(...skipping 3985 matching lines...) Expand 10 before | Expand all | Expand 10 after
14211 MockRead("Upgrade: websocket\r\n"), 14212 MockRead("Upgrade: websocket\r\n"),
14212 MockRead("Connection: Upgrade\r\n"), 14213 MockRead("Connection: Upgrade\r\n"),
14213 MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), 14214 MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"),
14214 }; 14215 };
14215 14216
14216 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, 14217 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
14217 arraysize(data_writes)); 14218 arraysize(data_writes));
14218 session_deps_.socket_factory->AddSocketDataProvider(&data); 14219 session_deps_.socket_factory->AddSocketDataProvider(&data);
14219 14220
14220 session->http_auth_cache()->Add( 14221 session->http_auth_cache()->Add(
14221 GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, 14222 url::Origin("http://myproxy:70"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC,
14222 "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); 14223 "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/");
14223 14224
14224 scoped_ptr<HttpTransaction> trans( 14225 scoped_ptr<HttpTransaction> trans(
14225 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 14226 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
14226 FakeWebSocketStreamCreateHelper websocket_stream_create_helper; 14227 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
14227 trans->SetWebSocketHandshakeStreamCreateHelper( 14228 trans->SetWebSocketHandshakeStreamCreateHelper(
14228 &websocket_stream_create_helper); 14229 &websocket_stream_create_helper);
14229 14230
14230 TestCompletionCallback callback; 14231 TestCompletionCallback callback;
14231 14232
14232 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 14233 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
14233 EXPECT_EQ(ERR_IO_PENDING, rv); 14234 EXPECT_EQ(ERR_IO_PENDING, rv);
14234 14235
14235 rv = callback.WaitForResult(); 14236 rv = callback.WaitForResult();
14236 EXPECT_EQ(OK, rv); 14237 EXPECT_EQ(OK, rv);
14237 14238
14238 const HttpResponseInfo* response = trans->GetResponseInfo(); 14239 const HttpResponseInfo* response = trans->GetResponseInfo();
14239 ASSERT_TRUE(response); 14240 ASSERT_TRUE(response);
14240 ASSERT_TRUE(response->headers.get()); 14241 ASSERT_TRUE(response->headers.get());
14241 14242
14242 EXPECT_EQ(101, response->headers->response_code()); 14243 EXPECT_EQ(101, response->headers->response_code());
14243 14244
14244 trans.reset(); 14245 trans.reset();
14245 session->CloseAllConnections(); 14246 session->CloseAllConnections();
14246 } 14247 }
14247 14248
14248 } // namespace net 14249 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698