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

Side by Side Diff: net/url_request/url_request_unittest.h

Issue 118100: Avoid doing concurrent DNS resolves of the same hostname (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Get compiling on mac 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
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 #ifndef NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ 5 #ifndef NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_
6 #define NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ 6 #define NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include <sstream> 10 #include <sstream>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/process_util.h" 19 #include "base/process_util.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/thread.h" 21 #include "base/thread.h"
22 #include "base/time.h" 22 #include "base/time.h"
23 #include "base/waitable_event.h" 23 #include "base/waitable_event.h"
24 #include "net/base/host_resolver.h"
24 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
25 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
26 #include "net/base/ssl_test_util.h" 27 #include "net/base/ssl_test_util.h"
27 #include "net/http/http_network_layer.h" 28 #include "net/http/http_network_layer.h"
28 #include "net/url_request/url_request.h" 29 #include "net/url_request/url_request.h"
29 #include "net/url_request/url_request_context.h" 30 #include "net/url_request/url_request_context.h"
30 #include "net/proxy/proxy_service.h" 31 #include "net/proxy/proxy_service.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 #include "googleurl/src/url_util.h" 33 #include "googleurl/src/url_util.h"
33 34
34 const int kHTTPDefaultPort = 1337; 35 const int kHTTPDefaultPort = 1337;
35 const int kFTPDefaultPort = 1338; 36 const int kFTPDefaultPort = 1338;
36 37
37 const std::string kDefaultHostName("localhost"); 38 const std::string kDefaultHostName("localhost");
38 39
39 using base::TimeDelta; 40 using base::TimeDelta;
40 41
41 // This URLRequestContext does not use a local cache. 42 // This URLRequestContext does not use a local cache.
42 class TestURLRequestContext : public URLRequestContext { 43 class TestURLRequestContext : public URLRequestContext {
43 public: 44 public:
44 TestURLRequestContext() { 45 TestURLRequestContext() {
46 host_resolver_ = new net::HostResolver;
45 proxy_service_ = net::ProxyService::CreateNull(); 47 proxy_service_ = net::ProxyService::CreateNull();
46 http_transaction_factory_ = 48 http_transaction_factory_ =
47 net::HttpNetworkLayer::CreateFactory(proxy_service_); 49 net::HttpNetworkLayer::CreateFactory(host_resolver_,
50 proxy_service_);
48 } 51 }
49 52
50 explicit TestURLRequestContext(const std::string& proxy) { 53 explicit TestURLRequestContext(const std::string& proxy) {
54 host_resolver_ = new net::HostResolver;
51 net::ProxyConfig proxy_config; 55 net::ProxyConfig proxy_config;
52 proxy_config.proxy_rules.ParseFromString(proxy); 56 proxy_config.proxy_rules.ParseFromString(proxy);
53 proxy_service_ = net::ProxyService::CreateFixed(proxy_config); 57 proxy_service_ = net::ProxyService::CreateFixed(proxy_config);
54 http_transaction_factory_ = 58 http_transaction_factory_ =
55 net::HttpNetworkLayer::CreateFactory(proxy_service_); 59 net::HttpNetworkLayer::CreateFactory(host_resolver_,
60 proxy_service_);
56 } 61 }
57 62
58 virtual ~TestURLRequestContext() { 63 virtual ~TestURLRequestContext() {
59 delete http_transaction_factory_; 64 delete http_transaction_factory_;
60 delete proxy_service_; 65 delete proxy_service_;
66 delete host_resolver_;
61 } 67 }
62 }; 68 };
63 69
64 class TestDelegate : public URLRequest::Delegate { 70 class TestDelegate : public URLRequest::Delegate {
65 public: 71 public:
66 TestDelegate() 72 TestDelegate()
67 : cancel_in_rr_(false), 73 : cancel_in_rr_(false),
68 cancel_in_rs_(false), 74 cancel_in_rs_(false),
69 cancel_in_rd_(false), 75 cancel_in_rd_(false),
70 cancel_in_rd_pending_(false), 76 cancel_in_rd_pending_(false),
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 550
545 MessageLoop::current()->Run(); 551 MessageLoop::current()->Run();
546 if (request.is_pending()) 552 if (request.is_pending())
547 return false; 553 return false;
548 554
549 return true; 555 return true;
550 } 556 }
551 }; 557 };
552 558
553 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ 559 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698