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

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

Issue 17030: Revert 7508.7509 and 7510 (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 scoped_refptr<HTTPTestServer> server = 341 TestServer server(kDocRoot);
342 HTTPTestServer::CreateServer(kDocRoot);
343 ASSERT_TRUE(NULL != server.get());
344 342
345 CreateFetcher(GURL(server->TestServerPage("defaultresponse"))); 343 CreateFetcher(GURL(server.TestServerPage("defaultresponse")));
346 344
347 MessageLoop::current()->Run(); 345 MessageLoop::current()->Run();
348 } 346 }
349 347
350 TEST_F(URLFetcherTest, DifferentThreadsTest) { 348 TEST_F(URLFetcherTest, DifferentThreadsTest) {
351 scoped_refptr<HTTPTestServer> server = 349 TestServer server(kDocRoot);
352 HTTPTestServer::CreateServer(kDocRoot);
353 ASSERT_TRUE(NULL != server.get());
354 // Create a separate thread that will create the URLFetcher. The current 350 // Create a separate thread that will create the URLFetcher. The current
355 // (main) thread will do the IO, and when the fetch is complete it will 351 // (main) thread will do the IO, and when the fetch is complete it will
356 // terminate the main thread's message loop; then the other thread's 352 // terminate the main thread's message loop; then the other thread's
357 // message loop will be shut down automatically as the thread goes out of 353 // message loop will be shut down automatically as the thread goes out of
358 // scope. 354 // scope.
359 base::Thread t("URLFetcher test thread"); 355 base::Thread t("URLFetcher test thread");
360 t.Start(); 356 t.Start();
361 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, 357 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this,
362 GURL(server->TestServerPage("defaultresponse")))); 358 GURL(server.TestServerPage("defaultresponse"))));
363 359
364 MessageLoop::current()->Run(); 360 MessageLoop::current()->Run();
365 } 361 }
366 362
367 TEST_F(URLFetcherPostTest, Basic) { 363 TEST_F(URLFetcherPostTest, Basic) {
368 scoped_refptr<HTTPTestServer> server = 364 TestServer server(kDocRoot);
369 HTTPTestServer::CreateServer(kDocRoot); 365 CreateFetcher(GURL(server.TestServerPage("echo")));
370 ASSERT_TRUE(NULL != server.get());
371 CreateFetcher(GURL(server->TestServerPage("echo")));
372 MessageLoop::current()->Run(); 366 MessageLoop::current()->Run();
373 } 367 }
374 368
375 TEST_F(URLFetcherHeadersTest, Headers) { 369 TEST_F(URLFetcherHeadersTest, Headers) {
376 scoped_refptr<HTTPTestServer> server = 370 TestServer server(L"net/data/url_request_unittest");
377 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); 371 CreateFetcher(GURL(server.TestServerPage("files/with-headers.html")));
378 ASSERT_TRUE(NULL != server.get());
379 CreateFetcher(GURL(server->TestServerPage("files/with-headers.html")));
380 MessageLoop::current()->Run(); 372 MessageLoop::current()->Run();
381 // The actual tests are in the URLFetcherHeadersTest fixture. 373 // The actual tests are in the URLFetcherHeadersTest fixture.
382 } 374 }
383 375
384 TEST_F(URLFetcherProtectTest, Overload) { 376 TEST_F(URLFetcherProtectTest, Overload) {
385 scoped_refptr<HTTPTestServer> server = 377 TestServer server(kDocRoot);
386 HTTPTestServer::CreateServer(kDocRoot); 378 GURL url = GURL(server.TestServerPage("defaultresponse"));
387 ASSERT_TRUE(NULL != server.get());
388 GURL url = GURL(server->TestServerPage("defaultresponse"));
389 379
390 // Registers an entry for test url. It only allows 3 requests to be sent 380 // Registers an entry for test url. It only allows 3 requests to be sent
391 // in 200 milliseconds. 381 // in 200 milliseconds.
392 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); 382 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance();
393 URLFetcherProtectEntry* entry = 383 URLFetcherProtectEntry* entry =
394 new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256); 384 new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256);
395 manager->Register(url.host(), entry); 385 manager->Register(url.host(), entry);
396 386
397 CreateFetcher(url); 387 CreateFetcher(url);
398 388
399 MessageLoop::current()->Run(); 389 MessageLoop::current()->Run();
400 } 390 }
401 391
402 TEST_F(URLFetcherProtectTest, ServerUnavailable) { 392 TEST_F(URLFetcherProtectTest, ServerUnavailable) {
403 scoped_refptr<HTTPTestServer> server = 393 TestServer server(L"chrome/test/data");
404 HTTPTestServer::CreateServer(L"chrome/test/data"); 394 GURL url = GURL(server.TestServerPage("files/server-unavailable.html"));
405 ASSERT_TRUE(NULL != server.get());
406 GURL url = GURL(server->TestServerPage("files/server-unavailable.html"));
407 395
408 // Registers an entry for test url. The backoff time is calculated by: 396 // Registers an entry for test url. The backoff time is calculated by:
409 // new_backoff = 2.0 * old_backoff + 0 397 // new_backoff = 2.0 * old_backoff + 0
410 // and maximum backoff time is 256 milliseconds. 398 // and maximum backoff time is 256 milliseconds.
411 // Maximum retries allowed is set to 11. 399 // Maximum retries allowed is set to 11.
412 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); 400 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance();
413 URLFetcherProtectEntry* entry = 401 URLFetcherProtectEntry* entry =
414 new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256); 402 new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256);
415 manager->Register(url.host(), entry); 403 manager->Register(url.host(), entry);
416 404
417 CreateFetcher(url); 405 CreateFetcher(url);
418 406
419 MessageLoop::current()->Run(); 407 MessageLoop::current()->Run();
420 } 408 }
421 409
422 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { 410 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) {
423 scoped_refptr<HTTPSTestServer> server = 411 HTTPSTestServer server(util_.kHostName, util_.kBadHTTPSPort,
424 HTTPSTestServer::CreateServer(util_.kHostName, util_.kBadHTTPSPort,
425 kDocRoot, util_.GetExpiredCertPath().ToWStringHack()); 412 kDocRoot, util_.GetExpiredCertPath().ToWStringHack());
426 ASSERT_TRUE(NULL != server.get());
427 413
428 CreateFetcher(GURL(server->TestServerPage("defaultresponse"))); 414 CreateFetcher(GURL(server.TestServerPage("defaultresponse")));
429 415
430 MessageLoop::current()->Run(); 416 MessageLoop::current()->Run();
431 } 417 }
432 418
433 TEST_F(URLFetcherCancelTest, ReleasesContext) { 419 TEST_F(URLFetcherCancelTest, ReleasesContext) {
434 scoped_refptr<HTTPTestServer> server = 420 TestServer server(L"chrome/test/data");
435 HTTPTestServer::CreateServer(L"chrome/test/data"); 421 GURL url = GURL(server.TestServerPage("files/server-unavailable.html"));
436 ASSERT_TRUE(NULL != server.get());
437 GURL url = GURL(server->TestServerPage("files/server-unavailable.html"));
438 422
439 // Registers an entry for test url. The backoff time is calculated by: 423 // Registers an entry for test url. The backoff time is calculated by:
440 // new_backoff = 2.0 * old_backoff + 0 424 // new_backoff = 2.0 * old_backoff + 0
441 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. 425 // The initial backoff is 2 seconds and maximum backoff is 4 seconds.
442 // Maximum retries allowed is set to 2. 426 // Maximum retries allowed is set to 2.
443 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); 427 URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance();
444 URLFetcherProtectEntry* entry = 428 URLFetcherProtectEntry* entry =
445 new URLFetcherProtectEntry(200, 3, 2, 2000, 2.0, 0, 4000); 429 new URLFetcherProtectEntry(200, 3, 2, 2000, 2.0, 0, 4000);
446 manager->Register(url.host(), entry); 430 manager->Register(url.host(), entry);
447 431
448 // Create a separate thread that will create the URLFetcher. The current 432 // Create a separate thread that will create the URLFetcher. The current
449 // (main) thread will do the IO, and when the fetch is complete it will 433 // (main) thread will do the IO, and when the fetch is complete it will
450 // terminate the main thread's message loop; then the other thread's 434 // terminate the main thread's message loop; then the other thread's
451 // message loop will be shut down automatically as the thread goes out of 435 // message loop will be shut down automatically as the thread goes out of
452 // scope. 436 // scope.
453 base::Thread t("URLFetcher test thread"); 437 base::Thread t("URLFetcher test thread");
454 t.Start(); 438 t.Start();
455 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); 439 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url));
456 440
457 MessageLoop::current()->Run(); 441 MessageLoop::current()->Run();
458 } 442 }
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