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

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

Issue 113811: Adding socks4 support for chromium. tested for windows and linux.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: final patch Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/net.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <math.h> // ceil 5 #include <math.h> // ceil
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "net/base/completion_callback.h" 8 #include "net/base/completion_callback.h"
9 #include "net/base/host_resolver_unittest.h" 9 #include "net/base/host_resolver_unittest.h"
10 #include "net/base/ssl_info.h" 10 #include "net/base/ssl_info.h"
(...skipping 2988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2999 2999
3000 TestCompletionCallback callback; 3000 TestCompletionCallback callback;
3001 3001
3002 int rv = trans->Start(&request, &callback); 3002 int rv = trans->Start(&request, &callback);
3003 EXPECT_EQ(ERR_IO_PENDING, rv); 3003 EXPECT_EQ(ERR_IO_PENDING, rv);
3004 3004
3005 rv = callback.WaitForResult(); 3005 rv = callback.WaitForResult();
3006 EXPECT_EQ(OK, rv); 3006 EXPECT_EQ(OK, rv);
3007 } 3007 }
3008 3008
3009 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) {
3010 SessionDependencies session_deps;
3011 session_deps.proxy_service.reset(CreateFixedProxyService(
3012 "socks4://myproxy:1080"));
3013
3014 scoped_ptr<HttpTransaction> trans(
3015 new HttpNetworkTransaction(
3016 CreateSession(&session_deps),
3017 &session_deps.socket_factory));
3018
3019 HttpRequestInfo request;
3020 request.method = "GET";
3021 request.url = GURL("http://www.google.com/");
3022 request.load_flags = 0;
3023
3024 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
3025 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
3026
3027 MockWrite data_writes[] = {
3028 MockWrite(true, write_buffer, 9),
3029 MockWrite("GET / HTTP/1.1\r\n"
3030 "Host: www.google.com\r\n"
3031 "Connection: keep-alive\r\n\r\n")
3032 };
3033
3034 MockRead data_reads[] = {
3035 MockWrite(true, read_buffer, 8),
3036 MockRead("HTTP/1.0 200 OK\r\n"),
3037 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
3038 MockRead("Payload"),
3039 MockRead(false, OK)
3040 };
3041
3042 StaticMockSocket data(data_reads, data_writes);
3043 session_deps.socket_factory.AddMockSocket(&data);
3044
3045 TestCompletionCallback callback;
3046
3047 int rv = trans->Start(&request, &callback);
3048 EXPECT_EQ(ERR_IO_PENDING, rv);
3049
3050 rv = callback.WaitForResult();
3051 EXPECT_EQ(OK, rv);
3052
3053 const HttpResponseInfo* response = trans->GetResponseInfo();
3054 EXPECT_FALSE(response == NULL);
3055
3056 std::string response_text;
3057 rv = ReadTransaction(trans.get(), &response_text);
3058 EXPECT_EQ(OK, rv);
3059 EXPECT_EQ("Payload", response_text);
3060 }
3061
3062 TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) {
3063 SessionDependencies session_deps;
3064 session_deps.proxy_service.reset(CreateFixedProxyService(
3065 "socks4://myproxy:1080"));
3066
3067 scoped_ptr<HttpTransaction> trans(
3068 new HttpNetworkTransaction(
3069 CreateSession(&session_deps),
3070 &session_deps.socket_factory));
3071
3072 HttpRequestInfo request;
3073 request.method = "GET";
3074 request.url = GURL("https://www.google.com/");
3075 request.load_flags = 0;
3076
3077 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 };
3078 unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
3079
3080 MockWrite data_writes[] = {
3081 MockWrite(true, reinterpret_cast<char*>(write_buffer), 9),
3082 MockWrite("GET / HTTP/1.1\r\n"
3083 "Host: www.google.com\r\n"
3084 "Connection: keep-alive\r\n\r\n")
3085 };
3086
3087 MockRead data_reads[] = {
3088 MockWrite(true, reinterpret_cast<char*>(read_buffer), 8),
3089 MockRead("HTTP/1.0 200 OK\r\n"),
3090 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
3091 MockRead("Payload"),
3092 MockRead(false, OK)
3093 };
3094
3095 StaticMockSocket data(data_reads, data_writes);
3096 session_deps.socket_factory.AddMockSocket(&data);
3097
3098 MockSSLSocket ssl(true, OK);
3099 session_deps.socket_factory.AddMockSSLSocket(&ssl);
3100
3101 TestCompletionCallback callback;
3102
3103 int rv = trans->Start(&request, &callback);
3104 EXPECT_EQ(ERR_IO_PENDING, rv);
3105
3106 rv = callback.WaitForResult();
3107 EXPECT_EQ(OK, rv);
3108
3109 const HttpResponseInfo* response = trans->GetResponseInfo();
3110 EXPECT_FALSE(response == NULL);
3111
3112 std::string response_text;
3113 rv = ReadTransaction(trans.get(), &response_text);
3114 EXPECT_EQ(OK, rv);
3115 EXPECT_EQ("Payload", response_text);
3116 }
3117
3009 TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { 3118 TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) {
3010 scoped_refptr<RuleBasedHostMapper> host_mapper(new RuleBasedHostMapper()); 3119 scoped_refptr<RuleBasedHostMapper> host_mapper(new RuleBasedHostMapper());
3011 ScopedHostMapper scoped_host_mapper(host_mapper.get()); 3120 ScopedHostMapper scoped_host_mapper(host_mapper.get());
3012 host_mapper->AddSimulatedFailure("*"); 3121 host_mapper->AddSimulatedFailure("*");
3013 3122
3014 SessionDependencies session_deps( 3123 SessionDependencies session_deps(
3015 CreateFixedProxyService("myproxy:70;foobar:80")); 3124 CreateFixedProxyService("myproxy:70;foobar:80"));
3016 scoped_ptr<HttpTransaction> trans( 3125 scoped_ptr<HttpTransaction> trans(
3017 new HttpNetworkTransaction( 3126 new HttpNetworkTransaction(
3018 CreateSession(&session_deps), 3127 CreateSession(&session_deps),
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3155 rv = trans->Start(&request, &callback); 3264 rv = trans->Start(&request, &callback);
3156 ASSERT_EQ(ERR_IO_PENDING, rv); 3265 ASSERT_EQ(ERR_IO_PENDING, rv);
3157 rv = callback.WaitForResult(); 3266 rv = callback.WaitForResult();
3158 3267
3159 // If we bypassed the cache, we would have gotten a failure while resolving 3268 // If we bypassed the cache, we would have gotten a failure while resolving
3160 // "www.google.com". 3269 // "www.google.com".
3161 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); 3270 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
3162 } 3271 }
3163 3272
3164 } // namespace net 3273 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698