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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 if (expected_file_error_ == OK) { | 869 if (expected_file_error_ == OK) { |
870 EXPECT_TRUE(source->GetStatus().is_success()); | 870 EXPECT_TRUE(source->GetStatus().is_success()); |
871 EXPECT_EQ(source->GetResponseCode(), 200); | 871 EXPECT_EQ(source->GetResponseCode(), 200); |
872 | 872 |
873 int error_code = OK; | 873 int error_code = OK; |
874 EXPECT_FALSE(fetcher_->FileErrorOccurred(&error_code)); | 874 EXPECT_FALSE(fetcher_->FileErrorOccurred(&error_code)); |
875 | 875 |
876 EXPECT_TRUE(source->GetResponseAsFilePath( | 876 EXPECT_TRUE(source->GetResponseAsFilePath( |
877 take_ownership_of_file_, &file_path_)); | 877 take_ownership_of_file_, &file_path_)); |
878 | 878 |
879 EXPECT_TRUE(file_util::ContentsEqual(expected_file_, file_path_)); | 879 EXPECT_TRUE(base::ContentsEqual(expected_file_, file_path_)); |
880 } else { | 880 } else { |
881 int error_code = OK; | 881 int error_code = OK; |
882 EXPECT_TRUE(fetcher_->FileErrorOccurred(&error_code)); | 882 EXPECT_TRUE(fetcher_->FileErrorOccurred(&error_code)); |
883 EXPECT_EQ(expected_file_error_, error_code); | 883 EXPECT_EQ(expected_file_error_, error_code); |
884 } | 884 } |
885 CleanupAfterFetchComplete(); | 885 CleanupAfterFetchComplete(); |
886 } | 886 } |
887 | 887 |
888 TEST_F(URLFetcherTest, SameThreadsTest) { | 888 TEST_F(URLFetcherTest, SameThreadsTest) { |
889 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 889 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1432 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1433 | 1433 |
1434 // Create a file before trying to fetch. | 1434 // Create a file before trying to fetch. |
1435 static const char kFileToFetch[] = "simple.html"; | 1435 static const char kFileToFetch[] = "simple.html"; |
1436 std::string data(10000, '?'); // Meant to be larger than simple.html. | 1436 std::string data(10000, '?'); // Meant to be larger than simple.html. |
1437 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); | 1437 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); |
1438 ASSERT_EQ(static_cast<int>(data.size()), | 1438 ASSERT_EQ(static_cast<int>(data.size()), |
1439 file_util::WriteFile(file_path_, data.data(), data.size())); | 1439 file_util::WriteFile(file_path_, data.data(), data.size())); |
1440 ASSERT_TRUE(base::PathExists(file_path_)); | 1440 ASSERT_TRUE(base::PathExists(file_path_)); |
1441 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1441 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1442 ASSERT_FALSE(file_util::ContentsEqual(file_path_, expected_file_)); | 1442 ASSERT_FALSE(base::ContentsEqual(file_path_, expected_file_)); |
1443 | 1443 |
1444 // Get a small file. | 1444 // Get a small file. |
1445 CreateFetcherForFile( | 1445 CreateFetcherForFile( |
1446 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1446 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1447 file_path_); | 1447 file_path_); |
1448 | 1448 |
1449 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1449 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1450 } | 1450 } |
1451 | 1451 |
1452 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) { | 1452 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 | 1532 |
1533 base::MessageLoop::current()->RunUntilIdle(); | 1533 base::MessageLoop::current()->RunUntilIdle(); |
1534 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << | 1534 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << |
1535 "FilePath: " << file_path_.value(); | 1535 "FilePath: " << file_path_.value(); |
1536 } | 1536 } |
1537 } | 1537 } |
1538 | 1538 |
1539 } // namespace | 1539 } // namespace |
1540 | 1540 |
1541 } // namespace net | 1541 } // namespace net |
OLD | NEW |