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

Side by Side Diff: content/common/net/url_fetcher_impl_unittest.cc

Issue 10412050: Change most content::URLFetcher references to net::URLFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ChromeOS, address comments Created 8 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
« no previous file with comments | « content/common/net/url_fetcher_impl.cc ('k') | content/public/common/url_fetcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/common/net/url_fetcher_impl.h" 5 #include "content/common/net/url_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // dispatches its requests to. When we wish to simulate being used from 119 // dispatches its requests to. When we wish to simulate being used from
120 // a UI thread, we dispatch a worker thread to do so. 120 // a UI thread, we dispatch a worker thread to do so.
121 MessageLoopForIO io_loop_; 121 MessageLoopForIO io_loop_;
122 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 122 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
123 123
124 URLFetcherImpl* fetcher_; 124 URLFetcherImpl* fetcher_;
125 const scoped_ptr<TestURLRequestContext> context_; 125 const scoped_ptr<TestURLRequestContext> context_;
126 }; 126 };
127 127
128 void URLFetcherTest::CreateFetcher(const GURL& url) { 128 void URLFetcherTest::CreateFetcher(const GURL& url) {
129 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 129 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this);
130 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 130 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
131 io_message_loop_proxy(), request_context())); 131 io_message_loop_proxy(), request_context()));
132 fetcher_->Start(); 132 fetcher_->Start();
133 } 133 }
134 134
135 void URLFetcherTest::OnURLFetchComplete(const net::URLFetcher* source) { 135 void URLFetcherTest::OnURLFetchComplete(const net::URLFetcher* source) {
136 EXPECT_TRUE(source->GetStatus().is_success()); 136 EXPECT_TRUE(source->GetStatus().is_success());
137 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK 137 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK
138 138
139 std::string data; 139 std::string data;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // the URLFetcher should own the temp file, so that we can test 357 // the URLFetcher should own the temp file, so that we can test
358 // disowning prevents the file from being deleted. 358 // disowning prevents the file from being deleted.
359 bool take_ownership_of_file_; 359 bool take_ownership_of_file_;
360 360
361 // Expected file error code for the test. 361 // Expected file error code for the test.
362 // PLATFORM_FILE_OK when expecting success. 362 // PLATFORM_FILE_OK when expecting success.
363 base::PlatformFileError expected_file_error_; 363 base::PlatformFileError expected_file_error_;
364 }; 364 };
365 365
366 void URLFetcherPostTest::CreateFetcher(const GURL& url) { 366 void URLFetcherPostTest::CreateFetcher(const GURL& url) {
367 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this); 367 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::POST, this);
368 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 368 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
369 io_message_loop_proxy(), request_context())); 369 io_message_loop_proxy(), request_context()));
370 fetcher_->SetUploadData("application/x-www-form-urlencoded", 370 fetcher_->SetUploadData("application/x-www-form-urlencoded",
371 "bobsyeruncle"); 371 "bobsyeruncle");
372 fetcher_->Start(); 372 fetcher_->Start();
373 } 373 }
374 374
375 void URLFetcherPostTest::OnURLFetchComplete(const net::URLFetcher* source) { 375 void URLFetcherPostTest::OnURLFetchComplete(const net::URLFetcher* source) {
376 std::string data; 376 std::string data;
377 EXPECT_TRUE(source->GetResponseAsString(&data)); 377 EXPECT_TRUE(source->GetResponseAsString(&data));
378 EXPECT_EQ(std::string("bobsyeruncle"), data); 378 EXPECT_EQ(std::string("bobsyeruncle"), data);
379 URLFetcherTest::OnURLFetchComplete(source); 379 URLFetcherTest::OnURLFetchComplete(source);
380 } 380 }
381 381
382 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { 382 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) {
383 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 383 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this);
384 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 384 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
385 io_message_loop_proxy(), request_context())); 385 io_message_loop_proxy(), request_context()));
386 previous_progress_ = 0; 386 previous_progress_ = 0;
387 fetcher_->Start(); 387 fetcher_->Start();
388 } 388 }
389 389
390 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( 390 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress(
391 const net::URLFetcher* source, int64 current, int64 total) { 391 const net::URLFetcher* source, int64 current, int64 total) {
392 // Increasing between 0 and total. 392 // Increasing between 0 and total.
393 EXPECT_LE(0, current); 393 EXPECT_LE(0, current);
394 EXPECT_GE(total, current); 394 EXPECT_GE(total, current);
395 EXPECT_LE(previous_progress_, current); 395 EXPECT_LE(previous_progress_, current);
396 previous_progress_ = current; 396 previous_progress_ = current;
397 EXPECT_EQ(expected_total_, total); 397 EXPECT_EQ(expected_total_, total);
398 } 398 }
399 399
400 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { 400 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) {
401 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 401 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this);
402 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 402 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
403 io_message_loop_proxy(), request_context())); 403 io_message_loop_proxy(), request_context()));
404 cancelled_ = false; 404 cancelled_ = false;
405 fetcher_->Start(); 405 fetcher_->Start();
406 } 406 }
407 407
408 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( 408 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress(
409 const net::URLFetcher* source, int64 current, int64 total) { 409 const net::URLFetcher* source, int64 current, int64 total) {
410 EXPECT_FALSE(cancelled_); 410 EXPECT_FALSE(cancelled_);
411 if (!cancelled_) { 411 if (!cancelled_) {
412 delete fetcher_; 412 delete fetcher_;
413 cancelled_ = true; 413 cancelled_ = true;
414 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 414 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
415 } 415 }
416 } 416 }
417 417
418 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( 418 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete(
419 const net::URLFetcher* source) { 419 const net::URLFetcher* source) {
420 // Should have been cancelled. 420 // Should have been cancelled.
421 ADD_FAILURE(); 421 ADD_FAILURE();
422 delete fetcher_; 422 delete fetcher_;
423 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 423 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
424 } 424 }
425 425
426 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { 426 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) {
427 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this); 427 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::POST, this);
428 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 428 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
429 io_message_loop_proxy(), request_context())); 429 io_message_loop_proxy(), request_context()));
430 previous_progress_ = 0; 430 previous_progress_ = 0;
431 // Large enough data to require more than one read from UploadDataStream. 431 // Large enough data to require more than one read from UploadDataStream.
432 chunk_.assign(1<<16, 'a'); 432 chunk_.assign(1<<16, 'a');
433 // Use chunked upload to wait for a timer event of progress notification. 433 // Use chunked upload to wait for a timer event of progress notification.
434 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); 434 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded");
435 fetcher_->Start(); 435 fetcher_->Start();
436 number_of_chunks_added_ = 1; 436 number_of_chunks_added_ = 1;
437 fetcher_->AppendChunkToUpload(chunk_, false); 437 fetcher_->AppendChunkToUpload(chunk_, false);
(...skipping 25 matching lines...) Expand all
463 } 463 }
464 464
465 void URLFetcherSocketAddressTest::OnURLFetchComplete( 465 void URLFetcherSocketAddressTest::OnURLFetchComplete(
466 const net::URLFetcher* source) { 466 const net::URLFetcher* source) {
467 EXPECT_EQ("127.0.0.1", source->GetSocketAddress().host()); 467 EXPECT_EQ("127.0.0.1", source->GetSocketAddress().host());
468 EXPECT_EQ(expected_port_, source->GetSocketAddress().port()); 468 EXPECT_EQ(expected_port_, source->GetSocketAddress().port());
469 URLFetcherTest::OnURLFetchComplete(source); 469 URLFetcherTest::OnURLFetchComplete(source);
470 } 470 }
471 471
472 void URLFetcherProtectTest::CreateFetcher(const GURL& url) { 472 void URLFetcherProtectTest::CreateFetcher(const GURL& url) {
473 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 473 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this);
474 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 474 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
475 io_message_loop_proxy(), request_context())); 475 io_message_loop_proxy(), request_context()));
476 start_time_ = Time::Now(); 476 start_time_ = Time::Now();
477 fetcher_->SetMaxRetries(11); 477 fetcher_->SetMaxRetries(11);
478 fetcher_->Start(); 478 fetcher_->Start();
479 } 479 }
480 480
481 void URLFetcherProtectTest::OnURLFetchComplete( 481 void URLFetcherProtectTest::OnURLFetchComplete(
482 const net::URLFetcher* source) { 482 const net::URLFetcher* source) {
483 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000); 483 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000);
(...skipping 19 matching lines...) Expand all
503 } else { 503 } else {
504 // We have already sent 20 requests continuously. And we expect that 504 // We have already sent 20 requests continuously. And we expect that
505 // it takes more than 1 second due to the overload protection settings. 505 // it takes more than 1 second due to the overload protection settings.
506 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); 506 EXPECT_TRUE(Time::Now() - start_time_ >= one_second);
507 URLFetcherTest::OnURLFetchComplete(source); 507 URLFetcherTest::OnURLFetchComplete(source);
508 } 508 }
509 } 509 }
510 } 510 }
511 511
512 void URLFetcherProtectTestPassedThrough::CreateFetcher(const GURL& url) { 512 void URLFetcherProtectTestPassedThrough::CreateFetcher(const GURL& url) {
513 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 513 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this);
514 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 514 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
515 io_message_loop_proxy(), request_context())); 515 io_message_loop_proxy(), request_context()));
516 fetcher_->SetAutomaticallyRetryOn5xx(false); 516 fetcher_->SetAutomaticallyRetryOn5xx(false);
517 start_time_ = Time::Now(); 517 start_time_ = Time::Now();
518 fetcher_->SetMaxRetries(11); 518 fetcher_->SetMaxRetries(11);
519 fetcher_->Start(); 519 fetcher_->Start();
520 } 520 }
521 521
522 void URLFetcherProtectTestPassedThrough::OnURLFetchComplete( 522 void URLFetcherProtectTestPassedThrough::OnURLFetchComplete(
523 const net::URLFetcher* source) { 523 const net::URLFetcher* source) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 std::string data; 566 std::string data;
567 EXPECT_TRUE(source->GetResponseAsString(&data)); 567 EXPECT_TRUE(source->GetResponseAsString(&data));
568 EXPECT_TRUE(data.empty()); 568 EXPECT_TRUE(data.empty());
569 569
570 // The rest is the same as URLFetcherTest::OnURLFetchComplete. 570 // The rest is the same as URLFetcherTest::OnURLFetchComplete.
571 delete fetcher_; 571 delete fetcher_;
572 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 572 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
573 } 573 }
574 574
575 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { 575 void URLFetcherCancelTest::CreateFetcher(const GURL& url) {
576 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 576 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this);
577 CancelTestURLRequestContextGetter* context_getter = 577 CancelTestURLRequestContextGetter* context_getter =
578 new CancelTestURLRequestContextGetter(io_message_loop_proxy(), 578 new CancelTestURLRequestContextGetter(io_message_loop_proxy(),
579 url); 579 url);
580 fetcher_->SetRequestContext(context_getter); 580 fetcher_->SetRequestContext(context_getter);
581 fetcher_->SetMaxRetries(2); 581 fetcher_->SetMaxRetries(2);
582 fetcher_->Start(); 582 fetcher_->Start();
583 // We need to wait for the creation of the net::URLRequestContext, since we 583 // We need to wait for the creation of the net::URLRequestContext, since we
584 // rely on it being destroyed as a signal to end the test. 584 // rely on it being destroyed as a signal to end the test.
585 context_getter->WaitForContextCreation(); 585 context_getter->WaitForContextCreation();
586 CancelRequest(); 586 CancelRequest();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 // same thread that CreateFetcher() did. 620 // same thread that CreateFetcher() did.
621 621
622 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 622 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
623 // If the current message loop is not the IO loop, it will be shut down when 623 // If the current message loop is not the IO loop, it will be shut down when
624 // the main loop returns and this thread subsequently goes out of scope. 624 // the main loop returns and this thread subsequently goes out of scope.
625 } 625 }
626 } 626 }
627 627
628 void URLFetcherFileTest::CreateFetcherForFile(const GURL& url, 628 void URLFetcherFileTest::CreateFetcherForFile(const GURL& url,
629 const FilePath& file_path) { 629 const FilePath& file_path) {
630 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 630 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this);
631 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 631 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
632 io_message_loop_proxy(), request_context())); 632 io_message_loop_proxy(), request_context()));
633 633
634 // Use the IO message loop to do the file operations in this test. 634 // Use the IO message loop to do the file operations in this test.
635 fetcher_->SaveResponseToFileAtPath(file_path, io_message_loop_proxy()); 635 fetcher_->SaveResponseToFileAtPath(file_path, io_message_loop_proxy());
636 fetcher_->Start(); 636 fetcher_->Start();
637 } 637 }
638 638
639 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) { 639 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) {
640 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 640 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this);
641 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 641 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
642 io_message_loop_proxy(), request_context())); 642 io_message_loop_proxy(), request_context()));
643 643
644 // Use the IO message loop to do the file operations in this test. 644 // Use the IO message loop to do the file operations in this test.
645 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); 645 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy());
646 fetcher_->Start(); 646 fetcher_->Start();
647 } 647 }
648 648
649 void URLFetcherFileTest::OnURLFetchComplete(const net::URLFetcher* source) { 649 void URLFetcherFileTest::OnURLFetchComplete(const net::URLFetcher* source) {
650 if (expected_file_error_ == base::PLATFORM_FILE_OK) { 650 if (expected_file_error_ == base::PLATFORM_FILE_OK) {
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 std::string(kTestServerFilePrefix) + kFileToFetch)); 1146 std::string(kTestServerFilePrefix) + kFileToFetch));
1147 1147
1148 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1148 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1149 1149
1150 MessageLoop::current()->RunAllPending(); 1150 MessageLoop::current()->RunAllPending();
1151 ASSERT_FALSE(file_util::PathExists(file_path_)) 1151 ASSERT_FALSE(file_util::PathExists(file_path_))
1152 << file_path_.value() << " not removed."; 1152 << file_path_.value() << " not removed.";
1153 } 1153 }
1154 1154
1155 } // namespace. 1155 } // namespace.
OLDNEW
« no previous file with comments | « content/common/net/url_fetcher_impl.cc ('k') | content/public/common/url_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698