| OLD | NEW |
| 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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 | 699 |
| 700 // Called after the prerendered page has been navigated to and then away from. | 700 // Called after the prerendered page has been navigated to and then away from. |
| 701 // Navigates back through the history to the prerendered page. | 701 // Navigates back through the history to the prerendered page. |
| 702 void GoBackToPrerender() { | 702 void GoBackToPrerender() { |
| 703 content::WindowedNotificationObserver back_nav_observer( | 703 content::WindowedNotificationObserver back_nav_observer( |
| 704 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 704 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 705 content::NotificationService::AllSources()); | 705 content::NotificationService::AllSources()); |
| 706 chrome::GoBack(current_browser(), CURRENT_TAB); | 706 chrome::GoBack(current_browser(), CURRENT_TAB); |
| 707 back_nav_observer.Wait(); | 707 back_nav_observer.Wait(); |
| 708 bool original_prerender_page = false; | 708 bool original_prerender_page = false; |
| 709 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 709 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 710 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), | 710 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), |
| 711 L"", L"window.domAutomationController.send(IsOriginalPrerenderPage())", | 711 L"", L"window.domAutomationController.send(IsOriginalPrerenderPage())", |
| 712 &original_prerender_page)); | 712 &original_prerender_page)); |
| 713 EXPECT_TRUE(original_prerender_page); | 713 EXPECT_TRUE(original_prerender_page); |
| 714 } | 714 } |
| 715 | 715 |
| 716 // Goes back to the page that was active before the prerender was swapped | 716 // Goes back to the page that was active before the prerender was swapped |
| 717 // in. This must be called when the prerendered page is the current page | 717 // in. This must be called when the prerendered page is the current page |
| 718 // in the active tab. | 718 // in the active tab. |
| 719 void GoBackToPageBeforePrerender() { | 719 void GoBackToPageBeforePrerender() { |
| 720 WebContents* tab = chrome::GetActiveWebContents(current_browser()); | 720 WebContents* tab = chrome::GetActiveWebContents(current_browser()); |
| 721 ASSERT_TRUE(tab); | 721 ASSERT_TRUE(tab); |
| 722 EXPECT_FALSE(tab->IsLoading()); | 722 EXPECT_FALSE(tab->IsLoading()); |
| 723 content::WindowedNotificationObserver back_nav_observer( | 723 content::WindowedNotificationObserver back_nav_observer( |
| 724 content::NOTIFICATION_LOAD_STOP, | 724 content::NOTIFICATION_LOAD_STOP, |
| 725 content::Source<NavigationController>(&tab->GetController())); | 725 content::Source<NavigationController>(&tab->GetController())); |
| 726 chrome::GoBack(current_browser(), CURRENT_TAB); | 726 chrome::GoBack(current_browser(), CURRENT_TAB); |
| 727 back_nav_observer.Wait(); | 727 back_nav_observer.Wait(); |
| 728 bool js_result; | 728 bool js_result; |
| 729 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 729 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 730 tab->GetRenderViewHost(), L"", | 730 tab->GetRenderViewHost(), L"", |
| 731 L"window.domAutomationController.send(DidBackToOriginalPagePass())", | 731 L"window.domAutomationController.send(DidBackToOriginalPagePass())", |
| 732 &js_result)); | 732 &js_result)); |
| 733 EXPECT_TRUE(js_result); | 733 EXPECT_TRUE(js_result); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void NavigateToURL(const std::string& dest_html_file) const { | 736 void NavigateToURL(const std::string& dest_html_file) const { |
| 737 GURL dest_url = test_server()->GetURL(dest_html_file); | 737 GURL dest_url = test_server()->GetURL(dest_html_file); |
| 738 NavigateToURLImpl(dest_url, CURRENT_TAB); | 738 NavigateToURLImpl(dest_url, CURRENT_TAB); |
| 739 } | 739 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 ASSERT_TRUE(prerender_contents != NULL); | 921 ASSERT_TRUE(prerender_contents != NULL); |
| 922 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); | 922 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); |
| 923 | 923 |
| 924 if (call_javascript_ && expected_number_of_loads > 0) { | 924 if (call_javascript_ && expected_number_of_loads > 0) { |
| 925 // Wait for the prerendered page to change title to signal it is ready | 925 // Wait for the prerendered page to change title to signal it is ready |
| 926 // if required. | 926 // if required. |
| 927 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); | 927 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); |
| 928 | 928 |
| 929 // Check if page behaves as expected while in prerendered state. | 929 // Check if page behaves as expected while in prerendered state. |
| 930 bool prerender_test_result = false; | 930 bool prerender_test_result = false; |
| 931 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 931 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 932 prerender_contents->GetRenderViewHostMutable(), L"", | 932 prerender_contents->GetRenderViewHostMutable(), L"", |
| 933 L"window.domAutomationController.send(DidPrerenderPass())", | 933 L"window.domAutomationController.send(DidPrerenderPass())", |
| 934 &prerender_test_result)); | 934 &prerender_test_result)); |
| 935 EXPECT_TRUE(prerender_test_result); | 935 EXPECT_TRUE(prerender_test_result); |
| 936 } | 936 } |
| 937 } else { | 937 } else { |
| 938 // In the failure case, we should have removed |dest_url_| from the | 938 // In the failure case, we should have removed |dest_url_| from the |
| 939 // prerender_manager. We ignore dummy PrerenderContents (as indicated | 939 // prerender_manager. We ignore dummy PrerenderContents (as indicated |
| 940 // by not having started), and PrerenderContents that are expected to | 940 // by not having started), and PrerenderContents that are expected to |
| 941 // be left in the manager until the test finishes. | 941 // be left in the manager until the test finishes. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 ui_test_utils::BROWSER_TEST_NONE); | 980 ui_test_utils::BROWSER_TEST_NONE); |
| 981 | 981 |
| 982 // Make sure the PrerenderContents found earlier was used or removed. | 982 // Make sure the PrerenderContents found earlier was used or removed. |
| 983 EXPECT_TRUE(GetPrerenderContents() == NULL); | 983 EXPECT_TRUE(GetPrerenderContents() == NULL); |
| 984 | 984 |
| 985 if (call_javascript_ && web_contents) { | 985 if (call_javascript_ && web_contents) { |
| 986 if (page_load_observer.get()) | 986 if (page_load_observer.get()) |
| 987 page_load_observer->Wait(); | 987 page_load_observer->Wait(); |
| 988 | 988 |
| 989 bool display_test_result = false; | 989 bool display_test_result = false; |
| 990 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 990 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 991 web_contents->GetRenderViewHost(), L"", | 991 web_contents->GetRenderViewHost(), L"", |
| 992 L"window.domAutomationController.send(DidDisplayPass())", | 992 L"window.domAutomationController.send(DidDisplayPass())", |
| 993 &display_test_result)); | 993 &display_test_result)); |
| 994 EXPECT_TRUE(display_test_result); | 994 EXPECT_TRUE(display_test_result); |
| 995 } | 995 } |
| 996 } | 996 } |
| 997 | 997 |
| 998 // Opens the prerendered page using javascript functions in the | 998 // Opens the prerendered page using javascript functions in the |
| 999 // loader page. |javascript_function_name| should be a 0 argument function | 999 // loader page. |javascript_function_name| should be a 0 argument function |
| 1000 // which is invoked. | 1000 // which is invoked. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 | 1175 |
| 1176 // Run this check again. When we try to load aa ppapi plugin, the | 1176 // Run this check again. When we try to load aa ppapi plugin, the |
| 1177 // "loadstart" event is asynchronously posted to a message loop. | 1177 // "loadstart" event is asynchronously posted to a message loop. |
| 1178 // It's possible that earlier call could have been run before the | 1178 // It's possible that earlier call could have been run before the |
| 1179 // the "loadstart" event was posted. | 1179 // the "loadstart" event was posted. |
| 1180 // TODO(mmenke): While this should reliably fail on regressions, the | 1180 // TODO(mmenke): While this should reliably fail on regressions, the |
| 1181 // reliability depends on the specifics of ppapi plugin | 1181 // reliability depends on the specifics of ppapi plugin |
| 1182 // loading. It would be great if we could avoid that. | 1182 // loading. It would be great if we could avoid that. |
| 1183 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1183 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 1184 bool display_test_result = false; | 1184 bool display_test_result = false; |
| 1185 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1185 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 1186 web_contents->GetRenderViewHost(), L"", | 1186 web_contents->GetRenderViewHost(), L"", |
| 1187 L"window.domAutomationController.send(DidDisplayPass())", | 1187 L"window.domAutomationController.send(DidDisplayPass())", |
| 1188 &display_test_result)); | 1188 &display_test_result)); |
| 1189 EXPECT_TRUE(display_test_result); | 1189 EXPECT_TRUE(display_test_result); |
| 1190 } | 1190 } |
| 1191 | 1191 |
| 1192 // Checks that plugins in an iframe are not loaded while a page is | 1192 // Checks that plugins in an iframe are not loaded while a page is |
| 1193 // being preloaded, but are loaded when the page is displayed. | 1193 // being preloaded, but are loaded when the page is displayed. |
| 1194 #if defined(USE_AURA) | 1194 #if defined(USE_AURA) |
| 1195 // http://crbug.com/103496 | 1195 // http://crbug.com/103496 |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 PrerenderNaClPluginEnabled) { | 2306 PrerenderNaClPluginEnabled) { |
| 2307 PrerenderTestURL("files/prerender/prerender_plugin_nacl_enabled.html", | 2307 PrerenderTestURL("files/prerender/prerender_plugin_nacl_enabled.html", |
| 2308 FINAL_STATUS_USED, | 2308 FINAL_STATUS_USED, |
| 2309 1); | 2309 1); |
| 2310 NavigateToDestURL(); | 2310 NavigateToDestURL(); |
| 2311 | 2311 |
| 2312 // To avoid any chance of a race, we have to let the script send its response | 2312 // To avoid any chance of a race, we have to let the script send its response |
| 2313 // asynchronously. | 2313 // asynchronously. |
| 2314 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 2314 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 2315 bool display_test_result = false; | 2315 bool display_test_result = false; |
| 2316 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 2316 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 2317 web_contents->GetRenderViewHost(), L"", | 2317 web_contents->GetRenderViewHost(), L"", |
| 2318 L"DidDisplayReallyPass()", | 2318 L"DidDisplayReallyPass()", |
| 2319 &display_test_result)); | 2319 &display_test_result)); |
| 2320 ASSERT_TRUE(display_test_result); | 2320 ASSERT_TRUE(display_test_result); |
| 2321 } | 2321 } |
| 2322 | 2322 |
| 2323 // Checks that the referrer policy is used when prerendering. | 2323 // Checks that the referrer policy is used when prerendering. |
| 2324 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrerPolicy) { | 2324 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrerPolicy) { |
| 2325 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html"); | 2325 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html"); |
| 2326 PrerenderTestURL("files/prerender/prerender_referrer_policy.html", | 2326 PrerenderTestURL("files/prerender/prerender_referrer_policy.html", |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2383 ResultCatcher catcher; | 2383 ResultCatcher catcher; |
| 2384 | 2384 |
| 2385 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 2385 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 2386 NavigateToDestURL(); | 2386 NavigateToDestURL(); |
| 2387 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); | 2387 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); |
| 2388 | 2388 |
| 2389 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 2389 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 2390 } | 2390 } |
| 2391 | 2391 |
| 2392 } // namespace prerender | 2392 } // namespace prerender |
| OLD | NEW |