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

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

Issue 160510: Better match IE's proxy settings.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix merge conflict Created 11 years, 4 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/single_threaded_proxy_resolver.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/waitable_event.h" 5 #include "base/waitable_event.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/base/test_completion_callback.h" 8 #include "net/base/test_completion_callback.h"
9 #include "net/proxy/proxy_info.h" 9 #include "net/proxy/proxy_info.h"
10 #include "net/proxy/single_threaded_proxy_resolver.h" 10 #include "net/proxy/single_threaded_proxy_resolver.h"
(...skipping 29 matching lines...) Expand all
40 results->UseNamedProxy(query_url.host()); 40 results->UseNamedProxy(query_url.host());
41 41
42 // Return a success code which represents the request's order. 42 // Return a success code which represents the request's order.
43 return request_count_++; 43 return request_count_++;
44 } 44 }
45 45
46 virtual void CancelRequest(RequestHandle request) { 46 virtual void CancelRequest(RequestHandle request) {
47 NOTREACHED(); 47 NOTREACHED();
48 } 48 }
49 49
50 virtual void SetPacScriptByDataInternal(const std::string& bytes) { 50 virtual int SetPacScript(const GURL& pac_url,
51 const std::string& bytes,
52 CompletionCallback* callback) {
51 CheckIsOnWorkerThread(); 53 CheckIsOnWorkerThread();
52 last_pac_bytes_ = bytes; 54 last_pac_bytes_ = bytes;
55 return OK;
53 } 56 }
54 57
55 const std::string& last_pac_bytes() const { return last_pac_bytes_; } 58 const std::string& last_pac_bytes() const { return last_pac_bytes_; }
56 59
57 void SetResolveLatency(int latency_ms) { 60 void SetResolveLatency(int latency_ms) {
58 resolve_latency_ms_ = latency_ms; 61 resolve_latency_ms_ = latency_ms;
59 } 62 }
60 63
61 private: 64 private:
62 void CheckIsOnWorkerThread() { 65 void CheckIsOnWorkerThread() {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 123
121 TEST(SingleThreadedProxyResolverTest, Basic) { 124 TEST(SingleThreadedProxyResolverTest, Basic) {
122 MockProxyResolver* mock = new MockProxyResolver; 125 MockProxyResolver* mock = new MockProxyResolver;
123 scoped_ptr<SingleThreadedProxyResolver> resolver( 126 scoped_ptr<SingleThreadedProxyResolver> resolver(
124 new SingleThreadedProxyResolver(mock)); 127 new SingleThreadedProxyResolver(mock));
125 128
126 int rv; 129 int rv;
127 130
128 EXPECT_TRUE(resolver->expects_pac_bytes()); 131 EXPECT_TRUE(resolver->expects_pac_bytes());
129 132
130 // Call SetPacScriptByData() -- we will make sure it reaches the sync resolver 133 // Call SetPacScriptByData() -- verify that it reaches the synchronous
131 // later on. 134 // resolver.
132 resolver->SetPacScriptByData("pac script bytes"); 135 TestCompletionCallback set_script_callback;
136 rv = resolver->SetPacScriptByData("pac script bytes", &set_script_callback);
137 EXPECT_EQ(ERR_IO_PENDING, rv);
138 EXPECT_EQ(OK, set_script_callback.WaitForResult());
139 EXPECT_EQ("pac script bytes", mock->last_pac_bytes());
133 140
134 // Start request 0. 141 // Start request 0.
135 TestCompletionCallback callback0; 142 TestCompletionCallback callback0;
136 ProxyInfo results0; 143 ProxyInfo results0;
137 rv = resolver->GetProxyForURL( 144 rv = resolver->GetProxyForURL(
138 GURL("http://request0"), &results0, &callback0, NULL); 145 GURL("http://request0"), &results0, &callback0, NULL);
139 EXPECT_EQ(ERR_IO_PENDING, rv); 146 EXPECT_EQ(ERR_IO_PENDING, rv);
140 147
141 // Wait for request 0 to finish. 148 // Wait for request 0 to finish.
142 rv = callback0.WaitForResult(); 149 rv = callback0.WaitForResult();
143 EXPECT_EQ(0, rv); 150 EXPECT_EQ(0, rv);
144 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); 151 EXPECT_EQ("PROXY request0:80", results0.ToPacString());
145 152
146 // Verify that the data from SetPacScriptByData() reached the resolver.
147 // (Since we waited for the first request to complete, we are guaranteed
148 // that the earlier post completed).
149 EXPECT_EQ("pac script bytes", mock->last_pac_bytes());
150
151 // Start 3 more requests (request1 to request3). 153 // Start 3 more requests (request1 to request3).
152 154
153 TestCompletionCallback callback1; 155 TestCompletionCallback callback1;
154 ProxyInfo results1; 156 ProxyInfo results1;
155 rv = resolver->GetProxyForURL( 157 rv = resolver->GetProxyForURL(
156 GURL("http://request1"), &results1, &callback1, NULL); 158 GURL("http://request1"), &results1, &callback1, NULL);
157 EXPECT_EQ(ERR_IO_PENDING, rv); 159 EXPECT_EQ(ERR_IO_PENDING, rv);
158 160
159 TestCompletionCallback callback2; 161 TestCompletionCallback callback2;
160 ProxyInfo results2; 162 ProxyInfo results2;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 304
303 // Give any posted tasks a chance to run (in case there is badness). 305 // Give any posted tasks a chance to run (in case there is badness).
304 MessageLoop::current()->RunAllPending(); 306 MessageLoop::current()->RunAllPending();
305 307
306 // Check that none of the outstanding requests were completed. 308 // Check that none of the outstanding requests were completed.
307 EXPECT_FALSE(callback0.have_result()); 309 EXPECT_FALSE(callback0.have_result());
308 EXPECT_FALSE(callback1.have_result()); 310 EXPECT_FALSE(callback1.have_result());
309 EXPECT_FALSE(callback2.have_result()); 311 EXPECT_FALSE(callback2.have_result());
310 } 312 }
311 313
314 // Cancel an outstanding call to SetPacScriptByData().
315 TEST(SingleThreadedProxyResolverTest, CancelSetPacScript) {
316 BlockableProxyResolver* mock = new BlockableProxyResolver;
317 scoped_ptr<SingleThreadedProxyResolver> resolver(
318 new SingleThreadedProxyResolver(mock));
319
320 int rv;
321
322 // Block the proxy resolver, so no request can complete.
323 mock->Block();
324
325 // Start request 0.
326 ProxyResolver::RequestHandle request0;
327 TestCompletionCallback callback0;
328 ProxyInfo results0;
329 rv = resolver->GetProxyForURL(
330 GURL("http://request0"), &results0, &callback0, &request0);
331 EXPECT_EQ(ERR_IO_PENDING, rv);
332
333 // Wait until requests 0 reaches the worker thread.
334 mock->WaitUntilBlocked();
335
336 TestCompletionCallback set_pac_script_callback;
337 rv = resolver->SetPacScriptByData("data", &set_pac_script_callback);
338 EXPECT_EQ(ERR_IO_PENDING, rv);
339
340 // Cancel the SetPacScriptByData request (it can't have finished yet,
341 // since the single-thread is currently blocked).
342 resolver->CancelSetPacScript();
343
344 // Start 1 more request.
345
346 TestCompletionCallback callback1;
347 ProxyInfo results1;
348 rv = resolver->GetProxyForURL(
349 GURL("http://request1"), &results1, &callback1, NULL);
350 EXPECT_EQ(ERR_IO_PENDING, rv);
351
352 // Unblock the worker thread so the requests can continue running.
353 mock->Unblock();
354
355 // Wait for requests 0 and 1 to finish.
356
357 rv = callback0.WaitForResult();
358 EXPECT_EQ(0, rv);
359 EXPECT_EQ("PROXY request0:80", results0.ToPacString());
360
361 rv = callback1.WaitForResult();
362 EXPECT_EQ(1, rv);
363 EXPECT_EQ("PROXY request1:80", results1.ToPacString());
364
365 // The SetPacScript callback should never have been completed.
366 EXPECT_FALSE(set_pac_script_callback.have_result());
367 }
368
312 } // namespace 369 } // namespace
313 } // namespace net 370 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/single_threaded_proxy_resolver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698