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

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

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

Powered by Google App Engine
This is Rietveld 408576698