Chromium Code Reviews| 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 "content/common/net/url_fetcher_impl.h" | 5 #include "content/common/net/url_fetcher_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 std::string data; | 454 std::string data; |
| 455 EXPECT_TRUE(source->GetResponseAsString(&data)); | 455 EXPECT_TRUE(source->GetResponseAsString(&data)); |
| 456 EXPECT_FALSE(data.empty()); | 456 EXPECT_FALSE(data.empty()); |
| 457 delete fetcher_; | 457 delete fetcher_; |
| 458 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 458 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 459 } else { | 459 } else { |
| 460 // Now running Overload test. | 460 // Now running Overload test. |
| 461 static int count = 0; | 461 static int count = 0; |
| 462 count++; | 462 count++; |
| 463 if (count < 20) { | 463 if (count < 20) { |
| 464 fetcher_->StartWithRequestContextGetter(new TestURLRequestContextGetter( | 464 fetcher_->SetRequestContext( |
| 465 io_message_loop_proxy())); | 465 new TestURLRequestContextGetter(io_message_loop_proxy())); |
| 466 fetcher_->Start(); | |
| 466 } else { | 467 } else { |
| 467 // We have already sent 20 requests continuously. And we expect that | 468 // We have already sent 20 requests continuously. And we expect that |
| 468 // it takes more than 1 second due to the overload protection settings. | 469 // it takes more than 1 second due to the overload protection settings. |
| 469 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); | 470 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); |
| 470 URLFetcherTest::OnURLFetchComplete(source); | 471 URLFetcherTest::OnURLFetchComplete(source); |
| 471 } | 472 } |
| 472 } | 473 } |
| 473 } | 474 } |
| 474 | 475 |
| 475 void URLFetcherProtectTestPassedThrough::CreateFetcher(const GURL& url) { | 476 void URLFetcherProtectTestPassedThrough::CreateFetcher(const GURL& url) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 | 566 |
| 566 void URLFetcherMultipleAttemptTest::OnURLFetchComplete( | 567 void URLFetcherMultipleAttemptTest::OnURLFetchComplete( |
| 567 const content::URLFetcher* source) { | 568 const content::URLFetcher* source) { |
| 568 EXPECT_TRUE(source->GetStatus().is_success()); | 569 EXPECT_TRUE(source->GetStatus().is_success()); |
| 569 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK | 570 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK |
| 570 std::string data; | 571 std::string data; |
| 571 EXPECT_TRUE(source->GetResponseAsString(&data)); | 572 EXPECT_TRUE(source->GetResponseAsString(&data)); |
| 572 EXPECT_FALSE(data.empty()); | 573 EXPECT_FALSE(data.empty()); |
| 573 if (!data.empty() && data_.empty()) { | 574 if (!data.empty() && data_.empty()) { |
| 574 data_ = data; | 575 data_ = data; |
| 575 fetcher_->StartWithRequestContextGetter( | 576 fetcher_->SetRequestContext( |
|
willchan no longer on Chromium
2012/03/06 02:59:01
Why did this change? OIC, they're functionally equ
| |
| 576 new TestURLRequestContextGetter(io_message_loop_proxy())); | 577 new TestURLRequestContextGetter(io_message_loop_proxy())); |
| 578 fetcher_->Start(); | |
| 577 } else { | 579 } else { |
| 578 EXPECT_EQ(data, data_); | 580 EXPECT_EQ(data, data_); |
| 579 delete fetcher_; // Have to delete this here and not in the destructor, | 581 delete fetcher_; // Have to delete this here and not in the destructor, |
| 580 // because the destructor won't necessarily run on the | 582 // because the destructor won't necessarily run on the |
| 581 // same thread that CreateFetcher() did. | 583 // same thread that CreateFetcher() did. |
| 582 | 584 |
| 583 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 585 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 584 // If the current message loop is not the IO loop, it will be shut down when | 586 // If the current message loop is not the IO loop, it will be shut down when |
| 585 // the main loop returns and this thread subsequently goes out of scope. | 587 // the main loop returns and this thread subsequently goes out of scope. |
| 586 } | 588 } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 io_message_loop_proxy()->PostTaskAndReply( | 915 io_message_loop_proxy()->PostTaskAndReply( |
| 914 FROM_HERE, | 916 FROM_HERE, |
| 915 base::Bind(&CancelAllOnIO), | 917 base::Bind(&CancelAllOnIO), |
| 916 MessageLoop::QuitClosure()); | 918 MessageLoop::QuitClosure()); |
| 917 MessageLoop::current()->Run(); | 919 MessageLoop::current()->Run(); |
| 918 EXPECT_EQ(0, GetNumFetcherCores()); | 920 EXPECT_EQ(0, GetNumFetcherCores()); |
| 919 delete fetcher_; | 921 delete fetcher_; |
| 920 } | 922 } |
| 921 | 923 |
| 922 } // namespace. | 924 } // namespace. |
| OLD | NEW |