OLD | NEW |
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/elements_upload_data_stream.h" | 10 #include "net/base/elements_upload_data_stream.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 return; | 151 return; |
152 } | 152 } |
153 if (server_thread_.get()) { | 153 if (server_thread_.get()) { |
154 server_thread_->Quit(); | 154 server_thread_->Quit(); |
155 server_thread_->Join(); | 155 server_thread_->Join(); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 // Adds an entry to the cache used by the QUIC server to serve | 159 // Adds an entry to the cache used by the QUIC server to serve |
160 // responses. | 160 // responses. |
161 void AddToCache(const StringPiece& method, | 161 void AddToCache(StringPiece path, |
162 const StringPiece& path, | 162 int response_code, |
163 const StringPiece& version, | 163 StringPiece response_detail, |
164 const StringPiece& response_code, | 164 StringPiece body) { |
165 const StringPiece& response_detail, | |
166 const StringPiece& body) { | |
167 QuicInMemoryCache::GetInstance()->AddSimpleResponse( | 165 QuicInMemoryCache::GetInstance()->AddSimpleResponse( |
168 method, path, version, response_code, response_detail, body); | 166 "www.google.com", path, response_code, response_detail, body); |
169 } | 167 } |
170 | 168 |
171 // Populates |request_body_| with |length_| ASCII bytes. | 169 // Populates |request_body_| with |length_| ASCII bytes. |
172 void GenerateBody(size_t length) { | 170 void GenerateBody(size_t length) { |
173 request_body_.clear(); | 171 request_body_.clear(); |
174 request_body_.reserve(length); | 172 request_body_.reserve(length); |
175 for (size_t i = 0; i < length; ++i) { | 173 for (size_t i = 0; i < length; ++i) { |
176 request_body_.append(1, static_cast<char>(32 + i % (126 - 32))); | 174 request_body_.append(1, static_cast<char>(32 + i % (126 - 32))); |
177 } | 175 } |
178 } | 176 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 IPEndPoint server_address_; | 218 IPEndPoint server_address_; |
221 std::string server_hostname_; | 219 std::string server_hostname_; |
222 QuicConfig server_config_; | 220 QuicConfig server_config_; |
223 bool server_started_; | 221 bool server_started_; |
224 bool strike_register_no_startup_period_; | 222 bool strike_register_no_startup_period_; |
225 }; | 223 }; |
226 | 224 |
227 TEST_F(QuicEndToEndTest, LargeGetWithNoPacketLoss) { | 225 TEST_F(QuicEndToEndTest, LargeGetWithNoPacketLoss) { |
228 std::string response(10 * 1024, 'x'); | 226 std::string response(10 * 1024, 'x'); |
229 | 227 |
230 AddToCache("GET", request_.url.spec(), | 228 AddToCache(request_.url.PathForRequest(), 200, "OK", response); |
231 "HTTP/1.1", "200", "OK", | |
232 response); | |
233 | 229 |
234 TestTransactionConsumer consumer(DEFAULT_PRIORITY, | 230 TestTransactionConsumer consumer(DEFAULT_PRIORITY, |
235 transaction_factory_.get()); | 231 transaction_factory_.get()); |
236 consumer.Start(&request_, BoundNetLog()); | 232 consumer.Start(&request_, BoundNetLog()); |
237 | 233 |
238 // Will terminate when the last consumer completes. | 234 // Will terminate when the last consumer completes. |
239 base::MessageLoop::current()->Run(); | 235 base::MessageLoop::current()->Run(); |
240 | 236 |
241 CheckResponse(consumer, "HTTP/1.1 200 OK", response); | 237 CheckResponse(consumer, "HTTP/1.1 200 OK", response); |
242 } | 238 } |
243 | 239 |
244 // http://crbug.com/307284 | 240 // http://crbug.com/307284 |
245 TEST_F(QuicEndToEndTest, DISABLED_LargePostWithNoPacketLoss) { | 241 TEST_F(QuicEndToEndTest, DISABLED_LargePostWithNoPacketLoss) { |
246 InitializePostRequest(10 * 1024 * 1024); | 242 InitializePostRequest(10 * 1024 * 1024); |
247 | 243 |
248 AddToCache("POST", request_.url.spec(), | 244 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); |
249 "HTTP/1.1", "200", "OK", | |
250 kResponseBody); | |
251 | 245 |
252 TestTransactionConsumer consumer(DEFAULT_PRIORITY, | 246 TestTransactionConsumer consumer(DEFAULT_PRIORITY, |
253 transaction_factory_.get()); | 247 transaction_factory_.get()); |
254 consumer.Start(&request_, BoundNetLog()); | 248 consumer.Start(&request_, BoundNetLog()); |
255 | 249 |
256 // Will terminate when the last consumer completes. | 250 // Will terminate when the last consumer completes. |
257 base::MessageLoop::current()->Run(); | 251 base::MessageLoop::current()->Run(); |
258 | 252 |
259 CheckResponse(consumer, "HTTP/1.1 200 OK", kResponseBody); | 253 CheckResponse(consumer, "HTTP/1.1 200 OK", kResponseBody); |
260 } | 254 } |
261 | 255 |
262 TEST_F(QuicEndToEndTest, LargePostWithPacketLoss) { | 256 TEST_F(QuicEndToEndTest, LargePostWithPacketLoss) { |
263 // FLAGS_fake_packet_loss_percentage = 30; | 257 // FLAGS_fake_packet_loss_percentage = 30; |
264 InitializePostRequest(1024 * 1024); | 258 InitializePostRequest(1024 * 1024); |
265 | 259 |
266 const char kResponseBody[] = "some really big response body"; | 260 const char kResponseBody[] = "some really big response body"; |
267 AddToCache("POST", request_.url.spec(), | 261 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); |
268 "HTTP/1.1", "200", "OK", | |
269 kResponseBody); | |
270 | 262 |
271 TestTransactionConsumer consumer(DEFAULT_PRIORITY, | 263 TestTransactionConsumer consumer(DEFAULT_PRIORITY, |
272 transaction_factory_.get()); | 264 transaction_factory_.get()); |
273 consumer.Start(&request_, BoundNetLog()); | 265 consumer.Start(&request_, BoundNetLog()); |
274 | 266 |
275 // Will terminate when the last consumer completes. | 267 // Will terminate when the last consumer completes. |
276 base::MessageLoop::current()->Run(); | 268 base::MessageLoop::current()->Run(); |
277 | 269 |
278 CheckResponse(consumer, "HTTP/1.1 200 OK", kResponseBody); | 270 CheckResponse(consumer, "HTTP/1.1 200 OK", kResponseBody); |
279 } | 271 } |
280 | 272 |
281 TEST_F(QuicEndToEndTest, UberTest) { | 273 TEST_F(QuicEndToEndTest, UberTest) { |
282 // FLAGS_fake_packet_loss_percentage = 30; | 274 // FLAGS_fake_packet_loss_percentage = 30; |
283 | 275 |
284 const char kResponseBody[] = "some really big response body"; | 276 const char kResponseBody[] = "some really big response body"; |
285 AddToCache("GET", request_.url.spec(), | 277 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); |
286 "HTTP/1.1", "200", "OK", | |
287 kResponseBody); | |
288 | 278 |
289 std::vector<TestTransactionConsumer*> consumers; | 279 std::vector<TestTransactionConsumer*> consumers; |
290 size_t num_requests = 100; | 280 size_t num_requests = 100; |
291 for (size_t i = 0; i < num_requests; ++i) { | 281 for (size_t i = 0; i < num_requests; ++i) { |
292 TestTransactionConsumer* consumer = | 282 TestTransactionConsumer* consumer = |
293 new TestTransactionConsumer(DEFAULT_PRIORITY, | 283 new TestTransactionConsumer(DEFAULT_PRIORITY, |
294 transaction_factory_.get()); | 284 transaction_factory_.get()); |
295 consumers.push_back(consumer); | 285 consumers.push_back(consumer); |
296 consumer->Start(&request_, BoundNetLog()); | 286 consumer->Start(&request_, BoundNetLog()); |
297 } | 287 } |
298 | 288 |
299 // Will terminate when the last consumer completes. | 289 // Will terminate when the last consumer completes. |
300 base::MessageLoop::current()->Run(); | 290 base::MessageLoop::current()->Run(); |
301 | 291 |
302 for (size_t i = 0; i < num_requests; ++i) { | 292 for (size_t i = 0; i < num_requests; ++i) { |
303 CheckResponse(*consumers[i], "HTTP/1.1 200 OK", kResponseBody); | 293 CheckResponse(*consumers[i], "HTTP/1.1 200 OK", kResponseBody); |
304 } | 294 } |
305 STLDeleteElements(&consumers); | 295 STLDeleteElements(&consumers); |
306 } | 296 } |
307 | 297 |
308 } // namespace test | 298 } // namespace test |
309 } // namespace net | 299 } // namespace net |
OLD | NEW |