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

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

Issue 9416031: Prerendered pages are swapped in at browser::Navigate time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Base files missing Created 8 years, 9 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 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // TabContents, at the end of a navigation caused by a call to 163 // TabContents, at the end of a navigation caused by a call to
164 // NavigateToURLImpl(). 164 // NavigateToURLImpl().
165 if (final_status() == FINAL_STATUS_USED) 165 if (final_status() == FINAL_STATUS_USED)
166 EXPECT_TRUE(new_render_view_host_); 166 EXPECT_TRUE(new_render_view_host_);
167 167
168 EXPECT_EQ(should_be_shown_, was_shown_); 168 EXPECT_EQ(should_be_shown_, was_shown_);
169 169
170 // When the PrerenderContents is destroyed, quit the UI message loop. 170 // When the PrerenderContents is destroyed, quit the UI message loop.
171 // This happens on navigation to used prerendered pages, and soon 171 // This happens on navigation to used prerendered pages, and soon
172 // after cancellation of unused prerendered pages. 172 // after cancellation of unused prerendered pages.
173 if (quit_message_loop_on_destruction_) 173 if (quit_message_loop_on_destruction_) {
174 MessageLoopForUI::current()->Quit(); 174 // The message loop may not be running if this is swapped in
175 // synchronously on a Navigation.
176 MessageLoop* loop = MessageLoopForUI::current();
177 if (loop->is_running())
178 loop->Quit();
179 }
175 } 180 }
176 181
177 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE { 182 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE {
178 // On quit, it's possible to end up here when render processes are closed 183 // On quit, it's possible to end up here when render processes are closed
179 // before the PrerenderManager is destroyed. As a result, it's possible to 184 // before the PrerenderManager is destroyed. As a result, it's possible to
180 // get either FINAL_STATUS_APP_TERMINATING or FINAL_STATUS_RENDERER_CRASHED 185 // get either FINAL_STATUS_APP_TERMINATING or FINAL_STATUS_RENDERER_CRASHED
181 // on quit. 186 // on quit.
182 // 187 //
183 // It's also possible for this to be called after we've been notified of 188 // It's also possible for this to be called after we've been notified of
184 // app termination, but before we've been deleted, which is why the second 189 // app termination, but before we've been deleted, which is why the second
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 expected_final_status); 484 expected_final_status);
480 PrerenderTestURL(html_file, 485 PrerenderTestURL(html_file,
481 expected_final_status_queue, 486 expected_final_status_queue,
482 expected_number_of_loads); 487 expected_number_of_loads);
483 } 488 }
484 489
485 void PrerenderTestURL( 490 void PrerenderTestURL(
486 const std::string& html_file, 491 const std::string& html_file,
487 const std::deque<FinalStatus>& expected_final_status_queue, 492 const std::deque<FinalStatus>& expected_final_status_queue,
488 int expected_number_of_loads) { 493 int expected_number_of_loads) {
489 PrerenderTestURLImpl(test_server()->GetURL(html_file), 494 GURL url = test_server()->GetURL(html_file);
495 PrerenderTestURLImpl(url, url,
490 expected_final_status_queue, 496 expected_final_status_queue,
491 expected_number_of_loads); 497 expected_number_of_loads);
492 } 498 }
493 499
494 void PrerenderTestURL( 500 void PrerenderTestURL(
495 const GURL& url, 501 const GURL& url,
496 FinalStatus expected_final_status, 502 FinalStatus expected_final_status,
497 int expected_number_of_loads) { 503 int expected_number_of_loads) {
498 std::deque<FinalStatus> expected_final_status_queue(1, 504 std::deque<FinalStatus> expected_final_status_queue(1,
499 expected_final_status); 505 expected_final_status);
500 PrerenderTestURLImpl(url, 506 PrerenderTestURLImpl(url, url,
501 expected_final_status_queue, 507 expected_final_status_queue,
502 expected_number_of_loads); 508 expected_number_of_loads);
503 } 509 }
510
511 void PrerenderTestURL(
512 const GURL& prerender_url,
513 const GURL& destination_url,
514 FinalStatus expected_final_status,
515 int expected_number_of_loads) {
516 std::deque<FinalStatus> expected_final_status_queue(1,
517 expected_final_status);
518 PrerenderTestURLImpl(prerender_url, destination_url,
519 expected_final_status_queue,
520 expected_number_of_loads);
521 }
504 522
505 void NavigateToDestURL() const { 523 void NavigateToDestURL() const {
506 NavigateToDestURLWithDisposition(CURRENT_TAB); 524 NavigateToDestURLWithDisposition(CURRENT_TAB);
507 } 525 }
508 526
509 // Opens the url in a new tab, with no opener. 527 // Opens the url in a new tab, with no opener.
510 void NavigateToDestURLWithDisposition( 528 void NavigateToDestURLWithDisposition(
511 WindowOpenDisposition disposition) const { 529 WindowOpenDisposition disposition) const {
512 NavigateToURLImpl(dest_url_, disposition); 530 NavigateToURLImpl(dest_url_, disposition);
513 } 531 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 std::string url_str(base::StringPrintf( 700 std::string url_str(base::StringPrintf(
683 "http://%s:%d/%s", 701 "http://%s:%d/%s",
684 secondary_domain.c_str(), 702 secondary_domain.c_str(),
685 test_server()->host_port_pair().port(), 703 test_server()->host_port_pair().port(),
686 path.c_str())); 704 path.c_str()));
687 return GURL(url_str); 705 return GURL(url_str);
688 } 706 }
689 707
690 private: 708 private:
691 void PrerenderTestURLImpl( 709 void PrerenderTestURLImpl(
692 const GURL& url, 710 const GURL& prerender_url,
711 const GURL& destination_url,
693 const std::deque<FinalStatus>& expected_final_status_queue, 712 const std::deque<FinalStatus>& expected_final_status_queue,
694 int expected_number_of_loads) { 713 int expected_number_of_loads) {
695 dest_url_ = url; 714 // TODO(cbentzel): Remove dest_url_?
715 dest_url_ = destination_url;
696 716
697 std::vector<net::TestServer::StringPair> replacement_text; 717 std::vector<net::TestServer::StringPair> replacement_text;
698 replacement_text.push_back( 718 replacement_text.push_back(
699 make_pair("REPLACE_WITH_PRERENDER_URL", dest_url_.spec())); 719 make_pair("REPLACE_WITH_PRERENDER_URL", prerender_url.spec()));
720 replacement_text.push_back(
721 make_pair("REPLACE_WITH_DESTINATION_URL", destination_url.spec()));
700 std::string replacement_path; 722 std::string replacement_path;
701 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( 723 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements(
702 loader_path_, 724 loader_path_,
703 replacement_text, 725 replacement_text,
704 &replacement_path)); 726 &replacement_path));
705 727
706 net::TestServer* src_server = test_server(); 728 net::TestServer* src_server = test_server();
707 scoped_ptr<net::TestServer> https_src_server; 729 scoped_ptr<net::TestServer> https_src_server;
708 if (use_https_src_server_) { 730 if (use_https_src_server_) {
709 https_src_server.reset( 731 https_src_server.reset(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 GetPrerenderContents()->prerender_contents()->web_contents(); 802 GetPrerenderContents()->prerender_contents()->web_contents();
781 if (GetPrerenderContents()->number_of_loads() == 0) { 803 if (GetPrerenderContents()->number_of_loads() == 0) {
782 page_load_observer.reset( 804 page_load_observer.reset(
783 new ui_test_utils::WindowedNotificationObserver( 805 new ui_test_utils::WindowedNotificationObserver(
784 content::NOTIFICATION_LOAD_STOP, 806 content::NOTIFICATION_LOAD_STOP,
785 content::Source<NavigationController>( 807 content::Source<NavigationController>(
786 &web_contents->GetController()))); 808 &web_contents->GetController())));
787 } 809 }
788 } 810 }
789 811
790 // ui_test_utils::NavigateToURL waits until DidStopLoading is called on 812 // Navigate to the prerendered URL, but don't run the message loop. Browser
791 // the current tab. As that tab is going to end up deleted, and may never 813 // issued navigations to prerendered pages will synchronously swap in the
792 // finish loading before that happens, exit the message loop on the deletion 814 // prerendered page.
793 // of the used prerender contents instead.
794 //
795 // As PrerenderTestURL waits until the prerendered page has completely
796 // loaded, there is no race between loading |dest_url| and swapping the
797 // prerendered TabContents into the tab.
798 ui_test_utils::NavigateToURLWithDisposition( 815 ui_test_utils::NavigateToURLWithDisposition(
799 browser(), dest_url, disposition, ui_test_utils::BROWSER_TEST_NONE); 816 browser(), dest_url, disposition, ui_test_utils::BROWSER_TEST_NONE);
800 ui_test_utils::RunMessageLoop();
801 817
802 // Make sure the PrerenderContents found earlier was used or removed. 818 // Make sure the PrerenderContents found earlier was used or removed.
803 EXPECT_TRUE(GetPrerenderContents() == NULL); 819 EXPECT_TRUE(GetPrerenderContents() == NULL);
804 820
805 if (call_javascript_ && web_contents) { 821 if (call_javascript_ && web_contents) {
806 if (page_load_observer.get()) 822 if (page_load_observer.get())
807 page_load_observer->Wait(); 823 page_load_observer->Wait();
808 824
809 bool display_test_result = false; 825 bool display_test_result = false;
810 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 826 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 // This version navigates to the final destination page, rather than the 975 // This version navigates to the final destination page, rather than the
960 // page which does the redirection. 976 // page which does the redirection.
961 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 977 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
962 PrerenderClientRedirectNavigateToSecond) { 978 PrerenderClientRedirectNavigateToSecond) {
963 PrerenderTestURL(CreateClientRedirect("files/prerender/prerender_page.html"), 979 PrerenderTestURL(CreateClientRedirect("files/prerender/prerender_page.html"),
964 FINAL_STATUS_USED, 980 FINAL_STATUS_USED,
965 2); 981 2);
966 NavigateToURL("files/prerender/prerender_page.html"); 982 NavigateToURL("files/prerender/prerender_page.html");
967 } 983 }
968 984
985 // Checks that client-issued redirects work with prerendering.
986 // This version navigates to the final destination page, rather than the
987 // page which does the redirection via a mouse click.
988 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
989 PrerenderClientRedirectNavigateToSecondViaClick) {
990 GURL prerender_url = test_server()->GetURL(
991 CreateClientRedirect("files/prerender/prerender_page.html"));
992 GURL destination_url = test_server()->GetURL(
993 "files/prerender/prerender_page.html");
994 PrerenderTestURL(prerender_url, destination_url, FINAL_STATUS_USED, 2);
995 OpenDestURLViaClick();
996 }
997
969 // Checks that a prerender for an https will prevent a prerender from happening. 998 // Checks that a prerender for an https will prevent a prerender from happening.
970 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHttps) { 999 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHttps) {
971 net::TestServer https_server(net::TestServer::TYPE_HTTPS, 1000 net::TestServer https_server(net::TestServer::TYPE_HTTPS,
972 net::TestServer::kLocalhost, 1001 net::TestServer::kLocalhost,
973 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 1002 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
974 ASSERT_TRUE(https_server.Start()); 1003 ASSERT_TRUE(https_server.Start());
975 GURL https_url = https_server.GetURL("files/prerender/prerender_page.html"); 1004 GURL https_url = https_server.GetURL("files/prerender/prerender_page.html");
976 PrerenderTestURL(https_url, 1005 PrerenderTestURL(https_url,
977 FINAL_STATUS_USED, 1006 FINAL_STATUS_USED,
978 1); 1007 1);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 // This version navigates to the final destination page, rather than the 1079 // This version navigates to the final destination page, rather than the
1051 // page which does the redirection. 1080 // page which does the redirection.
1052 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 1081 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
1053 PrerenderServerRedirectNavigateToSecond) { 1082 PrerenderServerRedirectNavigateToSecond) {
1054 PrerenderTestURL(CreateServerRedirect("files/prerender/prerender_page.html"), 1083 PrerenderTestURL(CreateServerRedirect("files/prerender/prerender_page.html"),
1055 FINAL_STATUS_USED, 1084 FINAL_STATUS_USED,
1056 1); 1085 1);
1057 NavigateToURL("files/prerender/prerender_page.html"); 1086 NavigateToURL("files/prerender/prerender_page.html");
1058 } 1087 }
1059 1088
1089 // Checks that server-issued redirects work with prerendering.
1090 // This version navigates to the final destination page, rather than the
1091 // page which does the redirection via a mouse click.
1092 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
1093 PrerenderServerRedirectNavigateToSecondViaClick) {
1094 GURL prerender_url = test_server()->GetURL(
1095 CreateServerRedirect("files/prerender/prerender_page.html"));
1096 GURL destination_url = test_server()->GetURL(
1097 "files/prerender/prerender_page.html");
1098 PrerenderTestURL(prerender_url, destination_url, FINAL_STATUS_USED, 1);
1099 OpenDestURLViaClick();
1100 }
1101
1060 // Checks that server-issued redirects from an http to an https 1102 // Checks that server-issued redirects from an http to an https
1061 // location will cancel prerendering. 1103 // location will cancel prerendering.
1062 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 1104 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
1063 PrerenderServerRedirectToHttps) { 1105 PrerenderServerRedirectToHttps) {
1064 net::TestServer https_server(net::TestServer::TYPE_HTTPS, 1106 net::TestServer https_server(net::TestServer::TYPE_HTTPS,
1065 net::TestServer::kLocalhost, 1107 net::TestServer::kLocalhost,
1066 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 1108 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1067 ASSERT_TRUE(https_server.Start()); 1109 ASSERT_TRUE(https_server.Start());
1068 GURL https_url = https_server.GetURL("files/prerender/prerender_page.html"); 1110 GURL https_url = https_server.GetURL("files/prerender/prerender_page.html");
1069 PrerenderTestURL(CreateServerRedirect(https_url.spec()), 1111 PrerenderTestURL(CreateServerRedirect(https_url.spec()),
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) { 1988 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) {
1947 std::deque<FinalStatus> expected_final_status_queue; 1989 std::deque<FinalStatus> expected_final_status_queue;
1948 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT); 1990 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT);
1949 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); 1991 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED);
1950 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", 1992 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html",
1951 expected_final_status_queue, 1); 1993 expected_final_status_queue, 1);
1952 NavigateToDestURL(); 1994 NavigateToDestURL();
1953 } 1995 }
1954 1996
1955 } // namespace prerender 1997 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_contents.h » ('j') | chrome/browser/prerender/prerender_contents.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698