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

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

Issue 11459003: Add Start/Stop event signalling on Prerenders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: one last test Created 8 years 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
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_link_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 OpenDestURLWithJSImpl("MetaClick()"); 737 OpenDestURLWithJSImpl("MetaClick()");
738 #else 738 #else
739 OpenDestURLWithJSImpl("CtrlClick()"); 739 OpenDestURLWithJSImpl("CtrlClick()");
740 #endif 740 #endif
741 } 741 }
742 742
743 void OpenDestURLViaWindowOpen() const { 743 void OpenDestURLViaWindowOpen() const {
744 OpenDestURLWithJSImpl("WindowOpen()"); 744 OpenDestURLWithJSImpl("WindowOpen()");
745 } 745 }
746 746
747 void RemoveLinkElementsAndNavigate() const { 747 void RemoveLinkElement(int i) const {
748 OpenDestURLWithJSImpl("RemoveLinkElementsAndNavigate()"); 748 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost()->
749 ExecuteJavascriptInWebFrame(
750 string16(),
751 ASCIIToUTF16(base::StringPrintf("RemoveLinkElement(%d)", i)));
749 } 752 }
750 753
751 void ClickToNextPageAfterPrerender() { 754 void ClickToNextPageAfterPrerender() {
752 content::WindowedNotificationObserver new_page_observer( 755 content::WindowedNotificationObserver new_page_observer(
753 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 756 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
754 content::NotificationService::AllSources()); 757 content::NotificationService::AllSources());
755 RenderViewHost* render_view_host = 758 RenderViewHost* render_view_host =
756 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(); 759 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost();
757 render_view_host->ExecuteJavascriptInWebFrame( 760 render_view_host->ExecuteJavascriptInWebFrame(
758 string16(), 761 string16(),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 return prerender_manager; 846 return prerender_manager;
844 } 847 }
845 848
846 const PrerenderLinkManager* GetPrerenderLinkManager() const { 849 const PrerenderLinkManager* GetPrerenderLinkManager() const {
847 PrerenderLinkManager* prerender_link_manager = 850 PrerenderLinkManager* prerender_link_manager =
848 PrerenderLinkManagerFactory::GetForProfile( 851 PrerenderLinkManagerFactory::GetForProfile(
849 current_browser()->profile()); 852 current_browser()->profile());
850 return prerender_link_manager; 853 return prerender_link_manager;
851 } 854 }
852 855
853 // Asserting on this can result in flaky tests. PrerenderHandles are only 856 bool DidReceivePrerenderStartEventForLinkNumber(int index) const {
854 // removed from the PrerenderLinkManager when the prerenders are cancelled 857 bool received_prerender_started;
855 // from the renderer process, or the channel for the renderer process is 858 std::wstring expression = base::StringPrintf(
856 // closed on the IO thread. In the latter case, the code must be careful to 859 L"window.domAutomationController.send(Boolean("
857 // wait for the channel to close, as it is done asynchronously after swapping 860 L"receivedPrerenderStartEvents[%d]))", index);
858 // out the old process. See ChannelDestructionWatcher. 861
862 CHECK(content::ExecuteJavaScriptAndExtractBool(
863 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(),
864 L"", expression,
865 &received_prerender_started));
866 return received_prerender_started;
867 }
868
869 bool DidReceivePrerenderStopEventForLinkNumber(int index) const {
870 bool received_prerender_stopped;
871 std::wstring expression = base::StringPrintf(
872 L"window.domAutomationController.send(Boolean("
873 L"receivedPrerenderStopEvents[%d]))", index);
874
875 CHECK(content::ExecuteJavaScriptAndExtractBool(
876 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(),
877 L"", expression,
878 &received_prerender_stopped));
879 return received_prerender_stopped;
880 }
881
882 // Asserting on this can result in flaky tests. PrerenderHandles are
883 // removed from the PrerenderLinkManager when the prerender is canceled from
884 // the browser, when the prerenders are cancelled from the renderer process,
885 // or the channel for the renderer process is closed on the IO thread. In the
886 // last case, the code must be careful to wait for the channel to close, as it
887 // is done asynchronously after swapping out the old process. See
888 // ChannelDestructionWatcher.
859 bool IsEmptyPrerenderLinkManager() const { 889 bool IsEmptyPrerenderLinkManager() const {
860 return GetPrerenderLinkManager()->IsEmpty(); 890 return GetPrerenderLinkManager()->IsEmpty();
861 } 891 }
862 892
863 // Returns length of |prerender_manager_|'s history, or -1 on failure. 893 // Returns length of |prerender_manager_|'s history, or -1 on failure.
864 int GetHistoryLength() const { 894 int GetHistoryLength() const {
865 scoped_ptr<DictionaryValue> prerender_dict( 895 scoped_ptr<DictionaryValue> prerender_dict(
866 static_cast<DictionaryValue*>(GetPrerenderManager()->GetAsValue())); 896 static_cast<DictionaryValue*>(GetPrerenderManager()->GetAsValue()));
867 if (!prerender_dict.get()) 897 if (!prerender_dict.get())
868 return -1; 898 return -1;
869 ListValue* history_list; 899 ListValue* history_list;
870 if (!prerender_dict->GetList("history", &history_list)) 900 if (!prerender_dict->GetList("history", &history_list))
871 return -1; 901 return -1;
872 return static_cast<int>(history_list->GetSize()); 902 return static_cast<int>(history_list->GetSize());
873 } 903 }
874 904
875 #if defined(FULL_SAFE_BROWSING) 905 #if defined(FULL_SAFE_BROWSING)
876 FakeSafeBrowsingDatabaseManager* GetFakeSafeBrowsingDatabaseManager() { 906 FakeSafeBrowsingDatabaseManager* GetFakeSafeBrowsingDatabaseManager() {
877 return safe_browsing_factory_->most_recent_service()-> 907 return safe_browsing_factory_->most_recent_service()->
878 fake_database_manager(); 908 fake_database_manager();
879 } 909 }
880 #endif 910 #endif
881 911
882 TestPrerenderContents* GetPrerenderContents() const { 912 TestPrerenderContents* GetPrerenderContentsFor(const GURL& url) const {
883 PrerenderManager::PrerenderData* prerender_data = 913 PrerenderManager::PrerenderData* prerender_data =
884 GetPrerenderManager()->FindPrerenderData( 914 GetPrerenderManager()->FindPrerenderData(
885 dest_url_, GetSessionStorageNamespace()); 915 url, GetSessionStorageNamespace());
886 return static_cast<TestPrerenderContents*>( 916 return static_cast<TestPrerenderContents*>(
887 prerender_data ? prerender_data->contents() : NULL); 917 prerender_data ? prerender_data->contents() : NULL);
888 } 918 }
889 919
920 TestPrerenderContents* GetPrerenderContents() const {
921 return GetPrerenderContentsFor(dest_url_);
922 }
923
890 void set_loader_path(const std::string& path) { 924 void set_loader_path(const std::string& path) {
891 loader_path_ = path; 925 loader_path_ = path;
892 } 926 }
893 927
894 void set_loader_query_and_fragment(const std::string& query_and_fragment) { 928 void set_loader_query_and_fragment(const std::string& query_and_fragment) {
895 loader_query_and_fragment_ = query_and_fragment; 929 loader_query_and_fragment_ = query_and_fragment;
896 } 930 }
897 931
898 GURL GetCrossDomainTestUrl(const std::string& path) { 932 GURL GetCrossDomainTestUrl(const std::string& path) {
899 static const std::string secondary_domain = "www.foo.com"; 933 static const std::string secondary_domain = "www.foo.com";
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 false)); 1021 false));
988 1022
989 content::RunMessageLoop(); 1023 content::RunMessageLoop();
990 // Now that we've run the prerender until it stopped loading, we can now 1024 // Now that we've run the prerender until it stopped loading, we can now
991 // also make sure the launcher has finished loading. 1025 // also make sure the launcher has finished loading.
992 loader_nav_observer.Wait(); 1026 loader_nav_observer.Wait();
993 1027
994 TestPrerenderContents* prerender_contents = GetPrerenderContents(); 1028 TestPrerenderContents* prerender_contents = GetPrerenderContents();
995 1029
996 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { 1030 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) {
997 ASSERT_TRUE(prerender_contents != NULL); 1031 ASSERT_NE(static_cast<PrerenderContents*>(NULL), prerender_contents);
998 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); 1032 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status());
999 1033
1000 if (call_javascript_ && expected_number_of_loads > 0) { 1034 if (call_javascript_ && expected_number_of_loads > 0) {
1001 // Wait for the prerendered page to change title to signal it is ready 1035 // Wait for the prerendered page to change title to signal it is ready
1002 // if required. 1036 // if required.
1003 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); 1037 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired();
1004 1038
1005 // Check if page behaves as expected while in prerendered state. 1039 // Check if page behaves as expected while in prerendered state.
1006 bool prerender_test_result = false; 1040 bool prerender_test_result = false;
1007 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 1041 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1008 prerender_contents->GetRenderViewHostMutable(), L"", 1042 prerender_contents->GetRenderViewHostMutable(), L"",
1009 L"window.domAutomationController.send(DidPrerenderPass())", 1043 L"window.domAutomationController.send(DidPrerenderPass())",
1010 &prerender_test_result)); 1044 &prerender_test_result));
1011 EXPECT_TRUE(prerender_test_result); 1045 EXPECT_TRUE(prerender_test_result);
1012 } 1046 }
1013 } else { 1047 } else {
1014 // In the failure case, we should have removed |dest_url_| from the 1048 // In the failure case, we should have removed |dest_url_| from the
1015 // prerender_manager. We ignore dummy PrerenderContents (as indicated 1049 // prerender_manager. We ignore dummy PrerenderContents (as indicated
1016 // by not having started), and PrerenderContents that are expected to 1050 // by not having started), and PrerenderContents that are expected to
1017 // be left in the manager until the test finishes. 1051 // be left in the manager until the test finishes.
1018 EXPECT_TRUE(prerender_contents == NULL || 1052 EXPECT_TRUE(prerender_contents == NULL ||
1019 !prerender_contents->prerendering_has_started()); 1053 !prerender_contents->prerendering_has_started());
1020 } 1054 }
1021 } 1055 }
1022 1056
1023 void NavigateToURLImpl(const GURL& dest_url, 1057 void NavigateToURLImpl(const GURL& dest_url,
1024 WindowOpenDisposition disposition) const { 1058 WindowOpenDisposition disposition) const {
1025 ASSERT_TRUE(GetPrerenderManager() != NULL); 1059 ASSERT_NE(static_cast<PrerenderManager*>(NULL), GetPrerenderManager());
1026 // Make sure in navigating we have a URL to use in the PrerenderManager. 1060 // Make sure in navigating we have a URL to use in the PrerenderManager.
1027 ASSERT_TRUE(GetPrerenderContents() != NULL); 1061 ASSERT_NE(static_cast<PrerenderContents*>(NULL), GetPrerenderContents());
1028 1062
1029 // If opening the page in a background tab, it won't be shown when swapped 1063 // If opening the page in a background tab, it won't be shown when swapped
1030 // in. 1064 // in.
1031 if (disposition == NEW_BACKGROUND_TAB) 1065 if (disposition == NEW_BACKGROUND_TAB)
1032 GetPrerenderContents()->set_should_be_shown(false); 1066 GetPrerenderContents()->set_should_be_shown(false);
1033 1067
1034 scoped_ptr<content::WindowedNotificationObserver> page_load_observer; 1068 scoped_ptr<content::WindowedNotificationObserver> page_load_observer;
1035 WebContents* web_contents = NULL; 1069 WebContents* web_contents = NULL;
1036 1070
1037 if (GetPrerenderContents()->prerender_contents()) { 1071 if (GetPrerenderContents()->prerender_contents()) {
(...skipping 10 matching lines...) Expand all
1048 } 1082 }
1049 1083
1050 // Navigate to the prerendered URL, but don't run the message loop. Browser 1084 // Navigate to the prerendered URL, but don't run the message loop. Browser
1051 // issued navigations to prerendered pages will synchronously swap in the 1085 // issued navigations to prerendered pages will synchronously swap in the
1052 // prerendered page. 1086 // prerendered page.
1053 ui_test_utils::NavigateToURLWithDisposition( 1087 ui_test_utils::NavigateToURLWithDisposition(
1054 current_browser(), dest_url, disposition, 1088 current_browser(), dest_url, disposition,
1055 ui_test_utils::BROWSER_TEST_NONE); 1089 ui_test_utils::BROWSER_TEST_NONE);
1056 1090
1057 // Make sure the PrerenderContents found earlier was used or removed. 1091 // Make sure the PrerenderContents found earlier was used or removed.
1058 EXPECT_TRUE(GetPrerenderContents() == NULL); 1092 EXPECT_EQ(static_cast<PrerenderContents*>(NULL), GetPrerenderContents());
1059 1093
1060 if (call_javascript_ && web_contents) { 1094 if (call_javascript_ && web_contents) {
1061 if (page_load_observer.get()) 1095 if (page_load_observer.get())
1062 page_load_observer->Wait(); 1096 page_load_observer->Wait();
1063 1097
1064 bool display_test_result = false; 1098 bool display_test_result = false;
1065 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 1099 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1066 web_contents->GetRenderViewHost(), L"", 1100 web_contents->GetRenderViewHost(), L"",
1067 L"window.domAutomationController.send(DidDisplayPass())", 1101 L"window.domAutomationController.send(DidDisplayPass())",
1068 &display_test_result)); 1102 &display_test_result));
1069 EXPECT_TRUE(display_test_result); 1103 EXPECT_TRUE(display_test_result);
1070 } 1104 }
1071 } 1105 }
1072 1106
1073 // Opens the prerendered page using javascript functions in the 1107 // Opens the prerendered page using javascript functions in the
1074 // loader page. |javascript_function_name| should be a 0 argument function 1108 // loader page. |javascript_function_name| should be a 0 argument function
1075 // which is invoked. 1109 // which is invoked.
1076 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) 1110 void OpenDestURLWithJSImpl(const std::string& javascript_function_name)
1077 const { 1111 const {
1078 TestPrerenderContents* prerender_contents = GetPrerenderContents(); 1112 TestPrerenderContents* prerender_contents = GetPrerenderContents();
1079 ASSERT_TRUE(prerender_contents != NULL); 1113 ASSERT_NE(static_cast<PrerenderContents*>(NULL), prerender_contents);
1080 1114
1081 RenderViewHost* render_view_host = 1115 RenderViewHost* render_view_host =
1082 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(); 1116 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost();
1083 1117
1084 render_view_host->ExecuteJavascriptInWebFrame( 1118 render_view_host->ExecuteJavascriptInWebFrame(
1085 string16(), ASCIIToUTF16(javascript_function_name)); 1119 string16(), ASCIIToUTF16(javascript_function_name));
1086 1120
1087 if (prerender_contents->quit_message_loop_on_destruction()) { 1121 if (prerender_contents->quit_message_loop_on_destruction()) {
1088 // Run message loop until the prerender contents is destroyed. 1122 // Run message loop until the prerender contents is destroyed.
1089 content::RunMessageLoop(); 1123 content::RunMessageLoop();
1090 } else { 1124 } else {
1091 // We don't expect to pick up a running prerender, so instead 1125 // We don't expect to pick up a running prerender, so instead
1092 // observe one navigation. 1126 // observe one navigation.
1093 content::TestNavigationObserver observer( 1127 content::TestNavigationObserver observer(
1094 content::NotificationService::AllSources(), NULL, 1); 1128 content::NotificationService::AllSources(), NULL, 1);
1095 base::RunLoop run_loop; 1129 base::RunLoop run_loop;
1096 observer.WaitForObservation( 1130 observer.WaitForObservation(
1097 base::Bind(&content::RunThisRunLoop, 1131 base::Bind(&content::RunThisRunLoop,
1098 base::Unretained(&run_loop)), 1132 base::Unretained(&run_loop)),
1099 content::GetQuitTaskForRunLoop(&run_loop)); 1133 content::GetQuitTaskForRunLoop(&run_loop));
(...skipping 20 matching lines...) Expand all
1120 1154
1121 ChannelDestructionWatcher channel_close_watcher; 1155 ChannelDestructionWatcher channel_close_watcher;
1122 channel_close_watcher.WatchChannel( 1156 channel_close_watcher.WatchChannel(
1123 chrome::GetActiveWebContents(browser())->GetRenderProcessHost()); 1157 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
1124 NavigateToDestURL(); 1158 NavigateToDestURL();
1125 channel_close_watcher.WaitForChannelClose(); 1159 channel_close_watcher.WaitForChannelClose();
1126 1160
1127 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 1161 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
1128 } 1162 }
1129 1163
1164 // Checks that pending prerenders launch and receive proper event treatment.
1165 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPagePending) {
1166 std::deque<FinalStatus> expected_final_status_queue;
1167 expected_final_status_queue.push_back(FINAL_STATUS_USED);
1168 expected_final_status_queue.push_back(FINAL_STATUS_USED);
1169 PrerenderTestURL("files/prerender/prerender_page_pending.html",
1170 expected_final_status_queue, 1);
1171
1172 ChannelDestructionWatcher first_channel_close_watcher;
1173
1174 first_channel_close_watcher.WatchChannel(
1175 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
1176 NavigateToDestURL();
1177 // NavigateToDestURL doesn't run a message loop. Normally that's fine, but in
1178 // this case, we need the pending prerenders to start.
1179 content::RunMessageLoop();
1180 first_channel_close_watcher.WaitForChannelClose();
1181
1182 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
1183 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
1184
1185 const GURL prerender_page_url =
1186 test_server()->GetURL("files/prerender/prerender_page.html");
1187 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1188 EXPECT_NE(static_cast<TestPrerenderContents*>(NULL),
1189 GetPrerenderContentsFor(prerender_page_url));
1190
1191 // Now navigate to our target page.
1192 ChannelDestructionWatcher second_channel_close_watcher;
1193 second_channel_close_watcher.WatchChannel(
1194 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
1195 ui_test_utils::NavigateToURLWithDisposition(
1196 current_browser(), prerender_page_url, CURRENT_TAB,
1197 ui_test_utils::BROWSER_TEST_NONE);
1198 second_channel_close_watcher.WaitForChannelClose();
1199
1200 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1201 }
1202
1203 // Checks that pending prerenders which are canceled before they are launched
1204 // never get started.
1205 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageRemovesPending) {
1206 PrerenderTestURL("files/prerender/prerender_page_removes_pending.html",
1207 FINAL_STATUS_USED, 1);
1208
1209 ChannelDestructionWatcher channel_close_watcher;
1210 channel_close_watcher.WatchChannel(
1211 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
1212 NavigateToDestURL();
1213 channel_close_watcher.WaitForChannelClose();
1214
1215 EXPECT_FALSE(DidReceivePrerenderStartEventForLinkNumber(1));
1216 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(1));
1217 // IsEmptyPrerenderLinkManager() is not racy because the earlier DidReceive*
1218 // calls did a thread/process hop to the renderer which insured pending
1219 // renderer events have arrived.
1220 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
1221 }
1222
1130 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageRemovingLink) { 1223 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageRemovingLink) {
1131 set_loader_path("files/prerender/prerender_loader_removing_links.html"); 1224 set_loader_path("files/prerender/prerender_loader_removing_links.html");
1132 set_loader_query_and_fragment("?links_to_insert=1&links_to_remove=1"); 1225 set_loader_query_and_fragment("?links_to_insert=1");
1133 PrerenderTestURL("files/prerender/prerender_page.html", 1226 PrerenderTestURL("files/prerender/prerender_page.html",
1134 FINAL_STATUS_CANCELLED, 1); 1227 FINAL_STATUS_CANCELLED, 1);
1228 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
1229 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
1230
1135 // No ChannelDestructionWatcher is needed here, since prerenders in the 1231 // No ChannelDestructionWatcher is needed here, since prerenders in the
1136 // PrerenderLinkManager should be deleted by removing the links, rather than 1232 // PrerenderLinkManager should be deleted by removing the links, rather than
1137 // shutting down the renderer process. 1233 // shutting down the renderer process.
1138 RemoveLinkElementsAndNavigate(); 1234 RemoveLinkElement(0);
1139 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 1235 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
1236 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
1237 // IsEmptyPrerenderLinkManager() is not racy because the earlier DidReceive*
1238 // calls did a thread/process hop to the renderer which insured pending
1239 // renderer events have arrived.
1240 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1140 } 1241 }
1141 1242
1142 IN_PROC_BROWSER_TEST_F( 1243 IN_PROC_BROWSER_TEST_F(
1143 PrerenderBrowserTest, PrerenderPageRemovingLinkWithTwoLinks) { 1244 PrerenderBrowserTest, PrerenderPageRemovingLinkWithTwoLinks) {
1144 set_loader_path("files/prerender/prerender_loader_removing_links.html"); 1245 set_loader_path("files/prerender/prerender_loader_removing_links.html");
1145 set_loader_query_and_fragment("?links_to_insert=2&links_to_remove=2"); 1246 set_loader_query_and_fragment("?links_to_insert=2");
1146 PrerenderTestURL("files/prerender/prerender_page.html", 1247 PrerenderTestURL("files/prerender/prerender_page.html",
1147 FINAL_STATUS_CANCELLED, 1); 1248 FINAL_STATUS_CANCELLED, 1);
1148 RemoveLinkElementsAndNavigate(); 1249 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
1149 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 1250 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
1251 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(1));
1252 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(1));
1253
1254 RemoveLinkElement(0);
1255 RemoveLinkElement(1);
1256 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
1257 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
1258 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(1));
1259 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(1));
1260 // IsEmptyPrerenderLinkManager() is not racy because the earlier DidReceive*
1261 // calls did a thread/process hop to the renderer which insured pending
1262 // renderer events have arrived.
1263 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1150 } 1264 }
1151 1265
1152 #if defined(OS_WIN) 1266 #if defined(OS_WIN)
1153 // TODO(gavinp): Fails on XP Rel - http://crbug.com/128841 1267 // TODO(gavinp): Fails on XP Rel - http://crbug.com/128841
1154 #define MAYBE_PrerenderPageRemovingLinkWithTwoLinksRemovingOne \ 1268 #define MAYBE_PrerenderPageRemovingLinkWithTwoLinksRemovingOne \
1155 DISABLED_PrerenderPageRemovingLinkWithTwoLinksRemovingOne 1269 DISABLED_PrerenderPageRemovingLinkWithTwoLinksRemovingOne
1156 #else 1270 #else
1157 #define MAYBE_PrerenderPageRemovingLinkWithTwoLinksRemovingOne \ 1271 #define MAYBE_PrerenderPageRemovingLinkWithTwoLinksRemovingOne \
1158 PrerenderPageRemovingLinkWithTwoLinksRemovingOne 1272 PrerenderPageRemovingLinkWithTwoLinksRemovingOne
1159 #endif // defined(OS_WIN) 1273 #endif // defined(OS_WIN)
1160 IN_PROC_BROWSER_TEST_F( 1274 IN_PROC_BROWSER_TEST_F(
1161 PrerenderBrowserTest, 1275 PrerenderBrowserTest,
1162 MAYBE_PrerenderPageRemovingLinkWithTwoLinksRemovingOne) { 1276 MAYBE_PrerenderPageRemovingLinkWithTwoLinksRemovingOne) {
1163 set_loader_path("files/prerender/prerender_loader_removing_links.html"); 1277 set_loader_path("files/prerender/prerender_loader_removing_links.html");
1164 set_loader_query_and_fragment("?links_to_insert=2&links_to_remove=1"); 1278 set_loader_query_and_fragment("?links_to_insert=2");
1165 PrerenderTestURL("files/prerender/prerender_page.html", 1279 PrerenderTestURL("files/prerender/prerender_page.html",
1166 FINAL_STATUS_USED, 1); 1280 FINAL_STATUS_USED, 1);
1167 RemoveLinkElementsAndNavigate(); 1281 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
1168 } 1282 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
1283 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(1));
1284 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(1));
1169 1285
1170 IN_PROC_BROWSER_TEST_F( 1286 RemoveLinkElement(0);
1171 PrerenderBrowserTest, PrerenderPageRemovingLinkWithOneLinkRemovingTwo) { 1287 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
1172 set_loader_path("files/prerender/prerender_loader_removing_links.html"); 1288 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
1173 set_loader_query_and_fragment("?links_to_insert=1&links_to_remove=2"); 1289 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(1));
1174 PrerenderTestURL("files/prerender/prerender_page.html", 1290 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(1));
1175 FINAL_STATUS_CANCELLED, 1); 1291 // IsEmptyPrerenderLinkManager() is not racy because the earlier DidReceive*
1176 RemoveLinkElementsAndNavigate(); 1292 // calls did a thread/process hop to the renderer which insured pending
1293 // renderer events have arrived.
1294 EXPECT_FALSE(IsEmptyPrerenderLinkManager());
1295
1296 ChannelDestructionWatcher channel_close_watcher;
1297 channel_close_watcher.WatchChannel(
1298 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
1299 NavigateToDestURL();
1300 channel_close_watcher.WaitForChannelClose();
1301
1302 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
1177 } 1303 }
1178 1304
1179 // Checks that prerendering works in incognito mode. 1305 // Checks that prerendering works in incognito mode.
1180 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderIncognito) { 1306 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderIncognito) {
1181 Profile* normal_profile = current_browser()->profile(); 1307 Profile* normal_profile = current_browser()->profile();
1182 set_browser( 1308 set_browser(
1183 ui_test_utils::OpenURLOffTheRecord(normal_profile, GURL("about:blank"))); 1309 ui_test_utils::OpenURLOffTheRecord(normal_profile, GURL("about:blank")));
1184 // Increase memory expectations on the incognito PrerenderManager. 1310 // Increase memory expectations on the incognito PrerenderManager.
1185 IncreasePrerenderMemory(); 1311 IncreasePrerenderMemory();
1186 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 1312 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
2265 // used to compare with PrerenderClearHistory test. 2391 // used to compare with PrerenderClearHistory test.
2266 EXPECT_EQ(1, GetHistoryLength()); 2392 EXPECT_EQ(1, GetHistoryLength());
2267 } 2393 }
2268 2394
2269 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) { 2395 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) {
2270 PrerenderTestURL("files/prerender/prerender_page.html", 2396 PrerenderTestURL("files/prerender/prerender_page.html",
2271 FINAL_STATUS_CANCELLED, 2397 FINAL_STATUS_CANCELLED,
2272 1); 2398 1);
2273 // Post a task to cancel all the prerenders. 2399 // Post a task to cancel all the prerenders.
2274 MessageLoop::current()->PostTask( 2400 MessageLoop::current()->PostTask(
2275 FROM_HERE, 2401 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2276 base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2277 content::RunMessageLoop(); 2402 content::RunMessageLoop();
2278 EXPECT_TRUE(GetPrerenderContents() == NULL); 2403 EXPECT_TRUE(GetPrerenderContents() == NULL);
2279 } 2404 }
2280 2405
2406 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEvents) {
2407 PrerenderTestURL("files/prerender/prerender_page.html",
2408 FINAL_STATUS_CANCELLED, 1);
2409 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
2410 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
2411
2412 MessageLoop::current()->PostTask(
2413 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2414 content::RunMessageLoop();
2415
2416 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
2417 EXPECT_TRUE(DidReceivePrerenderStopEventForLinkNumber(0));
2418 }
2419
2281 // Prerendering and history tests. 2420 // Prerendering and history tests.
2282 // The prerendered page is navigated to in several ways [navigate via 2421 // The prerendered page is navigated to in several ways [navigate via
2283 // omnibox, click on link, key-modified click to open in background tab, etc], 2422 // omnibox, click on link, key-modified click to open in background tab, etc],
2284 // followed by a navigation to another page from the prerendered page, followed 2423 // followed by a navigation to another page from the prerendered page, followed
2285 // by a back navigation. 2424 // by a back navigation.
2286 2425
2287 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNavigateClickGoBack) { 2426 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNavigateClickGoBack) {
2288 PrerenderTestURL("files/prerender/prerender_page_with_link.html", 2427 PrerenderTestURL("files/prerender/prerender_page_with_link.html",
2289 FINAL_STATUS_USED, 2428 FINAL_STATUS_USED,
2290 1); 2429 1);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
2507 channel_close_watcher.WatchChannel( 2646 channel_close_watcher.WatchChannel(
2508 chrome::GetActiveWebContents(browser())->GetRenderProcessHost()); 2647 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
2509 NavigateToDestURL(); 2648 NavigateToDestURL();
2510 channel_close_watcher.WaitForChannelClose(); 2649 channel_close_watcher.WaitForChannelClose();
2511 2650
2512 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 2651 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
2513 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 2652 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
2514 } 2653 }
2515 2654
2516 } // namespace prerender 2655 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_link_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698