OLD | NEW |
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_fetcher_impl.h" | 5 #include "net/url_request/url_fetcher_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 : public TestURLRequestContextGetter { | 60 : public TestURLRequestContextGetter { |
61 public: | 61 public: |
62 ThrottlingTestURLRequestContextGetter( | 62 ThrottlingTestURLRequestContextGetter( |
63 base::MessageLoopProxy* io_message_loop_proxy, | 63 base::MessageLoopProxy* io_message_loop_proxy, |
64 TestURLRequestContext* request_context) | 64 TestURLRequestContext* request_context) |
65 : TestURLRequestContextGetter(io_message_loop_proxy), | 65 : TestURLRequestContextGetter(io_message_loop_proxy), |
66 context_(request_context) { | 66 context_(request_context) { |
67 } | 67 } |
68 | 68 |
69 // TestURLRequestContextGetter: | 69 // TestURLRequestContextGetter: |
70 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { | 70 virtual TestURLRequestContext* GetURLRequestContext() override { |
71 return context_; | 71 return context_; |
72 } | 72 } |
73 | 73 |
74 protected: | 74 protected: |
75 virtual ~ThrottlingTestURLRequestContextGetter() {} | 75 virtual ~ThrottlingTestURLRequestContextGetter() {} |
76 | 76 |
77 TestURLRequestContext* const context_; | 77 TestURLRequestContext* const context_; |
78 }; | 78 }; |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 class URLFetcherTest : public testing::Test, | 82 class URLFetcherTest : public testing::Test, |
83 public URLFetcherDelegate { | 83 public URLFetcherDelegate { |
84 public: | 84 public: |
85 URLFetcherTest() : fetcher_(NULL) {} | 85 URLFetcherTest() : fetcher_(NULL) {} |
86 | 86 |
87 static int GetNumFetcherCores() { | 87 static int GetNumFetcherCores() { |
88 return URLFetcherImpl::GetNumFetcherCores(); | 88 return URLFetcherImpl::GetNumFetcherCores(); |
89 } | 89 } |
90 | 90 |
91 // Creates a URLFetcher, using the program's main thread to do IO. | 91 // Creates a URLFetcher, using the program's main thread to do IO. |
92 virtual void CreateFetcher(const GURL& url); | 92 virtual void CreateFetcher(const GURL& url); |
93 | 93 |
94 // URLFetcherDelegate: | 94 // URLFetcherDelegate: |
95 // Subclasses that override this should either call this function or | 95 // Subclasses that override this should either call this function or |
96 // CleanupAfterFetchComplete() at the end of their processing, depending on | 96 // CleanupAfterFetchComplete() at the end of their processing, depending on |
97 // whether they want to check for a non-empty HTTP 200 response or not. | 97 // whether they want to check for a non-empty HTTP 200 response or not. |
98 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 98 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
99 | 99 |
100 // Deletes |fetcher| and terminates the message loop. | 100 // Deletes |fetcher| and terminates the message loop. |
101 void CleanupAfterFetchComplete(); | 101 void CleanupAfterFetchComplete(); |
102 | 102 |
103 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { | 103 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { |
104 return io_message_loop_proxy_; | 104 return io_message_loop_proxy_; |
105 } | 105 } |
106 | 106 |
107 TestURLRequestContext* request_context() { | 107 TestURLRequestContext* request_context() { |
108 return context_.get(); | 108 return context_.get(); |
109 } | 109 } |
110 | 110 |
111 protected: | 111 protected: |
112 // testing::Test: | 112 // testing::Test: |
113 virtual void SetUp() OVERRIDE { | 113 virtual void SetUp() override { |
114 testing::Test::SetUp(); | 114 testing::Test::SetUp(); |
115 | 115 |
116 context_.reset(new ThrottlingTestURLRequestContext()); | 116 context_.reset(new ThrottlingTestURLRequestContext()); |
117 io_message_loop_proxy_ = base::MessageLoopProxy::current(); | 117 io_message_loop_proxy_ = base::MessageLoopProxy::current(); |
118 | 118 |
119 #if defined(USE_NSS) || defined(OS_IOS) | 119 #if defined(USE_NSS) || defined(OS_IOS) |
120 crypto::EnsureNSSInit(); | 120 crypto::EnsureNSSInit(); |
121 EnsureNSSHttpIOInit(); | 121 EnsureNSSHttpIOInit(); |
122 #endif | 122 #endif |
123 } | 123 } |
124 | 124 |
125 virtual void TearDown() OVERRIDE { | 125 virtual void TearDown() override { |
126 #if defined(USE_NSS) || defined(OS_IOS) | 126 #if defined(USE_NSS) || defined(OS_IOS) |
127 ShutdownNSSHttpIO(); | 127 ShutdownNSSHttpIO(); |
128 #endif | 128 #endif |
129 } | 129 } |
130 | 130 |
131 // URLFetcher is designed to run on the main UI thread, but in our tests | 131 // URLFetcher is designed to run on the main UI thread, but in our tests |
132 // we assume that the current thread is the IO thread where the URLFetcher | 132 // we assume that the current thread is the IO thread where the URLFetcher |
133 // dispatches its requests to. When we wish to simulate being used from | 133 // dispatches its requests to. When we wish to simulate being used from |
134 // a UI thread, we dispatch a worker thread to do so. | 134 // a UI thread, we dispatch a worker thread to do so. |
135 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 135 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
136 | 136 |
137 URLFetcherImpl* fetcher_; | 137 URLFetcherImpl* fetcher_; |
138 scoped_ptr<TestURLRequestContext> context_; | 138 scoped_ptr<TestURLRequestContext> context_; |
139 }; | 139 }; |
140 | 140 |
141 // A test fixture that uses a MockHostResolver, so that name resolutions can | 141 // A test fixture that uses a MockHostResolver, so that name resolutions can |
142 // be manipulated by the tests to keep connections in the resolving state. | 142 // be manipulated by the tests to keep connections in the resolving state. |
143 class URLFetcherMockDnsTest : public URLFetcherTest { | 143 class URLFetcherMockDnsTest : public URLFetcherTest { |
144 public: | 144 public: |
145 // testing::Test: | 145 // testing::Test: |
146 virtual void SetUp() OVERRIDE; | 146 virtual void SetUp() override; |
147 | 147 |
148 // URLFetcherTest: | 148 // URLFetcherTest: |
149 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 149 virtual void CreateFetcher(const GURL& url) override; |
150 | 150 |
151 // URLFetcherDelegate: | 151 // URLFetcherDelegate: |
152 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 152 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
153 | 153 |
154 protected: | 154 protected: |
155 GURL test_url_; | 155 GURL test_url_; |
156 scoped_ptr<SpawnedTestServer> test_server_; | 156 scoped_ptr<SpawnedTestServer> test_server_; |
157 MockHostResolver resolver_; | 157 MockHostResolver resolver_; |
158 scoped_ptr<URLFetcher> completed_fetcher_; | 158 scoped_ptr<URLFetcher> completed_fetcher_; |
159 }; | 159 }; |
160 | 160 |
161 void URLFetcherTest::CreateFetcher(const GURL& url) { | 161 void URLFetcherTest::CreateFetcher(const GURL& url) { |
162 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 162 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 EXPECT_EQ(test_url_, source->GetOriginalURL()); | 224 EXPECT_EQ(test_url_, source->GetOriginalURL()); |
225 completed_fetcher_.reset(fetcher_); | 225 completed_fetcher_.reset(fetcher_); |
226 } | 226 } |
227 | 227 |
228 namespace { | 228 namespace { |
229 | 229 |
230 // Version of URLFetcherTest that does a POST instead | 230 // Version of URLFetcherTest that does a POST instead |
231 class URLFetcherPostTest : public URLFetcherTest { | 231 class URLFetcherPostTest : public URLFetcherTest { |
232 public: | 232 public: |
233 // URLFetcherTest: | 233 // URLFetcherTest: |
234 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 234 virtual void CreateFetcher(const GURL& url) override; |
235 | 235 |
236 // URLFetcherDelegate: | 236 // URLFetcherDelegate: |
237 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 237 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
238 }; | 238 }; |
239 | 239 |
240 // Version of URLFetcherTest that does a POST of a file using | 240 // Version of URLFetcherTest that does a POST of a file using |
241 // SetUploadDataStream | 241 // SetUploadDataStream |
242 class URLFetcherPostFileTest : public URLFetcherTest { | 242 class URLFetcherPostFileTest : public URLFetcherTest { |
243 public: | 243 public: |
244 URLFetcherPostFileTest(); | 244 URLFetcherPostFileTest(); |
245 | 245 |
246 void SetUploadRange(uint64 range_offset, uint64 range_length) { | 246 void SetUploadRange(uint64 range_offset, uint64 range_length) { |
247 range_offset_ = range_offset; | 247 range_offset_ = range_offset; |
248 range_length_ = range_length; | 248 range_length_ = range_length; |
249 } | 249 } |
250 | 250 |
251 // URLFetcherTest: | 251 // URLFetcherTest: |
252 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 252 virtual void CreateFetcher(const GURL& url) override; |
253 | 253 |
254 // URLFetcherDelegate: | 254 // URLFetcherDelegate: |
255 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 255 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
256 | 256 |
257 private: | 257 private: |
258 base::FilePath path_; | 258 base::FilePath path_; |
259 uint64 range_offset_; | 259 uint64 range_offset_; |
260 uint64 range_length_; | 260 uint64 range_length_; |
261 }; | 261 }; |
262 | 262 |
263 // Version of URLFetcherTest that does a POST instead with empty upload body | 263 // Version of URLFetcherTest that does a POST instead with empty upload body |
264 class URLFetcherEmptyPostTest : public URLFetcherTest { | 264 class URLFetcherEmptyPostTest : public URLFetcherTest { |
265 public: | 265 public: |
266 // URLFetcherTest: | 266 // URLFetcherTest: |
267 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 267 virtual void CreateFetcher(const GURL& url) override; |
268 | 268 |
269 // URLFetcherDelegate: | 269 // URLFetcherDelegate: |
270 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 270 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
271 }; | 271 }; |
272 | 272 |
273 // Version of URLFetcherTest that tests download progress reports. | 273 // Version of URLFetcherTest that tests download progress reports. |
274 class URLFetcherDownloadProgressTest : public URLFetcherTest { | 274 class URLFetcherDownloadProgressTest : public URLFetcherTest { |
275 public: | 275 public: |
276 URLFetcherDownloadProgressTest() | 276 URLFetcherDownloadProgressTest() |
277 : previous_progress_(0), | 277 : previous_progress_(0), |
278 expected_total_(0) { | 278 expected_total_(0) { |
279 } | 279 } |
280 | 280 |
281 // URLFetcherTest: | 281 // URLFetcherTest: |
282 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 282 virtual void CreateFetcher(const GURL& url) override; |
283 | 283 |
284 // URLFetcherDelegate: | 284 // URLFetcherDelegate: |
285 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, | 285 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, |
286 int64 current, | 286 int64 current, |
287 int64 total) OVERRIDE; | 287 int64 total) override; |
288 | 288 |
289 protected: | 289 protected: |
290 // Download progress returned by the previous callback. | 290 // Download progress returned by the previous callback. |
291 int64 previous_progress_; | 291 int64 previous_progress_; |
292 // Size of the file being downloaded, known in advance (provided by each test | 292 // Size of the file being downloaded, known in advance (provided by each test |
293 // case). | 293 // case). |
294 int64 expected_total_; | 294 int64 expected_total_; |
295 }; | 295 }; |
296 | 296 |
297 // Version of URLFetcherTest that tests progress reports at cancellation. | 297 // Version of URLFetcherTest that tests progress reports at cancellation. |
298 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { | 298 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { |
299 public: | 299 public: |
300 // URLFetcherTest: | 300 // URLFetcherTest: |
301 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 301 virtual void CreateFetcher(const GURL& url) override; |
302 | 302 |
303 // URLFetcherDelegate: | 303 // URLFetcherDelegate: |
304 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 304 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
305 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, | 305 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, |
306 int64 current, | 306 int64 current, |
307 int64 total) OVERRIDE; | 307 int64 total) override; |
308 protected: | 308 protected: |
309 bool cancelled_; | 309 bool cancelled_; |
310 }; | 310 }; |
311 | 311 |
312 // Version of URLFetcherTest that tests upload progress reports. | 312 // Version of URLFetcherTest that tests upload progress reports. |
313 class URLFetcherUploadProgressTest : public URLFetcherTest { | 313 class URLFetcherUploadProgressTest : public URLFetcherTest { |
314 public: | 314 public: |
315 // URLFetcherTest: | 315 // URLFetcherTest: |
316 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 316 virtual void CreateFetcher(const GURL& url) override; |
317 | 317 |
318 // URLFetcherDelegate: | 318 // URLFetcherDelegate: |
319 virtual void OnURLFetchUploadProgress(const URLFetcher* source, | 319 virtual void OnURLFetchUploadProgress(const URLFetcher* source, |
320 int64 current, | 320 int64 current, |
321 int64 total) OVERRIDE; | 321 int64 total) override; |
322 protected: | 322 protected: |
323 int64 previous_progress_; | 323 int64 previous_progress_; |
324 std::string chunk_; | 324 std::string chunk_; |
325 int64 number_of_chunks_added_; | 325 int64 number_of_chunks_added_; |
326 }; | 326 }; |
327 | 327 |
328 // Version of URLFetcherTest that tests headers. | 328 // Version of URLFetcherTest that tests headers. |
329 class URLFetcherHeadersTest : public URLFetcherTest { | 329 class URLFetcherHeadersTest : public URLFetcherTest { |
330 public: | 330 public: |
331 // URLFetcherDelegate: | 331 // URLFetcherDelegate: |
332 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 332 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
333 }; | 333 }; |
334 | 334 |
335 // Version of URLFetcherTest that tests SocketAddress. | 335 // Version of URLFetcherTest that tests SocketAddress. |
336 class URLFetcherSocketAddressTest : public URLFetcherTest { | 336 class URLFetcherSocketAddressTest : public URLFetcherTest { |
337 public: | 337 public: |
338 // URLFetcherDelegate: | 338 // URLFetcherDelegate: |
339 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 339 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
340 protected: | 340 protected: |
341 std::string expected_host_; | 341 std::string expected_host_; |
342 uint16 expected_port_; | 342 uint16 expected_port_; |
343 }; | 343 }; |
344 | 344 |
345 // Version of URLFetcherTest that tests stopping on a redirect. | 345 // Version of URLFetcherTest that tests stopping on a redirect. |
346 class URLFetcherStopOnRedirectTest : public URLFetcherTest { | 346 class URLFetcherStopOnRedirectTest : public URLFetcherTest { |
347 public: | 347 public: |
348 URLFetcherStopOnRedirectTest(); | 348 URLFetcherStopOnRedirectTest(); |
349 virtual ~URLFetcherStopOnRedirectTest(); | 349 virtual ~URLFetcherStopOnRedirectTest(); |
350 | 350 |
351 // URLFetcherTest: | 351 // URLFetcherTest: |
352 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 352 virtual void CreateFetcher(const GURL& url) override; |
353 | 353 |
354 // URLFetcherDelegate: | 354 // URLFetcherDelegate: |
355 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 355 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
356 | 356 |
357 protected: | 357 protected: |
358 // The URL we should be redirected to. | 358 // The URL we should be redirected to. |
359 static const char* kRedirectTarget; | 359 static const char* kRedirectTarget; |
360 | 360 |
361 bool callback_called_; // Set to true in OnURLFetchComplete(). | 361 bool callback_called_; // Set to true in OnURLFetchComplete(). |
362 }; | 362 }; |
363 | 363 |
364 // Version of URLFetcherTest that tests overload protection. | 364 // Version of URLFetcherTest that tests overload protection. |
365 class URLFetcherProtectTest : public URLFetcherTest { | 365 class URLFetcherProtectTest : public URLFetcherTest { |
366 public: | 366 public: |
367 // URLFetcherTest: | 367 // URLFetcherTest: |
368 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 368 virtual void CreateFetcher(const GURL& url) override; |
369 | 369 |
370 // URLFetcherDelegate: | 370 // URLFetcherDelegate: |
371 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 371 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
372 private: | 372 private: |
373 Time start_time_; | 373 Time start_time_; |
374 }; | 374 }; |
375 | 375 |
376 // Version of URLFetcherTest that tests overload protection, when responses | 376 // Version of URLFetcherTest that tests overload protection, when responses |
377 // passed through. | 377 // passed through. |
378 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { | 378 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { |
379 public: | 379 public: |
380 // URLFetcherTest: | 380 // URLFetcherTest: |
381 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 381 virtual void CreateFetcher(const GURL& url) override; |
382 | 382 |
383 // URLFetcherDelegate: | 383 // URLFetcherDelegate: |
384 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 384 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
385 private: | 385 private: |
386 Time start_time_; | 386 Time start_time_; |
387 }; | 387 }; |
388 | 388 |
389 // Version of URLFetcherTest that tests bad HTTPS requests. | 389 // Version of URLFetcherTest that tests bad HTTPS requests. |
390 class URLFetcherBadHTTPSTest : public URLFetcherTest { | 390 class URLFetcherBadHTTPSTest : public URLFetcherTest { |
391 public: | 391 public: |
392 URLFetcherBadHTTPSTest(); | 392 URLFetcherBadHTTPSTest(); |
393 | 393 |
394 // URLFetcherDelegate: | 394 // URLFetcherDelegate: |
395 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 395 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
396 | 396 |
397 private: | 397 private: |
398 base::FilePath cert_dir_; | 398 base::FilePath cert_dir_; |
399 }; | 399 }; |
400 | 400 |
401 // Version of URLFetcherTest that tests request cancellation on shutdown. | 401 // Version of URLFetcherTest that tests request cancellation on shutdown. |
402 class URLFetcherCancelTest : public URLFetcherTest { | 402 class URLFetcherCancelTest : public URLFetcherTest { |
403 public: | 403 public: |
404 // URLFetcherTest: | 404 // URLFetcherTest: |
405 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 405 virtual void CreateFetcher(const GURL& url) override; |
406 | 406 |
407 // URLFetcherDelegate: | 407 // URLFetcherDelegate: |
408 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 408 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
409 | 409 |
410 void CancelRequest(); | 410 void CancelRequest(); |
411 }; | 411 }; |
412 | 412 |
413 // Version of TestURLRequestContext that posts a Quit task to the IO | 413 // Version of TestURLRequestContext that posts a Quit task to the IO |
414 // thread once it is deleted. | 414 // thread once it is deleted. |
415 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { | 415 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { |
416 public: | 416 public: |
417 explicit CancelTestURLRequestContext() { | 417 explicit CancelTestURLRequestContext() { |
418 } | 418 } |
(...skipping 13 matching lines...) Expand all Loading... |
432 CancelTestURLRequestContextGetter( | 432 CancelTestURLRequestContextGetter( |
433 base::MessageLoopProxy* io_message_loop_proxy, | 433 base::MessageLoopProxy* io_message_loop_proxy, |
434 const GURL& throttle_for_url) | 434 const GURL& throttle_for_url) |
435 : TestURLRequestContextGetter(io_message_loop_proxy), | 435 : TestURLRequestContextGetter(io_message_loop_proxy), |
436 io_message_loop_proxy_(io_message_loop_proxy), | 436 io_message_loop_proxy_(io_message_loop_proxy), |
437 context_created_(false, false), | 437 context_created_(false, false), |
438 throttle_for_url_(throttle_for_url) { | 438 throttle_for_url_(throttle_for_url) { |
439 } | 439 } |
440 | 440 |
441 // TestURLRequestContextGetter: | 441 // TestURLRequestContextGetter: |
442 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { | 442 virtual TestURLRequestContext* GetURLRequestContext() override { |
443 if (!context_.get()) { | 443 if (!context_.get()) { |
444 context_.reset(new CancelTestURLRequestContext()); | 444 context_.reset(new CancelTestURLRequestContext()); |
445 DCHECK(context_->throttler_manager()); | 445 DCHECK(context_->throttler_manager()); |
446 | 446 |
447 // Registers an entry for test url. The backoff time is calculated by: | 447 // Registers an entry for test url. The backoff time is calculated by: |
448 // new_backoff = 2.0 * old_backoff + 0 | 448 // new_backoff = 2.0 * old_backoff + 0 |
449 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. | 449 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. |
450 // Maximum retries allowed is set to 2. | 450 // Maximum retries allowed is set to 2. |
451 scoped_refptr<URLRequestThrottlerEntry> entry( | 451 scoped_refptr<URLRequestThrottlerEntry> entry( |
452 new URLRequestThrottlerEntry(context_->throttler_manager(), | 452 new URLRequestThrottlerEntry(context_->throttler_manager(), |
(...skipping 27 matching lines...) Expand all Loading... |
480 scoped_ptr<TestURLRequestContext> context_; | 480 scoped_ptr<TestURLRequestContext> context_; |
481 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 481 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
482 base::WaitableEvent context_created_; | 482 base::WaitableEvent context_created_; |
483 GURL throttle_for_url_; | 483 GURL throttle_for_url_; |
484 }; | 484 }; |
485 | 485 |
486 // Version of URLFetcherTest that tests retying the same request twice. | 486 // Version of URLFetcherTest that tests retying the same request twice. |
487 class URLFetcherMultipleAttemptTest : public URLFetcherTest { | 487 class URLFetcherMultipleAttemptTest : public URLFetcherTest { |
488 public: | 488 public: |
489 // URLFetcherDelegate: | 489 // URLFetcherDelegate: |
490 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 490 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
491 private: | 491 private: |
492 std::string data_; | 492 std::string data_; |
493 }; | 493 }; |
494 | 494 |
495 class URLFetcherFileTest : public URLFetcherTest { | 495 class URLFetcherFileTest : public URLFetcherTest { |
496 public: | 496 public: |
497 URLFetcherFileTest() : take_ownership_of_file_(false), | 497 URLFetcherFileTest() : take_ownership_of_file_(false), |
498 expected_file_error_(OK) {} | 498 expected_file_error_(OK) {} |
499 | 499 |
500 void CreateFetcherForFile(const GURL& url, const base::FilePath& file_path); | 500 void CreateFetcherForFile(const GURL& url, const base::FilePath& file_path); |
501 void CreateFetcherForTempFile(const GURL& url); | 501 void CreateFetcherForTempFile(const GURL& url); |
502 | 502 |
503 // URLFetcherDelegate: | 503 // URLFetcherDelegate: |
504 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 504 virtual void OnURLFetchComplete(const URLFetcher* source) override; |
505 | 505 |
506 protected: | 506 protected: |
507 base::FilePath expected_file_; | 507 base::FilePath expected_file_; |
508 base::FilePath file_path_; | 508 base::FilePath file_path_; |
509 | 509 |
510 // Set by the test. Used in OnURLFetchComplete() to decide if | 510 // Set by the test. Used in OnURLFetchComplete() to decide if |
511 // the URLFetcher should own the temp file, so that we can test | 511 // the URLFetcher should own the temp file, so that we can test |
512 // disowning prevents the file from being deleted. | 512 // disowning prevents the file from being deleted. |
513 bool take_ownership_of_file_; | 513 bool take_ownership_of_file_; |
514 | 514 |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 | 1529 |
1530 base::MessageLoop::current()->RunUntilIdle(); | 1530 base::MessageLoop::current()->RunUntilIdle(); |
1531 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << | 1531 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << |
1532 "FilePath: " << file_path_.value(); | 1532 "FilePath: " << file_path_.value(); |
1533 } | 1533 } |
1534 } | 1534 } |
1535 | 1535 |
1536 } // namespace | 1536 } // namespace |
1537 | 1537 |
1538 } // namespace net | 1538 } // namespace net |
OLD | NEW |