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

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

Issue 11931024: Removed static factories for data, ftp, file, and about jobs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address erikwright's comments Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/mock_cert_verifier.h" 13 #include "net/base/mock_cert_verifier.h"
14 #include "net/base/mock_host_resolver.h" 14 #include "net/base/mock_host_resolver.h"
15 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
16 #include "net/base/load_flags.h" 16 #include "net/base/load_flags.h"
17 #include "net/base/ssl_config_service_defaults.h" 17 #include "net/base/ssl_config_service_defaults.h"
18 #include "net/base/test_completion_callback.h" 18 #include "net/base/test_completion_callback.h"
19 #include "net/disk_cache/disk_cache.h" 19 #include "net/disk_cache/disk_cache.h"
20 #include "net/http/http_cache.h" 20 #include "net/http/http_cache.h"
21 #include "net/http/http_network_session.h" 21 #include "net/http/http_network_session.h"
22 #include "net/http/http_server_properties_impl.h" 22 #include "net/http/http_server_properties_impl.h"
23 #include "net/test/test_server.h" 23 #include "net/test/test_server.h"
24 #include "net/url_request/file_protocol_handler.h"
24 #include "net/url_request/url_request_context_storage.h" 25 #include "net/url_request/url_request_context_storage.h"
25 #include "net/url_request/url_request_file_job.h" 26 #include "net/url_request/url_request_file_job.h"
26 #include "net/url_request/url_request_job_factory_impl.h" 27 #include "net/url_request/url_request_job_factory_impl.h"
27 #include "net/url_request/url_request_test_util.h" 28 #include "net/url_request/url_request_test_util.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #include "testing/platform_test.h" 30 #include "testing/platform_test.h"
30 31
31 namespace net { 32 namespace net {
32 33
33 // TODO(eroman): 34 // TODO(eroman):
34 // - Test canceling an outstanding request. 35 // - Test canceling an outstanding request.
35 // - Test deleting ProxyScriptFetcher while a request is in progress. 36 // - Test deleting ProxyScriptFetcher while a request is in progress.
36 37
37 namespace { 38 namespace {
38 39
39 const FilePath::CharType kDocRoot[] = 40 const FilePath::CharType kDocRoot[] =
40 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); 41 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest");
41 42
42 struct FetchResult { 43 struct FetchResult {
43 int code; 44 int code;
44 string16 text; 45 string16 text;
45 }; 46 };
46 47
47 // A non-mock URL request which can access http:// and file:// urls. 48 // A non-mock URL request which can access http:// and file:// urls.
mmenke 2013/01/22 16:50:37 This comment is no longer correct. Should either
48 class RequestContext : public URLRequestContext { 49 class RequestContext : public URLRequestContext {
49 public: 50 public:
50 RequestContext() : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { 51 RequestContext() : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) {
51 ProxyConfig no_proxy; 52 ProxyConfig no_proxy;
52 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver)); 53 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver));
53 storage_.set_cert_verifier(new MockCertVerifier); 54 storage_.set_cert_verifier(new MockCertVerifier);
54 storage_.set_proxy_service(ProxyService::CreateFixed(no_proxy)); 55 storage_.set_proxy_service(ProxyService::CreateFixed(no_proxy));
55 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); 56 storage_.set_ssl_config_service(new SSLConfigServiceDefaults);
56 storage_.set_http_server_properties(new HttpServerPropertiesImpl); 57 storage_.set_http_server_properties(new HttpServerPropertiesImpl);
57 58
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 context_.set_network_delegate(&network_delegate_); 189 context_.set_network_delegate(&network_delegate_);
189 } 190 }
190 191
191 protected: 192 protected:
192 TestServer test_server_; 193 TestServer test_server_;
193 BasicNetworkDelegate network_delegate_; 194 BasicNetworkDelegate network_delegate_;
194 RequestContext context_; 195 RequestContext context_;
195 }; 196 };
196 197
197 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { 198 TEST_F(ProxyScriptFetcherImplTest, FileUrl) {
199 URLRequestJobFactoryImpl job_factory;
200 job_factory.SetProtocolHandler("file", new FileProtocolHandler());
201 context_.set_job_factory(&job_factory);
202
198 ProxyScriptFetcherImpl pac_fetcher(&context_); 203 ProxyScriptFetcherImpl pac_fetcher(&context_);
199 204
200 { // Fetch a non-existent file. 205 { // Fetch a non-existent file.
201 string16 text; 206 string16 text;
202 TestCompletionCallback callback; 207 TestCompletionCallback callback;
203 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), 208 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"),
204 &text, callback.callback()); 209 &text, callback.callback());
205 EXPECT_EQ(ERR_IO_PENDING, result); 210 EXPECT_EQ(ERR_IO_PENDING, result);
206 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); 211 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult());
207 EXPECT_TRUE(text.empty()); 212 EXPECT_TRUE(text.empty());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 EXPECT_EQ(ERR_CONNECTION_RESET, callback.WaitForResult()); 336 EXPECT_EQ(ERR_CONNECTION_RESET, callback.WaitForResult());
332 #else 337 #else
333 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); 338 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
334 #endif 339 #endif
335 } 340 }
336 } 341 }
337 342
338 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { 343 TEST_F(ProxyScriptFetcherImplTest, TooLarge) {
339 ASSERT_TRUE(test_server_.Start()); 344 ASSERT_TRUE(test_server_.Start());
340 345
346 URLRequestJobFactoryImpl job_factory;
347 job_factory.SetProtocolHandler("file", new FileProtocolHandler());
348 context_.set_job_factory(&job_factory);
349
341 ProxyScriptFetcherImpl pac_fetcher(&context_); 350 ProxyScriptFetcherImpl pac_fetcher(&context_);
342 351
343 // Set the maximum response size to 50 bytes. 352 // Set the maximum response size to 50 bytes.
344 int prev_size = pac_fetcher.SetSizeConstraint(50); 353 int prev_size = pac_fetcher.SetSizeConstraint(50);
345 354
346 // These two URLs are the same file, but are http:// vs file:// 355 // These two URLs are the same file, but are http:// vs file://
347 GURL urls[] = { 356 GURL urls[] = {
348 test_server_.GetURL("files/large-pac.nsproxy"), 357 test_server_.GetURL("files/large-pac.nsproxy"),
349 GetTestFileUrl("large-pac.nsproxy") 358 GetTestFileUrl("large-pac.nsproxy")
350 }; 359 };
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 { 482 {
474 GURL url(kEncodedUrlBroken); 483 GURL url(kEncodedUrlBroken);
475 string16 text; 484 string16 text;
476 TestCompletionCallback callback; 485 TestCompletionCallback callback;
477 int result = pac_fetcher.Fetch(url, &text, callback.callback()); 486 int result = pac_fetcher.Fetch(url, &text, callback.callback());
478 EXPECT_EQ(ERR_FAILED, result); 487 EXPECT_EQ(ERR_FAILED, result);
479 } 488 }
480 } 489 }
481 490
482 } // namespace net 491 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698