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

Side by Side Diff: net/proxy/proxy_service_unittest.cc

Issue 113482: Adding the ability to alter Chrome's proxy settings via the automation interf... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | 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 (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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "googleurl/src/gurl.h" 6 #include "googleurl/src/gurl.h"
7 #include "net/base/net_errors.h" 7 #include "net/base/net_errors.h"
8 #include "net/proxy/proxy_config_service.h" 8 #include "net/proxy/proxy_config_service.h"
9 #include "net/proxy/proxy_resolver.h" 9 #include "net/proxy/proxy_resolver.h"
10 #include "net/proxy/proxy_script_fetcher.h" 10 #include "net/proxy/proxy_script_fetcher.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 // Start the request. Return once ProxyService::GetProxyForURL() or 132 // Start the request. Return once ProxyService::GetProxyForURL() or
133 // ProxyService::ReconsiderProxyAfterError() returns. 133 // ProxyService::ReconsiderProxyAfterError() returns.
134 void StartRequest(const GURL& url, RequestMethod method) { 134 void StartRequest(const GURL& url, RequestMethod method) {
135 DCHECK(MessageLoop::current() != io_message_loop_); 135 DCHECK(MessageLoop::current() != io_message_loop_);
136 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( 136 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
137 this, &ResultFuture::DoStartRequest, url, method)); 137 this, &ResultFuture::DoStartRequest, url, method));
138 started_.Wait(); 138 started_.Wait();
139 } 139 }
140 140
141 void StartResetConfigService(
142 net::ProxyConfigService* new_proxy_config_service) {
143 DCHECK(MessageLoop::current() != io_message_loop_);
144 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
145 this, &ResultFuture::DoResetConfigService, new_proxy_config_service));
146 started_.Wait();
147 }
148
141 // Called on |io_message_loop_|. 149 // Called on |io_message_loop_|.
142 void DoStartRequest(const GURL& url, RequestMethod method) { 150 void DoStartRequest(const GURL& url, RequestMethod method) {
143 DCHECK(MessageLoop::current() == io_message_loop_); 151 DCHECK(MessageLoop::current() == io_message_loop_);
144 int rv = (service_->*method)(url, &proxy_info_, &callback_, &request_); 152 int rv = (service_->*method)(url, &proxy_info_, &callback_, &request_);
145 if (rv != net::ERR_IO_PENDING) { 153 if (rv != net::ERR_IO_PENDING) {
146 // Completed synchronously. 154 // Completed synchronously.
147 OnCompletion(rv); 155 OnCompletion(rv);
148 } 156 }
149 started_.Signal(); 157 started_.Signal();
150 } 158 }
151 159
152 // Called on |io_message_loop_|. 160 // Called on |io_message_loop_|.
161 void DoResetConfigService(net::ProxyConfigService* new_proxy_config_service) {
162 DCHECK(MessageLoop::current() == io_message_loop_);
163 service_->ResetConfigService(new_proxy_config_service);
164 started_.Signal();
165 OnCompletion(0);
166 }
167
168 // Called on |io_message_loop_|.
153 void DoCancel() { 169 void DoCancel() {
154 DCHECK(MessageLoop::current() == io_message_loop_); 170 DCHECK(MessageLoop::current() == io_message_loop_);
155 if (!did_complete_) 171 if (!did_complete_)
156 service_->CancelPacRequest(request_); 172 service_->CancelPacRequest(request_);
157 cancelled_.Signal(); 173 cancelled_.Signal();
158 } 174 }
159 175
160 // Called on |io_message_loop_|. 176 // Called on |io_message_loop_|.
161 void OnCompletion(int result) { 177 void OnCompletion(int result) {
162 DCHECK(MessageLoop::current() == io_message_loop_); 178 DCHECK(MessageLoop::current() == io_message_loop_);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 239
224 // Same as above, but for "ReconsiderProxyAfterError()". 240 // Same as above, but for "ReconsiderProxyAfterError()".
225 void ReconsiderProxyAfterError(scoped_refptr<ResultFuture>* result, 241 void ReconsiderProxyAfterError(scoped_refptr<ResultFuture>* result,
226 const GURL& url, 242 const GURL& url,
227 const net::ProxyInfo& proxy_info) { 243 const net::ProxyInfo& proxy_info) {
228 *result = new ResultFuture(io_thread_.message_loop(), 244 *result = new ResultFuture(io_thread_.message_loop(),
229 io_thread_state_->service); 245 io_thread_state_->service);
230 (*result)->StartReconsider(url, proxy_info); 246 (*result)->StartReconsider(url, proxy_info);
231 } 247 }
232 248
249 void ResetConfigService(scoped_refptr<ResultFuture>* result,
250 net::ProxyConfigService* new_proxy_config_service) {
251 *result = new ResultFuture(io_thread_.message_loop(),
252 io_thread_state_->service);
253 (*result)->StartResetConfigService(new_proxy_config_service);
254 }
255
233 void SetProxyScriptFetcher(net::ProxyScriptFetcher* proxy_script_fetcher) { 256 void SetProxyScriptFetcher(net::ProxyScriptFetcher* proxy_script_fetcher) {
234 io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 257 io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
235 io_thread_state_.get(), &IOThreadState::DoSetProxyScriptFetcher, 258 io_thread_state_.get(), &IOThreadState::DoSetProxyScriptFetcher,
236 proxy_script_fetcher)); 259 proxy_script_fetcher));
237 io_thread_state_->event.Wait(); 260 io_thread_state_->event.Wait();
238 } 261 }
239 262
240 private: 263 private:
241 // Class that encapsulates the state living on IO thread. It needs to be 264 // Class that encapsulates the state living on IO thread. It needs to be
242 // ref-counted for posting tasks. 265 // ref-counted for posting tasks.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 return result->GetResultCode(); 308 return result->GetResultCode();
286 } 309 }
287 310
288 int ReconsiderProxyAfterError(const GURL& url, net::ProxyInfo* proxy_info) { 311 int ReconsiderProxyAfterError(const GURL& url, net::ProxyInfo* proxy_info) {
289 scoped_refptr<ResultFuture> result; 312 scoped_refptr<ResultFuture> result;
290 service_.ReconsiderProxyAfterError(&result, url, *proxy_info); 313 service_.ReconsiderProxyAfterError(&result, url, *proxy_info);
291 *proxy_info = result->GetProxyInfo(); 314 *proxy_info = result->GetProxyInfo();
292 return result->GetResultCode(); 315 return result->GetResultCode();
293 } 316 }
294 317
318 int ResetConfigService(net::ProxyConfigService* new_proxy_config_service) {
319 scoped_refptr<ResultFuture> result;
320 service_.ResetConfigService(&result, new_proxy_config_service);
321 return result->GetResultCode();
322 }
323
295 private: 324 private:
296 ProxyServiceWithFutures service_; 325 ProxyServiceWithFutures service_;
297 }; 326 };
298 327
299 // A ProxyResolver which can be set to block upon reaching GetProxyForURL. 328 // A ProxyResolver which can be set to block upon reaching GetProxyForURL.
300 class BlockableProxyResolver : public net::ProxyResolver { 329 class BlockableProxyResolver : public net::ProxyResolver {
301 public: 330 public:
302 BlockableProxyResolver() : net::ProxyResolver(true), 331 BlockableProxyResolver() : net::ProxyResolver(true),
303 should_block_(false), 332 should_block_(false),
304 unblocked_(true, true), 333 unblocked_(true, true),
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 result3->WaitUntilCompleted(); 1118 result3->WaitUntilCompleted();
1090 1119
1091 EXPECT_FALSE(result1->IsCompleted()); // Cancelled. 1120 EXPECT_FALSE(result1->IsCompleted()); // Cancelled.
1092 EXPECT_FALSE(result2->IsCompleted()); // Cancelled. 1121 EXPECT_FALSE(result2->IsCompleted()); // Cancelled.
1093 1122
1094 EXPECT_TRUE(result3->IsCompleted()); 1123 EXPECT_TRUE(result3->IsCompleted());
1095 EXPECT_EQ(net::OK, result3->GetResultCode()); 1124 EXPECT_EQ(net::OK, result3->GetResultCode());
1096 EXPECT_EQ("pac-v1.request3:80", 1125 EXPECT_EQ("pac-v1.request3:80",
1097 result3->GetProxyInfo().proxy_server().ToURI()); 1126 result3->GetProxyInfo().proxy_server().ToURI());
1098 } 1127 }
1128
1129 TEST(ProxyServiceTest, ResetProxyConfigService) {
1130 net::ProxyConfig config1;
1131 config1.proxy_rules.ParseFromString("foopy1:8080");
1132 config1.auto_detect = false;
1133 scoped_ptr<SyncProxyService> service(
1134 new SyncProxyService(new MockProxyConfigService(config1),
1135 new MockProxyResolverWithoutFetch));
1136
1137 net::ProxyInfo info;
1138 service->ResolveProxy(GURL("http://request1"), &info);
1139 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1140
1141 net::ProxyConfig config2;
1142 config2.proxy_rules.ParseFromString("foopy2:8080");
1143 config2.auto_detect = false;
1144 int result = service->ResetConfigService(new MockProxyConfigService(config2));
1145 DCHECK(result == 0);
1146 service->ResolveProxy(GURL("http://request2"), &info);
1147 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI());
1148 }
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698