Chromium Code Reviews| 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 <set> | 5 #include <set> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "chrome/browser/net/url_request_mock_util.h" | 13 #include "chrome/browser/net/url_request_mock_util.h" |
| 14 #include "chrome/browser/prerender/prerender_contents.h" | 14 #include "chrome/browser/prerender/prerender_contents.h" |
| 15 #include "chrome/browser/prerender/prerender_manager.h" | 15 #include "chrome/browser/prerender/prerender_manager.h" |
| 16 #include "chrome/browser/prerender/prerender_resource_throttle.h" | 16 #include "chrome/browser/prerender/prerender_resource_throttle.h" |
| 17 #include "chrome/browser/prerender/prerender_tracker.h" | 17 #include "chrome/browser/prerender/prerender_tracker.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 20 #include "content/public/browser/resource_request_info.h" | 20 #include "content/public/browser/resource_request_info.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
| 22 #include "content/test/net/url_request_mock_http_job.h" | 22 #include "content/test/net/url_request_mock_http_job.h" |
| 23 #include "net/base/request_priority.h" | |
| 23 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 24 #include "net/url_request/url_request_test_util.h" | 25 #include "net/url_request/url_request_test_util.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 using content::BrowserThread; | 28 using content::BrowserThread; |
| 28 | 29 |
| 29 namespace prerender { | 30 namespace prerender { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 test_contents()->Start(); | 521 test_contents()->Start(); |
| 521 // This calls AddPrerenderOnIOThreadTask(). | 522 // This calls AddPrerenderOnIOThreadTask(). |
| 522 RunEvents(); | 523 RunEvents(); |
| 523 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( | 524 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( |
| 524 kDefaultChildId, kDefaultRouteId)); | 525 kDefaultChildId, kDefaultRouteId)); |
| 525 | 526 |
| 526 // Fake a request. | 527 // Fake a request. |
| 527 net::TestURLRequestContext url_request_context; | 528 net::TestURLRequestContext url_request_context; |
| 528 DeferredRedirectDelegate delegate; | 529 DeferredRedirectDelegate delegate; |
| 529 net::URLRequest request( | 530 net::URLRequest request( |
| 530 content::URLRequestMockHTTPJob::GetMockUrl( | 531 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 531 base::FilePath(kRedirectPath)), | 532 net::DEFAULT_PRIORITY, |
| 532 &delegate, &url_request_context); | 533 &delegate, |
| 534 &url_request_context, | |
| 535 NULL); | |
|
mmenke
2013/10/30 15:27:11
Again, don't want to add assumptions here.
akalin
2013/10/30 21:44:37
removed arg.
| |
| 533 content::ResourceRequestInfo::AllocateForTesting( | 536 content::ResourceRequestInfo::AllocateForTesting( |
| 534 &request, ResourceType::IMAGE, NULL, | 537 &request, ResourceType::IMAGE, NULL, |
| 535 kDefaultChildId, kDefaultRouteId, true); | 538 kDefaultChildId, kDefaultRouteId, true); |
| 536 | 539 |
| 537 // Install a prerender throttle. | 540 // Install a prerender throttle. |
| 538 PrerenderResourceThrottle throttle(&request, prerender_tracker()); | 541 PrerenderResourceThrottle throttle(&request, prerender_tracker()); |
| 539 delegate.SetThrottle(&throttle); | 542 delegate.SetThrottle(&throttle); |
| 540 | 543 |
| 541 // Start the request and wait for a redirect. | 544 // Start the request and wait for a redirect. |
| 542 request.Start(); | 545 request.Start(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 559 test_contents()->Start(); | 562 test_contents()->Start(); |
| 560 // This calls AddPrerenderOnIOThreadTask(). | 563 // This calls AddPrerenderOnIOThreadTask(). |
| 561 RunEvents(); | 564 RunEvents(); |
| 562 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( | 565 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( |
| 563 kDefaultChildId, kDefaultRouteId)); | 566 kDefaultChildId, kDefaultRouteId)); |
| 564 | 567 |
| 565 // Fake a request. | 568 // Fake a request. |
| 566 net::TestURLRequestContext url_request_context; | 569 net::TestURLRequestContext url_request_context; |
| 567 DeferredRedirectDelegate delegate; | 570 DeferredRedirectDelegate delegate; |
| 568 net::URLRequest request( | 571 net::URLRequest request( |
| 569 content::URLRequestMockHTTPJob::GetMockUrl( | 572 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 570 base::FilePath(kRedirectPath)), | 573 net::DEFAULT_PRIORITY, |
| 571 &delegate, &url_request_context); | 574 &delegate, |
| 575 &url_request_context, | |
| 576 NULL); | |
| 572 content::ResourceRequestInfo::AllocateForTesting( | 577 content::ResourceRequestInfo::AllocateForTesting( |
| 573 &request, ResourceType::IMAGE, NULL, | 578 &request, ResourceType::IMAGE, NULL, |
| 574 kDefaultChildId, kDefaultRouteId, true); | 579 kDefaultChildId, kDefaultRouteId, true); |
| 575 | 580 |
| 576 // Install a prerender throttle. | 581 // Install a prerender throttle. |
| 577 PrerenderResourceThrottle throttle(&request, prerender_tracker()); | 582 PrerenderResourceThrottle throttle(&request, prerender_tracker()); |
| 578 delegate.SetThrottle(&throttle); | 583 delegate.SetThrottle(&throttle); |
| 579 | 584 |
| 580 // Start the request and wait for a redirect. | 585 // Start the request and wait for a redirect. |
| 581 request.Start(); | 586 request.Start(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 598 test_contents()->Start(); | 603 test_contents()->Start(); |
| 599 // This calls AddPrerenderOnIOThreadTask(). | 604 // This calls AddPrerenderOnIOThreadTask(). |
| 600 RunEvents(); | 605 RunEvents(); |
| 601 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( | 606 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( |
| 602 kDefaultChildId, kDefaultRouteId)); | 607 kDefaultChildId, kDefaultRouteId)); |
| 603 | 608 |
| 604 // Fake a request. | 609 // Fake a request. |
| 605 net::TestURLRequestContext url_request_context; | 610 net::TestURLRequestContext url_request_context; |
| 606 DeferredRedirectDelegate delegate; | 611 DeferredRedirectDelegate delegate; |
| 607 net::URLRequest request( | 612 net::URLRequest request( |
| 608 content::URLRequestMockHTTPJob::GetMockUrl( | 613 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 609 base::FilePath(kRedirectPath)), | 614 net::DEFAULT_PRIORITY, |
| 610 &delegate, &url_request_context); | 615 &delegate, |
| 616 &url_request_context, | |
| 617 NULL); | |
| 611 content::ResourceRequestInfo::AllocateForTesting( | 618 content::ResourceRequestInfo::AllocateForTesting( |
| 612 &request, ResourceType::MAIN_FRAME, NULL, | 619 &request, ResourceType::MAIN_FRAME, NULL, |
| 613 kDefaultChildId, kDefaultRouteId, true); | 620 kDefaultChildId, kDefaultRouteId, true); |
| 614 | 621 |
| 615 // Install a prerender throttle. | 622 // Install a prerender throttle. |
| 616 PrerenderResourceThrottle throttle(&request, prerender_tracker()); | 623 PrerenderResourceThrottle throttle(&request, prerender_tracker()); |
| 617 delegate.SetThrottle(&throttle); | 624 delegate.SetThrottle(&throttle); |
| 618 | 625 |
| 619 // Start the request and wait for a redirect. This time, it should | 626 // Start the request and wait for a redirect. This time, it should |
| 620 // not be deferred. | 627 // not be deferred. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 636 test_contents()->Start(); | 643 test_contents()->Start(); |
| 637 // This calls AddPrerenderOnIOThreadTask(). | 644 // This calls AddPrerenderOnIOThreadTask(). |
| 638 RunEvents(); | 645 RunEvents(); |
| 639 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( | 646 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( |
| 640 kDefaultChildId, kDefaultRouteId)); | 647 kDefaultChildId, kDefaultRouteId)); |
| 641 | 648 |
| 642 // Fake a request. | 649 // Fake a request. |
| 643 net::TestURLRequestContext url_request_context; | 650 net::TestURLRequestContext url_request_context; |
| 644 DeferredRedirectDelegate delegate; | 651 DeferredRedirectDelegate delegate; |
| 645 net::URLRequest request( | 652 net::URLRequest request( |
| 646 content::URLRequestMockHTTPJob::GetMockUrl( | 653 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 647 base::FilePath(kRedirectPath)), | 654 net::DEFAULT_PRIORITY, |
| 648 &delegate, &url_request_context); | 655 &delegate, |
| 656 &url_request_context, | |
| 657 NULL); | |
| 649 content::ResourceRequestInfo::AllocateForTesting( | 658 content::ResourceRequestInfo::AllocateForTesting( |
| 650 &request, ResourceType::XHR, NULL, | 659 &request, ResourceType::XHR, NULL, |
| 651 kDefaultChildId, kDefaultRouteId, false); | 660 kDefaultChildId, kDefaultRouteId, false); |
| 652 | 661 |
| 653 // Install a prerender throttle. | 662 // Install a prerender throttle. |
| 654 PrerenderResourceThrottle throttle(&request, prerender_tracker()); | 663 PrerenderResourceThrottle throttle(&request, prerender_tracker()); |
| 655 delegate.SetThrottle(&throttle); | 664 delegate.SetThrottle(&throttle); |
| 656 | 665 |
| 657 // Start the request and wait for a redirect. | 666 // Start the request and wait for a redirect. |
| 658 request.Start(); | 667 request.Start(); |
| 659 delegate.Run(); | 668 delegate.Run(); |
| 660 EXPECT_FALSE(delegate.was_deferred()); | 669 EXPECT_FALSE(delegate.was_deferred()); |
| 661 | 670 |
| 662 // We should have cancelled the prerender. | 671 // We should have cancelled the prerender. |
| 663 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, GetCurrentStatus( | 672 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, GetCurrentStatus( |
| 664 kDefaultChildId, kDefaultRouteId)); | 673 kDefaultChildId, kDefaultRouteId)); |
| 665 | 674 |
| 666 // Cleanup work so the prerender is gone. | 675 // Cleanup work so the prerender is gone. |
| 667 test_contents()->Cancel(); | 676 test_contents()->Cancel(); |
| 668 RunEvents(); | 677 RunEvents(); |
| 669 } | 678 } |
| 670 | 679 |
| 671 } // namespace prerender | 680 } // namespace prerender |
| OLD | NEW |