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 <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 23 matching lines...) Expand all Loading... |
34 namespace net { | 34 namespace net { |
35 | 35 |
36 using base::Time; | 36 using base::Time; |
37 using base::TimeDelta; | 37 using base::TimeDelta; |
38 | 38 |
39 // TODO(eroman): Add a regression test for http://crbug.com/40505. | 39 // TODO(eroman): Add a regression test for http://crbug.com/40505. |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 // TODO(akalin): Move all the test data to somewhere under net/. | 43 // TODO(akalin): Move all the test data to somewhere under net/. |
44 const base::FilePath::CharType kDocRoot[] = | |
45 FILE_PATH_LITERAL("chrome/test/data"); | |
46 const char kTestServerFilePrefix[] = "files/"; | 44 const char kTestServerFilePrefix[] = "files/"; |
47 | 45 |
48 class ThrottlingTestURLRequestContext : public TestURLRequestContext { | 46 class ThrottlingTestURLRequestContext : public TestURLRequestContext { |
49 public: | 47 public: |
50 ThrottlingTestURLRequestContext() : TestURLRequestContext(true) { | 48 ThrottlingTestURLRequestContext() : TestURLRequestContext(true) { |
51 set_throttler_manager(&throttler_manager_); | 49 set_throttler_manager(&throttler_manager_); |
52 Init(); | 50 Init(); |
53 DCHECK(throttler_manager() != NULL); | 51 DCHECK(throttler_manager() != NULL); |
54 } | 52 } |
55 | 53 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 193 |
196 resolver_.set_ondemand_mode(true); | 194 resolver_.set_ondemand_mode(true); |
197 resolver_.rules()->AddRule("example.com", "127.0.0.1"); | 195 resolver_.rules()->AddRule("example.com", "127.0.0.1"); |
198 | 196 |
199 context_.reset(new TestURLRequestContext(true)); | 197 context_.reset(new TestURLRequestContext(true)); |
200 context_->set_host_resolver(&resolver_); | 198 context_->set_host_resolver(&resolver_); |
201 context_->Init(); | 199 context_->Init(); |
202 | 200 |
203 test_server_.reset(new TestServer(TestServer::TYPE_HTTP, | 201 test_server_.reset(new TestServer(TestServer::TYPE_HTTP, |
204 TestServer::kLocalhost, | 202 TestServer::kLocalhost, |
205 base::FilePath(kDocRoot))); | 203 TestServer::GetTestDataPath())); |
206 ASSERT_TRUE(test_server_->Start()); | 204 ASSERT_TRUE(test_server_->Start()); |
207 | 205 |
208 // test_server_.GetURL() returns a URL with 127.0.0.1 (kLocalhost), that is | 206 // test_server_.GetURL() returns a URL with 127.0.0.1 (kLocalhost), that is |
209 // immediately resolved by the MockHostResolver. Use a hostname instead to | 207 // immediately resolved by the MockHostResolver. Use a hostname instead to |
210 // trigger an async resolve. | 208 // trigger an async resolve. |
211 test_url_ = GURL( | 209 test_url_ = GURL( |
212 base::StringPrintf("http://example.com:%d/defaultresponse", | 210 base::StringPrintf("http://example.com:%d/defaultresponse", |
213 test_server_->host_port_pair().port())); | 211 test_server_->host_port_pair().port())); |
214 ASSERT_TRUE(test_url_.is_valid()); | 212 ASSERT_TRUE(test_url_.is_valid()); |
215 } | 213 } |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; | 869 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; |
872 EXPECT_TRUE(fetcher_->FileErrorOccurred(&error_code)); | 870 EXPECT_TRUE(fetcher_->FileErrorOccurred(&error_code)); |
873 EXPECT_EQ(expected_file_error_, error_code); | 871 EXPECT_EQ(expected_file_error_, error_code); |
874 } | 872 } |
875 CleanupAfterFetchComplete(); | 873 CleanupAfterFetchComplete(); |
876 } | 874 } |
877 | 875 |
878 TEST_F(URLFetcherTest, SameThreadsTest) { | 876 TEST_F(URLFetcherTest, SameThreadsTest) { |
879 TestServer test_server(TestServer::TYPE_HTTP, | 877 TestServer test_server(TestServer::TYPE_HTTP, |
880 TestServer::kLocalhost, | 878 TestServer::kLocalhost, |
881 base::FilePath(kDocRoot)); | 879 TestServer::GetTestDataPath()); |
882 ASSERT_TRUE(test_server.Start()); | 880 ASSERT_TRUE(test_server.Start()); |
883 | 881 |
884 // Create the fetcher on the main thread. Since IO will happen on the main | 882 // Create the fetcher on the main thread. Since IO will happen on the main |
885 // thread, this will test URLFetcher's ability to do everything on one | 883 // thread, this will test URLFetcher's ability to do everything on one |
886 // thread. | 884 // thread. |
887 CreateFetcher(test_server.GetURL("defaultresponse")); | 885 CreateFetcher(test_server.GetURL("defaultresponse")); |
888 | 886 |
889 MessageLoop::current()->Run(); | 887 MessageLoop::current()->Run(); |
890 } | 888 } |
891 | 889 |
892 TEST_F(URLFetcherTest, DifferentThreadsTest) { | 890 TEST_F(URLFetcherTest, DifferentThreadsTest) { |
893 TestServer test_server(TestServer::TYPE_HTTP, | 891 TestServer test_server(TestServer::TYPE_HTTP, |
894 TestServer::kLocalhost, | 892 TestServer::kLocalhost, |
895 base::FilePath(kDocRoot)); | 893 TestServer::GetTestDataPath()); |
896 ASSERT_TRUE(test_server.Start()); | 894 ASSERT_TRUE(test_server.Start()); |
897 | 895 |
898 // Create a separate thread that will create the URLFetcher. The current | 896 // Create a separate thread that will create the URLFetcher. The current |
899 // (main) thread will do the IO, and when the fetch is complete it will | 897 // (main) thread will do the IO, and when the fetch is complete it will |
900 // terminate the main thread's message loop; then the other thread's | 898 // terminate the main thread's message loop; then the other thread's |
901 // message loop will be shut down automatically as the thread goes out of | 899 // message loop will be shut down automatically as the thread goes out of |
902 // scope. | 900 // scope. |
903 base::Thread t("URLFetcher test thread"); | 901 base::Thread t("URLFetcher test thread"); |
904 ASSERT_TRUE(t.Start()); | 902 ASSERT_TRUE(t.Start()); |
905 t.message_loop()->PostTask( | 903 t.message_loop()->PostTask( |
906 FROM_HERE, | 904 FROM_HERE, |
907 base::Bind(&URLFetcherTest::CreateFetcher, | 905 base::Bind(&URLFetcherTest::CreateFetcher, |
908 base::Unretained(this), | 906 base::Unretained(this), |
909 test_server.GetURL("defaultresponse"))); | 907 test_server.GetURL("defaultresponse"))); |
910 | 908 |
911 MessageLoop::current()->Run(); | 909 MessageLoop::current()->Run(); |
912 } | 910 } |
913 | 911 |
914 void CancelAllOnIO() { | 912 void CancelAllOnIO() { |
915 EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); | 913 EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); |
916 URLFetcherImpl::CancelAll(); | 914 URLFetcherImpl::CancelAll(); |
917 EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); | 915 EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); |
918 } | 916 } |
919 | 917 |
920 // Tests to make sure CancelAll() will successfully cancel existing URLFetchers. | 918 // Tests to make sure CancelAll() will successfully cancel existing URLFetchers. |
921 TEST_F(URLFetcherTest, CancelAll) { | 919 TEST_F(URLFetcherTest, CancelAll) { |
922 TestServer test_server(TestServer::TYPE_HTTP, | 920 TestServer test_server(TestServer::TYPE_HTTP, |
923 TestServer::kLocalhost, | 921 TestServer::kLocalhost, |
924 base::FilePath(kDocRoot)); | 922 TestServer::GetTestDataPath()); |
925 ASSERT_TRUE(test_server.Start()); | 923 ASSERT_TRUE(test_server.Start()); |
926 EXPECT_EQ(0, GetNumFetcherCores()); | 924 EXPECT_EQ(0, GetNumFetcherCores()); |
927 | 925 |
928 CreateFetcher(test_server.GetURL("defaultresponse")); | 926 CreateFetcher(test_server.GetURL("defaultresponse")); |
929 io_message_loop_proxy()->PostTaskAndReply( | 927 io_message_loop_proxy()->PostTaskAndReply( |
930 FROM_HERE, | 928 FROM_HERE, |
931 base::Bind(&CancelAllOnIO), | 929 base::Bind(&CancelAllOnIO), |
932 MessageLoop::QuitClosure()); | 930 MessageLoop::QuitClosure()); |
933 MessageLoop::current()->Run(); | 931 MessageLoop::current()->Run(); |
934 EXPECT_EQ(0, GetNumFetcherCores()); | 932 EXPECT_EQ(0, GetNumFetcherCores()); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 ASSERT_TRUE(completed_fetcher_); | 1037 ASSERT_TRUE(completed_fetcher_); |
1040 | 1038 |
1041 // This time the request succeeded. | 1039 // This time the request succeeded. |
1042 EXPECT_EQ(OK, completed_fetcher_->GetStatus().error()); | 1040 EXPECT_EQ(OK, completed_fetcher_->GetStatus().error()); |
1043 EXPECT_EQ(200, completed_fetcher_->GetResponseCode()); | 1041 EXPECT_EQ(200, completed_fetcher_->GetResponseCode()); |
1044 } | 1042 } |
1045 | 1043 |
1046 TEST_F(URLFetcherPostTest, Basic) { | 1044 TEST_F(URLFetcherPostTest, Basic) { |
1047 TestServer test_server(TestServer::TYPE_HTTP, | 1045 TestServer test_server(TestServer::TYPE_HTTP, |
1048 TestServer::kLocalhost, | 1046 TestServer::kLocalhost, |
1049 base::FilePath(kDocRoot)); | 1047 TestServer::GetTestDataPath()); |
1050 ASSERT_TRUE(test_server.Start()); | 1048 ASSERT_TRUE(test_server.Start()); |
1051 | 1049 |
1052 CreateFetcher(test_server.GetURL("echo")); | 1050 CreateFetcher(test_server.GetURL("echo")); |
1053 MessageLoop::current()->Run(); | 1051 MessageLoop::current()->Run(); |
1054 } | 1052 } |
1055 | 1053 |
1056 TEST_F(URLFetcherPostFileTest, Basic) { | 1054 TEST_F(URLFetcherPostFileTest, Basic) { |
1057 TestServer test_server(TestServer::TYPE_HTTP, | 1055 TestServer test_server(TestServer::TYPE_HTTP, |
1058 TestServer::kLocalhost, | 1056 TestServer::kLocalhost, |
1059 base::FilePath(kDocRoot)); | 1057 TestServer::GetTestDataPath()); |
1060 ASSERT_TRUE(test_server.Start()); | 1058 ASSERT_TRUE(test_server.Start()); |
1061 | 1059 |
1062 CreateFetcher(test_server.GetURL("echo")); | 1060 CreateFetcher(test_server.GetURL("echo")); |
1063 MessageLoop::current()->Run(); | 1061 MessageLoop::current()->Run(); |
1064 } | 1062 } |
1065 | 1063 |
1066 TEST_F(URLFetcherEmptyPostTest, Basic) { | 1064 TEST_F(URLFetcherEmptyPostTest, Basic) { |
1067 TestServer test_server(TestServer::TYPE_HTTP, | 1065 TestServer test_server(TestServer::TYPE_HTTP, |
1068 TestServer::kLocalhost, | 1066 TestServer::kLocalhost, |
1069 base::FilePath(kDocRoot)); | 1067 TestServer::GetTestDataPath()); |
1070 ASSERT_TRUE(test_server.Start()); | 1068 ASSERT_TRUE(test_server.Start()); |
1071 | 1069 |
1072 CreateFetcher(test_server.GetURL("echo")); | 1070 CreateFetcher(test_server.GetURL("echo")); |
1073 MessageLoop::current()->Run(); | 1071 MessageLoop::current()->Run(); |
1074 } | 1072 } |
1075 | 1073 |
1076 TEST_F(URLFetcherUploadProgressTest, Basic) { | 1074 TEST_F(URLFetcherUploadProgressTest, Basic) { |
1077 TestServer test_server(TestServer::TYPE_HTTP, | 1075 TestServer test_server(TestServer::TYPE_HTTP, |
1078 TestServer::kLocalhost, | 1076 TestServer::kLocalhost, |
1079 base::FilePath(kDocRoot)); | 1077 TestServer::GetTestDataPath()); |
1080 ASSERT_TRUE(test_server.Start()); | 1078 ASSERT_TRUE(test_server.Start()); |
1081 | 1079 |
1082 CreateFetcher(test_server.GetURL("echo")); | 1080 CreateFetcher(test_server.GetURL("echo")); |
1083 MessageLoop::current()->Run(); | 1081 MessageLoop::current()->Run(); |
1084 } | 1082 } |
1085 | 1083 |
1086 TEST_F(URLFetcherDownloadProgressTest, Basic) { | 1084 TEST_F(URLFetcherDownloadProgressTest, Basic) { |
1087 TestServer test_server(TestServer::TYPE_HTTP, | 1085 TestServer test_server(TestServer::TYPE_HTTP, |
1088 TestServer::kLocalhost, | 1086 TestServer::kLocalhost, |
1089 base::FilePath(kDocRoot)); | 1087 TestServer::GetTestDataPath()); |
1090 ASSERT_TRUE(test_server.Start()); | 1088 ASSERT_TRUE(test_server.Start()); |
1091 | 1089 |
1092 // Get a file large enough to require more than one read into | 1090 // Get a file large enough to require more than one read into |
1093 // URLFetcher::Core's IOBuffer. | 1091 // URLFetcher::Core's IOBuffer. |
1094 static const char kFileToFetch[] = "animate1.gif"; | 1092 static const char kFileToFetch[] = "animate1.gif"; |
1095 // Hardcoded file size - it cannot be easily fetched when a remote http server | 1093 // Hardcoded file size - it cannot be easily fetched when a remote http server |
1096 // is used for testing. | 1094 // is used for testing. |
1097 static const int64 kFileSize = 19021; | 1095 static const int64 kFileSize = 19021; |
1098 | 1096 |
1099 expected_total_ = kFileSize; | 1097 expected_total_ = kFileSize; |
1100 | 1098 |
1101 CreateFetcher(test_server.GetURL( | 1099 CreateFetcher(test_server.GetURL( |
1102 std::string(kTestServerFilePrefix) + kFileToFetch)); | 1100 std::string(kTestServerFilePrefix) + kFileToFetch)); |
1103 | 1101 |
1104 MessageLoop::current()->Run(); | 1102 MessageLoop::current()->Run(); |
1105 } | 1103 } |
1106 | 1104 |
1107 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) { | 1105 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) { |
1108 TestServer test_server(TestServer::TYPE_HTTP, | 1106 TestServer test_server(TestServer::TYPE_HTTP, |
1109 TestServer::kLocalhost, | 1107 TestServer::kLocalhost, |
1110 base::FilePath(kDocRoot)); | 1108 TestServer::GetTestDataPath()); |
1111 ASSERT_TRUE(test_server.Start()); | 1109 ASSERT_TRUE(test_server.Start()); |
1112 | 1110 |
1113 // Get a file large enough to require more than one read into | 1111 // Get a file large enough to require more than one read into |
1114 // URLFetcher::Core's IOBuffer. | 1112 // URLFetcher::Core's IOBuffer. |
1115 static const char kFileToFetch[] = "animate1.gif"; | 1113 static const char kFileToFetch[] = "animate1.gif"; |
1116 CreateFetcher(test_server.GetURL( | 1114 CreateFetcher(test_server.GetURL( |
1117 std::string(kTestServerFilePrefix) + kFileToFetch)); | 1115 std::string(kTestServerFilePrefix) + kFileToFetch)); |
1118 | 1116 |
1119 MessageLoop::current()->Run(); | 1117 MessageLoop::current()->Run(); |
1120 } | 1118 } |
1121 | 1119 |
1122 TEST_F(URLFetcherHeadersTest, Headers) { | 1120 TEST_F(URLFetcherHeadersTest, Headers) { |
1123 TestServer test_server( | 1121 TestServer test_server( |
1124 TestServer::TYPE_HTTP, | 1122 TestServer::TYPE_HTTP, |
1125 TestServer::kLocalhost, | 1123 TestServer::kLocalhost, |
1126 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 1124 TestServer::GetSourceRelativePath( |
| 1125 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")))); |
1127 ASSERT_TRUE(test_server.Start()); | 1126 ASSERT_TRUE(test_server.Start()); |
1128 | 1127 |
1129 CreateFetcher(test_server.GetURL("files/with-headers.html")); | 1128 CreateFetcher(test_server.GetURL("files/with-headers.html")); |
1130 MessageLoop::current()->Run(); | 1129 MessageLoop::current()->Run(); |
1131 // The actual tests are in the URLFetcherHeadersTest fixture. | 1130 // The actual tests are in the URLFetcherHeadersTest fixture. |
1132 } | 1131 } |
1133 | 1132 |
1134 TEST_F(URLFetcherSocketAddressTest, SocketAddress) { | 1133 TEST_F(URLFetcherSocketAddressTest, SocketAddress) { |
1135 TestServer test_server( | 1134 TestServer test_server( |
1136 TestServer::TYPE_HTTP, | 1135 TestServer::TYPE_HTTP, |
1137 TestServer::kLocalhost, | 1136 TestServer::kLocalhost, |
1138 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 1137 TestServer::GetSourceRelativePath( |
| 1138 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")))); |
1139 ASSERT_TRUE(test_server.Start()); | 1139 ASSERT_TRUE(test_server.Start()); |
1140 expected_port_ = test_server.host_port_pair().port(); | 1140 expected_port_ = test_server.host_port_pair().port(); |
1141 | 1141 |
1142 // Reusing "with-headers.html" but doesn't really matter. | 1142 // Reusing "with-headers.html" but doesn't really matter. |
1143 CreateFetcher(test_server.GetURL("files/with-headers.html")); | 1143 CreateFetcher(test_server.GetURL("files/with-headers.html")); |
1144 MessageLoop::current()->Run(); | 1144 MessageLoop::current()->Run(); |
1145 // The actual tests are in the URLFetcherSocketAddressTest fixture. | 1145 // The actual tests are in the URLFetcherSocketAddressTest fixture. |
1146 } | 1146 } |
1147 | 1147 |
1148 TEST_F(URLFetcherStopOnRedirectTest, StopOnRedirect) { | 1148 TEST_F(URLFetcherStopOnRedirectTest, StopOnRedirect) { |
1149 TestServer test_server(TestServer::TYPE_HTTP, | 1149 TestServer test_server(TestServer::TYPE_HTTP, |
1150 TestServer::kLocalhost, | 1150 TestServer::kLocalhost, |
1151 base::FilePath(kDocRoot)); | 1151 TestServer::GetTestDataPath()); |
1152 ASSERT_TRUE(test_server.Start()); | 1152 ASSERT_TRUE(test_server.Start()); |
1153 | 1153 |
1154 CreateFetcher( | 1154 CreateFetcher( |
1155 test_server.GetURL(std::string("server-redirect?") + kRedirectTarget)); | 1155 test_server.GetURL(std::string("server-redirect?") + kRedirectTarget)); |
1156 MessageLoop::current()->Run(); | 1156 MessageLoop::current()->Run(); |
1157 EXPECT_TRUE(callback_called_); | 1157 EXPECT_TRUE(callback_called_); |
1158 } | 1158 } |
1159 | 1159 |
1160 TEST_F(URLFetcherProtectTest, Overload) { | 1160 TEST_F(URLFetcherProtectTest, Overload) { |
1161 TestServer test_server(TestServer::TYPE_HTTP, | 1161 TestServer test_server(TestServer::TYPE_HTTP, |
1162 TestServer::kLocalhost, | 1162 TestServer::kLocalhost, |
1163 base::FilePath(kDocRoot)); | 1163 TestServer::GetTestDataPath()); |
1164 ASSERT_TRUE(test_server.Start()); | 1164 ASSERT_TRUE(test_server.Start()); |
1165 | 1165 |
1166 GURL url(test_server.GetURL("defaultresponse")); | 1166 GURL url(test_server.GetURL("defaultresponse")); |
1167 | 1167 |
1168 // Registers an entry for test url. It only allows 3 requests to be sent | 1168 // Registers an entry for test url. It only allows 3 requests to be sent |
1169 // in 200 milliseconds. | 1169 // in 200 milliseconds. |
1170 scoped_refptr<URLRequestThrottlerEntry> entry( | 1170 scoped_refptr<URLRequestThrottlerEntry> entry( |
1171 new URLRequestThrottlerEntry( | 1171 new URLRequestThrottlerEntry( |
1172 request_context()->throttler_manager(), | 1172 request_context()->throttler_manager(), |
1173 "", 200, 3, 1, 2.0, 0.0, 256)); | 1173 "", 200, 3, 1, 2.0, 0.0, 256)); |
1174 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); | 1174 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); |
1175 | 1175 |
1176 CreateFetcher(url); | 1176 CreateFetcher(url); |
1177 | 1177 |
1178 MessageLoop::current()->Run(); | 1178 MessageLoop::current()->Run(); |
1179 } | 1179 } |
1180 | 1180 |
1181 TEST_F(URLFetcherProtectTest, ServerUnavailable) { | 1181 TEST_F(URLFetcherProtectTest, ServerUnavailable) { |
1182 TestServer test_server(TestServer::TYPE_HTTP, | 1182 TestServer test_server(TestServer::TYPE_HTTP, |
1183 TestServer::kLocalhost, | 1183 TestServer::kLocalhost, |
1184 base::FilePath(kDocRoot)); | 1184 TestServer::GetTestDataPath()); |
1185 ASSERT_TRUE(test_server.Start()); | 1185 ASSERT_TRUE(test_server.Start()); |
1186 | 1186 |
1187 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1187 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1188 | 1188 |
1189 // Registers an entry for test url. The backoff time is calculated by: | 1189 // Registers an entry for test url. The backoff time is calculated by: |
1190 // new_backoff = 2.0 * old_backoff + 0 | 1190 // new_backoff = 2.0 * old_backoff + 0 |
1191 // and maximum backoff time is 256 milliseconds. | 1191 // and maximum backoff time is 256 milliseconds. |
1192 // Maximum retries allowed is set to 11. | 1192 // Maximum retries allowed is set to 11. |
1193 scoped_refptr<URLRequestThrottlerEntry> entry( | 1193 scoped_refptr<URLRequestThrottlerEntry> entry( |
1194 new URLRequestThrottlerEntry( | 1194 new URLRequestThrottlerEntry( |
1195 request_context()->throttler_manager(), | 1195 request_context()->throttler_manager(), |
1196 "", 200, 3, 1, 2.0, 0.0, 256)); | 1196 "", 200, 3, 1, 2.0, 0.0, 256)); |
1197 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); | 1197 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); |
1198 | 1198 |
1199 CreateFetcher(url); | 1199 CreateFetcher(url); |
1200 | 1200 |
1201 MessageLoop::current()->Run(); | 1201 MessageLoop::current()->Run(); |
1202 } | 1202 } |
1203 | 1203 |
1204 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { | 1204 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { |
1205 TestServer test_server(TestServer::TYPE_HTTP, | 1205 TestServer test_server(TestServer::TYPE_HTTP, |
1206 TestServer::kLocalhost, | 1206 TestServer::kLocalhost, |
1207 base::FilePath(kDocRoot)); | 1207 TestServer::GetTestDataPath()); |
1208 ASSERT_TRUE(test_server.Start()); | 1208 ASSERT_TRUE(test_server.Start()); |
1209 | 1209 |
1210 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1210 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1211 | 1211 |
1212 // Registers an entry for test url. The backoff time is calculated by: | 1212 // Registers an entry for test url. The backoff time is calculated by: |
1213 // new_backoff = 2.0 * old_backoff + 0 | 1213 // new_backoff = 2.0 * old_backoff + 0 |
1214 // and maximum backoff time is 150000 milliseconds. | 1214 // and maximum backoff time is 150000 milliseconds. |
1215 // Maximum retries allowed is set to 11. | 1215 // Maximum retries allowed is set to 11. |
1216 scoped_refptr<URLRequestThrottlerEntry> entry( | 1216 scoped_refptr<URLRequestThrottlerEntry> entry( |
1217 new URLRequestThrottlerEntry( | 1217 new URLRequestThrottlerEntry( |
1218 request_context()->throttler_manager(), | 1218 request_context()->throttler_manager(), |
1219 "", 200, 3, 100, 2.0, 0.0, 150000)); | 1219 "", 200, 3, 100, 2.0, 0.0, 150000)); |
1220 // Total time if *not* for not doing automatic backoff would be 150s. | 1220 // Total time if *not* for not doing automatic backoff would be 150s. |
1221 // In reality it should be "as soon as server responds". | 1221 // In reality it should be "as soon as server responds". |
1222 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); | 1222 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); |
1223 | 1223 |
1224 CreateFetcher(url); | 1224 CreateFetcher(url); |
1225 | 1225 |
1226 MessageLoop::current()->Run(); | 1226 MessageLoop::current()->Run(); |
1227 } | 1227 } |
1228 | 1228 |
1229 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { | 1229 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { |
1230 TestServer::SSLOptions ssl_options( | 1230 TestServer::SSLOptions ssl_options( |
1231 TestServer::SSLOptions::CERT_EXPIRED); | 1231 TestServer::SSLOptions::CERT_EXPIRED); |
1232 TestServer test_server(TestServer::TYPE_HTTPS, | 1232 TestServer test_server(TestServer::TYPE_HTTPS, |
1233 ssl_options, | 1233 ssl_options, |
1234 base::FilePath(kDocRoot)); | 1234 TestServer::GetTestDataPath()); |
1235 ASSERT_TRUE(test_server.Start()); | 1235 ASSERT_TRUE(test_server.Start()); |
1236 | 1236 |
1237 CreateFetcher(test_server.GetURL("defaultresponse")); | 1237 CreateFetcher(test_server.GetURL("defaultresponse")); |
1238 MessageLoop::current()->Run(); | 1238 MessageLoop::current()->Run(); |
1239 } | 1239 } |
1240 | 1240 |
1241 TEST_F(URLFetcherCancelTest, ReleasesContext) { | 1241 TEST_F(URLFetcherCancelTest, ReleasesContext) { |
1242 TestServer test_server(TestServer::TYPE_HTTP, | 1242 TestServer test_server(TestServer::TYPE_HTTP, |
1243 TestServer::kLocalhost, | 1243 TestServer::kLocalhost, |
1244 base::FilePath(kDocRoot)); | 1244 TestServer::GetTestDataPath()); |
1245 ASSERT_TRUE(test_server.Start()); | 1245 ASSERT_TRUE(test_server.Start()); |
1246 | 1246 |
1247 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1247 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1248 | 1248 |
1249 // Create a separate thread that will create the URLFetcher. The current | 1249 // Create a separate thread that will create the URLFetcher. The current |
1250 // (main) thread will do the IO, and when the fetch is complete it will | 1250 // (main) thread will do the IO, and when the fetch is complete it will |
1251 // terminate the main thread's message loop; then the other thread's | 1251 // terminate the main thread's message loop; then the other thread's |
1252 // message loop will be shut down automatically as the thread goes out of | 1252 // message loop will be shut down automatically as the thread goes out of |
1253 // scope. | 1253 // scope. |
1254 base::Thread t("URLFetcher test thread"); | 1254 base::Thread t("URLFetcher test thread"); |
1255 ASSERT_TRUE(t.Start()); | 1255 ASSERT_TRUE(t.Start()); |
1256 t.message_loop()->PostTask( | 1256 t.message_loop()->PostTask( |
1257 FROM_HERE, | 1257 FROM_HERE, |
1258 base::Bind(&URLFetcherCancelTest::CreateFetcher, | 1258 base::Bind(&URLFetcherCancelTest::CreateFetcher, |
1259 base::Unretained(this), url)); | 1259 base::Unretained(this), url)); |
1260 | 1260 |
1261 MessageLoop::current()->Run(); | 1261 MessageLoop::current()->Run(); |
1262 } | 1262 } |
1263 | 1263 |
1264 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { | 1264 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { |
1265 TestServer test_server(TestServer::TYPE_HTTP, | 1265 TestServer test_server(TestServer::TYPE_HTTP, |
1266 TestServer::kLocalhost, | 1266 TestServer::kLocalhost, |
1267 base::FilePath(kDocRoot)); | 1267 TestServer::GetTestDataPath()); |
1268 ASSERT_TRUE(test_server.Start()); | 1268 ASSERT_TRUE(test_server.Start()); |
1269 | 1269 |
1270 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1270 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1271 | 1271 |
1272 // Register an entry for test url. | 1272 // Register an entry for test url. |
1273 // Using a sliding window of 4 seconds, and max of 1 request, under a fast | 1273 // Using a sliding window of 4 seconds, and max of 1 request, under a fast |
1274 // run we expect to have a 4 second delay when posting the Start task. | 1274 // run we expect to have a 4 second delay when posting the Start task. |
1275 scoped_refptr<URLRequestThrottlerEntry> entry( | 1275 scoped_refptr<URLRequestThrottlerEntry> entry( |
1276 new URLRequestThrottlerEntry( | 1276 new URLRequestThrottlerEntry( |
1277 request_context()->throttler_manager(), | 1277 request_context()->throttler_manager(), |
(...skipping 11 matching lines...) Expand all Loading... |
1289 t.message_loop()->PostTask( | 1289 t.message_loop()->PostTask( |
1290 FROM_HERE, | 1290 FROM_HERE, |
1291 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); | 1291 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); |
1292 | 1292 |
1293 MessageLoop::current()->Run(); | 1293 MessageLoop::current()->Run(); |
1294 } | 1294 } |
1295 | 1295 |
1296 TEST_F(URLFetcherMultipleAttemptTest, SameData) { | 1296 TEST_F(URLFetcherMultipleAttemptTest, SameData) { |
1297 TestServer test_server(TestServer::TYPE_HTTP, | 1297 TestServer test_server(TestServer::TYPE_HTTP, |
1298 TestServer::kLocalhost, | 1298 TestServer::kLocalhost, |
1299 base::FilePath(kDocRoot)); | 1299 TestServer::GetTestDataPath()); |
1300 ASSERT_TRUE(test_server.Start()); | 1300 ASSERT_TRUE(test_server.Start()); |
1301 | 1301 |
1302 // Create the fetcher on the main thread. Since IO will happen on the main | 1302 // Create the fetcher on the main thread. Since IO will happen on the main |
1303 // thread, this will test URLFetcher's ability to do everything on one | 1303 // thread, this will test URLFetcher's ability to do everything on one |
1304 // thread. | 1304 // thread. |
1305 CreateFetcher(test_server.GetURL("defaultresponse")); | 1305 CreateFetcher(test_server.GetURL("defaultresponse")); |
1306 | 1306 |
1307 MessageLoop::current()->Run(); | 1307 MessageLoop::current()->Run(); |
1308 } | 1308 } |
1309 | 1309 |
1310 TEST_F(URLFetcherFileTest, SmallGet) { | 1310 TEST_F(URLFetcherFileTest, SmallGet) { |
1311 TestServer test_server(TestServer::TYPE_HTTP, | 1311 TestServer test_server(TestServer::TYPE_HTTP, |
1312 TestServer::kLocalhost, | 1312 TestServer::kLocalhost, |
1313 base::FilePath(kDocRoot)); | 1313 TestServer::GetTestDataPath()); |
1314 ASSERT_TRUE(test_server.Start()); | 1314 ASSERT_TRUE(test_server.Start()); |
1315 | 1315 |
1316 base::ScopedTempDir temp_dir; | 1316 base::ScopedTempDir temp_dir; |
1317 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1317 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1318 | 1318 |
1319 // Get a small file. | 1319 // Get a small file. |
1320 static const char kFileToFetch[] = "simple.html"; | 1320 static const char kFileToFetch[] = "simple.html"; |
1321 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1321 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1322 CreateFetcherForFile( | 1322 CreateFetcherForFile( |
1323 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1323 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1324 temp_dir.path().AppendASCII(kFileToFetch)); | 1324 temp_dir.path().AppendASCII(kFileToFetch)); |
1325 | 1325 |
1326 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1326 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1327 | 1327 |
1328 ASSERT_FALSE(file_util::PathExists(file_path_)) | 1328 ASSERT_FALSE(file_util::PathExists(file_path_)) |
1329 << file_path_.value() << " not removed."; | 1329 << file_path_.value() << " not removed."; |
1330 } | 1330 } |
1331 | 1331 |
1332 TEST_F(URLFetcherFileTest, LargeGet) { | 1332 TEST_F(URLFetcherFileTest, LargeGet) { |
1333 TestServer test_server(TestServer::TYPE_HTTP, | 1333 TestServer test_server(TestServer::TYPE_HTTP, |
1334 TestServer::kLocalhost, | 1334 TestServer::kLocalhost, |
1335 base::FilePath(kDocRoot)); | 1335 TestServer::GetTestDataPath()); |
1336 ASSERT_TRUE(test_server.Start()); | 1336 ASSERT_TRUE(test_server.Start()); |
1337 | 1337 |
1338 base::ScopedTempDir temp_dir; | 1338 base::ScopedTempDir temp_dir; |
1339 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1339 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1340 | 1340 |
1341 // Get a file large enough to require more than one read into | 1341 // Get a file large enough to require more than one read into |
1342 // URLFetcher::Core's IOBuffer. | 1342 // URLFetcher::Core's IOBuffer. |
1343 static const char kFileToFetch[] = "animate1.gif"; | 1343 static const char kFileToFetch[] = "animate1.gif"; |
1344 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1344 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1345 CreateFetcherForFile( | 1345 CreateFetcherForFile( |
1346 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1346 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1347 temp_dir.path().AppendASCII(kFileToFetch)); | 1347 temp_dir.path().AppendASCII(kFileToFetch)); |
1348 | 1348 |
1349 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1349 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1350 } | 1350 } |
1351 | 1351 |
1352 TEST_F(URLFetcherFileTest, CanTakeOwnershipOfFile) { | 1352 TEST_F(URLFetcherFileTest, CanTakeOwnershipOfFile) { |
1353 TestServer test_server(TestServer::TYPE_HTTP, | 1353 TestServer test_server(TestServer::TYPE_HTTP, |
1354 TestServer::kLocalhost, | 1354 TestServer::kLocalhost, |
1355 base::FilePath(kDocRoot)); | 1355 TestServer::GetTestDataPath()); |
1356 ASSERT_TRUE(test_server.Start()); | 1356 ASSERT_TRUE(test_server.Start()); |
1357 | 1357 |
1358 base::ScopedTempDir temp_dir; | 1358 base::ScopedTempDir temp_dir; |
1359 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1359 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1360 | 1360 |
1361 // Get a small file. | 1361 // Get a small file. |
1362 static const char kFileToFetch[] = "simple.html"; | 1362 static const char kFileToFetch[] = "simple.html"; |
1363 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1363 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1364 CreateFetcherForFile( | 1364 CreateFetcherForFile( |
1365 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1365 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1366 temp_dir.path().AppendASCII(kFileToFetch)); | 1366 temp_dir.path().AppendASCII(kFileToFetch)); |
1367 | 1367 |
1368 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1368 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1369 | 1369 |
1370 MessageLoop::current()->RunUntilIdle(); | 1370 MessageLoop::current()->RunUntilIdle(); |
1371 ASSERT_FALSE(file_util::PathExists(file_path_)) | 1371 ASSERT_FALSE(file_util::PathExists(file_path_)) |
1372 << file_path_.value() << " not removed."; | 1372 << file_path_.value() << " not removed."; |
1373 } | 1373 } |
1374 | 1374 |
1375 | 1375 |
1376 TEST_F(URLFetcherFileTest, OverwriteExistingFile) { | 1376 TEST_F(URLFetcherFileTest, OverwriteExistingFile) { |
1377 TestServer test_server(TestServer::TYPE_HTTP, | 1377 TestServer test_server(TestServer::TYPE_HTTP, |
1378 TestServer::kLocalhost, | 1378 TestServer::kLocalhost, |
1379 base::FilePath(kDocRoot)); | 1379 TestServer::GetTestDataPath()); |
1380 ASSERT_TRUE(test_server.Start()); | 1380 ASSERT_TRUE(test_server.Start()); |
1381 | 1381 |
1382 base::ScopedTempDir temp_dir; | 1382 base::ScopedTempDir temp_dir; |
1383 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1383 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1384 | 1384 |
1385 // Create a file before trying to fetch. | 1385 // Create a file before trying to fetch. |
1386 static const char kFileToFetch[] = "simple.html"; | 1386 static const char kFileToFetch[] = "simple.html"; |
1387 static const char kData[] = "abcdefghijklmnopqrstuvwxyz"; | 1387 static const char kData[] = "abcdefghijklmnopqrstuvwxyz"; |
1388 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); | 1388 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); |
1389 const int data_size = arraysize(kData); | 1389 const int data_size = arraysize(kData); |
1390 ASSERT_EQ(file_util::WriteFile(file_path_, kData, data_size), data_size); | 1390 ASSERT_EQ(file_util::WriteFile(file_path_, kData, data_size), data_size); |
1391 ASSERT_TRUE(file_util::PathExists(file_path_)); | 1391 ASSERT_TRUE(file_util::PathExists(file_path_)); |
1392 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1392 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1393 ASSERT_FALSE(file_util::ContentsEqual(file_path_, expected_file_)); | 1393 ASSERT_FALSE(file_util::ContentsEqual(file_path_, expected_file_)); |
1394 | 1394 |
1395 // Get a small file. | 1395 // Get a small file. |
1396 CreateFetcherForFile( | 1396 CreateFetcherForFile( |
1397 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1397 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1398 file_path_); | 1398 file_path_); |
1399 | 1399 |
1400 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1400 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1401 } | 1401 } |
1402 | 1402 |
1403 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) { | 1403 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) { |
1404 TestServer test_server(TestServer::TYPE_HTTP, | 1404 TestServer test_server(TestServer::TYPE_HTTP, |
1405 TestServer::kLocalhost, | 1405 TestServer::kLocalhost, |
1406 base::FilePath(kDocRoot)); | 1406 TestServer::GetTestDataPath()); |
1407 ASSERT_TRUE(test_server.Start()); | 1407 ASSERT_TRUE(test_server.Start()); |
1408 | 1408 |
1409 base::ScopedTempDir temp_dir; | 1409 base::ScopedTempDir temp_dir; |
1410 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1410 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1411 | 1411 |
1412 // Create a directory before trying to fetch. | 1412 // Create a directory before trying to fetch. |
1413 static const char kFileToFetch[] = "simple.html"; | 1413 static const char kFileToFetch[] = "simple.html"; |
1414 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); | 1414 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); |
1415 ASSERT_TRUE(file_util::CreateDirectory(file_path_)); | 1415 ASSERT_TRUE(file_util::CreateDirectory(file_path_)); |
1416 ASSERT_TRUE(file_util::PathExists(file_path_)); | 1416 ASSERT_TRUE(file_util::PathExists(file_path_)); |
1417 | 1417 |
1418 // Get a small file. | 1418 // Get a small file. |
1419 expected_file_error_ = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; | 1419 expected_file_error_ = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; |
1420 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1420 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1421 CreateFetcherForFile( | 1421 CreateFetcherForFile( |
1422 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1422 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1423 file_path_); | 1423 file_path_); |
1424 | 1424 |
1425 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1425 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1426 | 1426 |
1427 MessageLoop::current()->RunUntilIdle(); | 1427 MessageLoop::current()->RunUntilIdle(); |
1428 } | 1428 } |
1429 | 1429 |
1430 TEST_F(URLFetcherFileTest, SmallGetToTempFile) { | 1430 TEST_F(URLFetcherFileTest, SmallGetToTempFile) { |
1431 TestServer test_server(TestServer::TYPE_HTTP, | 1431 TestServer test_server(TestServer::TYPE_HTTP, |
1432 TestServer::kLocalhost, | 1432 TestServer::kLocalhost, |
1433 base::FilePath(kDocRoot)); | 1433 TestServer::GetTestDataPath()); |
1434 ASSERT_TRUE(test_server.Start()); | 1434 ASSERT_TRUE(test_server.Start()); |
1435 | 1435 |
1436 // Get a small file. | 1436 // Get a small file. |
1437 static const char kFileToFetch[] = "simple.html"; | 1437 static const char kFileToFetch[] = "simple.html"; |
1438 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1438 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1439 CreateFetcherForTempFile( | 1439 CreateFetcherForTempFile( |
1440 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | 1440 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
1441 | 1441 |
1442 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1442 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1443 | 1443 |
1444 ASSERT_FALSE(file_util::PathExists(file_path_)) | 1444 ASSERT_FALSE(file_util::PathExists(file_path_)) |
1445 << file_path_.value() << " not removed."; | 1445 << file_path_.value() << " not removed."; |
1446 } | 1446 } |
1447 | 1447 |
1448 TEST_F(URLFetcherFileTest, LargeGetToTempFile) { | 1448 TEST_F(URLFetcherFileTest, LargeGetToTempFile) { |
1449 TestServer test_server(TestServer::TYPE_HTTP, | 1449 TestServer test_server(TestServer::TYPE_HTTP, |
1450 TestServer::kLocalhost, | 1450 TestServer::kLocalhost, |
1451 base::FilePath(kDocRoot)); | 1451 TestServer::GetTestDataPath()); |
1452 ASSERT_TRUE(test_server.Start()); | 1452 ASSERT_TRUE(test_server.Start()); |
1453 | 1453 |
1454 // Get a file large enough to require more than one read into | 1454 // Get a file large enough to require more than one read into |
1455 // URLFetcher::Core's IOBuffer. | 1455 // URLFetcher::Core's IOBuffer. |
1456 static const char kFileToFetch[] = "animate1.gif"; | 1456 static const char kFileToFetch[] = "animate1.gif"; |
1457 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1457 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1458 CreateFetcherForTempFile(test_server.GetURL( | 1458 CreateFetcherForTempFile(test_server.GetURL( |
1459 std::string(kTestServerFilePrefix) + kFileToFetch)); | 1459 std::string(kTestServerFilePrefix) + kFileToFetch)); |
1460 | 1460 |
1461 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1461 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1462 } | 1462 } |
1463 | 1463 |
1464 TEST_F(URLFetcherFileTest, CanTakeOwnershipOfTempFile) { | 1464 TEST_F(URLFetcherFileTest, CanTakeOwnershipOfTempFile) { |
1465 TestServer test_server(TestServer::TYPE_HTTP, | 1465 TestServer test_server(TestServer::TYPE_HTTP, |
1466 TestServer::kLocalhost, | 1466 TestServer::kLocalhost, |
1467 base::FilePath(kDocRoot)); | 1467 TestServer::GetTestDataPath()); |
1468 ASSERT_TRUE(test_server.Start()); | 1468 ASSERT_TRUE(test_server.Start()); |
1469 | 1469 |
1470 // Get a small file. | 1470 // Get a small file. |
1471 static const char kFileToFetch[] = "simple.html"; | 1471 static const char kFileToFetch[] = "simple.html"; |
1472 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1472 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1473 CreateFetcherForTempFile(test_server.GetURL( | 1473 CreateFetcherForTempFile(test_server.GetURL( |
1474 std::string(kTestServerFilePrefix) + kFileToFetch)); | 1474 std::string(kTestServerFilePrefix) + kFileToFetch)); |
1475 | 1475 |
1476 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1476 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1477 | 1477 |
1478 MessageLoop::current()->RunUntilIdle(); | 1478 MessageLoop::current()->RunUntilIdle(); |
1479 ASSERT_FALSE(file_util::PathExists(file_path_)) | 1479 ASSERT_FALSE(file_util::PathExists(file_path_)) |
1480 << file_path_.value() << " not removed."; | 1480 << file_path_.value() << " not removed."; |
1481 } | 1481 } |
1482 | 1482 |
1483 } // namespace | 1483 } // namespace |
1484 | 1484 |
1485 } // namespace net | 1485 } // namespace net |
OLD | NEW |