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

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

Issue 6402002: Simplify HttpCache/HttpNetworkLayer/HttpNetworkSession interaction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 9 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_network_layer_unittest.cc ('k') | net/spdy/spdy_test_util.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/proxy/proxy_script_fetcher_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "net/base/ssl_config_service_defaults.h" 14 #include "net/base/ssl_config_service_defaults.h"
15 #include "net/base/test_completion_callback.h" 15 #include "net/base/test_completion_callback.h"
16 #include "net/disk_cache/disk_cache.h" 16 #include "net/disk_cache/disk_cache.h"
17 #include "net/http/http_cache.h" 17 #include "net/http/http_cache.h"
18 #include "net/http/http_network_session.h"
19 #include "net/socket/client_socket_factory.h"
20 #include "net/spdy/spdy_session_pool.h"
18 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
20 #include "testing/platform_test.h" 23 #include "testing/platform_test.h"
21 24
25 namespace net {
26
22 // TODO(eroman): 27 // TODO(eroman):
23 // - Test canceling an outstanding request. 28 // - Test canceling an outstanding request.
24 // - Test deleting ProxyScriptFetcher while a request is in progress. 29 // - Test deleting ProxyScriptFetcher while a request is in progress.
25 30
31 namespace {
32
26 const FilePath::CharType kDocRoot[] = 33 const FilePath::CharType kDocRoot[] =
27 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); 34 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest");
28 35
29 struct FetchResult { 36 struct FetchResult {
30 int code; 37 int code;
31 string16 text; 38 string16 text;
32 }; 39 };
33 40
34 // A non-mock URL request which can access http:// and file:// urls. 41 // A non-mock URL request which can access http:// and file:// urls.
35 class RequestContext : public net::URLRequestContext { 42 class RequestContext : public URLRequestContext {
36 public: 43 public:
37 RequestContext() { 44 RequestContext() {
38 net::ProxyConfig no_proxy; 45 ProxyConfig no_proxy;
39 host_resolver_ = 46 host_resolver_ =
40 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 47 CreateSystemHostResolver(HostResolver::kDefaultParallelism,
41 NULL, NULL); 48 NULL, NULL);
42 cert_verifier_ = new net::CertVerifier; 49 cert_verifier_ = new CertVerifier;
43 proxy_service_ = net::ProxyService::CreateFixed(no_proxy); 50 proxy_service_ = ProxyService::CreateFixed(no_proxy);
44 ssl_config_service_ = new net::SSLConfigServiceDefaults; 51 ssl_config_service_ = new SSLConfigServiceDefaults;
45 52
46 http_transaction_factory_ = new net::HttpCache( 53 scoped_refptr<HttpNetworkSession> network_session(
47 net::HttpNetworkLayer::CreateFactory(host_resolver_, cert_verifier_, 54 new HttpNetworkSession(
48 NULL, NULL, NULL, proxy_service_, ssl_config_service_, NULL, NULL, 55 host_resolver_,
49 NULL), 56 cert_verifier_,
50 NULL, 57 NULL /* dnsrr_resolver */,
51 net::HttpCache::DefaultBackend::InMemory(0)); 58 NULL /* dns_cert_checker */,
59 NULL /* ssl_host_info_factory */,
60 proxy_service_,
61 ClientSocketFactory::GetDefaultFactory(),
62 ssl_config_service_,
63 new SpdySessionPool(NULL),
64 NULL,
65 NULL,
66 NULL));
67 http_transaction_factory_ = new HttpCache(
68 network_session,
69 HttpCache::DefaultBackend::InMemory(0));
52 } 70 }
53 71
54 private: 72 private:
55 ~RequestContext() { 73 ~RequestContext() {
56 delete http_transaction_factory_; 74 delete http_transaction_factory_;
57 delete cert_verifier_; 75 delete cert_verifier_;
58 delete host_resolver_; 76 delete host_resolver_;
59 } 77 }
60 }; 78 };
61 79
62 // Required to be in net namespace by FRIEND_TEST.
63 namespace net {
64
65 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest. 80 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest.
66 GURL GetTestFileUrl(const std::string& relpath) { 81 GURL GetTestFileUrl(const std::string& relpath) {
67 FilePath path; 82 FilePath path;
68 PathService::Get(base::DIR_SOURCE_ROOT, &path); 83 PathService::Get(base::DIR_SOURCE_ROOT, &path);
69 path = path.AppendASCII("net"); 84 path = path.AppendASCII("net");
70 path = path.AppendASCII("data"); 85 path = path.AppendASCII("data");
71 path = path.AppendASCII("proxy_script_fetcher_unittest"); 86 path = path.AppendASCII("proxy_script_fetcher_unittest");
72 GURL base_url = FilePathToFileURL(path); 87 GURL base_url = FilePathToFileURL(path);
73 return GURL(base_url.spec() + "/" + relpath); 88 return GURL(base_url.spec() + "/" + relpath);
74 } 89 }
75 90
91 } // namespace
92
76 class ProxyScriptFetcherImplTest : public PlatformTest { 93 class ProxyScriptFetcherImplTest : public PlatformTest {
77 public: 94 public:
78 ProxyScriptFetcherImplTest() 95 ProxyScriptFetcherImplTest()
79 : test_server_(TestServer::TYPE_HTTP, FilePath(kDocRoot)) { 96 : test_server_(TestServer::TYPE_HTTP, FilePath(kDocRoot)) {
80 } 97 }
81 98
82 static void SetUpTestCase() { 99 static void SetUpTestCase() {
83 URLRequest::AllowFileAccess(); 100 URLRequest::AllowFileAccess();
84 } 101 }
85 102
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 string16 text; 343 string16 text;
327 TestCompletionCallback callback; 344 TestCompletionCallback callback;
328 int result = pac_fetcher.Fetch(url, &text, &callback); 345 int result = pac_fetcher.Fetch(url, &text, &callback);
329 EXPECT_EQ(ERR_IO_PENDING, result); 346 EXPECT_EQ(ERR_IO_PENDING, result);
330 EXPECT_EQ(OK, callback.WaitForResult()); 347 EXPECT_EQ(OK, callback.WaitForResult());
331 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); 348 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text);
332 } 349 }
333 } 350 }
334 351
335 } // namespace net 352 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_layer_unittest.cc ('k') | net/spdy/spdy_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698