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

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

Issue 300693005: Make URLRequestFilter use URLRequestInterceptors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge Created 6 years, 6 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 | Annotate | Revision Log
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 #include "extensions/common/switches.h" 86 #include "extensions/common/switches.h"
87 #include "grit/generated_resources.h" 87 #include "grit/generated_resources.h"
88 #include "net/base/escape.h" 88 #include "net/base/escape.h"
89 #include "net/cert/x509_certificate.h" 89 #include "net/cert/x509_certificate.h"
90 #include "net/dns/mock_host_resolver.h" 90 #include "net/dns/mock_host_resolver.h"
91 #include "net/ssl/client_cert_store.h" 91 #include "net/ssl/client_cert_store.h"
92 #include "net/ssl/ssl_cert_request_info.h" 92 #include "net/ssl/ssl_cert_request_info.h"
93 #include "net/url_request/url_request_context.h" 93 #include "net/url_request/url_request_context.h"
94 #include "net/url_request/url_request_context_getter.h" 94 #include "net/url_request/url_request_context_getter.h"
95 #include "net/url_request/url_request_filter.h" 95 #include "net/url_request/url_request_filter.h"
96 #include "net/url_request/url_request_interceptor.h"
96 #include "net/url_request/url_request_job.h" 97 #include "net/url_request/url_request_job.h"
97 #include "ui/base/l10n/l10n_util.h" 98 #include "ui/base/l10n/l10n_util.h"
98 #include "url/gurl.h" 99 #include "url/gurl.h"
99 100
100 using content::BrowserThread; 101 using content::BrowserThread;
101 using content::DevToolsAgentHost; 102 using content::DevToolsAgentHost;
102 using content::DevToolsClientHost; 103 using content::DevToolsClientHost;
103 using content::DevToolsManager; 104 using content::DevToolsManager;
104 using content::NavigationController; 105 using content::NavigationController;
105 using content::OpenURLParams; 106 using content::OpenURLParams;
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 net::NetworkDelegate* network_delegate) 772 net::NetworkDelegate* network_delegate)
772 : net::URLRequestJob(request, network_delegate) { 773 : net::URLRequestJob(request, network_delegate) {
773 } 774 }
774 775
775 virtual void Start() OVERRIDE {} 776 virtual void Start() OVERRIDE {}
776 777
777 private: 778 private:
778 virtual ~HangingURLRequestJob() {} 779 virtual ~HangingURLRequestJob() {}
779 }; 780 };
780 781
781 class HangingFirstRequestProtocolHandler 782 class HangingFirstRequestInterceptor : public net::URLRequestInterceptor {
782 : public net::URLRequestJobFactory::ProtocolHandler {
783 public: 783 public:
784 HangingFirstRequestProtocolHandler(const base::FilePath& file, 784 HangingFirstRequestInterceptor(const base::FilePath& file,
785 base::Closure callback) 785 base::Closure callback)
786 : file_(file), 786 : file_(file),
787 callback_(callback), 787 callback_(callback),
788 first_run_(true) { 788 first_run_(true) {
789 } 789 }
790 virtual ~HangingFirstRequestProtocolHandler() {} 790 virtual ~HangingFirstRequestInterceptor() {}
791 791
792 virtual net::URLRequestJob* MaybeCreateJob( 792 virtual net::URLRequestJob* MaybeInterceptRequest(
793 net::URLRequest* request, 793 net::URLRequest* request,
794 net::NetworkDelegate* network_delegate) const OVERRIDE { 794 net::NetworkDelegate* network_delegate) const OVERRIDE {
795 if (first_run_) { 795 if (first_run_) {
796 first_run_ = false; 796 first_run_ = false;
797 if (!callback_.is_null()) { 797 if (!callback_.is_null()) {
798 BrowserThread::PostTask( 798 BrowserThread::PostTask(
799 BrowserThread::UI, FROM_HERE, callback_); 799 BrowserThread::UI, FROM_HERE, callback_);
800 } 800 }
801 return new HangingURLRequestJob(request, network_delegate); 801 return new HangingURLRequestJob(request, network_delegate);
802 } 802 }
803 return new content::URLRequestMockHTTPJob(request, network_delegate, file_); 803 return new content::URLRequestMockHTTPJob(request, network_delegate, file_);
804 } 804 }
805 805
806 private: 806 private:
807 base::FilePath file_; 807 base::FilePath file_;
808 base::Closure callback_; 808 base::Closure callback_;
809 mutable bool first_run_; 809 mutable bool first_run_;
810 }; 810 };
811 811
812 // Makes |url| never respond on the first load, and then with the contents of 812 // Makes |url| never respond on the first load, and then with the contents of
813 // |file| afterwards. When the first load has been scheduled, runs |callback| on 813 // |file| afterwards. When the first load has been scheduled, runs |callback| on
814 // the UI thread. 814 // the UI thread.
815 void CreateHangingFirstRequestProtocolHandlerOnIO(const GURL& url, 815 void CreateHangingFirstRequestInterceptorOnIO(
816 const base::FilePath& file, 816 const GURL& url, const base::FilePath& file, base::Closure callback) {
817 base::Closure callback) {
818 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 817 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
819 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> never_respond_handler( 818 scoped_ptr<net::URLRequestInterceptor> never_respond_handler(
820 new HangingFirstRequestProtocolHandler(file, callback)); 819 new HangingFirstRequestInterceptor(file, callback));
821 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 820 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
822 url, never_respond_handler.Pass()); 821 url, never_respond_handler.Pass());
823 } 822 }
824 823
825 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks. 824 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks.
826 class MockHTTPJob : public content::URLRequestMockHTTPJob { 825 class MockHTTPJob : public content::URLRequestMockHTTPJob {
827 public: 826 public:
828 MockHTTPJob(net::URLRequest* request, 827 MockHTTPJob(net::URLRequest* request,
829 net::NetworkDelegate* delegate, 828 net::NetworkDelegate* delegate,
830 const base::FilePath& file) 829 const base::FilePath& file)
831 : content::URLRequestMockHTTPJob(request, delegate, file) { 830 : content::URLRequestMockHTTPJob(request, delegate, file) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 871
873 EXPECT_EQ(expected_count, count_); 872 EXPECT_EQ(expected_count, count_);
874 } 873 }
875 private: 874 private:
876 int count_; 875 int count_;
877 int expected_count_; 876 int expected_count_;
878 scoped_ptr<base::RunLoop> loop_; 877 scoped_ptr<base::RunLoop> loop_;
879 }; 878 };
880 879
881 // Protocol handler which counts the number of requests that start. 880 // Protocol handler which counts the number of requests that start.
882 class CountingProtocolHandler 881 class CountingInterceptor : public net::URLRequestInterceptor {
883 : public net::URLRequestJobFactory::ProtocolHandler {
884 public: 882 public:
885 CountingProtocolHandler(const base::FilePath& file, 883 CountingInterceptor(const base::FilePath& file,
886 const base::WeakPtr<RequestCounter>& counter) 884 const base::WeakPtr<RequestCounter>& counter)
887 : file_(file), 885 : file_(file),
888 counter_(counter), 886 counter_(counter),
889 weak_factory_(this) { 887 weak_factory_(this) {
890 } 888 }
891 virtual ~CountingProtocolHandler() {} 889 virtual ~CountingInterceptor() {}
892 890
893 virtual net::URLRequestJob* MaybeCreateJob( 891 virtual net::URLRequestJob* MaybeInterceptRequest(
894 net::URLRequest* request, 892 net::URLRequest* request,
895 net::NetworkDelegate* network_delegate) const OVERRIDE { 893 net::NetworkDelegate* network_delegate) const OVERRIDE {
896 MockHTTPJob* job = new MockHTTPJob(request, network_delegate, file_); 894 MockHTTPJob* job = new MockHTTPJob(request, network_delegate, file_);
897 job->set_start_callback(base::Bind(&CountingProtocolHandler::RequestStarted, 895 job->set_start_callback(base::Bind(&CountingInterceptor::RequestStarted,
898 weak_factory_.GetWeakPtr())); 896 weak_factory_.GetWeakPtr()));
899 return job; 897 return job;
900 } 898 }
901 899
902 void RequestStarted() { 900 void RequestStarted() {
903 BrowserThread::PostTask( 901 BrowserThread::PostTask(
904 BrowserThread::UI, FROM_HERE, 902 BrowserThread::UI, FROM_HERE,
905 base::Bind(&RequestCounter::RequestStarted, counter_)); 903 base::Bind(&RequestCounter::RequestStarted, counter_));
906 } 904 }
907 905
908 private: 906 private:
909 base::FilePath file_; 907 base::FilePath file_;
910 base::WeakPtr<RequestCounter> counter_; 908 base::WeakPtr<RequestCounter> counter_;
911 mutable base::WeakPtrFactory<CountingProtocolHandler> weak_factory_; 909 mutable base::WeakPtrFactory<CountingInterceptor> weak_factory_;
912 }; 910 };
913 911
914 // Makes |url| respond to requests with the contents of |file|, counting the 912 // Makes |url| respond to requests with the contents of |file|, counting the
915 // number that start in |counter|. 913 // number that start in |counter|.
916 void CreateCountingProtocolHandlerOnIO( 914 void CreateCountingInterceptorOnIO(
917 const GURL& url, 915 const GURL& url,
918 const base::FilePath& file, 916 const base::FilePath& file,
919 const base::WeakPtr<RequestCounter>& counter) { 917 const base::WeakPtr<RequestCounter>& counter) {
920 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 918 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
921 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> protocol_handler( 919 scoped_ptr<net::URLRequestInterceptor> request_interceptor(
922 new CountingProtocolHandler(file, counter)); 920 new CountingInterceptor(file, counter));
923 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 921 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
924 url, protocol_handler.Pass()); 922 url, request_interceptor.Pass());
925 } 923 }
926 924
927 // Makes |url| respond to requests with the contents of |file|. 925 // Makes |url| respond to requests with the contents of |file|.
928 void CreateMockProtocolHandlerOnIO(const GURL& url, 926 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) {
929 const base::FilePath& file) {
930 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 927 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
931 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 928 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
932 url, content::URLRequestMockHTTPJob::CreateProtocolHandlerForSingleFile( 929 url,
933 file)); 930 content::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(file));
934 } 931 }
935 932
936 // A ContentBrowserClient that cancels all prerenderers on OpenURL. 933 // A ContentBrowserClient that cancels all prerenderers on OpenURL.
937 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { 934 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
938 public: 935 public:
939 TestContentBrowserClient() {} 936 TestContentBrowserClient() {}
940 virtual ~TestContentBrowserClient() {} 937 virtual ~TestContentBrowserClient() {}
941 938
942 // chrome::ChromeContentBrowserClient implementation. 939 // chrome::ChromeContentBrowserClient implementation.
943 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance, 940 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance,
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 // Checks that the prerendering of a page is canceled correctly if we try to 1887 // Checks that the prerendering of a page is canceled correctly if we try to
1891 // swap it in before it commits. 1888 // swap it in before it commits.
1892 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap) { 1889 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap) {
1893 // Navigate to a page that triggers a prerender for a URL that never commits. 1890 // Navigate to a page that triggers a prerender for a URL that never commits.
1894 const GURL kNoCommitUrl("http://never-respond.example.com"); 1891 const GURL kNoCommitUrl("http://never-respond.example.com");
1895 base::FilePath file(GetTestPath("prerender_page.html")); 1892 base::FilePath file(GetTestPath("prerender_page.html"));
1896 1893
1897 base::RunLoop prerender_start_loop; 1894 base::RunLoop prerender_start_loop;
1898 BrowserThread::PostTask( 1895 BrowserThread::PostTask(
1899 BrowserThread::IO, FROM_HERE, 1896 BrowserThread::IO, FROM_HERE,
1900 base::Bind(&CreateHangingFirstRequestProtocolHandlerOnIO, 1897 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, kNoCommitUrl, file,
1901 kNoCommitUrl, file, prerender_start_loop.QuitClosure())); 1898 prerender_start_loop.QuitClosure()));
1902 DisableJavascriptCalls(); 1899 DisableJavascriptCalls();
1903 PrerenderTestURL(kNoCommitUrl, 1900 PrerenderTestURL(kNoCommitUrl,
1904 FINAL_STATUS_NAVIGATION_UNCOMMITTED, 1901 FINAL_STATUS_NAVIGATION_UNCOMMITTED,
1905 0); 1902 0);
1906 // Wait for the hanging request to be scheduled. 1903 // Wait for the hanging request to be scheduled.
1907 prerender_start_loop.Run(); 1904 prerender_start_loop.Run();
1908 1905
1909 // Navigate to the URL, but assume the contents won't be swapped in. 1906 // Navigate to the URL, but assume the contents won't be swapped in.
1910 NavigateToDestURLWithDisposition(CURRENT_TAB, false); 1907 NavigateToDestURLWithDisposition(CURRENT_TAB, false);
1911 } 1908 }
1912 1909
1913 // Checks that client redirects don't add alias URLs until after they commit. 1910 // Checks that client redirects don't add alias URLs until after they commit.
1914 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap2) { 1911 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap2) {
1915 // Navigate to a page that then navigates to a URL that never commits. 1912 // Navigate to a page that then navigates to a URL that never commits.
1916 const GURL kNoCommitUrl("http://never-respond.example.com"); 1913 const GURL kNoCommitUrl("http://never-respond.example.com");
1917 base::FilePath file(GetTestPath("prerender_page.html")); 1914 base::FilePath file(GetTestPath("prerender_page.html"));
1918 1915
1919 base::RunLoop prerender_start_loop; 1916 base::RunLoop prerender_start_loop;
1920 BrowserThread::PostTask( 1917 BrowserThread::PostTask(
1921 BrowserThread::IO, FROM_HERE, 1918 BrowserThread::IO, FROM_HERE,
1922 base::Bind(&CreateHangingFirstRequestProtocolHandlerOnIO, 1919 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, kNoCommitUrl, file,
1923 kNoCommitUrl, file, prerender_start_loop.QuitClosure())); 1920 prerender_start_loop.QuitClosure()));
1924 DisableJavascriptCalls(); 1921 DisableJavascriptCalls();
1925 PrerenderTestURL(CreateClientRedirect(kNoCommitUrl.spec()), 1922 PrerenderTestURL(CreateClientRedirect(kNoCommitUrl.spec()),
1926 FINAL_STATUS_APP_TERMINATING, 1); 1923 FINAL_STATUS_APP_TERMINATING, 1);
1927 // Wait for the hanging request to be scheduled. 1924 // Wait for the hanging request to be scheduled.
1928 prerender_start_loop.Run(); 1925 prerender_start_loop.Run();
1929 1926
1930 // Navigating to the second URL should not swap. 1927 // Navigating to the second URL should not swap.
1931 NavigateToURLWithDisposition(kNoCommitUrl, CURRENT_TAB, false); 1928 NavigateToURLWithDisposition(kNoCommitUrl, CURRENT_TAB, false);
1932 } 1929 }
1933 1930
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 // Checks that when a prerendered page is swapped in to a referring page, the 3113 // Checks that when a prerendered page is swapped in to a referring page, the
3117 // unload handlers on the referring page are executed. 3114 // unload handlers on the referring page are executed.
3118 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { 3115 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) {
3119 // Matches URL in prerender_loader_with_unload.html. 3116 // Matches URL in prerender_loader_with_unload.html.
3120 const GURL unload_url("http://unload-url.test"); 3117 const GURL unload_url("http://unload-url.test");
3121 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 3118 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
3122 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 3119 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
3123 RequestCounter unload_counter; 3120 RequestCounter unload_counter;
3124 BrowserThread::PostTask( 3121 BrowserThread::PostTask(
3125 BrowserThread::IO, FROM_HERE, 3122 BrowserThread::IO, FROM_HERE,
3126 base::Bind(&CreateCountingProtocolHandlerOnIO, 3123 base::Bind(&CreateCountingInterceptorOnIO,
3127 unload_url, empty_file, unload_counter.AsWeakPtr())); 3124 unload_url, empty_file, unload_counter.AsWeakPtr()));
3128 3125
3129 set_loader_path("files/prerender/prerender_loader_with_unload.html"); 3126 set_loader_path("files/prerender/prerender_loader_with_unload.html");
3130 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 3127 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
3131 NavigateToDestURL(); 3128 NavigateToDestURL();
3132 unload_counter.WaitForCount(1); 3129 unload_counter.WaitForCount(1);
3133 } 3130 }
3134 3131
3135 // Checks that a hanging unload on the referring page of a prerender swap does 3132 // Checks that a hanging unload on the referring page of a prerender swap does
3136 // not crash the browser on exit. 3133 // not crash the browser on exit.
3137 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHangingUnload) { 3134 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHangingUnload) {
3138 // Matches URL in prerender_loader_with_unload.html. 3135 // Matches URL in prerender_loader_with_unload.html.
3139 const GURL hang_url("http://unload-url.test"); 3136 const GURL hang_url("http://unload-url.test");
3140 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 3137 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
3141 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 3138 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
3142 BrowserThread::PostTask( 3139 BrowserThread::PostTask(
3143 BrowserThread::IO, FROM_HERE, 3140 BrowserThread::IO, FROM_HERE,
3144 base::Bind(&CreateHangingFirstRequestProtocolHandlerOnIO, 3141 base::Bind(&CreateHangingFirstRequestInterceptorOnIO,
3145 hang_url, empty_file, 3142 hang_url, empty_file,
3146 base::Closure())); 3143 base::Closure()));
3147 3144
3148 set_loader_path("files/prerender/prerender_loader_with_unload.html"); 3145 set_loader_path("files/prerender/prerender_loader_with_unload.html");
3149 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 3146 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
3150 NavigateToDestURL(); 3147 NavigateToDestURL();
3151 } 3148 }
3152 3149
3153 3150
3154 // Checks that when the history is cleared, prerendering is cancelled and 3151 // Checks that when the history is cleared, prerendering is cancelled and
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
3378 MatchCompleteDummyCancelNavigation) { 3375 MatchCompleteDummyCancelNavigation) {
3379 UMAHistogramHelper histograms; 3376 UMAHistogramHelper histograms;
3380 3377
3381 // Arrange for a URL to hang. 3378 // Arrange for a URL to hang.
3382 const GURL kNoCommitUrl("http://never-respond.example.com"); 3379 const GURL kNoCommitUrl("http://never-respond.example.com");
3383 base::FilePath file(FILE_PATH_LITERAL( 3380 base::FilePath file(FILE_PATH_LITERAL(
3384 "chrome/test/data/prerender/prerender_page.html")); 3381 "chrome/test/data/prerender/prerender_page.html"));
3385 base::RunLoop hang_loop; 3382 base::RunLoop hang_loop;
3386 BrowserThread::PostTask( 3383 BrowserThread::PostTask(
3387 BrowserThread::IO, FROM_HERE, 3384 BrowserThread::IO, FROM_HERE,
3388 base::Bind(&CreateHangingFirstRequestProtocolHandlerOnIO, 3385 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, kNoCommitUrl,
3389 kNoCommitUrl, file, hang_loop.QuitClosure())); 3386 file, hang_loop.QuitClosure()));
3390 3387
3391 // First, fire a prerender that aborts after it completes its load. 3388 // First, fire a prerender that aborts after it completes its load.
3392 std::vector<FinalStatus> expected_final_status_queue; 3389 std::vector<FinalStatus> expected_final_status_queue;
3393 expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD); 3390 expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD);
3394 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); 3391 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED);
3395 PrerenderTestURL("files/prerender/prerender_xhr_put.html", 3392 PrerenderTestURL("files/prerender/prerender_xhr_put.html",
3396 expected_final_status_queue, 1); 3393 expected_final_status_queue, 1);
3397 histograms.Fetch(); 3394 histograms.Fetch();
3398 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1); 3395 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
3399 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 3396 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
3765 // Cross-process navigation logic for renderer-initiated navigations 3762 // Cross-process navigation logic for renderer-initiated navigations
3766 // is partially controlled by the renderer, namely 3763 // is partially controlled by the renderer, namely
3767 // ChromeContentRendererClient. This test instead relies on the Web 3764 // ChromeContentRendererClient. This test instead relies on the Web
3768 // Store triggering such navigations. 3765 // Store triggering such navigations.
3769 std::string webstore_url = extension_urls::GetWebstoreLaunchURL(); 3766 std::string webstore_url = extension_urls::GetWebstoreLaunchURL();
3770 3767
3771 // Mock out requests to the Web Store. 3768 // Mock out requests to the Web Store.
3772 base::FilePath file(GetTestPath("prerender_page.html")); 3769 base::FilePath file(GetTestPath("prerender_page.html"));
3773 BrowserThread::PostTask( 3770 BrowserThread::PostTask(
3774 BrowserThread::IO, FROM_HERE, 3771 BrowserThread::IO, FROM_HERE,
3775 base::Bind(&CreateMockProtocolHandlerOnIO, 3772 base::Bind(&CreateMockInterceptorOnIO, GURL(webstore_url), file));
3776 GURL(webstore_url), file));
3777 3773
3778 PrerenderTestURL(CreateClientRedirect(webstore_url), 3774 PrerenderTestURL(CreateClientRedirect(webstore_url),
3779 FINAL_STATUS_OPEN_URL, 1); 3775 FINAL_STATUS_OPEN_URL, 1);
3780 } 3776 }
3781 3777
3782 // Checks that canceling a MatchComplete dummy doesn't result in two 3778 // Checks that canceling a MatchComplete dummy doesn't result in two
3783 // stop events. 3779 // stop events.
3784 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, CancelMatchCompleteDummy) { 3780 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, CancelMatchCompleteDummy) {
3785 std::vector<FinalStatus> expected_final_status_queue; 3781 std::vector<FinalStatus> expected_final_status_queue;
3786 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT); 3782 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3938 // Attempt a swap-in in a new tab, verifying that session storage namespace 3934 // Attempt a swap-in in a new tab, verifying that session storage namespace
3939 // merging works. 3935 // merging works.
3940 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageNewTab) { 3936 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageNewTab) {
3941 // Mock out some URLs and count the number of requests to one of them. Both 3937 // Mock out some URLs and count the number of requests to one of them. Both
3942 // prerender_session_storage.html and init_session_storage.html need to be 3938 // prerender_session_storage.html and init_session_storage.html need to be
3943 // mocked so they are same-origin. 3939 // mocked so they are same-origin.
3944 const GURL kInitURL("http://prerender.test/init_session_storage.html"); 3940 const GURL kInitURL("http://prerender.test/init_session_storage.html");
3945 base::FilePath init_file = GetTestPath("init_session_storage.html"); 3941 base::FilePath init_file = GetTestPath("init_session_storage.html");
3946 BrowserThread::PostTask( 3942 BrowserThread::PostTask(
3947 BrowserThread::IO, FROM_HERE, 3943 BrowserThread::IO, FROM_HERE,
3948 base::Bind(&CreateMockProtocolHandlerOnIO, kInitURL, init_file)); 3944 base::Bind(&CreateMockInterceptorOnIO, kInitURL, init_file));
3949 3945
3950 const GURL kTestURL("http://prerender.test/prerender_session_storage.html"); 3946 const GURL kTestURL("http://prerender.test/prerender_session_storage.html");
3951 base::FilePath test_file = GetTestPath("prerender_session_storage.html"); 3947 base::FilePath test_file = GetTestPath("prerender_session_storage.html");
3952 RequestCounter counter; 3948 RequestCounter counter;
3953 BrowserThread::PostTask( 3949 BrowserThread::PostTask(
3954 BrowserThread::IO, FROM_HERE, 3950 BrowserThread::IO, FROM_HERE,
3955 base::Bind(&CreateCountingProtocolHandlerOnIO, 3951 base::Bind(&CreateCountingInterceptorOnIO,
3956 kTestURL, test_file, counter.AsWeakPtr())); 3952 kTestURL, test_file, counter.AsWeakPtr()));
3957 3953
3958 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1); 3954 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1);
3959 3955
3960 // Open a new tab to navigate in. 3956 // Open a new tab to navigate in.
3961 ui_test_utils::NavigateToURLWithDisposition( 3957 ui_test_utils::NavigateToURLWithDisposition(
3962 current_browser(), kInitURL, NEW_FOREGROUND_TAB, 3958 current_browser(), kInitURL, NEW_FOREGROUND_TAB,
3963 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 3959 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
3964 3960
3965 // Now navigate in the new tab. Set expect_swap_to_succeed to false because 3961 // Now navigate in the new tab. Set expect_swap_to_succeed to false because
(...skipping 22 matching lines...) Expand all
3988 base::FilePath test_data_dir; 3984 base::FilePath test_data_dir;
3989 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 3985 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
3990 3986
3991 // Mock out some URLs and count the number of requests to one of them. Both 3987 // Mock out some URLs and count the number of requests to one of them. Both
3992 // prerender_session_storage.html and init_session_storage.html need to be 3988 // prerender_session_storage.html and init_session_storage.html need to be
3993 // mocked so they are same-origin. 3989 // mocked so they are same-origin.
3994 const GURL kInitURL("http://prerender.test/init_session_storage.html"); 3990 const GURL kInitURL("http://prerender.test/init_session_storage.html");
3995 base::FilePath init_file = GetTestPath("init_session_storage.html"); 3991 base::FilePath init_file = GetTestPath("init_session_storage.html");
3996 BrowserThread::PostTask( 3992 BrowserThread::PostTask(
3997 BrowserThread::IO, FROM_HERE, 3993 BrowserThread::IO, FROM_HERE,
3998 base::Bind(&CreateMockProtocolHandlerOnIO, kInitURL, init_file)); 3994 base::Bind(&CreateMockInterceptorOnIO, kInitURL, init_file));
3999 3995
4000 const GURL kTestURL("http://prerender.test/prerender_session_storage.html"); 3996 const GURL kTestURL("http://prerender.test/prerender_session_storage.html");
4001 base::FilePath test_file = GetTestPath("prerender_session_storage.html"); 3997 base::FilePath test_file = GetTestPath("prerender_session_storage.html");
4002 RequestCounter counter; 3998 RequestCounter counter;
4003 BrowserThread::PostTask( 3999 BrowserThread::PostTask(
4004 BrowserThread::IO, FROM_HERE, 4000 BrowserThread::IO, FROM_HERE,
4005 base::Bind(&CreateCountingProtocolHandlerOnIO, 4001 base::Bind(&CreateCountingInterceptorOnIO,
4006 kTestURL, test_file, counter.AsWeakPtr())); 4002 kTestURL, test_file, counter.AsWeakPtr()));
4007 4003
4008 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1); 4004 PrerenderTestURL(kTestURL, FINAL_STATUS_USED, 1);
4009 4005
4010 // Open a new tab to navigate in. 4006 // Open a new tab to navigate in.
4011 ui_test_utils::NavigateToURLWithDisposition( 4007 ui_test_utils::NavigateToURLWithDisposition(
4012 current_browser(), kInitURL, NEW_FOREGROUND_TAB, 4008 current_browser(), kInitURL, NEW_FOREGROUND_TAB,
4013 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 4009 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
4014 4010
4015 // Navigate to about:blank so the next navigation is cross-process. 4011 // Navigate to about:blank so the next navigation is cross-process.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
4162 4158
4163 // Checks that <a ping> requests are not dropped in prerender. 4159 // Checks that <a ping> requests are not dropped in prerender.
4164 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) { 4160 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) {
4165 // Count hits to a certain URL. 4161 // Count hits to a certain URL.
4166 const GURL kPingURL("http://prerender.test/ping"); 4162 const GURL kPingURL("http://prerender.test/ping");
4167 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 4163 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
4168 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 4164 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
4169 RequestCounter ping_counter; 4165 RequestCounter ping_counter;
4170 BrowserThread::PostTask( 4166 BrowserThread::PostTask(
4171 BrowserThread::IO, FROM_HERE, 4167 BrowserThread::IO, FROM_HERE,
4172 base::Bind(&CreateCountingProtocolHandlerOnIO, 4168 base::Bind(&CreateCountingInterceptorOnIO,
4173 kPingURL, empty_file, ping_counter.AsWeakPtr())); 4169 kPingURL, empty_file, ping_counter.AsWeakPtr()));
4174 4170
4175 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 4171 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
4176 OpenDestURLViaClickPing(kPingURL); 4172 OpenDestURLViaClickPing(kPingURL);
4177 4173
4178 ping_counter.WaitForCount(1); 4174 ping_counter.WaitForCount(1);
4179 } 4175 }
4180 4176
4181 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPPLTNormalNavigation) { 4177 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPPLTNormalNavigation) {
4182 UMAHistogramHelper histograms; 4178 UMAHistogramHelper histograms;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
4411 4407
4412 // Navigate to the URL entered. 4408 // Navigate to the URL entered.
4413 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); 4409 omnibox_view->model()->AcceptInput(CURRENT_TAB, false);
4414 4410
4415 // Prerender should be running, but abandoned. 4411 // Prerender should be running, but abandoned.
4416 EXPECT_TRUE( 4412 EXPECT_TRUE(
4417 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); 4413 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting());
4418 } 4414 }
4419 4415
4420 } // namespace prerender 4416 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_browsertest.cc ('k') | content/test/net/url_request_mock_http_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698