| 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, network_delegate, file_, |
| 802 content::BrowserThread::GetBlockingPool()); |
| 801 } | 803 } |
| 802 | 804 |
| 803 private: | 805 private: |
| 804 base::FilePath file_; | 806 base::FilePath file_; |
| 805 base::Closure callback_; | 807 base::Closure callback_; |
| 806 mutable bool first_run_; | 808 mutable bool first_run_; |
| 807 }; | 809 }; |
| 808 | 810 |
| 809 // Makes |url| never respond on the first load, and then with the contents of | 811 // 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 | 812 // |file| afterwards. When the first load has been scheduled, runs |callback| on |
| 811 // the UI thread. | 813 // the UI thread. |
| 812 void CreateHangingFirstRequestInterceptorOnIO( | 814 void CreateHangingFirstRequestInterceptorOnIO( |
| 813 const GURL& url, const base::FilePath& file, base::Closure callback) { | 815 const GURL& url, const base::FilePath& file, base::Closure callback) { |
| 814 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 816 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 815 scoped_ptr<net::URLRequestInterceptor> never_respond_handler( | 817 scoped_ptr<net::URLRequestInterceptor> never_respond_handler( |
| 816 new HangingFirstRequestInterceptor(file, callback)); | 818 new HangingFirstRequestInterceptor(file, callback)); |
| 817 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 819 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 818 url, never_respond_handler.Pass()); | 820 url, never_respond_handler.Pass()); |
| 819 } | 821 } |
| 820 | 822 |
| 821 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks. | 823 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks. |
| 822 class MockHTTPJob : public content::URLRequestMockHTTPJob { | 824 class MockHTTPJob : public net::URLRequestMockHTTPJob { |
| 823 public: | 825 public: |
| 824 MockHTTPJob(net::URLRequest* request, | 826 MockHTTPJob(net::URLRequest* request, |
| 825 net::NetworkDelegate* delegate, | 827 net::NetworkDelegate* delegate, |
| 826 const base::FilePath& file) | 828 const base::FilePath& file) |
| 827 : content::URLRequestMockHTTPJob(request, delegate, file) { | 829 : net::URLRequestMockHTTPJob( |
| 828 } | 830 request, delegate, file, |
| 831 content::BrowserThread::GetBlockingPool()) {} |
| 829 | 832 |
| 830 void set_start_callback(const base::Closure& start_callback) { | 833 void set_start_callback(const base::Closure& start_callback) { |
| 831 start_callback_ = start_callback; | 834 start_callback_ = start_callback; |
| 832 } | 835 } |
| 833 | 836 |
| 834 virtual void Start() OVERRIDE { | 837 virtual void Start() OVERRIDE { |
| 835 if (!start_callback_.is_null()) | 838 if (!start_callback_.is_null()) |
| 836 start_callback_.Run(); | 839 start_callback_.Run(); |
| 837 content::URLRequestMockHTTPJob::Start(); | 840 net::URLRequestMockHTTPJob::Start(); |
| 838 } | 841 } |
| 839 | 842 |
| 840 private: | 843 private: |
| 841 virtual ~MockHTTPJob() {} | 844 virtual ~MockHTTPJob() {} |
| 842 | 845 |
| 843 base::Closure start_callback_; | 846 base::Closure start_callback_; |
| 844 }; | 847 }; |
| 845 | 848 |
| 846 // Dummy counter class to live on the UI thread for counting requests. | 849 // Dummy counter class to live on the UI thread for counting requests. |
| 847 class RequestCounter : public base::SupportsWeakPtr<RequestCounter> { | 850 class RequestCounter : public base::SupportsWeakPtr<RequestCounter> { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 new CountingInterceptor(file, counter)); | 920 new CountingInterceptor(file, counter)); |
| 918 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 921 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 919 url, request_interceptor.Pass()); | 922 url, request_interceptor.Pass()); |
| 920 } | 923 } |
| 921 | 924 |
| 922 // Makes |url| respond to requests with the contents of |file|. | 925 // Makes |url| respond to requests with the contents of |file|. |
| 923 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { | 926 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { |
| 924 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 927 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 925 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 928 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 926 url, | 929 url, |
| 927 content::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(file)); | 930 net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
| 931 file, |
| 932 content::BrowserThread::GetBlockingPool())); |
| 928 } | 933 } |
| 929 | 934 |
| 930 // A ContentBrowserClient that cancels all prerenderers on OpenURL. | 935 // A ContentBrowserClient that cancels all prerenderers on OpenURL. |
| 931 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { | 936 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { |
| 932 public: | 937 public: |
| 933 TestContentBrowserClient() {} | 938 TestContentBrowserClient() {} |
| 934 virtual ~TestContentBrowserClient() {} | 939 virtual ~TestContentBrowserClient() {} |
| 935 | 940 |
| 936 // chrome::ChromeContentBrowserClient implementation. | 941 // chrome::ChromeContentBrowserClient implementation. |
| 937 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance, | 942 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance, |
| (...skipping 3478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4416 | 4421 |
| 4417 // Navigate to the URL entered. | 4422 // Navigate to the URL entered. |
| 4418 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); | 4423 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); |
| 4419 | 4424 |
| 4420 // Prerender should be running, but abandoned. | 4425 // Prerender should be running, but abandoned. |
| 4421 EXPECT_TRUE( | 4426 EXPECT_TRUE( |
| 4422 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); | 4427 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); |
| 4423 } | 4428 } |
| 4424 | 4429 |
| 4425 } // namespace prerender | 4430 } // namespace prerender |
| OLD | NEW |