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

Side by Side Diff: trunk/src/net/url_request/url_request_ftp_job_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698