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

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

Issue 501082: Implement delaying resource requests until privacy blacklists are ready. (Closed)
Patch Set: don't get stuck on errors Created 10 years, 11 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
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | net/url_request/url_request_unittest.cc » ('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) 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 #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/cookie_monster.h"
24 #include "net/base/host_resolver.h" 25 #include "net/base/host_resolver.h"
25 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
26 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
27 #include "net/base/net_test_constants.h" 28 #include "net/base/net_test_constants.h"
28 #include "net/base/ssl_config_service_defaults.h" 29 #include "net/base/ssl_config_service_defaults.h"
30 #include "net/disk_cache/disk_cache.h"
31 #include "net/ftp/ftp_network_layer.h"
32 #include "net/http/http_cache.h"
29 #include "net/http/http_network_layer.h" 33 #include "net/http/http_network_layer.h"
30 #include "net/socket/ssl_test_util.h" 34 #include "net/socket/ssl_test_util.h"
31 #include "net/url_request/url_request.h" 35 #include "net/url_request/url_request.h"
32 #include "net/url_request/url_request_context.h" 36 #include "net/url_request/url_request_context.h"
33 #include "net/proxy/proxy_service.h" 37 #include "net/proxy/proxy_service.h"
34 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
35 #include "googleurl/src/url_util.h" 39 #include "googleurl/src/url_util.h"
36 40
37 const int kHTTPDefaultPort = 1337; 41 const int kHTTPDefaultPort = 1337;
38 const int kFTPDefaultPort = 1338; 42 const int kFTPDefaultPort = 1338;
39 43
40 const std::string kDefaultHostName("localhost"); 44 const std::string kDefaultHostName("localhost");
41 45
42 using base::TimeDelta; 46 using base::TimeDelta;
43 47
44 // This URLRequestContext does not use a local cache.
45 class TestURLRequestContext : public URLRequestContext { 48 class TestURLRequestContext : public URLRequestContext {
46 public: 49 public:
47 TestURLRequestContext() { 50 TestURLRequestContext() {
48 host_resolver_ = net::CreateSystemHostResolver(); 51 host_resolver_ = net::CreateSystemHostResolver();
49 proxy_service_ = net::ProxyService::CreateNull(); 52 proxy_service_ = net::ProxyService::CreateNull();
50 ssl_config_service_ = new net::SSLConfigServiceDefaults; 53 Init();
51 http_transaction_factory_ =
52 net::HttpNetworkLayer::CreateFactory(host_resolver_,
53 proxy_service_, ssl_config_service_);
54 } 54 }
55 55
56 explicit TestURLRequestContext(const std::string& proxy) { 56 explicit TestURLRequestContext(const std::string& proxy) {
57 host_resolver_ = net::CreateSystemHostResolver(); 57 host_resolver_ = net::CreateSystemHostResolver();
58 net::ProxyConfig proxy_config; 58 net::ProxyConfig proxy_config;
59 proxy_config.proxy_rules.ParseFromString(proxy); 59 proxy_config.proxy_rules.ParseFromString(proxy);
60 proxy_service_ = net::ProxyService::CreateFixed(proxy_config); 60 proxy_service_ = net::ProxyService::CreateFixed(proxy_config);
61 ssl_config_service_ = new net::SSLConfigServiceDefaults; 61 Init();
62 http_transaction_factory_ =
63 net::HttpNetworkLayer::CreateFactory(host_resolver_,
64 proxy_service_, ssl_config_service_);
65 } 62 }
66 63
67 protected: 64 protected:
68 ~TestURLRequestContext() { 65 virtual ~TestURLRequestContext() {
66 delete ftp_transaction_factory_;
69 delete http_transaction_factory_; 67 delete http_transaction_factory_;
70 } 68 }
69
70 private:
71 void Init() {
72 ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_);
73 ssl_config_service_ = new net::SSLConfigServiceDefaults;
74 http_transaction_factory_ =
75 new net::HttpCache(
76 net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_,
77 ssl_config_service_),
78 disk_cache::CreateInMemoryCacheBackend(0));
79 // In-memory cookie store.
80 cookie_store_ = new net::CookieMonster();
81 accept_language_ = "en-us,fr";
82 accept_charset_ = "iso-8859-1,*,utf-8";
83 }
84 };
85
86 // TODO(phajdan.jr): Migrate callers to the new name and remove the typedef.
87 typedef TestURLRequestContext URLRequestTestContext;
88
89 class TestURLRequest : public URLRequest {
90 public:
91 TestURLRequest(const GURL& url, Delegate* delegate)
92 : URLRequest(url, delegate) {
93 set_context(new TestURLRequestContext());
94 }
71 }; 95 };
72 96
73 class TestDelegate : public URLRequest::Delegate { 97 class TestDelegate : public URLRequest::Delegate {
74 public: 98 public:
75 TestDelegate() 99 TestDelegate()
76 : cancel_in_rr_(false), 100 : cancel_in_rr_(false),
77 cancel_in_rs_(false), 101 cancel_in_rs_(false),
78 cancel_in_rd_(false), 102 cancel_in_rd_(false),
79 cancel_in_rd_pending_(false), 103 cancel_in_rd_pending_(false),
80 quit_on_complete_(true), 104 quit_on_complete_(true),
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 return false; 630 return false;
607 631
608 return true; 632 return true;
609 } 633 }
610 634
611 private: 635 private:
612 ~FTPTestServer() {} 636 ~FTPTestServer() {}
613 }; 637 };
614 638
615 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ 639 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698