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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 scoped_refptr<URLRequestThrottlerEntry> entry( | 454 scoped_refptr<URLRequestThrottlerEntry> entry( |
455 new URLRequestThrottlerEntry(context_->throttler_manager(), | 455 new URLRequestThrottlerEntry(context_->throttler_manager(), |
456 std::string(), | 456 std::string(), |
457 200, | 457 200, |
458 3, | 458 3, |
459 2000, | 459 2000, |
460 2.0, | 460 2.0, |
461 0.0, | 461 0.0, |
462 4000)); | 462 4000)); |
463 context_->throttler_manager() | 463 context_->throttler_manager() |
464 ->OverrideEntryForTests(throttle_for_url_, entry); | 464 ->OverrideEntryForTests(throttle_for_url_, entry.get()); |
465 | 465 |
466 context_created_.Signal(); | 466 context_created_.Signal(); |
467 } | 467 } |
468 return context_.get(); | 468 return context_.get(); |
469 } | 469 } |
470 | 470 |
471 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | 471 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { |
472 return io_message_loop_proxy_; | 472 return io_message_loop_proxy_; |
473 } | 473 } |
474 | 474 |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 // in 200 milliseconds. | 1195 // in 200 milliseconds. |
1196 scoped_refptr<URLRequestThrottlerEntry> entry( | 1196 scoped_refptr<URLRequestThrottlerEntry> entry( |
1197 new URLRequestThrottlerEntry(request_context()->throttler_manager(), | 1197 new URLRequestThrottlerEntry(request_context()->throttler_manager(), |
1198 std::string(), | 1198 std::string(), |
1199 200, | 1199 200, |
1200 3, | 1200 3, |
1201 1, | 1201 1, |
1202 2.0, | 1202 2.0, |
1203 0.0, | 1203 0.0, |
1204 256)); | 1204 256)); |
1205 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); | 1205 request_context()->throttler_manager() |
| 1206 ->OverrideEntryForTests(url, entry.get()); |
1206 | 1207 |
1207 CreateFetcher(url); | 1208 CreateFetcher(url); |
1208 | 1209 |
1209 base::MessageLoop::current()->Run(); | 1210 base::MessageLoop::current()->Run(); |
1210 } | 1211 } |
1211 | 1212 |
1212 TEST_F(URLFetcherProtectTest, ServerUnavailable) { | 1213 TEST_F(URLFetcherProtectTest, ServerUnavailable) { |
1213 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1214 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1214 SpawnedTestServer::kLocalhost, | 1215 SpawnedTestServer::kLocalhost, |
1215 base::FilePath(kDocRoot)); | 1216 base::FilePath(kDocRoot)); |
1216 ASSERT_TRUE(test_server.Start()); | 1217 ASSERT_TRUE(test_server.Start()); |
1217 | 1218 |
1218 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1219 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1219 | 1220 |
1220 // Registers an entry for test url. The backoff time is calculated by: | 1221 // Registers an entry for test url. The backoff time is calculated by: |
1221 // new_backoff = 2.0 * old_backoff + 0 | 1222 // new_backoff = 2.0 * old_backoff + 0 |
1222 // and maximum backoff time is 256 milliseconds. | 1223 // and maximum backoff time is 256 milliseconds. |
1223 // Maximum retries allowed is set to 11. | 1224 // Maximum retries allowed is set to 11. |
1224 scoped_refptr<URLRequestThrottlerEntry> entry( | 1225 scoped_refptr<URLRequestThrottlerEntry> entry( |
1225 new URLRequestThrottlerEntry(request_context()->throttler_manager(), | 1226 new URLRequestThrottlerEntry(request_context()->throttler_manager(), |
1226 std::string(), | 1227 std::string(), |
1227 200, | 1228 200, |
1228 3, | 1229 3, |
1229 1, | 1230 1, |
1230 2.0, | 1231 2.0, |
1231 0.0, | 1232 0.0, |
1232 256)); | 1233 256)); |
1233 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); | 1234 request_context()->throttler_manager() |
| 1235 ->OverrideEntryForTests(url, entry.get()); |
1234 | 1236 |
1235 CreateFetcher(url); | 1237 CreateFetcher(url); |
1236 | 1238 |
1237 base::MessageLoop::current()->Run(); | 1239 base::MessageLoop::current()->Run(); |
1238 } | 1240 } |
1239 | 1241 |
1240 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { | 1242 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { |
1241 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1243 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1242 SpawnedTestServer::kLocalhost, | 1244 SpawnedTestServer::kLocalhost, |
1243 base::FilePath(kDocRoot)); | 1245 base::FilePath(kDocRoot)); |
1244 ASSERT_TRUE(test_server.Start()); | 1246 ASSERT_TRUE(test_server.Start()); |
1245 | 1247 |
1246 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1248 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1247 | 1249 |
1248 // Registers an entry for test url. The backoff time is calculated by: | 1250 // Registers an entry for test url. The backoff time is calculated by: |
1249 // new_backoff = 2.0 * old_backoff + 0 | 1251 // new_backoff = 2.0 * old_backoff + 0 |
1250 // and maximum backoff time is 150000 milliseconds. | 1252 // and maximum backoff time is 150000 milliseconds. |
1251 // Maximum retries allowed is set to 11. | 1253 // Maximum retries allowed is set to 11. |
1252 scoped_refptr<URLRequestThrottlerEntry> entry( | 1254 scoped_refptr<URLRequestThrottlerEntry> entry( |
1253 new URLRequestThrottlerEntry(request_context()->throttler_manager(), | 1255 new URLRequestThrottlerEntry(request_context()->throttler_manager(), |
1254 std::string(), | 1256 std::string(), |
1255 200, | 1257 200, |
1256 3, | 1258 3, |
1257 100, | 1259 100, |
1258 2.0, | 1260 2.0, |
1259 0.0, | 1261 0.0, |
1260 150000)); | 1262 150000)); |
1261 // Total time if *not* for not doing automatic backoff would be 150s. | 1263 // Total time if *not* for not doing automatic backoff would be 150s. |
1262 // In reality it should be "as soon as server responds". | 1264 // In reality it should be "as soon as server responds". |
1263 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); | 1265 request_context()->throttler_manager() |
| 1266 ->OverrideEntryForTests(url, entry.get()); |
1264 | 1267 |
1265 CreateFetcher(url); | 1268 CreateFetcher(url); |
1266 | 1269 |
1267 base::MessageLoop::current()->Run(); | 1270 base::MessageLoop::current()->Run(); |
1268 } | 1271 } |
1269 | 1272 |
1270 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { | 1273 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { |
1271 SpawnedTestServer::SSLOptions ssl_options( | 1274 SpawnedTestServer::SSLOptions ssl_options( |
1272 SpawnedTestServer::SSLOptions::CERT_EXPIRED); | 1275 SpawnedTestServer::SSLOptions::CERT_EXPIRED); |
1273 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, | 1276 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 // run we expect to have a 4 second delay when posting the Start task. | 1318 // run we expect to have a 4 second delay when posting the Start task. |
1316 scoped_refptr<URLRequestThrottlerEntry> entry( | 1319 scoped_refptr<URLRequestThrottlerEntry> entry( |
1317 new URLRequestThrottlerEntry(request_context()->throttler_manager(), | 1320 new URLRequestThrottlerEntry(request_context()->throttler_manager(), |
1318 std::string(), | 1321 std::string(), |
1319 4000, | 1322 4000, |
1320 1, | 1323 1, |
1321 2000, | 1324 2000, |
1322 2.0, | 1325 2.0, |
1323 0.0, | 1326 0.0, |
1324 4000)); | 1327 4000)); |
1325 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); | 1328 request_context()->throttler_manager() |
| 1329 ->OverrideEntryForTests(url, entry.get()); |
1326 // Fake that a request has just started. | 1330 // Fake that a request has just started. |
1327 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); | 1331 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); |
1328 | 1332 |
1329 // The next request we try to send will be delayed by ~4 seconds. | 1333 // The next request we try to send will be delayed by ~4 seconds. |
1330 // The slower the test runs, the less the delay will be (since it takes the | 1334 // The slower the test runs, the less the delay will be (since it takes the |
1331 // time difference from now). | 1335 // time difference from now). |
1332 | 1336 |
1333 base::Thread t("URLFetcher test thread"); | 1337 base::Thread t("URLFetcher test thread"); |
1334 ASSERT_TRUE(t.Start()); | 1338 ASSERT_TRUE(t.Start()); |
1335 t.message_loop()->PostTask( | 1339 t.message_loop()->PostTask( |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1526 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1523 | 1527 |
1524 base::MessageLoop::current()->RunUntilIdle(); | 1528 base::MessageLoop::current()->RunUntilIdle(); |
1525 ASSERT_FALSE(file_util::PathExists(file_path_)) << file_path_.value() | 1529 ASSERT_FALSE(file_util::PathExists(file_path_)) << file_path_.value() |
1526 << " not removed."; | 1530 << " not removed."; |
1527 } | 1531 } |
1528 | 1532 |
1529 } // namespace | 1533 } // namespace |
1530 | 1534 |
1531 } // namespace net | 1535 } // namespace net |
OLD | NEW |