| 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); |
| 533 content::ResourceRequestInfo::AllocateForTesting( | 535 content::ResourceRequestInfo::AllocateForTesting( |
| 534 &request, ResourceType::IMAGE, NULL, | 536 &request, ResourceType::IMAGE, NULL, |
| 535 kDefaultChildId, kDefaultRouteId, true); | 537 kDefaultChildId, kDefaultRouteId, true); |
| 536 | 538 |
| 537 // Install a prerender throttle. | 539 // Install a prerender throttle. |
| 538 PrerenderResourceThrottle throttle(&request, prerender_tracker()); | 540 PrerenderResourceThrottle throttle(&request, prerender_tracker()); |
| 539 delegate.SetThrottle(&throttle); | 541 delegate.SetThrottle(&throttle); |
| 540 | 542 |
| 541 // Start the request and wait for a redirect. | 543 // Start the request and wait for a redirect. |
| 542 request.Start(); | 544 request.Start(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 559 test_contents()->Start(); | 561 test_contents()->Start(); |
| 560 // This calls AddPrerenderOnIOThreadTask(). | 562 // This calls AddPrerenderOnIOThreadTask(). |
| 561 RunEvents(); | 563 RunEvents(); |
| 562 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( | 564 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( |
| 563 kDefaultChildId, kDefaultRouteId)); | 565 kDefaultChildId, kDefaultRouteId)); |
| 564 | 566 |
| 565 // Fake a request. | 567 // Fake a request. |
| 566 net::TestURLRequestContext url_request_context; | 568 net::TestURLRequestContext url_request_context; |
| 567 DeferredRedirectDelegate delegate; | 569 DeferredRedirectDelegate delegate; |
| 568 net::URLRequest request( | 570 net::URLRequest request( |
| 569 content::URLRequestMockHTTPJob::GetMockUrl( | 571 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 570 base::FilePath(kRedirectPath)), | 572 net::DEFAULT_PRIORITY, |
| 571 &delegate, &url_request_context); | 573 &delegate, |
| 574 &url_request_context); |
| 572 content::ResourceRequestInfo::AllocateForTesting( | 575 content::ResourceRequestInfo::AllocateForTesting( |
| 573 &request, ResourceType::IMAGE, NULL, | 576 &request, ResourceType::IMAGE, NULL, |
| 574 kDefaultChildId, kDefaultRouteId, true); | 577 kDefaultChildId, kDefaultRouteId, true); |
| 575 | 578 |
| 576 // Install a prerender throttle. | 579 // Install a prerender throttle. |
| 577 PrerenderResourceThrottle throttle(&request, prerender_tracker()); | 580 PrerenderResourceThrottle throttle(&request, prerender_tracker()); |
| 578 delegate.SetThrottle(&throttle); | 581 delegate.SetThrottle(&throttle); |
| 579 | 582 |
| 580 // Start the request and wait for a redirect. | 583 // Start the request and wait for a redirect. |
| 581 request.Start(); | 584 request.Start(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 598 test_contents()->Start(); | 601 test_contents()->Start(); |
| 599 // This calls AddPrerenderOnIOThreadTask(). | 602 // This calls AddPrerenderOnIOThreadTask(). |
| 600 RunEvents(); | 603 RunEvents(); |
| 601 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( | 604 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( |
| 602 kDefaultChildId, kDefaultRouteId)); | 605 kDefaultChildId, kDefaultRouteId)); |
| 603 | 606 |
| 604 // Fake a request. | 607 // Fake a request. |
| 605 net::TestURLRequestContext url_request_context; | 608 net::TestURLRequestContext url_request_context; |
| 606 DeferredRedirectDelegate delegate; | 609 DeferredRedirectDelegate delegate; |
| 607 net::URLRequest request( | 610 net::URLRequest request( |
| 608 content::URLRequestMockHTTPJob::GetMockUrl( | 611 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 609 base::FilePath(kRedirectPath)), | 612 net::DEFAULT_PRIORITY, |
| 610 &delegate, &url_request_context); | 613 &delegate, |
| 614 &url_request_context); |
| 611 content::ResourceRequestInfo::AllocateForTesting( | 615 content::ResourceRequestInfo::AllocateForTesting( |
| 612 &request, ResourceType::MAIN_FRAME, NULL, | 616 &request, ResourceType::MAIN_FRAME, NULL, |
| 613 kDefaultChildId, kDefaultRouteId, true); | 617 kDefaultChildId, kDefaultRouteId, true); |
| 614 | 618 |
| 615 // Install a prerender throttle. | 619 // Install a prerender throttle. |
| 616 PrerenderResourceThrottle throttle(&request, prerender_tracker()); | 620 PrerenderResourceThrottle throttle(&request, prerender_tracker()); |
| 617 delegate.SetThrottle(&throttle); | 621 delegate.SetThrottle(&throttle); |
| 618 | 622 |
| 619 // Start the request and wait for a redirect. This time, it should | 623 // Start the request and wait for a redirect. This time, it should |
| 620 // not be deferred. | 624 // not be deferred. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 636 test_contents()->Start(); | 640 test_contents()->Start(); |
| 637 // This calls AddPrerenderOnIOThreadTask(). | 641 // This calls AddPrerenderOnIOThreadTask(). |
| 638 RunEvents(); | 642 RunEvents(); |
| 639 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( | 643 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread( |
| 640 kDefaultChildId, kDefaultRouteId)); | 644 kDefaultChildId, kDefaultRouteId)); |
| 641 | 645 |
| 642 // Fake a request. | 646 // Fake a request. |
| 643 net::TestURLRequestContext url_request_context; | 647 net::TestURLRequestContext url_request_context; |
| 644 DeferredRedirectDelegate delegate; | 648 DeferredRedirectDelegate delegate; |
| 645 net::URLRequest request( | 649 net::URLRequest request( |
| 646 content::URLRequestMockHTTPJob::GetMockUrl( | 650 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 647 base::FilePath(kRedirectPath)), | 651 net::DEFAULT_PRIORITY, |
| 648 &delegate, &url_request_context); | 652 &delegate, |
| 653 &url_request_context); |
| 649 content::ResourceRequestInfo::AllocateForTesting( | 654 content::ResourceRequestInfo::AllocateForTesting( |
| 650 &request, ResourceType::XHR, NULL, | 655 &request, ResourceType::XHR, NULL, |
| 651 kDefaultChildId, kDefaultRouteId, false); | 656 kDefaultChildId, kDefaultRouteId, false); |
| 652 | 657 |
| 653 // Install a prerender throttle. | 658 // Install a prerender throttle. |
| 654 PrerenderResourceThrottle throttle(&request, prerender_tracker()); | 659 PrerenderResourceThrottle throttle(&request, prerender_tracker()); |
| 655 delegate.SetThrottle(&throttle); | 660 delegate.SetThrottle(&throttle); |
| 656 | 661 |
| 657 // Start the request and wait for a redirect. | 662 // Start the request and wait for a redirect. |
| 658 request.Start(); | 663 request.Start(); |
| 659 delegate.Run(); | 664 delegate.Run(); |
| 660 EXPECT_FALSE(delegate.was_deferred()); | 665 EXPECT_FALSE(delegate.was_deferred()); |
| 661 | 666 |
| 662 // We should have cancelled the prerender. | 667 // We should have cancelled the prerender. |
| 663 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, GetCurrentStatus( | 668 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, GetCurrentStatus( |
| 664 kDefaultChildId, kDefaultRouteId)); | 669 kDefaultChildId, kDefaultRouteId)); |
| 665 | 670 |
| 666 // Cleanup work so the prerender is gone. | 671 // Cleanup work so the prerender is gone. |
| 667 test_contents()->Cancel(); | 672 test_contents()->Cancel(); |
| 668 RunEvents(); | 673 RunEvents(); |
| 669 } | 674 } |
| 670 | 675 |
| 671 } // namespace prerender | 676 } // namespace prerender |
| OLD | NEW |