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

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

Issue 501163002: Make URLRequest's constructor private, and make URLRequestContext a friend class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge yet again Created 6 years, 3 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
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/url_request/url_request_ftp_job.h" 5 #include "net/url_request/url_request_ftp_job.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "net/base/host_port_pair.h" 11 #include "net/base/host_port_pair.h"
11 #include "net/base/request_priority.h" 12 #include "net/base/request_priority.h"
12 #include "net/ftp/ftp_auth_cache.h" 13 #include "net/ftp/ftp_auth_cache.h"
13 #include "net/http/http_transaction_test_util.h" 14 #include "net/http/http_transaction_test_util.h"
14 #include "net/proxy/mock_proxy_resolver.h" 15 #include "net/proxy/mock_proxy_resolver.h"
15 #include "net/proxy/proxy_config_service.h" 16 #include "net/proxy/proxy_config_service.h"
16 #include "net/proxy/proxy_config_service_fixed.h" 17 #include "net/proxy/proxy_config_service_fixed.h"
17 #include "net/socket/socket_test_util.h" 18 #include "net/socket/socket_test_util.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 119
119 virtual void Suspend(bool suspend) OVERRIDE {} 120 virtual void Suspend(bool suspend) OVERRIDE {}
120 }; 121 };
121 122
122 // Fixture for priority-related tests. Priority matters when there is 123 // Fixture for priority-related tests. Priority matters when there is
123 // an HTTP proxy. 124 // an HTTP proxy.
124 class URLRequestFtpJobPriorityTest : public testing::Test { 125 class URLRequestFtpJobPriorityTest : public testing::Test {
125 protected: 126 protected:
126 URLRequestFtpJobPriorityTest() 127 URLRequestFtpJobPriorityTest()
127 : proxy_service_(new SimpleProxyConfigService, NULL, NULL), 128 : proxy_service_(new SimpleProxyConfigService, NULL, NULL),
128 req_(GURL("ftp://ftp.example.com"), 129 req_(context_.CreateRequest(GURL("ftp://ftp.example.com"),
129 DEFAULT_PRIORITY, 130 DEFAULT_PRIORITY,
130 &delegate_, 131 &delegate_,
131 &context_) { 132 NULL)) {
132 context_.set_proxy_service(&proxy_service_); 133 context_.set_proxy_service(&proxy_service_);
133 context_.set_http_transaction_factory(&network_layer_); 134 context_.set_http_transaction_factory(&network_layer_);
134 } 135 }
135 136
136 ProxyService proxy_service_; 137 ProxyService proxy_service_;
137 MockNetworkLayer network_layer_; 138 MockNetworkLayer network_layer_;
138 MockFtpTransactionFactory ftp_factory_; 139 MockFtpTransactionFactory ftp_factory_;
139 FtpAuthCache ftp_auth_cache_; 140 FtpAuthCache ftp_auth_cache_;
140 TestURLRequestContext context_; 141 TestURLRequestContext context_;
141 TestDelegate delegate_; 142 TestDelegate delegate_;
142 TestURLRequest req_; 143 scoped_ptr<URLRequest> req_;
143 }; 144 };
144 145
145 // Make sure that SetPriority actually sets the URLRequestFtpJob's 146 // Make sure that SetPriority actually sets the URLRequestFtpJob's
146 // priority, both before and after start. 147 // priority, both before and after start.
147 TEST_F(URLRequestFtpJobPriorityTest, SetPriorityBasic) { 148 TEST_F(URLRequestFtpJobPriorityTest, SetPriorityBasic) {
148 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( 149 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(
149 &req_, &ftp_factory_, &ftp_auth_cache_)); 150 req_.get(), &ftp_factory_, &ftp_auth_cache_));
150 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 151 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
151 152
152 job->SetPriority(LOWEST); 153 job->SetPriority(LOWEST);
153 EXPECT_EQ(LOWEST, job->priority()); 154 EXPECT_EQ(LOWEST, job->priority());
154 155
155 job->SetPriority(LOW); 156 job->SetPriority(LOW);
156 EXPECT_EQ(LOW, job->priority()); 157 EXPECT_EQ(LOW, job->priority());
157 158
158 job->Start(); 159 job->Start();
159 EXPECT_EQ(LOW, job->priority()); 160 EXPECT_EQ(LOW, job->priority());
160 161
161 job->SetPriority(MEDIUM); 162 job->SetPriority(MEDIUM);
162 EXPECT_EQ(MEDIUM, job->priority()); 163 EXPECT_EQ(MEDIUM, job->priority());
163 } 164 }
164 165
165 // Make sure that URLRequestFtpJob passes on its priority to its 166 // Make sure that URLRequestFtpJob passes on its priority to its
166 // transaction on start. 167 // transaction on start.
167 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriorityOnStart) { 168 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriorityOnStart) {
168 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( 169 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(
169 &req_, &ftp_factory_, &ftp_auth_cache_)); 170 req_.get(), &ftp_factory_, &ftp_auth_cache_));
170 job->SetPriority(LOW); 171 job->SetPriority(LOW);
171 172
172 EXPECT_FALSE(network_layer_.last_transaction()); 173 EXPECT_FALSE(network_layer_.last_transaction());
173 174
174 job->Start(); 175 job->Start();
175 176
176 ASSERT_TRUE(network_layer_.last_transaction()); 177 ASSERT_TRUE(network_layer_.last_transaction());
177 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); 178 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
178 } 179 }
179 180
180 // Make sure that URLRequestFtpJob passes on its priority updates to 181 // Make sure that URLRequestFtpJob passes on its priority updates to
181 // its transaction. 182 // its transaction.
182 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriority) { 183 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriority) {
183 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( 184 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(
184 &req_, &ftp_factory_, &ftp_auth_cache_)); 185 req_.get(), &ftp_factory_, &ftp_auth_cache_));
185 job->SetPriority(LOW); 186 job->SetPriority(LOW);
186 job->Start(); 187 job->Start();
187 ASSERT_TRUE(network_layer_.last_transaction()); 188 ASSERT_TRUE(network_layer_.last_transaction());
188 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); 189 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
189 190
190 job->SetPriority(HIGHEST); 191 job->SetPriority(HIGHEST);
191 EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); 192 EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority());
192 } 193 }
193 194
194 // Make sure that URLRequestFtpJob passes on its priority updates to 195 // Make sure that URLRequestFtpJob passes on its priority updates to
195 // newly-created transactions after the first one. 196 // newly-created transactions after the first one.
196 TEST_F(URLRequestFtpJobPriorityTest, SetSubsequentTransactionPriority) { 197 TEST_F(URLRequestFtpJobPriorityTest, SetSubsequentTransactionPriority) {
197 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( 198 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(
198 &req_, &ftp_factory_, &ftp_auth_cache_)); 199 req_.get(), &ftp_factory_, &ftp_auth_cache_));
199 job->Start(); 200 job->Start();
200 201
201 job->SetPriority(LOW); 202 job->SetPriority(LOW);
202 ASSERT_TRUE(network_layer_.last_transaction()); 203 ASSERT_TRUE(network_layer_.last_transaction());
203 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); 204 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
204 205
205 job->Kill(); 206 job->Kill();
206 network_layer_.ClearLastTransaction(); 207 network_layer_.ClearLastTransaction();
207 208
208 // Creates a second transaction. 209 // Creates a second transaction.
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 EXPECT_TRUE(url_request2->status().is_success()); 702 EXPECT_TRUE(url_request2->status().is_success());
702 EXPECT_EQ(2, network_delegate()->completed_requests()); 703 EXPECT_EQ(2, network_delegate()->completed_requests());
703 EXPECT_EQ(0, network_delegate()->error_count()); 704 EXPECT_EQ(0, network_delegate()->error_count());
704 EXPECT_FALSE(request_delegate2.auth_required_called()); 705 EXPECT_FALSE(request_delegate2.auth_required_called());
705 EXPECT_EQ("test2.html", request_delegate2.data_received()); 706 EXPECT_EQ("test2.html", request_delegate2.data_received());
706 } 707 }
707 708
708 } // namespace 709 } // namespace
709 710
710 } // namespace net 711 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_filter_unittest.cc ('k') | net/url_request/url_request_http_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698