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

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 541743002: Move url_request_mock_http_job to net/test/url_request/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 3 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
OLDNEW
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
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 "extensions/test/result_catcher.h" 85 #include "extensions/test/result_catcher.h"
87 #include "net/base/escape.h" 86 #include "net/base/escape.h"
88 #include "net/cert/x509_certificate.h" 87 #include "net/cert/x509_certificate.h"
89 #include "net/dns/mock_host_resolver.h" 88 #include "net/dns/mock_host_resolver.h"
90 #include "net/ssl/client_cert_store.h" 89 #include "net/ssl/client_cert_store.h"
91 #include "net/ssl/ssl_cert_request_info.h" 90 #include "net/ssl/ssl_cert_request_info.h"
91 #include "net/test/url_request/url_request_mock_http_job.h"
92 #include "net/url_request/url_request_context.h" 92 #include "net/url_request/url_request_context.h"
93 #include "net/url_request/url_request_context_getter.h" 93 #include "net/url_request/url_request_context_getter.h"
94 #include "net/url_request/url_request_filter.h" 94 #include "net/url_request/url_request_filter.h"
95 #include "net/url_request/url_request_interceptor.h" 95 #include "net/url_request/url_request_interceptor.h"
96 #include "net/url_request/url_request_job.h" 96 #include "net/url_request/url_request_job.h"
97 #include "ui/base/l10n/l10n_util.h" 97 #include "ui/base/l10n/l10n_util.h"
98 #include "url/gurl.h" 98 #include "url/gurl.h"
99 99
100 using content::BrowserThread; 100 using content::BrowserThread;
101 using content::DevToolsAgentHost; 101 using content::DevToolsAgentHost;
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 net::URLRequest* request, 791 net::URLRequest* request,
792 net::NetworkDelegate* network_delegate) const OVERRIDE { 792 net::NetworkDelegate* network_delegate) const OVERRIDE {
793 if (first_run_) { 793 if (first_run_) {
794 first_run_ = false; 794 first_run_ = false;
795 if (!callback_.is_null()) { 795 if (!callback_.is_null()) {
796 BrowserThread::PostTask( 796 BrowserThread::PostTask(
797 BrowserThread::UI, FROM_HERE, callback_); 797 BrowserThread::UI, FROM_HERE, callback_);
798 } 798 }
799 return new HangingURLRequestJob(request, network_delegate); 799 return new HangingURLRequestJob(request, network_delegate);
800 } 800 }
801 return new content::URLRequestMockHTTPJob(request, network_delegate, file_); 801 return new net::URLRequestMockHTTPJob(
802 request,
803 network_delegate,
804 file_,
805 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
806 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
802 } 807 }
803 808
804 private: 809 private:
805 base::FilePath file_; 810 base::FilePath file_;
806 base::Closure callback_; 811 base::Closure callback_;
807 mutable bool first_run_; 812 mutable bool first_run_;
808 }; 813 };
809 814
810 // 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
811 // |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
812 // the UI thread. 817 // the UI thread.
813 void CreateHangingFirstRequestInterceptorOnIO( 818 void CreateHangingFirstRequestInterceptorOnIO(
814 const GURL& url, const base::FilePath& file, base::Closure callback) { 819 const GURL& url, const base::FilePath& file, base::Closure callback) {
815 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 820 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
816 scoped_ptr<net::URLRequestInterceptor> never_respond_handler( 821 scoped_ptr<net::URLRequestInterceptor> never_respond_handler(
817 new HangingFirstRequestInterceptor(file, callback)); 822 new HangingFirstRequestInterceptor(file, callback));
818 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 823 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
819 url, never_respond_handler.Pass()); 824 url, never_respond_handler.Pass());
820 } 825 }
821 826
822 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks. 827 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks.
823 class MockHTTPJob : public content::URLRequestMockHTTPJob { 828 class MockHTTPJob : public net::URLRequestMockHTTPJob {
824 public: 829 public:
825 MockHTTPJob(net::URLRequest* request, 830 MockHTTPJob(net::URLRequest* request,
826 net::NetworkDelegate* delegate, 831 net::NetworkDelegate* delegate,
827 const base::FilePath& file) 832 const base::FilePath& file)
828 : content::URLRequestMockHTTPJob(request, delegate, file) { 833 : net::URLRequestMockHTTPJob(
829 } 834 request,
835 delegate,
836 file,
837 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
838 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {}
830 839
831 void set_start_callback(const base::Closure& start_callback) { 840 void set_start_callback(const base::Closure& start_callback) {
832 start_callback_ = start_callback; 841 start_callback_ = start_callback;
833 } 842 }
834 843
835 virtual void Start() OVERRIDE { 844 virtual void Start() OVERRIDE {
836 if (!start_callback_.is_null()) 845 if (!start_callback_.is_null())
837 start_callback_.Run(); 846 start_callback_.Run();
838 content::URLRequestMockHTTPJob::Start(); 847 net::URLRequestMockHTTPJob::Start();
839 } 848 }
840 849
841 private: 850 private:
842 virtual ~MockHTTPJob() {} 851 virtual ~MockHTTPJob() {}
843 852
844 base::Closure start_callback_; 853 base::Closure start_callback_;
845 }; 854 };
846 855
847 // Dummy counter class to live on the UI thread for counting requests. 856 // Dummy counter class to live on the UI thread for counting requests.
848 class RequestCounter : public base::SupportsWeakPtr<RequestCounter> { 857 class RequestCounter : public base::SupportsWeakPtr<RequestCounter> {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 new CountingInterceptor(file, counter)); 927 new CountingInterceptor(file, counter));
919 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 928 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
920 url, request_interceptor.Pass()); 929 url, request_interceptor.Pass());
921 } 930 }
922 931
923 // Makes |url| respond to requests with the contents of |file|. 932 // Makes |url| respond to requests with the contents of |file|.
924 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { 933 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) {
925 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 934 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
926 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 935 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
927 url, 936 url,
928 content::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(file)); 937 net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(
938 file, BrowserThread::GetBlockingPool()));
929 } 939 }
930 940
931 // A ContentBrowserClient that cancels all prerenderers on OpenURL. 941 // A ContentBrowserClient that cancels all prerenderers on OpenURL.
932 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { 942 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
933 public: 943 public:
934 TestContentBrowserClient() {} 944 TestContentBrowserClient() {}
935 virtual ~TestContentBrowserClient() {} 945 virtual ~TestContentBrowserClient() {}
936 946
937 // chrome::ChromeContentBrowserClient implementation. 947 // chrome::ChromeContentBrowserClient implementation.
938 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance, 948 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance,
(...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after
4418 4428
4419 // Navigate to the URL entered. 4429 // Navigate to the URL entered.
4420 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); 4430 omnibox_view->model()->AcceptInput(CURRENT_TAB, false);
4421 4431
4422 // Prerender should be running, but abandoned. 4432 // Prerender should be running, but abandoned.
4423 EXPECT_TRUE( 4433 EXPECT_TRUE(
4424 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); 4434 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting());
4425 } 4435 }
4426 4436
4427 } // namespace prerender 4437 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_browsertest.cc ('k') | chrome/browser/prerender/prerender_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698