| 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 <deque> | 5 #include <deque> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 #include "content/public/browser/render_frame_host.h" | 74 #include "content/public/browser/render_frame_host.h" |
| 75 #include "content/public/browser/render_process_host.h" | 75 #include "content/public/browser/render_process_host.h" |
| 76 #include "content/public/browser/render_view_host.h" | 76 #include "content/public/browser/render_view_host.h" |
| 77 #include "content/public/browser/site_instance.h" | 77 #include "content/public/browser/site_instance.h" |
| 78 #include "content/public/browser/web_contents.h" | 78 #include "content/public/browser/web_contents.h" |
| 79 #include "content/public/browser/web_contents_observer.h" | 79 #include "content/public/browser/web_contents_observer.h" |
| 80 #include "content/public/common/url_constants.h" | 80 #include "content/public/common/url_constants.h" |
| 81 #include "content/public/test/browser_test_utils.h" | 81 #include "content/public/test/browser_test_utils.h" |
| 82 #include "content/public/test/test_navigation_observer.h" | 82 #include "content/public/test/test_navigation_observer.h" |
| 83 #include "content/public/test/test_utils.h" | 83 #include "content/public/test/test_utils.h" |
| 84 #include "content/test/net/url_request_mock_http_job.h" | |
| 85 #include "extensions/common/switches.h" | 84 #include "extensions/common/switches.h" |
| 86 #include "net/base/escape.h" | 85 #include "net/base/escape.h" |
| 87 #include "net/cert/x509_certificate.h" | 86 #include "net/cert/x509_certificate.h" |
| 88 #include "net/dns/mock_host_resolver.h" | 87 #include "net/dns/mock_host_resolver.h" |
| 89 #include "net/ssl/client_cert_store.h" | 88 #include "net/ssl/client_cert_store.h" |
| 90 #include "net/ssl/ssl_cert_request_info.h" | 89 #include "net/ssl/ssl_cert_request_info.h" |
| 90 #include "net/test/url_request/url_request_mock_http_job.h" |
| 91 #include "net/url_request/url_request_context.h" | 91 #include "net/url_request/url_request_context.h" |
| 92 #include "net/url_request/url_request_context_getter.h" | 92 #include "net/url_request/url_request_context_getter.h" |
| 93 #include "net/url_request/url_request_filter.h" | 93 #include "net/url_request/url_request_filter.h" |
| 94 #include "net/url_request/url_request_interceptor.h" | 94 #include "net/url_request/url_request_interceptor.h" |
| 95 #include "net/url_request/url_request_job.h" | 95 #include "net/url_request/url_request_job.h" |
| 96 #include "ui/base/l10n/l10n_util.h" | 96 #include "ui/base/l10n/l10n_util.h" |
| 97 #include "url/gurl.h" | 97 #include "url/gurl.h" |
| 98 | 98 |
| 99 using content::BrowserThread; | 99 using content::BrowserThread; |
| 100 using content::DevToolsAgentHost; | 100 using content::DevToolsAgentHost; |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 net::URLRequest* request, | 790 net::URLRequest* request, |
| 791 net::NetworkDelegate* network_delegate) const OVERRIDE { | 791 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 792 if (first_run_) { | 792 if (first_run_) { |
| 793 first_run_ = false; | 793 first_run_ = false; |
| 794 if (!callback_.is_null()) { | 794 if (!callback_.is_null()) { |
| 795 BrowserThread::PostTask( | 795 BrowserThread::PostTask( |
| 796 BrowserThread::UI, FROM_HERE, callback_); | 796 BrowserThread::UI, FROM_HERE, callback_); |
| 797 } | 797 } |
| 798 return new HangingURLRequestJob(request, network_delegate); | 798 return new HangingURLRequestJob(request, network_delegate); |
| 799 } | 799 } |
| 800 return new content::URLRequestMockHTTPJob(request, network_delegate, file_); | 800 return new net::URLRequestMockHTTPJob( |
| 801 request, |
| 802 network_delegate, |
| 803 file_, |
| 804 content::BrowserThread::GetBlockingPool() |
| 805 ->GetTaskRunnerWithShutdownBehavior( |
| 806 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 801 } | 807 } |
| 802 | 808 |
| 803 private: | 809 private: |
| 804 base::FilePath file_; | 810 base::FilePath file_; |
| 805 base::Closure callback_; | 811 base::Closure callback_; |
| 806 mutable bool first_run_; | 812 mutable bool first_run_; |
| 807 }; | 813 }; |
| 808 | 814 |
| 809 // Makes |url| never respond on the first load, and then with the contents of | 815 // Makes |url| never respond on the first load, and then with the contents of |
| 810 // |file| afterwards. When the first load has been scheduled, runs |callback| on | 816 // |file| afterwards. When the first load has been scheduled, runs |callback| on |
| 811 // the UI thread. | 817 // the UI thread. |
| 812 void CreateHangingFirstRequestInterceptorOnIO( | 818 void CreateHangingFirstRequestInterceptorOnIO( |
| 813 const GURL& url, const base::FilePath& file, base::Closure callback) { | 819 const GURL& url, const base::FilePath& file, base::Closure callback) { |
| 814 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 820 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 815 scoped_ptr<net::URLRequestInterceptor> never_respond_handler( | 821 scoped_ptr<net::URLRequestInterceptor> never_respond_handler( |
| 816 new HangingFirstRequestInterceptor(file, callback)); | 822 new HangingFirstRequestInterceptor(file, callback)); |
| 817 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 823 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 818 url, never_respond_handler.Pass()); | 824 url, never_respond_handler.Pass()); |
| 819 } | 825 } |
| 820 | 826 |
| 821 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks. | 827 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks. |
| 822 class MockHTTPJob : public content::URLRequestMockHTTPJob { | 828 class MockHTTPJob : public net::URLRequestMockHTTPJob { |
| 823 public: | 829 public: |
| 824 MockHTTPJob(net::URLRequest* request, | 830 MockHTTPJob(net::URLRequest* request, |
| 825 net::NetworkDelegate* delegate, | 831 net::NetworkDelegate* delegate, |
| 826 const base::FilePath& file) | 832 const base::FilePath& file) |
| 827 : content::URLRequestMockHTTPJob(request, delegate, file) { | 833 : net::URLRequestMockHTTPJob( |
| 828 } | 834 request, |
| 835 delegate, |
| 836 file, |
| 837 content::BrowserThread::GetBlockingPool() |
| 838 ->GetTaskRunnerWithShutdownBehavior( |
| 839 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {} |
| 829 | 840 |
| 830 void set_start_callback(const base::Closure& start_callback) { | 841 void set_start_callback(const base::Closure& start_callback) { |
| 831 start_callback_ = start_callback; | 842 start_callback_ = start_callback; |
| 832 } | 843 } |
| 833 | 844 |
| 834 virtual void Start() OVERRIDE { | 845 virtual void Start() OVERRIDE { |
| 835 if (!start_callback_.is_null()) | 846 if (!start_callback_.is_null()) |
| 836 start_callback_.Run(); | 847 start_callback_.Run(); |
| 837 content::URLRequestMockHTTPJob::Start(); | 848 net::URLRequestMockHTTPJob::Start(); |
| 838 } | 849 } |
| 839 | 850 |
| 840 private: | 851 private: |
| 841 virtual ~MockHTTPJob() {} | 852 virtual ~MockHTTPJob() {} |
| 842 | 853 |
| 843 base::Closure start_callback_; | 854 base::Closure start_callback_; |
| 844 }; | 855 }; |
| 845 | 856 |
| 846 // Dummy counter class to live on the UI thread for counting requests. | 857 // Dummy counter class to live on the UI thread for counting requests. |
| 847 class RequestCounter : public base::SupportsWeakPtr<RequestCounter> { | 858 class RequestCounter : public base::SupportsWeakPtr<RequestCounter> { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 new CountingInterceptor(file, counter)); | 928 new CountingInterceptor(file, counter)); |
| 918 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 929 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 919 url, request_interceptor.Pass()); | 930 url, request_interceptor.Pass()); |
| 920 } | 931 } |
| 921 | 932 |
| 922 // Makes |url| respond to requests with the contents of |file|. | 933 // Makes |url| respond to requests with the contents of |file|. |
| 923 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { | 934 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { |
| 924 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 935 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 925 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 936 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 926 url, | 937 url, |
| 927 content::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(file)); | 938 net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
| 939 file, content::BrowserThread::GetBlockingPool())); |
| 928 } | 940 } |
| 929 | 941 |
| 930 // A ContentBrowserClient that cancels all prerenderers on OpenURL. | 942 // A ContentBrowserClient that cancels all prerenderers on OpenURL. |
| 931 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { | 943 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { |
| 932 public: | 944 public: |
| 933 TestContentBrowserClient() {} | 945 TestContentBrowserClient() {} |
| 934 virtual ~TestContentBrowserClient() {} | 946 virtual ~TestContentBrowserClient() {} |
| 935 | 947 |
| 936 // chrome::ChromeContentBrowserClient implementation. | 948 // chrome::ChromeContentBrowserClient implementation. |
| 937 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance, | 949 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance, |
| (...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4417 | 4429 |
| 4418 // Navigate to the URL entered. | 4430 // Navigate to the URL entered. |
| 4419 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); | 4431 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); |
| 4420 | 4432 |
| 4421 // Prerender should be running, but abandoned. | 4433 // Prerender should be running, but abandoned. |
| 4422 EXPECT_TRUE( | 4434 EXPECT_TRUE( |
| 4423 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); | 4435 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); |
| 4424 } | 4436 } |
| 4425 | 4437 |
| 4426 } // namespace prerender | 4438 } // namespace prerender |
| OLD | NEW |