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 TestURLRequestContext* GetURLRequestContext() override { return context_; } |
71 return context_; | |
72 } | |
73 | 71 |
74 protected: | 72 protected: |
75 virtual ~ThrottlingTestURLRequestContextGetter() {} | 73 ~ThrottlingTestURLRequestContextGetter() override {} |
76 | 74 |
77 TestURLRequestContext* const context_; | 75 TestURLRequestContext* const context_; |
78 }; | 76 }; |
79 | 77 |
80 } // namespace | 78 } // namespace |
81 | 79 |
82 class URLFetcherTest : public testing::Test, | 80 class URLFetcherTest : public testing::Test, |
83 public URLFetcherDelegate { | 81 public URLFetcherDelegate { |
84 public: | 82 public: |
85 URLFetcherTest() : fetcher_(NULL) {} | 83 URLFetcherTest() : fetcher_(NULL) {} |
86 | 84 |
87 static int GetNumFetcherCores() { | 85 static int GetNumFetcherCores() { |
88 return URLFetcherImpl::GetNumFetcherCores(); | 86 return URLFetcherImpl::GetNumFetcherCores(); |
89 } | 87 } |
90 | 88 |
91 // Creates a URLFetcher, using the program's main thread to do IO. | 89 // Creates a URLFetcher, using the program's main thread to do IO. |
92 virtual void CreateFetcher(const GURL& url); | 90 virtual void CreateFetcher(const GURL& url); |
93 | 91 |
94 // URLFetcherDelegate: | 92 // URLFetcherDelegate: |
95 // Subclasses that override this should either call this function or | 93 // Subclasses that override this should either call this function or |
96 // CleanupAfterFetchComplete() at the end of their processing, depending on | 94 // CleanupAfterFetchComplete() at the end of their processing, depending on |
97 // whether they want to check for a non-empty HTTP 200 response or not. | 95 // whether they want to check for a non-empty HTTP 200 response or not. |
98 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 96 void OnURLFetchComplete(const URLFetcher* source) override; |
99 | 97 |
100 // Deletes |fetcher| and terminates the message loop. | 98 // Deletes |fetcher| and terminates the message loop. |
101 void CleanupAfterFetchComplete(); | 99 void CleanupAfterFetchComplete(); |
102 | 100 |
103 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { | 101 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { |
104 return io_message_loop_proxy_; | 102 return io_message_loop_proxy_; |
105 } | 103 } |
106 | 104 |
107 TestURLRequestContext* request_context() { | 105 TestURLRequestContext* request_context() { |
108 return context_.get(); | 106 return context_.get(); |
(...skipping 30 matching lines...) Expand all Loading... |
139 }; | 137 }; |
140 | 138 |
141 // A test fixture that uses a MockHostResolver, so that name resolutions can | 139 // 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. | 140 // be manipulated by the tests to keep connections in the resolving state. |
143 class URLFetcherMockDnsTest : public URLFetcherTest { | 141 class URLFetcherMockDnsTest : public URLFetcherTest { |
144 public: | 142 public: |
145 // testing::Test: | 143 // testing::Test: |
146 virtual void SetUp() override; | 144 virtual void SetUp() override; |
147 | 145 |
148 // URLFetcherTest: | 146 // URLFetcherTest: |
149 virtual void CreateFetcher(const GURL& url) override; | 147 void CreateFetcher(const GURL& url) override; |
150 | 148 |
151 // URLFetcherDelegate: | 149 // URLFetcherDelegate: |
152 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 150 void OnURLFetchComplete(const URLFetcher* source) override; |
153 | 151 |
154 protected: | 152 protected: |
155 GURL test_url_; | 153 GURL test_url_; |
156 scoped_ptr<SpawnedTestServer> test_server_; | 154 scoped_ptr<SpawnedTestServer> test_server_; |
157 MockHostResolver resolver_; | 155 MockHostResolver resolver_; |
158 scoped_ptr<URLFetcher> completed_fetcher_; | 156 scoped_ptr<URLFetcher> completed_fetcher_; |
159 }; | 157 }; |
160 | 158 |
161 void URLFetcherTest::CreateFetcher(const GURL& url) { | 159 void URLFetcherTest::CreateFetcher(const GURL& url) { |
162 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 160 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()); | 222 EXPECT_EQ(test_url_, source->GetOriginalURL()); |
225 completed_fetcher_.reset(fetcher_); | 223 completed_fetcher_.reset(fetcher_); |
226 } | 224 } |
227 | 225 |
228 namespace { | 226 namespace { |
229 | 227 |
230 // Version of URLFetcherTest that does a POST instead | 228 // Version of URLFetcherTest that does a POST instead |
231 class URLFetcherPostTest : public URLFetcherTest { | 229 class URLFetcherPostTest : public URLFetcherTest { |
232 public: | 230 public: |
233 // URLFetcherTest: | 231 // URLFetcherTest: |
234 virtual void CreateFetcher(const GURL& url) override; | 232 void CreateFetcher(const GURL& url) override; |
235 | 233 |
236 // URLFetcherDelegate: | 234 // URLFetcherDelegate: |
237 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 235 void OnURLFetchComplete(const URLFetcher* source) override; |
238 }; | 236 }; |
239 | 237 |
240 // Version of URLFetcherTest that does a POST of a file using | 238 // Version of URLFetcherTest that does a POST of a file using |
241 // SetUploadDataStream | 239 // SetUploadDataStream |
242 class URLFetcherPostFileTest : public URLFetcherTest { | 240 class URLFetcherPostFileTest : public URLFetcherTest { |
243 public: | 241 public: |
244 URLFetcherPostFileTest(); | 242 URLFetcherPostFileTest(); |
245 | 243 |
246 void SetUploadRange(uint64 range_offset, uint64 range_length) { | 244 void SetUploadRange(uint64 range_offset, uint64 range_length) { |
247 range_offset_ = range_offset; | 245 range_offset_ = range_offset; |
248 range_length_ = range_length; | 246 range_length_ = range_length; |
249 } | 247 } |
250 | 248 |
251 // URLFetcherTest: | 249 // URLFetcherTest: |
252 virtual void CreateFetcher(const GURL& url) override; | 250 void CreateFetcher(const GURL& url) override; |
253 | 251 |
254 // URLFetcherDelegate: | 252 // URLFetcherDelegate: |
255 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 253 void OnURLFetchComplete(const URLFetcher* source) override; |
256 | 254 |
257 private: | 255 private: |
258 base::FilePath path_; | 256 base::FilePath path_; |
259 uint64 range_offset_; | 257 uint64 range_offset_; |
260 uint64 range_length_; | 258 uint64 range_length_; |
261 }; | 259 }; |
262 | 260 |
263 // Version of URLFetcherTest that does a POST instead with empty upload body | 261 // Version of URLFetcherTest that does a POST instead with empty upload body |
264 class URLFetcherEmptyPostTest : public URLFetcherTest { | 262 class URLFetcherEmptyPostTest : public URLFetcherTest { |
265 public: | 263 public: |
266 // URLFetcherTest: | 264 // URLFetcherTest: |
267 virtual void CreateFetcher(const GURL& url) override; | 265 void CreateFetcher(const GURL& url) override; |
268 | 266 |
269 // URLFetcherDelegate: | 267 // URLFetcherDelegate: |
270 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 268 void OnURLFetchComplete(const URLFetcher* source) override; |
271 }; | 269 }; |
272 | 270 |
273 // Version of URLFetcherTest that tests download progress reports. | 271 // Version of URLFetcherTest that tests download progress reports. |
274 class URLFetcherDownloadProgressTest : public URLFetcherTest { | 272 class URLFetcherDownloadProgressTest : public URLFetcherTest { |
275 public: | 273 public: |
276 URLFetcherDownloadProgressTest() | 274 URLFetcherDownloadProgressTest() |
277 : previous_progress_(0), | 275 : previous_progress_(0), |
278 expected_total_(0) { | 276 expected_total_(0) { |
279 } | 277 } |
280 | 278 |
281 // URLFetcherTest: | 279 // URLFetcherTest: |
282 virtual void CreateFetcher(const GURL& url) override; | 280 void CreateFetcher(const GURL& url) override; |
283 | 281 |
284 // URLFetcherDelegate: | 282 // URLFetcherDelegate: |
285 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, | 283 void OnURLFetchDownloadProgress(const URLFetcher* source, |
286 int64 current, | 284 int64 current, |
287 int64 total) override; | 285 int64 total) override; |
288 | 286 |
289 protected: | 287 protected: |
290 // Download progress returned by the previous callback. | 288 // Download progress returned by the previous callback. |
291 int64 previous_progress_; | 289 int64 previous_progress_; |
292 // Size of the file being downloaded, known in advance (provided by each test | 290 // Size of the file being downloaded, known in advance (provided by each test |
293 // case). | 291 // case). |
294 int64 expected_total_; | 292 int64 expected_total_; |
295 }; | 293 }; |
296 | 294 |
297 // Version of URLFetcherTest that tests progress reports at cancellation. | 295 // Version of URLFetcherTest that tests progress reports at cancellation. |
298 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { | 296 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { |
299 public: | 297 public: |
300 // URLFetcherTest: | 298 // URLFetcherTest: |
301 virtual void CreateFetcher(const GURL& url) override; | 299 void CreateFetcher(const GURL& url) override; |
302 | 300 |
303 // URLFetcherDelegate: | 301 // URLFetcherDelegate: |
304 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 302 void OnURLFetchComplete(const URLFetcher* source) override; |
305 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, | 303 void OnURLFetchDownloadProgress(const URLFetcher* source, |
306 int64 current, | 304 int64 current, |
307 int64 total) override; | 305 int64 total) override; |
| 306 |
308 protected: | 307 protected: |
309 bool cancelled_; | 308 bool cancelled_; |
310 }; | 309 }; |
311 | 310 |
312 // Version of URLFetcherTest that tests upload progress reports. | 311 // Version of URLFetcherTest that tests upload progress reports. |
313 class URLFetcherUploadProgressTest : public URLFetcherTest { | 312 class URLFetcherUploadProgressTest : public URLFetcherTest { |
314 public: | 313 public: |
315 // URLFetcherTest: | 314 // URLFetcherTest: |
316 virtual void CreateFetcher(const GURL& url) override; | 315 void CreateFetcher(const GURL& url) override; |
317 | 316 |
318 // URLFetcherDelegate: | 317 // URLFetcherDelegate: |
319 virtual void OnURLFetchUploadProgress(const URLFetcher* source, | 318 void OnURLFetchUploadProgress(const URLFetcher* source, |
320 int64 current, | 319 int64 current, |
321 int64 total) override; | 320 int64 total) override; |
| 321 |
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 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 void OnURLFetchComplete(const URLFetcher* source) override; |
| 340 |
340 protected: | 341 protected: |
341 std::string expected_host_; | 342 std::string expected_host_; |
342 uint16 expected_port_; | 343 uint16 expected_port_; |
343 }; | 344 }; |
344 | 345 |
345 // Version of URLFetcherTest that tests stopping on a redirect. | 346 // Version of URLFetcherTest that tests stopping on a redirect. |
346 class URLFetcherStopOnRedirectTest : public URLFetcherTest { | 347 class URLFetcherStopOnRedirectTest : public URLFetcherTest { |
347 public: | 348 public: |
348 URLFetcherStopOnRedirectTest(); | 349 URLFetcherStopOnRedirectTest(); |
349 virtual ~URLFetcherStopOnRedirectTest(); | 350 virtual ~URLFetcherStopOnRedirectTest(); |
350 | 351 |
351 // URLFetcherTest: | 352 // URLFetcherTest: |
352 virtual void CreateFetcher(const GURL& url) override; | 353 void CreateFetcher(const GURL& url) override; |
353 | 354 |
354 // URLFetcherDelegate: | 355 // URLFetcherDelegate: |
355 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 356 void OnURLFetchComplete(const URLFetcher* source) override; |
356 | 357 |
357 protected: | 358 protected: |
358 // The URL we should be redirected to. | 359 // The URL we should be redirected to. |
359 static const char* kRedirectTarget; | 360 static const char* kRedirectTarget; |
360 | 361 |
361 bool callback_called_; // Set to true in OnURLFetchComplete(). | 362 bool callback_called_; // Set to true in OnURLFetchComplete(). |
362 }; | 363 }; |
363 | 364 |
364 // Version of URLFetcherTest that tests overload protection. | 365 // Version of URLFetcherTest that tests overload protection. |
365 class URLFetcherProtectTest : public URLFetcherTest { | 366 class URLFetcherProtectTest : public URLFetcherTest { |
366 public: | 367 public: |
367 // URLFetcherTest: | 368 // URLFetcherTest: |
368 virtual void CreateFetcher(const GURL& url) override; | 369 void CreateFetcher(const GURL& url) override; |
369 | 370 |
370 // URLFetcherDelegate: | 371 // URLFetcherDelegate: |
371 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 372 void OnURLFetchComplete(const URLFetcher* source) override; |
| 373 |
372 private: | 374 private: |
373 Time start_time_; | 375 Time start_time_; |
374 }; | 376 }; |
375 | 377 |
376 // Version of URLFetcherTest that tests overload protection, when responses | 378 // Version of URLFetcherTest that tests overload protection, when responses |
377 // passed through. | 379 // passed through. |
378 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { | 380 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { |
379 public: | 381 public: |
380 // URLFetcherTest: | 382 // URLFetcherTest: |
381 virtual void CreateFetcher(const GURL& url) override; | 383 void CreateFetcher(const GURL& url) override; |
382 | 384 |
383 // URLFetcherDelegate: | 385 // URLFetcherDelegate: |
384 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 386 void OnURLFetchComplete(const URLFetcher* source) override; |
| 387 |
385 private: | 388 private: |
386 Time start_time_; | 389 Time start_time_; |
387 }; | 390 }; |
388 | 391 |
389 // Version of URLFetcherTest that tests bad HTTPS requests. | 392 // Version of URLFetcherTest that tests bad HTTPS requests. |
390 class URLFetcherBadHTTPSTest : public URLFetcherTest { | 393 class URLFetcherBadHTTPSTest : public URLFetcherTest { |
391 public: | 394 public: |
392 URLFetcherBadHTTPSTest(); | 395 URLFetcherBadHTTPSTest(); |
393 | 396 |
394 // URLFetcherDelegate: | 397 // URLFetcherDelegate: |
395 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 398 void OnURLFetchComplete(const URLFetcher* source) override; |
396 | 399 |
397 private: | 400 private: |
398 base::FilePath cert_dir_; | 401 base::FilePath cert_dir_; |
399 }; | 402 }; |
400 | 403 |
401 // Version of URLFetcherTest that tests request cancellation on shutdown. | 404 // Version of URLFetcherTest that tests request cancellation on shutdown. |
402 class URLFetcherCancelTest : public URLFetcherTest { | 405 class URLFetcherCancelTest : public URLFetcherTest { |
403 public: | 406 public: |
404 // URLFetcherTest: | 407 // URLFetcherTest: |
405 virtual void CreateFetcher(const GURL& url) override; | 408 void CreateFetcher(const GURL& url) override; |
406 | 409 |
407 // URLFetcherDelegate: | 410 // URLFetcherDelegate: |
408 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 411 void OnURLFetchComplete(const URLFetcher* source) override; |
409 | 412 |
410 void CancelRequest(); | 413 void CancelRequest(); |
411 }; | 414 }; |
412 | 415 |
413 // Version of TestURLRequestContext that posts a Quit task to the IO | 416 // Version of TestURLRequestContext that posts a Quit task to the IO |
414 // thread once it is deleted. | 417 // thread once it is deleted. |
415 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { | 418 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { |
416 public: | 419 public: |
417 explicit CancelTestURLRequestContext() { | 420 explicit CancelTestURLRequestContext() { |
418 } | 421 } |
419 | 422 |
420 private: | 423 private: |
421 virtual ~CancelTestURLRequestContext() { | 424 ~CancelTestURLRequestContext() override { |
422 // The d'tor should execute in the IO thread. Post the quit task to the | 425 // The d'tor should execute in the IO thread. Post the quit task to the |
423 // current thread. | 426 // current thread. |
424 base::MessageLoop::current()->PostTask(FROM_HERE, | 427 base::MessageLoop::current()->PostTask(FROM_HERE, |
425 base::MessageLoop::QuitClosure()); | 428 base::MessageLoop::QuitClosure()); |
426 } | 429 } |
427 }; | 430 }; |
428 | 431 |
429 class CancelTestURLRequestContextGetter | 432 class CancelTestURLRequestContextGetter |
430 : public TestURLRequestContextGetter { | 433 : public TestURLRequestContextGetter { |
431 public: | 434 public: |
432 CancelTestURLRequestContextGetter( | 435 CancelTestURLRequestContextGetter( |
433 base::MessageLoopProxy* io_message_loop_proxy, | 436 base::MessageLoopProxy* io_message_loop_proxy, |
434 const GURL& throttle_for_url) | 437 const GURL& throttle_for_url) |
435 : TestURLRequestContextGetter(io_message_loop_proxy), | 438 : TestURLRequestContextGetter(io_message_loop_proxy), |
436 io_message_loop_proxy_(io_message_loop_proxy), | 439 io_message_loop_proxy_(io_message_loop_proxy), |
437 context_created_(false, false), | 440 context_created_(false, false), |
438 throttle_for_url_(throttle_for_url) { | 441 throttle_for_url_(throttle_for_url) { |
439 } | 442 } |
440 | 443 |
441 // TestURLRequestContextGetter: | 444 // TestURLRequestContextGetter: |
442 virtual TestURLRequestContext* GetURLRequestContext() override { | 445 TestURLRequestContext* GetURLRequestContext() override { |
443 if (!context_.get()) { | 446 if (!context_.get()) { |
444 context_.reset(new CancelTestURLRequestContext()); | 447 context_.reset(new CancelTestURLRequestContext()); |
445 DCHECK(context_->throttler_manager()); | 448 DCHECK(context_->throttler_manager()); |
446 | 449 |
447 // Registers an entry for test url. The backoff time is calculated by: | 450 // Registers an entry for test url. The backoff time is calculated by: |
448 // new_backoff = 2.0 * old_backoff + 0 | 451 // new_backoff = 2.0 * old_backoff + 0 |
449 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. | 452 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. |
450 // Maximum retries allowed is set to 2. | 453 // Maximum retries allowed is set to 2. |
451 scoped_refptr<URLRequestThrottlerEntry> entry( | 454 scoped_refptr<URLRequestThrottlerEntry> entry( |
452 new URLRequestThrottlerEntry(context_->throttler_manager(), | 455 new URLRequestThrottlerEntry(context_->throttler_manager(), |
(...skipping 14 matching lines...) Expand all Loading... |
467 | 470 |
468 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | 471 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { |
469 return io_message_loop_proxy_; | 472 return io_message_loop_proxy_; |
470 } | 473 } |
471 | 474 |
472 void WaitForContextCreation() { | 475 void WaitForContextCreation() { |
473 context_created_.Wait(); | 476 context_created_.Wait(); |
474 } | 477 } |
475 | 478 |
476 protected: | 479 protected: |
477 virtual ~CancelTestURLRequestContextGetter() {} | 480 ~CancelTestURLRequestContextGetter() override {} |
478 | 481 |
479 private: | 482 private: |
480 scoped_ptr<TestURLRequestContext> context_; | 483 scoped_ptr<TestURLRequestContext> context_; |
481 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 484 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
482 base::WaitableEvent context_created_; | 485 base::WaitableEvent context_created_; |
483 GURL throttle_for_url_; | 486 GURL throttle_for_url_; |
484 }; | 487 }; |
485 | 488 |
486 // Version of URLFetcherTest that tests retying the same request twice. | 489 // Version of URLFetcherTest that tests retying the same request twice. |
487 class URLFetcherMultipleAttemptTest : public URLFetcherTest { | 490 class URLFetcherMultipleAttemptTest : public URLFetcherTest { |
488 public: | 491 public: |
489 // URLFetcherDelegate: | 492 // URLFetcherDelegate: |
490 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 493 void OnURLFetchComplete(const URLFetcher* source) override; |
| 494 |
491 private: | 495 private: |
492 std::string data_; | 496 std::string data_; |
493 }; | 497 }; |
494 | 498 |
495 class URLFetcherFileTest : public URLFetcherTest { | 499 class URLFetcherFileTest : public URLFetcherTest { |
496 public: | 500 public: |
497 URLFetcherFileTest() : take_ownership_of_file_(false), | 501 URLFetcherFileTest() : take_ownership_of_file_(false), |
498 expected_file_error_(OK) {} | 502 expected_file_error_(OK) {} |
499 | 503 |
500 void CreateFetcherForFile(const GURL& url, const base::FilePath& file_path); | 504 void CreateFetcherForFile(const GURL& url, const base::FilePath& file_path); |
501 void CreateFetcherForTempFile(const GURL& url); | 505 void CreateFetcherForTempFile(const GURL& url); |
502 | 506 |
503 // URLFetcherDelegate: | 507 // URLFetcherDelegate: |
504 virtual void OnURLFetchComplete(const URLFetcher* source) override; | 508 void OnURLFetchComplete(const URLFetcher* source) override; |
505 | 509 |
506 protected: | 510 protected: |
507 base::FilePath expected_file_; | 511 base::FilePath expected_file_; |
508 base::FilePath file_path_; | 512 base::FilePath file_path_; |
509 | 513 |
510 // Set by the test. Used in OnURLFetchComplete() to decide if | 514 // Set by the test. Used in OnURLFetchComplete() to decide if |
511 // the URLFetcher should own the temp file, so that we can test | 515 // the URLFetcher should own the temp file, so that we can test |
512 // disowning prevents the file from being deleted. | 516 // disowning prevents the file from being deleted. |
513 bool take_ownership_of_file_; | 517 bool take_ownership_of_file_; |
514 | 518 |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 | 1533 |
1530 base::MessageLoop::current()->RunUntilIdle(); | 1534 base::MessageLoop::current()->RunUntilIdle(); |
1531 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << | 1535 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << |
1532 "FilePath: " << file_path_.value(); | 1536 "FilePath: " << file_path_.value(); |
1533 } | 1537 } |
1534 } | 1538 } |
1535 | 1539 |
1536 } // namespace | 1540 } // namespace |
1537 | 1541 |
1538 } // namespace net | 1542 } // namespace net |
OLD | NEW |