OLD | NEW |
---|---|
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 |
26 const FilePath::CharType kDocRoot[] = | 31 const FilePath::CharType kDocRoot[] = |
27 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); | 32 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); |
28 | 33 |
29 struct FetchResult { | 34 struct FetchResult { |
30 int code; | 35 int code; |
31 string16 text; | 36 string16 text; |
32 }; | 37 }; |
33 | 38 |
34 // A non-mock URL request which can access http:// and file:// urls. | 39 // A non-mock URL request which can access http:// and file:// urls. |
35 class RequestContext : public net::URLRequestContext { | 40 class RequestContext : public URLRequestContext { |
36 public: | 41 public: |
37 RequestContext() { | 42 RequestContext() { |
38 net::ProxyConfig no_proxy; | 43 ProxyConfig no_proxy; |
39 host_resolver_ = | 44 host_resolver_ = |
40 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, | 45 CreateSystemHostResolver(HostResolver::kDefaultParallelism, |
41 NULL, NULL); | 46 NULL, NULL); |
42 cert_verifier_ = new net::CertVerifier; | 47 cert_verifier_ = new CertVerifier; |
43 proxy_service_ = net::ProxyService::CreateFixed(no_proxy); | 48 proxy_service_ = ProxyService::CreateFixed(no_proxy); |
44 ssl_config_service_ = new net::SSLConfigServiceDefaults; | 49 ssl_config_service_ = new SSLConfigServiceDefaults; |
45 | 50 |
46 http_transaction_factory_ = new net::HttpCache( | 51 scoped_refptr<HttpNetworkSession> network_session( |
47 net::HttpNetworkLayer::CreateFactory(host_resolver_, cert_verifier_, | 52 new HttpNetworkSession( |
48 NULL, NULL, NULL, proxy_service_, ssl_config_service_, NULL, NULL, | 53 host_resolver_, |
49 NULL), | 54 cert_verifier_, |
50 NULL, | 55 NULL /* dnsrr_resolver */, |
51 net::HttpCache::DefaultBackend::InMemory(0)); | 56 NULL /* dns_cert_checker */, |
57 NULL /* ssl_host_info_factory */, | |
58 proxy_service_, | |
59 ClientSocketFactory::GetDefaultFactory(), | |
60 ssl_config_service_, | |
61 new SpdySessionPool(NULL), | |
62 NULL, | |
63 NULL, | |
64 NULL)); | |
65 http_transaction_factory_ = new HttpCache( | |
66 network_session, | |
67 HttpCache::DefaultBackend::InMemory(0)); | |
52 } | 68 } |
53 | 69 |
54 private: | 70 private: |
55 ~RequestContext() { | 71 ~RequestContext() { |
56 delete http_transaction_factory_; | 72 delete http_transaction_factory_; |
57 delete cert_verifier_; | 73 delete cert_verifier_; |
58 delete host_resolver_; | 74 delete host_resolver_; |
59 } | 75 } |
60 }; | 76 }; |
wtc
2011/01/28 01:51:23
Should we put lines 31-76 in an unnamed namespace,
| |
61 | 77 |
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. | 78 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest. |
66 GURL GetTestFileUrl(const std::string& relpath) { | 79 GURL GetTestFileUrl(const std::string& relpath) { |
67 FilePath path; | 80 FilePath path; |
68 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 81 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
69 path = path.AppendASCII("net"); | 82 path = path.AppendASCII("net"); |
70 path = path.AppendASCII("data"); | 83 path = path.AppendASCII("data"); |
71 path = path.AppendASCII("proxy_script_fetcher_unittest"); | 84 path = path.AppendASCII("proxy_script_fetcher_unittest"); |
72 GURL base_url = FilePathToFileURL(path); | 85 GURL base_url = FilePathToFileURL(path); |
73 return GURL(base_url.spec() + "/" + relpath); | 86 return GURL(base_url.spec() + "/" + relpath); |
74 } | 87 } |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 string16 text; | 339 string16 text; |
327 TestCompletionCallback callback; | 340 TestCompletionCallback callback; |
328 int result = pac_fetcher.Fetch(url, &text, &callback); | 341 int result = pac_fetcher.Fetch(url, &text, &callback); |
329 EXPECT_EQ(ERR_IO_PENDING, result); | 342 EXPECT_EQ(ERR_IO_PENDING, result); |
330 EXPECT_EQ(OK, callback.WaitForResult()); | 343 EXPECT_EQ(OK, callback.WaitForResult()); |
331 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); | 344 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); |
332 } | 345 } |
333 } | 346 } |
334 | 347 |
335 } // namespace net | 348 } // namespace net |
OLD | NEW |