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

Side by Side Diff: net/url_request/url_request_ftp_job_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: Add test for IsSafeRedirectTarget Created 7 years, 10 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 "base/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "net/proxy/proxy_config_service.h" 7 #include "net/proxy/proxy_config_service.h"
8 #include "net/socket/socket_test_util.h" 8 #include "net/socket/socket_test_util.h"
9 #include "net/url_request/ftp_protocol_handler.h"
9 #include "net/url_request/url_request.h" 10 #include "net/url_request/url_request.h"
10 #include "net/url_request/url_request_context.h" 11 #include "net/url_request/url_request_context.h"
12 #include "net/url_request/url_request_job_factory_impl.h"
11 #include "net/url_request/url_request_status.h" 13 #include "net/url_request/url_request_status.h"
12 #include "net/url_request/url_request_test_util.h" 14 #include "net/url_request/url_request_test_util.h"
15 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
14 17
15 namespace net { 18 namespace net {
16 19
17 namespace { 20 namespace {
18 21
19 class SimpleProxyConfigService : public ProxyConfigService { 22 class SimpleProxyConfigService : public ProxyConfigService {
20 public: 23 public:
21 SimpleProxyConfigService() { 24 SimpleProxyConfigService() {
22 // Any FTP requests that ever go through HTTP paths are proxied requests. 25 // Any FTP requests that ever go through HTTP paths are proxied requests.
(...skipping 19 matching lines...) Expand all
42 void IncrementConfigId() { 45 void IncrementConfigId() {
43 config_.set_id(config_.id() + 1); 46 config_.set_id(config_.id() + 1);
44 observer_->OnProxyConfigChanged(config_, ProxyConfigService::CONFIG_VALID); 47 observer_->OnProxyConfigChanged(config_, ProxyConfigService::CONFIG_VALID);
45 } 48 }
46 49
47 private: 50 private:
48 ProxyConfig config_; 51 ProxyConfig config_;
49 Observer* observer_; 52 Observer* observer_;
50 }; 53 };
51 54
55 class MockFtpTransactionFactory : public FtpTransactionFactory {
56 public:
57 MOCK_METHOD0(CreateTransaction, FtpTransaction*());
58 MOCK_METHOD1(Suspend, void(bool suspend));
59 };
60
52 class FtpTestURLRequestContext : public TestURLRequestContext { 61 class FtpTestURLRequestContext : public TestURLRequestContext {
53 public: 62 public:
54 FtpTestURLRequestContext(ClientSocketFactory* socket_factory, 63 FtpTestURLRequestContext(ClientSocketFactory* socket_factory,
55 ProxyService* proxy_service, 64 ProxyService* proxy_service,
56 NetworkDelegate* network_delegate) 65 NetworkDelegate* network_delegate,
66 FtpTransactionFactory* ftp_transaction_factory)
57 : TestURLRequestContext(true) { 67 : TestURLRequestContext(true) {
58 set_client_socket_factory(socket_factory); 68 set_client_socket_factory(socket_factory);
59 context_storage_.set_proxy_service(proxy_service); 69 context_storage_.set_proxy_service(proxy_service);
60 set_network_delegate(network_delegate); 70 set_network_delegate(network_delegate);
71 URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl;
72 job_factory->SetProtocolHandler(
73 "ftp", new FtpProtocolHandler(ftp_transaction_factory));
74 context_storage_.set_job_factory(job_factory);
61 Init(); 75 Init();
62 } 76 }
63 }; 77 };
64 78
65 class URLRequestFtpJobTest : public testing::Test { 79 class URLRequestFtpJobTest : public testing::Test {
66 public: 80 public:
67 URLRequestFtpJobTest() 81 URLRequestFtpJobTest()
68 : proxy_service_(new ProxyService( 82 : proxy_service_(new ProxyService(
69 new SimpleProxyConfigService, NULL, NULL)), 83 new SimpleProxyConfigService, NULL, NULL)),
70 request_context_(&socket_factory_, 84 request_context_(&socket_factory_,
71 proxy_service_, 85 proxy_service_,
72 &network_delegate_) { 86 &network_delegate_,
87 &ftp_transaction_factory_) {
73 } 88 }
74 89
75 virtual ~URLRequestFtpJobTest() { 90 virtual ~URLRequestFtpJobTest() {
76 // Clean up any remaining tasks that mess up unrelated tests. 91 // Clean up any remaining tasks that mess up unrelated tests.
77 base::RunLoop run_loop; 92 base::RunLoop run_loop;
78 run_loop.RunUntilIdle(); 93 run_loop.RunUntilIdle();
79 } 94 }
80 95
81 void AddSocket(MockRead* reads, size_t reads_size, 96 void AddSocket(MockRead* reads, size_t reads_size,
82 MockWrite* writes, size_t writes_size) { 97 MockWrite* writes, size_t writes_size) {
83 DeterministicSocketData* socket_data = new DeterministicSocketData( 98 DeterministicSocketData* socket_data = new DeterministicSocketData(
84 reads, reads_size, writes, writes_size); 99 reads, reads_size, writes, writes_size);
85 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); 100 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK));
86 socket_data->StopAfter(reads_size + writes_size - 1); 101 socket_data->StopAfter(reads_size + writes_size - 1);
87 socket_factory_.AddSocketDataProvider(socket_data); 102 socket_factory_.AddSocketDataProvider(socket_data);
88 103
89 socket_data_.push_back(socket_data); 104 socket_data_.push_back(socket_data);
90 } 105 }
91 106
92 URLRequestContext* request_context() { return &request_context_; } 107 URLRequestContext* request_context() { return &request_context_; }
93 TestNetworkDelegate* network_delegate() { return &network_delegate_; } 108 TestNetworkDelegate* network_delegate() { return &network_delegate_; }
94 DeterministicSocketData* socket_data(size_t index) { 109 DeterministicSocketData* socket_data(size_t index) {
95 return socket_data_[index]; 110 return socket_data_[index];
96 } 111 }
97 112
98 private: 113 private:
99 ScopedVector<DeterministicSocketData> socket_data_; 114 ScopedVector<DeterministicSocketData> socket_data_;
100 DeterministicMockClientSocketFactory socket_factory_; 115 DeterministicMockClientSocketFactory socket_factory_;
101 TestNetworkDelegate network_delegate_; 116 TestNetworkDelegate network_delegate_;
117 ::testing::StrictMock<MockFtpTransactionFactory> ftp_transaction_factory_;
102 118
103 // Owned by |request_context_|: 119 // Owned by |request_context_|:
104 ProxyService* proxy_service_; 120 ProxyService* proxy_service_;
105 121
106 FtpTestURLRequestContext request_context_; 122 FtpTestURLRequestContext request_context_;
107 }; 123 };
108 124
109 TEST_F(URLRequestFtpJobTest, FtpProxyRequest) { 125 TEST_F(URLRequestFtpJobTest, FtpProxyRequest) {
110 MockWrite writes[] = { 126 MockWrite writes[] = {
111 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" 127 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 EXPECT_TRUE(url_request2.status().is_success()); 367 EXPECT_TRUE(url_request2.status().is_success());
352 EXPECT_EQ(2, network_delegate()->completed_requests()); 368 EXPECT_EQ(2, network_delegate()->completed_requests());
353 EXPECT_EQ(0, network_delegate()->error_count()); 369 EXPECT_EQ(0, network_delegate()->error_count());
354 EXPECT_FALSE(request_delegate2.auth_required_called()); 370 EXPECT_FALSE(request_delegate2.auth_required_called());
355 EXPECT_EQ("test2.html", request_delegate2.data_received()); 371 EXPECT_EQ("test2.html", request_delegate2.data_received());
356 } 372 }
357 373
358 } // namespace 374 } // namespace
359 375
360 } // namespace net 376 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698