Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: net/url_request/url_fetcher_impl_unittest.cc

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { 434 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE {
435 if (!context_.get()) { 435 if (!context_.get()) {
436 context_.reset(new CancelTestURLRequestContext()); 436 context_.reset(new CancelTestURLRequestContext());
437 DCHECK(context_->throttler_manager()); 437 DCHECK(context_->throttler_manager());
438 438
439 // Registers an entry for test url. The backoff time is calculated by: 439 // Registers an entry for test url. The backoff time is calculated by:
440 // new_backoff = 2.0 * old_backoff + 0 440 // new_backoff = 2.0 * old_backoff + 0
441 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. 441 // The initial backoff is 2 seconds and maximum backoff is 4 seconds.
442 // Maximum retries allowed is set to 2. 442 // Maximum retries allowed is set to 2.
443 scoped_refptr<URLRequestThrottlerEntry> entry( 443 scoped_refptr<URLRequestThrottlerEntry> entry(
444 new URLRequestThrottlerEntry( 444 new URLRequestThrottlerEntry(context_->throttler_manager(),
445 context_->throttler_manager(), 445 std::string(),
446 "", 200, 3, 2000, 2.0, 0.0, 4000)); 446 200,
447 context_->throttler_manager()->OverrideEntryForTests( 447 3,
448 throttle_for_url_, entry); 448 2000,
449 2.0,
450 0.0,
451 4000));
452 context_->throttler_manager()
453 ->OverrideEntryForTests(throttle_for_url_, entry);
449 454
450 context_created_.Signal(); 455 context_created_.Signal();
451 } 456 }
452 return context_.get(); 457 return context_.get();
453 } 458 }
454 459
455 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { 460 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
456 return io_message_loop_proxy_; 461 return io_message_loop_proxy_;
457 } 462 }
458 463
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 std::string data; 551 std::string data;
547 EXPECT_TRUE(source->GetResponseAsString(&data)); 552 EXPECT_TRUE(source->GetResponseAsString(&data));
548 EXPECT_EQ(std::string(&expected[0], size), data); 553 EXPECT_EQ(std::string(&expected[0], size), data);
549 URLFetcherTest::OnURLFetchComplete(source); 554 URLFetcherTest::OnURLFetchComplete(source);
550 } 555 }
551 556
552 void URLFetcherEmptyPostTest::CreateFetcher(const GURL& url) { 557 void URLFetcherEmptyPostTest::CreateFetcher(const GURL& url) {
553 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); 558 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
554 fetcher_->SetRequestContext(new TestURLRequestContextGetter( 559 fetcher_->SetRequestContext(new TestURLRequestContextGetter(
555 io_message_loop_proxy())); 560 io_message_loop_proxy()));
556 fetcher_->SetUploadData("text/plain", ""); 561 fetcher_->SetUploadData("text/plain", std::string());
557 fetcher_->Start(); 562 fetcher_->Start();
558 } 563 }
559 564
560 void URLFetcherEmptyPostTest::OnURLFetchComplete(const URLFetcher* source) { 565 void URLFetcherEmptyPostTest::OnURLFetchComplete(const URLFetcher* source) {
561 EXPECT_TRUE(source->GetStatus().is_success()); 566 EXPECT_TRUE(source->GetStatus().is_success());
562 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK 567 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK
563 568
564 std::string data; 569 std::string data;
565 EXPECT_TRUE(source->GetResponseAsString(&data)); 570 EXPECT_TRUE(source->GetResponseAsString(&data));
566 EXPECT_TRUE(data.empty()); 571 EXPECT_TRUE(data.empty());
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 TestServer test_server(TestServer::TYPE_HTTP, 1161 TestServer test_server(TestServer::TYPE_HTTP,
1157 TestServer::kLocalhost, 1162 TestServer::kLocalhost,
1158 base::FilePath(kDocRoot)); 1163 base::FilePath(kDocRoot));
1159 ASSERT_TRUE(test_server.Start()); 1164 ASSERT_TRUE(test_server.Start());
1160 1165
1161 GURL url(test_server.GetURL("defaultresponse")); 1166 GURL url(test_server.GetURL("defaultresponse"));
1162 1167
1163 // 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
1164 // in 200 milliseconds. 1169 // in 200 milliseconds.
1165 scoped_refptr<URLRequestThrottlerEntry> entry( 1170 scoped_refptr<URLRequestThrottlerEntry> entry(
1166 new URLRequestThrottlerEntry( 1171 new URLRequestThrottlerEntry(request_context()->throttler_manager(),
1167 request_context()->throttler_manager(), 1172 std::string(),
1168 "", 200, 3, 1, 2.0, 0.0, 256)); 1173 200,
1174 3,
1175 1,
1176 2.0,
1177 0.0,
1178 256));
1169 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); 1179 request_context()->throttler_manager()->OverrideEntryForTests(url, entry);
1170 1180
1171 CreateFetcher(url); 1181 CreateFetcher(url);
1172 1182
1173 MessageLoop::current()->Run(); 1183 MessageLoop::current()->Run();
1174 } 1184 }
1175 1185
1176 TEST_F(URLFetcherProtectTest, ServerUnavailable) { 1186 TEST_F(URLFetcherProtectTest, ServerUnavailable) {
1177 TestServer test_server(TestServer::TYPE_HTTP, 1187 TestServer test_server(TestServer::TYPE_HTTP,
1178 TestServer::kLocalhost, 1188 TestServer::kLocalhost,
1179 base::FilePath(kDocRoot)); 1189 base::FilePath(kDocRoot));
1180 ASSERT_TRUE(test_server.Start()); 1190 ASSERT_TRUE(test_server.Start());
1181 1191
1182 GURL url(test_server.GetURL("files/server-unavailable.html")); 1192 GURL url(test_server.GetURL("files/server-unavailable.html"));
1183 1193
1184 // Registers an entry for test url. The backoff time is calculated by: 1194 // Registers an entry for test url. The backoff time is calculated by:
1185 // new_backoff = 2.0 * old_backoff + 0 1195 // new_backoff = 2.0 * old_backoff + 0
1186 // and maximum backoff time is 256 milliseconds. 1196 // and maximum backoff time is 256 milliseconds.
1187 // Maximum retries allowed is set to 11. 1197 // Maximum retries allowed is set to 11.
1188 scoped_refptr<URLRequestThrottlerEntry> entry( 1198 scoped_refptr<URLRequestThrottlerEntry> entry(
1189 new URLRequestThrottlerEntry( 1199 new URLRequestThrottlerEntry(request_context()->throttler_manager(),
1190 request_context()->throttler_manager(), 1200 std::string(),
1191 "", 200, 3, 1, 2.0, 0.0, 256)); 1201 200,
1202 3,
1203 1,
1204 2.0,
1205 0.0,
1206 256));
1192 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); 1207 request_context()->throttler_manager()->OverrideEntryForTests(url, entry);
1193 1208
1194 CreateFetcher(url); 1209 CreateFetcher(url);
1195 1210
1196 MessageLoop::current()->Run(); 1211 MessageLoop::current()->Run();
1197 } 1212 }
1198 1213
1199 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { 1214 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) {
1200 TestServer test_server(TestServer::TYPE_HTTP, 1215 TestServer test_server(TestServer::TYPE_HTTP,
1201 TestServer::kLocalhost, 1216 TestServer::kLocalhost,
1202 base::FilePath(kDocRoot)); 1217 base::FilePath(kDocRoot));
1203 ASSERT_TRUE(test_server.Start()); 1218 ASSERT_TRUE(test_server.Start());
1204 1219
1205 GURL url(test_server.GetURL("files/server-unavailable.html")); 1220 GURL url(test_server.GetURL("files/server-unavailable.html"));
1206 1221
1207 // Registers an entry for test url. The backoff time is calculated by: 1222 // Registers an entry for test url. The backoff time is calculated by:
1208 // new_backoff = 2.0 * old_backoff + 0 1223 // new_backoff = 2.0 * old_backoff + 0
1209 // and maximum backoff time is 150000 milliseconds. 1224 // and maximum backoff time is 150000 milliseconds.
1210 // Maximum retries allowed is set to 11. 1225 // Maximum retries allowed is set to 11.
1211 scoped_refptr<URLRequestThrottlerEntry> entry( 1226 scoped_refptr<URLRequestThrottlerEntry> entry(
1212 new URLRequestThrottlerEntry( 1227 new URLRequestThrottlerEntry(request_context()->throttler_manager(),
1213 request_context()->throttler_manager(), 1228 std::string(),
1214 "", 200, 3, 100, 2.0, 0.0, 150000)); 1229 200,
1230 3,
1231 100,
1232 2.0,
1233 0.0,
1234 150000));
1215 // Total time if *not* for not doing automatic backoff would be 150s. 1235 // Total time if *not* for not doing automatic backoff would be 150s.
1216 // In reality it should be "as soon as server responds". 1236 // In reality it should be "as soon as server responds".
1217 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); 1237 request_context()->throttler_manager()->OverrideEntryForTests(url, entry);
1218 1238
1219 CreateFetcher(url); 1239 CreateFetcher(url);
1220 1240
1221 MessageLoop::current()->Run(); 1241 MessageLoop::current()->Run();
1222 } 1242 }
1223 1243
1224 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { 1244 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 TestServer::kLocalhost, 1281 TestServer::kLocalhost,
1262 base::FilePath(kDocRoot)); 1282 base::FilePath(kDocRoot));
1263 ASSERT_TRUE(test_server.Start()); 1283 ASSERT_TRUE(test_server.Start());
1264 1284
1265 GURL url(test_server.GetURL("files/server-unavailable.html")); 1285 GURL url(test_server.GetURL("files/server-unavailable.html"));
1266 1286
1267 // Register an entry for test url. 1287 // Register an entry for test url.
1268 // Using a sliding window of 4 seconds, and max of 1 request, under a fast 1288 // Using a sliding window of 4 seconds, and max of 1 request, under a fast
1269 // run we expect to have a 4 second delay when posting the Start task. 1289 // run we expect to have a 4 second delay when posting the Start task.
1270 scoped_refptr<URLRequestThrottlerEntry> entry( 1290 scoped_refptr<URLRequestThrottlerEntry> entry(
1271 new URLRequestThrottlerEntry( 1291 new URLRequestThrottlerEntry(request_context()->throttler_manager(),
1272 request_context()->throttler_manager(), 1292 std::string(),
1273 "", 4000, 1, 2000, 2.0, 0.0, 4000)); 1293 4000,
1294 1,
1295 2000,
1296 2.0,
1297 0.0,
1298 4000));
1274 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); 1299 request_context()->throttler_manager()->OverrideEntryForTests(url, entry);
1275 // Fake that a request has just started. 1300 // Fake that a request has just started.
1276 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); 1301 entry->ReserveSendingTimeForNextRequest(base::TimeTicks());
1277 1302
1278 // The next request we try to send will be delayed by ~4 seconds. 1303 // The next request we try to send will be delayed by ~4 seconds.
1279 // The slower the test runs, the less the delay will be (since it takes the 1304 // The slower the test runs, the less the delay will be (since it takes the
1280 // time difference from now). 1305 // time difference from now).
1281 1306
1282 base::Thread t("URLFetcher test thread"); 1307 base::Thread t("URLFetcher test thread");
1283 ASSERT_TRUE(t.Start()); 1308 ASSERT_TRUE(t.Start());
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1496 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1472 1497
1473 MessageLoop::current()->RunUntilIdle(); 1498 MessageLoop::current()->RunUntilIdle();
1474 ASSERT_FALSE(file_util::PathExists(file_path_)) 1499 ASSERT_FALSE(file_util::PathExists(file_path_))
1475 << file_path_.value() << " not removed."; 1500 << file_path_.value() << " not removed.";
1476 } 1501 }
1477 1502
1478 } // namespace 1503 } // namespace
1479 1504
1480 } // namespace net 1505 } // namespace net
OLDNEW
« no previous file with comments | « net/udp/udp_socket_unittest.cc ('k') | net/url_request/url_request_throttler_simulation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698