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

Side by Side Diff: net/quic/quic_end_to_end_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 28 matching lines...) Expand all
39 namespace { 39 namespace {
40 40
41 const char kResponseBody[] = "some arbitrary response body"; 41 const char kResponseBody[] = "some arbitrary response body";
42 42
43 // Factory for creating HttpTransactions, used by TestTransactionConsumer. 43 // Factory for creating HttpTransactions, used by TestTransactionConsumer.
44 class TestTransactionFactory : public HttpTransactionFactory { 44 class TestTransactionFactory : public HttpTransactionFactory {
45 public: 45 public:
46 TestTransactionFactory(const HttpNetworkSession::Params& params) 46 TestTransactionFactory(const HttpNetworkSession::Params& params)
47 : session_(new HttpNetworkSession(params)) {} 47 : session_(new HttpNetworkSession(params)) {}
48 48
49 virtual ~TestTransactionFactory() { 49 virtual ~TestTransactionFactory() {}
50 }
51 50
52 // HttpTransactionFactory methods 51 // HttpTransactionFactory methods
53 virtual int CreateTransaction(RequestPriority priority, 52 virtual int CreateTransaction(RequestPriority priority,
54 scoped_ptr<HttpTransaction>* trans) OVERRIDE { 53 scoped_ptr<HttpTransaction>* trans) OVERRIDE {
55 trans->reset(new HttpNetworkTransaction(priority, session_)); 54 trans->reset(new HttpNetworkTransaction(priority, session_));
56 return OK; 55 return OK;
57 } 56 }
58 57
59 virtual HttpCache* GetCache() OVERRIDE { 58 virtual HttpCache* GetCache() OVERRIDE { return NULL; }
60 return NULL;
61 }
62 59
63 virtual HttpNetworkSession* GetSession() OVERRIDE { 60 virtual HttpNetworkSession* GetSession() OVERRIDE {
64 return session_; 61 return session_;
65 }; 62 };
66 63
67 private: 64 private:
68 scoped_refptr<HttpNetworkSession> session_; 65 scoped_refptr<HttpNetworkSession> session_;
69 }; 66 };
70 67
71 } // namespace 68 } // namespace
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return resolver; 101 return resolver;
105 } 102 }
106 103
107 virtual void SetUp() { 104 virtual void SetUp() {
108 QuicInMemoryCachePeer::ResetForTests(); 105 QuicInMemoryCachePeer::ResetForTests();
109 StartServer(); 106 StartServer();
110 107
111 // Use a mapped host resolver so that request for www.google.com (port 80) 108 // Use a mapped host resolver so that request for www.google.com (port 80)
112 // reach the server running on localhost. 109 // reach the server running on localhost.
113 std::string map_rule = "MAP www.google.com www.google.com:" + 110 std::string map_rule = "MAP www.google.com www.google.com:" +
114 base::IntToString(server_thread_->GetPort()); 111 base::IntToString(server_thread_->GetPort());
115 EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule)); 112 EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule));
116 113
117 // To simplify the test, and avoid the race with the HTTP request, we force 114 // To simplify the test, and avoid the race with the HTTP request, we force
118 // QUIC for these requests. 115 // QUIC for these requests.
119 params_.origin_to_force_quic_on = 116 params_.origin_to_force_quic_on =
120 HostPortPair::FromString("www.google.com:80"); 117 HostPortPair::FromString("www.google.com:80");
121 118
122 transaction_factory_.reset(new TestTransactionFactory(params_)); 119 transaction_factory_.reset(new TestTransactionFactory(params_));
123 } 120 }
124 121
125 virtual void TearDown() { 122 virtual void TearDown() {
126 StopServer(); 123 StopServer();
127 QuicInMemoryCachePeer::ResetForTests(); 124 QuicInMemoryCachePeer::ResetForTests();
128 } 125 }
129 126
130 // Starts the QUIC server listening on a random port. 127 // Starts the QUIC server listening on a random port.
131 void StartServer() { 128 void StartServer() {
132 net::IPAddressNumber ip; 129 net::IPAddressNumber ip;
133 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); 130 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip));
134 server_address_ = IPEndPoint(ip, 0); 131 server_address_ = IPEndPoint(ip, 0);
135 server_config_.SetDefaults(); 132 server_config_.SetDefaults();
136 server_thread_.reset(new ServerThread(server_address_, server_config_, 133 server_thread_.reset(new ServerThread(server_address_,
134 server_config_,
137 QuicSupportedVersions(), 135 QuicSupportedVersions(),
138 strike_register_no_startup_period_, 136 strike_register_no_startup_period_,
139 kInitialFlowControlWindowForTest)); 137 kInitialFlowControlWindowForTest));
140 server_thread_->Initialize(); 138 server_thread_->Initialize();
141 server_address_ = IPEndPoint(server_address_.address(), 139 server_address_ =
142 server_thread_->GetPort()); 140 IPEndPoint(server_address_.address(), server_thread_->GetPort());
143 server_thread_->Start(); 141 server_thread_->Start();
144 server_started_ = true; 142 server_started_ = true;
145 } 143 }
146 144
147 // Stops the QUIC server. 145 // Stops the QUIC server.
148 void StopServer() { 146 void StopServer() {
149 if (!server_started_) { 147 if (!server_started_) {
150 return; 148 return;
151 } 149 }
152 if (server_thread_.get()) { 150 if (server_thread_.get()) {
(...skipping 20 matching lines...) Expand all
173 request_body_.reserve(length); 171 request_body_.reserve(length);
174 for (size_t i = 0; i < length; ++i) { 172 for (size_t i = 0; i < length; ++i) {
175 request_body_.append(1, static_cast<char>(32 + i % (126 - 32))); 173 request_body_.append(1, static_cast<char>(32 + i % (126 - 32)));
176 } 174 }
177 } 175 }
178 176
179 // Initializes |request_| for a post of |length| bytes. 177 // Initializes |request_| for a post of |length| bytes.
180 void InitializePostRequest(size_t length) { 178 void InitializePostRequest(size_t length) {
181 GenerateBody(length); 179 GenerateBody(length);
182 ScopedVector<UploadElementReader> element_readers; 180 ScopedVector<UploadElementReader> element_readers;
183 element_readers.push_back( 181 element_readers.push_back(new UploadBytesElementReader(
184 new UploadBytesElementReader(request_body_.data(), 182 request_body_.data(), request_body_.length()));
185 request_body_.length()));
186 upload_data_stream_.reset(new UploadDataStream(element_readers.Pass(), 0)); 183 upload_data_stream_.reset(new UploadDataStream(element_readers.Pass(), 0));
187 request_.method = "POST"; 184 request_.method = "POST";
188 request_.url = GURL("http://www.google.com/"); 185 request_.url = GURL("http://www.google.com/");
189 request_.upload_data_stream = upload_data_stream_.get(); 186 request_.upload_data_stream = upload_data_stream_.get();
190 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); 187 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback()));
191 } 188 }
192 189
193 // Checks that |consumer| completed and received |status_line| and |body|. 190 // Checks that |consumer| completed and received |status_line| and |body|.
194 void CheckResponse(const TestTransactionConsumer& consumer, 191 void CheckResponse(const TestTransactionConsumer& consumer,
195 const std::string& status_line, 192 const std::string& status_line,
196 const std::string& body) { 193 const std::string& body) {
197 ASSERT_TRUE(consumer.is_done()); 194 ASSERT_TRUE(consumer.is_done());
198 EXPECT_EQ(OK, consumer.error()); 195 EXPECT_EQ(OK, consumer.error());
199 EXPECT_EQ(status_line, 196 EXPECT_EQ(status_line, consumer.response_info()->headers->GetStatusLine());
200 consumer.response_info()->headers->GetStatusLine());
201 EXPECT_EQ(body, consumer.content()); 197 EXPECT_EQ(body, consumer.content());
202 } 198 }
203 199
204 scoped_ptr<MockHostResolver> host_resolver_impl_; 200 scoped_ptr<MockHostResolver> host_resolver_impl_;
205 MappedHostResolver host_resolver_; 201 MappedHostResolver host_resolver_;
206 MockCertVerifier cert_verifier_; 202 MockCertVerifier cert_verifier_;
207 TransportSecurityState transport_security_state_; 203 TransportSecurityState transport_security_state_;
208 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; 204 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_;
209 scoped_ptr<ProxyService> proxy_service_; 205 scoped_ptr<ProxyService> proxy_service_;
210 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; 206 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_;
211 HttpServerPropertiesImpl http_server_properties; 207 HttpServerPropertiesImpl http_server_properties;
212 HttpNetworkSession::Params params_; 208 HttpNetworkSession::Params params_;
213 scoped_ptr<TestTransactionFactory> transaction_factory_; 209 scoped_ptr<TestTransactionFactory> transaction_factory_;
214 HttpRequestInfo request_; 210 HttpRequestInfo request_;
215 std::string request_body_; 211 std::string request_body_;
216 scoped_ptr<UploadDataStream> upload_data_stream_; 212 scoped_ptr<UploadDataStream> upload_data_stream_;
217 scoped_ptr<ServerThread> server_thread_; 213 scoped_ptr<ServerThread> server_thread_;
218 IPEndPoint server_address_; 214 IPEndPoint server_address_;
219 std::string server_hostname_; 215 std::string server_hostname_;
220 QuicConfig server_config_; 216 QuicConfig server_config_;
221 bool server_started_; 217 bool server_started_;
222 bool strike_register_no_startup_period_; 218 bool strike_register_no_startup_period_;
223 }; 219 };
224 220
225 TEST_F(QuicEndToEndTest, LargeGetWithNoPacketLoss) { 221 TEST_F(QuicEndToEndTest, LargeGetWithNoPacketLoss) {
226 std::string response(10 * 1024, 'x'); 222 std::string response(10 * 1024, 'x');
227 223
228 AddToCache("GET", request_.url.spec(), 224 AddToCache("GET", request_.url.spec(), "HTTP/1.1", "200", "OK", response);
229 "HTTP/1.1", "200", "OK",
230 response);
231 225
232 TestTransactionConsumer consumer(DEFAULT_PRIORITY, 226 TestTransactionConsumer consumer(DEFAULT_PRIORITY,
233 transaction_factory_.get()); 227 transaction_factory_.get());
234 consumer.Start(&request_, BoundNetLog()); 228 consumer.Start(&request_, BoundNetLog());
235 229
236 // Will terminate when the last consumer completes. 230 // Will terminate when the last consumer completes.
237 base::MessageLoop::current()->Run(); 231 base::MessageLoop::current()->Run();
238 232
239 CheckResponse(consumer, "HTTP/1.1 200 OK", response); 233 CheckResponse(consumer, "HTTP/1.1 200 OK", response);
240 } 234 }
241 235
242 // http://crbug.com/307284 236 // http://crbug.com/307284
243 TEST_F(QuicEndToEndTest, DISABLED_LargePostWithNoPacketLoss) { 237 TEST_F(QuicEndToEndTest, DISABLED_LargePostWithNoPacketLoss) {
244 InitializePostRequest(10 * 1024 * 1024); 238 InitializePostRequest(10 * 1024 * 1024);
245 239
246 AddToCache("POST", request_.url.spec(), 240 AddToCache(
247 "HTTP/1.1", "200", "OK", 241 "POST", request_.url.spec(), "HTTP/1.1", "200", "OK", kResponseBody);
248 kResponseBody);
249 242
250 TestTransactionConsumer consumer(DEFAULT_PRIORITY, 243 TestTransactionConsumer consumer(DEFAULT_PRIORITY,
251 transaction_factory_.get()); 244 transaction_factory_.get());
252 consumer.Start(&request_, BoundNetLog()); 245 consumer.Start(&request_, BoundNetLog());
253 246
254 // Will terminate when the last consumer completes. 247 // Will terminate when the last consumer completes.
255 base::MessageLoop::current()->Run(); 248 base::MessageLoop::current()->Run();
256 249
257 CheckResponse(consumer, "HTTP/1.1 200 OK", kResponseBody); 250 CheckResponse(consumer, "HTTP/1.1 200 OK", kResponseBody);
258 } 251 }
259 252
260 TEST_F(QuicEndToEndTest, LargePostWithPacketLoss) { 253 TEST_F(QuicEndToEndTest, LargePostWithPacketLoss) {
261 // FLAGS_fake_packet_loss_percentage = 30; 254 // FLAGS_fake_packet_loss_percentage = 30;
262 InitializePostRequest(1024 * 1024); 255 InitializePostRequest(1024 * 1024);
263 256
264 const char kResponseBody[] = "some really big response body"; 257 const char kResponseBody[] = "some really big response body";
265 AddToCache("POST", request_.url.spec(), 258 AddToCache(
266 "HTTP/1.1", "200", "OK", 259 "POST", request_.url.spec(), "HTTP/1.1", "200", "OK", kResponseBody);
267 kResponseBody);
268 260
269 TestTransactionConsumer consumer(DEFAULT_PRIORITY, 261 TestTransactionConsumer consumer(DEFAULT_PRIORITY,
270 transaction_factory_.get()); 262 transaction_factory_.get());
271 consumer.Start(&request_, BoundNetLog()); 263 consumer.Start(&request_, BoundNetLog());
272 264
273 // Will terminate when the last consumer completes. 265 // Will terminate when the last consumer completes.
274 base::MessageLoop::current()->Run(); 266 base::MessageLoop::current()->Run();
275 267
276 CheckResponse(consumer, "HTTP/1.1 200 OK", kResponseBody); 268 CheckResponse(consumer, "HTTP/1.1 200 OK", kResponseBody);
277 } 269 }
278 270
279 TEST_F(QuicEndToEndTest, UberTest) { 271 TEST_F(QuicEndToEndTest, UberTest) {
280 // FLAGS_fake_packet_loss_percentage = 30; 272 // FLAGS_fake_packet_loss_percentage = 30;
281 273
282 const char kResponseBody[] = "some really big response body"; 274 const char kResponseBody[] = "some really big response body";
283 AddToCache("GET", request_.url.spec(), 275 AddToCache(
284 "HTTP/1.1", "200", "OK", 276 "GET", request_.url.spec(), "HTTP/1.1", "200", "OK", kResponseBody);
285 kResponseBody);
286 277
287 std::vector<TestTransactionConsumer*> consumers; 278 std::vector<TestTransactionConsumer*> consumers;
288 size_t num_requests = 100; 279 size_t num_requests = 100;
289 for (size_t i = 0; i < num_requests; ++i) { 280 for (size_t i = 0; i < num_requests; ++i) {
290 TestTransactionConsumer* consumer = 281 TestTransactionConsumer* consumer = new TestTransactionConsumer(
291 new TestTransactionConsumer(DEFAULT_PRIORITY, 282 DEFAULT_PRIORITY, transaction_factory_.get());
292 transaction_factory_.get()); 283 consumers.push_back(consumer);
293 consumers.push_back(consumer); 284 consumer->Start(&request_, BoundNetLog());
294 consumer->Start(&request_, BoundNetLog());
295 } 285 }
296 286
297 // Will terminate when the last consumer completes. 287 // Will terminate when the last consumer completes.
298 base::MessageLoop::current()->Run(); 288 base::MessageLoop::current()->Run();
299 289
300 for (size_t i = 0; i < num_requests; ++i) { 290 for (size_t i = 0; i < num_requests; ++i) {
301 CheckResponse(*consumers[i], "HTTP/1.1 200 OK", kResponseBody); 291 CheckResponse(*consumers[i], "HTTP/1.1 200 OK", kResponseBody);
302 } 292 }
303 STLDeleteElements(&consumers); 293 STLDeleteElements(&consumers);
304 } 294 }
305 295
306 } // namespace test 296 } // namespace test
307 } // namespace net 297 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698