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

Side by Side Diff: chrome/browser/url_fetcher_unittest.cc

Issue 16490: Add FTP unit test in preparation for portable FTP implementation.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 11 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
« no previous file with comments | « chrome/browser/tab_restore_uitest.cc ('k') | chrome/browser/view_source_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/thread.h" 5 #include "base/thread.h"
6 #include "base/time.h" 6 #include "base/time.h"
7 #include "chrome/browser/url_fetcher.h" 7 #include "chrome/browser/url_fetcher.h"
8 #include "chrome/browser/url_fetcher_protect.h" 8 #include "chrome/browser/url_fetcher_protect.h"
9 #include "net/base/ssl_test_util.h" 9 #include "net/base/ssl_test_util.h"
10 #include "net/url_request/url_request_unittest.h" 10 #include "net/url_request/url_request_unittest.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 timer_.Stop(); 331 timer_.Stop();
332 io_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask()); 332 io_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask());
333 } 333 }
334 334
335 } // namespace. 335 } // namespace.
336 336
337 TEST_F(URLFetcherTest, SameThreadsTest) { 337 TEST_F(URLFetcherTest, SameThreadsTest) {
338 // Create the fetcher on the main thread. Since IO will happen on the main 338 // Create the fetcher on the main thread. Since IO will happen on the main
339 // thread, this will test URLFetcher's ability to do everything on one 339 // thread, this will test URLFetcher's ability to do everything on one
340 // thread. 340 // thread.
341 TestServer server(kDocRoot); 341 scoped_refptr<HTTPTestServer> server =
342 HTTPTestServer::CreateServer(kDocRoot);
343 ASSERT_TRUE(NULL != server.get());
342 344
343 CreateFetcher(GURL(server.TestServerPage("defaultresponse"))); 345 CreateFetcher(GURL(server->TestServerPage("defaultresponse")));
344 346
345 MessageLoop::current()->Run(); 347 MessageLoop::current()->Run();
346 } 348 }
347 349
348 TEST_F(URLFetcherTest, DifferentThreadsTest) { 350 TEST_F(URLFetcherTest, DifferentThreadsTest) {
349 TestServer server(kDocRoot); 351 scoped_refptr<HTTPTestServer> server =
352 HTTPTestServer::CreateServer(kDocRoot);
353 ASSERT_TRUE(NULL != server.get());
350 // Create a separate thread that will create the URLFetcher. The current 354 // Create a separate thread that will create the URLFetcher. The current
351 // (main) thread will do the IO, and when the fetch is complete it will 355 // (main) thread will do the IO, and when the fetch is complete it will
352 // terminate the main thread's message loop; then the other thread's 356 // terminate the main thread's message loop; then the other thread's
353 // message loop will be shut down automatically as the thread goes out of 357 // message loop will be shut down automatically as the thread goes out of
354 // scope. 358 // scope.
355 base::Thread t("URLFetcher test thread"); 359 base::Thread t("URLFetcher test thread");
356 t.Start(); 360 t.Start();
357 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, 361 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this,
358 GURL(server.TestServerPage("defaultresponse")))); 362 GURL(server->TestServerPage("defaultresponse"))));
359 363
360 MessageLoop::current()->Run(); 364 MessageLoop::current()->Run();
361 } 365 }
362 366
363 TEST_F(URLFetcherPostTest, Basic) { 367 TEST_F(URLFetcherPostTest, Basic) {
364 TestServer server(kDocRoot); 368 scoped_refptr<HTTPTestServer> server =
365 CreateFetcher(GURL(server.TestServerPage("echo"))); 369 HTTPTestServer::CreateServer(kDocRoot);
370 ASSERT_TRUE(NULL != server.get());
371 CreateFetcher(GURL(server->TestServerPage("echo")));
366 MessageLoop::current()->Run(); 372 MessageLoop::current()->Run();
367 } 373 }
368 374
369 TEST_F(URLFetcherHeadersTest, Headers) { 375 TEST_F(URLFetcherHeadersTest, Headers) {
370 TestServer server(L"net/data/url_request_unittest"); 376 scoped_refptr<HTTPTestServer> server =
371 CreateFetcher(GURL(server.TestServerPage("files/with-headers.html"))); 377 HTTPTestServer::CreateServer(L"net/data/url_request_unittest");
378 ASSERT_TRUE(NULL != server.get());
379 CreateFetcher(GURL(server->TestServerPage("files/with-headers.html")));
372 MessageLoop::current()->Run(); 380 MessageLoop::current()->Run();
373 // The actual tests are in the URLFetcherHeadersTest fixture. 381 // The actual tests are in the URLFetcherHeadersTest fixture.
374 } 382 }
375 383
376 TEST_F(URLFetcherProtectTest, Overload) { 384 TEST_F(URLFetcherProtectTest, Overload) {
377 TestServer server(kDocRoot); 385 scoped_refptr<HTTPTestServer> server =
378 GURL url = GURL(server.TestServerPage("defaultresponse")); 386 HTTPTestServer::CreateServer(kDocRoot);
387 ASSERT_TRUE(NULL != server.get());
388 GURL url = GURL(server->TestServerPage("defaultresponse"));
379 389
380 // Registers an entry for test url. It only allows 3 requests to be sent 390 // Registers an entry for test url. It only allows 3 requests to be sent
381 // in 200 milliseconds. 391 // in 200 milliseconds.
382 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); 392 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance();
383 URLFetcherProtectEntry* entry = 393 URLFetcherProtectEntry* entry =
384 new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256); 394 new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256);
385 manager->Register(url.host(), entry); 395 manager->Register(url.host(), entry);
386 396
387 CreateFetcher(url); 397 CreateFetcher(url);
388 398
389 MessageLoop::current()->Run(); 399 MessageLoop::current()->Run();
390 } 400 }
391 401
392 TEST_F(URLFetcherProtectTest, ServerUnavailable) { 402 TEST_F(URLFetcherProtectTest, ServerUnavailable) {
393 TestServer server(L"chrome/test/data"); 403 scoped_refptr<HTTPTestServer> server =
394 GURL url = GURL(server.TestServerPage("files/server-unavailable.html")); 404 HTTPTestServer::CreateServer(L"chrome/test/data");
405 ASSERT_TRUE(NULL != server.get());
406 GURL url = GURL(server->TestServerPage("files/server-unavailable.html"));
395 407
396 // Registers an entry for test url. The backoff time is calculated by: 408 // Registers an entry for test url. The backoff time is calculated by:
397 // new_backoff = 2.0 * old_backoff + 0 409 // new_backoff = 2.0 * old_backoff + 0
398 // and maximum backoff time is 256 milliseconds. 410 // and maximum backoff time is 256 milliseconds.
399 // Maximum retries allowed is set to 11. 411 // Maximum retries allowed is set to 11.
400 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); 412 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance();
401 URLFetcherProtectEntry* entry = 413 URLFetcherProtectEntry* entry =
402 new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256); 414 new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256);
403 manager->Register(url.host(), entry); 415 manager->Register(url.host(), entry);
404 416
405 CreateFetcher(url); 417 CreateFetcher(url);
406 418
407 MessageLoop::current()->Run(); 419 MessageLoop::current()->Run();
408 } 420 }
409 421
410 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { 422 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) {
411 HTTPSTestServer server(util_.kHostName, util_.kBadHTTPSPort, 423 scoped_refptr<HTTPSTestServer> server =
424 HTTPSTestServer::CreateServer(util_.kHostName, util_.kBadHTTPSPort,
412 kDocRoot, util_.GetExpiredCertPath().ToWStringHack()); 425 kDocRoot, util_.GetExpiredCertPath().ToWStringHack());
426 ASSERT_TRUE(NULL != server.get());
413 427
414 CreateFetcher(GURL(server.TestServerPage("defaultresponse"))); 428 CreateFetcher(GURL(server->TestServerPage("defaultresponse")));
415 429
416 MessageLoop::current()->Run(); 430 MessageLoop::current()->Run();
417 } 431 }
418 432
419 TEST_F(URLFetcherCancelTest, ReleasesContext) { 433 TEST_F(URLFetcherCancelTest, ReleasesContext) {
420 TestServer server(L"chrome/test/data"); 434 scoped_refptr<HTTPTestServer> server =
421 GURL url = GURL(server.TestServerPage("files/server-unavailable.html")); 435 HTTPTestServer::CreateServer(L"chrome/test/data");
436 ASSERT_TRUE(NULL != server.get());
437 GURL url = GURL(server->TestServerPage("files/server-unavailable.html"));
422 438
423 // 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:
424 // new_backoff = 2.0 * old_backoff + 0 440 // new_backoff = 2.0 * old_backoff + 0
425 // 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.
426 // Maximum retries allowed is set to 2. 442 // Maximum retries allowed is set to 2.
427 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); 443 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance();
428 URLFetcherProtectEntry* entry = 444 URLFetcherProtectEntry* entry =
429 new URLFetcherProtectEntry(200, 3, 2, 2000, 2.0, 0, 4000); 445 new URLFetcherProtectEntry(200, 3, 2, 2000, 2.0, 0, 4000);
430 manager->Register(url.host(), entry); 446 manager->Register(url.host(), entry);
431 447
432 // Create a separate thread that will create the URLFetcher. The current 448 // Create a separate thread that will create the URLFetcher. The current
433 // (main) thread will do the IO, and when the fetch is complete it will 449 // (main) thread will do the IO, and when the fetch is complete it will
434 // terminate the main thread's message loop; then the other thread's 450 // terminate the main thread's message loop; then the other thread's
435 // message loop will be shut down automatically as the thread goes out of 451 // message loop will be shut down automatically as the thread goes out of
436 // scope. 452 // scope.
437 base::Thread t("URLFetcher test thread"); 453 base::Thread t("URLFetcher test thread");
438 t.Start(); 454 t.Start();
439 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); 455 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url));
440 456
441 MessageLoop::current()->Run(); 457 MessageLoop::current()->Run();
442 } 458 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_restore_uitest.cc ('k') | chrome/browser/view_source_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698