Index: content/common/net/url_fetcher_impl_unittest.cc |
diff --git a/content/common/net/url_fetcher_impl_unittest.cc b/content/common/net/url_fetcher_impl_unittest.cc |
index 909bb6f0247c24a93797f79b0b55c9c8feb1e940..44d6e54591546af6e43e3fd64bb21b14bdd13c3c 100644 |
--- a/content/common/net/url_fetcher_impl_unittest.cc |
+++ b/content/common/net/url_fetcher_impl_unittest.cc |
@@ -295,69 +295,6 @@ class URLFetcherTempFileTest : public URLFetcherTest { |
bool take_ownership_of_temp_file_; |
}; |
-void URLFetcherTempFileTest::CreateFetcher(const GURL& url) { |
- fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); |
- fetcher_->SetRequestContext(new TestURLRequestContextGetter( |
- io_message_loop_proxy())); |
- |
- // Use the IO message loop to do the file operations in this test. |
- fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); |
- fetcher_->Start(); |
-} |
- |
-TEST_F(URLFetcherTempFileTest, SmallGet) { |
- net::TestServer test_server(net::TestServer::TYPE_HTTP, |
- net::TestServer::kLocalhost, |
- FilePath(kDocRoot)); |
- ASSERT_TRUE(test_server.Start()); |
- |
- // Get a small file. |
- static const char kFileToFetch[] = "simple.html"; |
- expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
- CreateFetcher( |
- test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
- |
- MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
- |
- ASSERT_FALSE(file_util::PathExists(temp_file_)) |
- << temp_file_.value() << " not removed."; |
-} |
- |
-TEST_F(URLFetcherTempFileTest, LargeGet) { |
- net::TestServer test_server(net::TestServer::TYPE_HTTP, |
- net::TestServer::kLocalhost, |
- FilePath(kDocRoot)); |
- ASSERT_TRUE(test_server.Start()); |
- |
- // Get a file large enough to require more than one read into |
- // URLFetcher::Core's IOBuffer. |
- static const char kFileToFetch[] = "animate1.gif"; |
- expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
- CreateFetcher(test_server.GetURL( |
- std::string(kTestServerFilePrefix) + kFileToFetch)); |
- |
- MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
-} |
- |
-TEST_F(URLFetcherTempFileTest, CanTakeOwnershipOfFile) { |
- net::TestServer test_server(net::TestServer::TYPE_HTTP, |
- net::TestServer::kLocalhost, |
- FilePath(kDocRoot)); |
- ASSERT_TRUE(test_server.Start()); |
- |
- // Get a small file. |
- static const char kFileToFetch[] = "simple.html"; |
- expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
- CreateFetcher(test_server.GetURL( |
- std::string(kTestServerFilePrefix) + kFileToFetch)); |
- |
- MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
- |
- MessageLoop::current()->RunAllPending(); |
- ASSERT_FALSE(file_util::PathExists(temp_file_)) |
- << temp_file_.value() << " not removed."; |
-} |
- |
void URLFetcherPostTest::CreateFetcher(const GURL& url) { |
fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this); |
fetcher_->SetRequestContext(new TestURLRequestContextGetter( |
@@ -601,6 +538,16 @@ void URLFetcherTempFileTest::OnURLFetchComplete( |
io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
} |
+void URLFetcherTempFileTest::CreateFetcher(const GURL& url) { |
+ fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); |
+ fetcher_->SetRequestContext(new TestURLRequestContextGetter( |
+ io_message_loop_proxy())); |
+ |
+ // Use the IO message loop to do the file operations in this test. |
+ fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); |
+ fetcher_->Start(); |
+} |
+ |
TEST_F(URLFetcherTest, SameThreadsTest) { |
net::TestServer test_server(net::TestServer::TYPE_HTTP, |
net::TestServer::kLocalhost, |
@@ -642,6 +589,30 @@ TEST_F(URLFetcherTest, DifferentThreadsTest) { |
MessageLoop::current()->Run(); |
} |
+void CancelAllOnIO() { |
+ EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); |
+ URLFetcherImpl::CancelAll(); |
+ EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); |
+} |
+ |
+// Tests to make sure CancelAll() will successfully cancel existing URLFetchers. |
+TEST_F(URLFetcherTest, CancelAll) { |
+ net::TestServer test_server(net::TestServer::TYPE_HTTP, |
+ net::TestServer::kLocalhost, |
+ FilePath(kDocRoot)); |
+ ASSERT_TRUE(test_server.Start()); |
+ EXPECT_EQ(0, GetNumFetcherCores()); |
+ |
+ CreateFetcher(test_server.GetURL("defaultresponse")); |
+ io_message_loop_proxy()->PostTaskAndReply( |
+ FROM_HERE, |
+ base::Bind(&CancelAllOnIO), |
+ MessageLoop::QuitClosure()); |
+ MessageLoop::current()->Run(); |
+ EXPECT_EQ(0, GetNumFetcherCores()); |
+ delete fetcher_; |
+} |
+ |
#if defined(OS_MACOSX) |
// SIGSEGV on Mac: http://crbug.com/60426 |
TEST_F(URLFetcherPostTest, DISABLED_Basic) { |
@@ -820,7 +791,7 @@ TEST_F(URLFetcherCancelTest, ReleasesContext) { |
GURL url(test_server.GetURL("files/server-unavailable.html")); |
// Registers an entry for test url. The backoff time is calculated by: |
- // new_backoff = 2.0 * old_backoff +0 |
+ // new_backoff = 2.0 * old_backoff + 0 |
hashimoto
2012/03/02 10:26:42
fixed a tiny format error.
|
// The initial backoff is 2 seconds and maximum backoff is 4 seconds. |
// Maximum retries allowed is set to 2. |
net::URLRequestThrottlerManager* manager = |
@@ -895,28 +866,57 @@ TEST_F(URLFetcherMultipleAttemptTest, SameData) { |
MessageLoop::current()->Run(); |
} |
-void CancelAllOnIO() { |
- EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); |
- URLFetcherImpl::CancelAll(); |
- EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); |
+TEST_F(URLFetcherTempFileTest, SmallGet) { |
+ net::TestServer test_server(net::TestServer::TYPE_HTTP, |
+ net::TestServer::kLocalhost, |
+ FilePath(kDocRoot)); |
+ ASSERT_TRUE(test_server.Start()); |
+ |
+ // Get a small file. |
+ static const char kFileToFetch[] = "simple.html"; |
+ expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
+ CreateFetcher( |
+ test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
+ |
+ MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
+ |
+ ASSERT_FALSE(file_util::PathExists(temp_file_)) |
+ << temp_file_.value() << " not removed."; |
} |
-// Tests to make sure CancelAll() will successfully cancel existing URLFetchers. |
-TEST_F(URLFetcherTest, CancelAll) { |
+TEST_F(URLFetcherTempFileTest, LargeGet) { |
net::TestServer test_server(net::TestServer::TYPE_HTTP, |
net::TestServer::kLocalhost, |
FilePath(kDocRoot)); |
ASSERT_TRUE(test_server.Start()); |
- EXPECT_EQ(0, GetNumFetcherCores()); |
- CreateFetcher(test_server.GetURL("defaultresponse")); |
- io_message_loop_proxy()->PostTaskAndReply( |
- FROM_HERE, |
- base::Bind(&CancelAllOnIO), |
- MessageLoop::QuitClosure()); |
- MessageLoop::current()->Run(); |
- EXPECT_EQ(0, GetNumFetcherCores()); |
- delete fetcher_; |
+ // Get a file large enough to require more than one read into |
+ // URLFetcher::Core's IOBuffer. |
+ static const char kFileToFetch[] = "animate1.gif"; |
+ expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
+ CreateFetcher(test_server.GetURL( |
+ std::string(kTestServerFilePrefix) + kFileToFetch)); |
+ |
+ MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
+} |
+ |
+TEST_F(URLFetcherTempFileTest, CanTakeOwnershipOfFile) { |
+ net::TestServer test_server(net::TestServer::TYPE_HTTP, |
+ net::TestServer::kLocalhost, |
+ FilePath(kDocRoot)); |
+ ASSERT_TRUE(test_server.Start()); |
+ |
+ // Get a small file. |
+ static const char kFileToFetch[] = "simple.html"; |
+ expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
+ CreateFetcher(test_server.GetURL( |
+ std::string(kTestServerFilePrefix) + kFileToFetch)); |
+ |
+ MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
+ |
+ MessageLoop::current()->RunAllPending(); |
+ ASSERT_FALSE(file_util::PathExists(temp_file_)) |
+ << temp_file_.value() << " not removed."; |
} |
} // namespace. |