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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 // Navigates back through the history to the prerendered page. | 777 // Navigates back through the history to the prerendered page. |
778 void GoBackToPrerender() { | 778 void GoBackToPrerender() { |
779 content::WindowedNotificationObserver back_nav_observer( | 779 content::WindowedNotificationObserver back_nav_observer( |
780 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 780 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
781 content::NotificationService::AllSources()); | 781 content::NotificationService::AllSources()); |
782 chrome::GoBack(current_browser(), CURRENT_TAB); | 782 chrome::GoBack(current_browser(), CURRENT_TAB); |
783 back_nav_observer.Wait(); | 783 back_nav_observer.Wait(); |
784 bool original_prerender_page = false; | 784 bool original_prerender_page = false; |
785 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 785 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
786 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), | 786 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), |
787 L"", L"window.domAutomationController.send(IsOriginalPrerenderPage())", | 787 "", |
| 788 "window.domAutomationController.send(IsOriginalPrerenderPage())", |
788 &original_prerender_page)); | 789 &original_prerender_page)); |
789 EXPECT_TRUE(original_prerender_page); | 790 EXPECT_TRUE(original_prerender_page); |
790 } | 791 } |
791 | 792 |
792 // Goes back to the page that was active before the prerender was swapped | 793 // Goes back to the page that was active before the prerender was swapped |
793 // in. This must be called when the prerendered page is the current page | 794 // in. This must be called when the prerendered page is the current page |
794 // in the active tab. | 795 // in the active tab. |
795 void GoBackToPageBeforePrerender() { | 796 void GoBackToPageBeforePrerender() { |
796 WebContents* tab = chrome::GetActiveWebContents(current_browser()); | 797 WebContents* tab = chrome::GetActiveWebContents(current_browser()); |
797 ASSERT_TRUE(tab); | 798 ASSERT_TRUE(tab); |
798 EXPECT_FALSE(tab->IsLoading()); | 799 EXPECT_FALSE(tab->IsLoading()); |
799 content::WindowedNotificationObserver back_nav_observer( | 800 content::WindowedNotificationObserver back_nav_observer( |
800 content::NOTIFICATION_LOAD_STOP, | 801 content::NOTIFICATION_LOAD_STOP, |
801 content::Source<NavigationController>(&tab->GetController())); | 802 content::Source<NavigationController>(&tab->GetController())); |
802 chrome::GoBack(current_browser(), CURRENT_TAB); | 803 chrome::GoBack(current_browser(), CURRENT_TAB); |
803 back_nav_observer.Wait(); | 804 back_nav_observer.Wait(); |
804 bool js_result; | 805 bool js_result; |
805 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 806 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
806 tab->GetRenderViewHost(), L"", | 807 tab->GetRenderViewHost(), |
807 L"window.domAutomationController.send(DidBackToOriginalPagePass())", | 808 "", |
| 809 "window.domAutomationController.send(DidBackToOriginalPagePass())", |
808 &js_result)); | 810 &js_result)); |
809 EXPECT_TRUE(js_result); | 811 EXPECT_TRUE(js_result); |
810 } | 812 } |
811 | 813 |
812 void NavigateToURL(const std::string& dest_html_file) const { | 814 void NavigateToURL(const std::string& dest_html_file) const { |
813 GURL dest_url = test_server()->GetURL(dest_html_file); | 815 GURL dest_url = test_server()->GetURL(dest_html_file); |
814 NavigateToURLImpl(dest_url, CURRENT_TAB); | 816 NavigateToURLImpl(dest_url, CURRENT_TAB); |
815 } | 817 } |
816 | 818 |
817 bool UrlIsInPrerenderManager(const std::string& html_file) const { | 819 bool UrlIsInPrerenderManager(const std::string& html_file) const { |
(...skipping 25 matching lines...) Expand all Loading... |
843 | 845 |
844 const PrerenderLinkManager* GetPrerenderLinkManager() const { | 846 const PrerenderLinkManager* GetPrerenderLinkManager() const { |
845 PrerenderLinkManager* prerender_link_manager = | 847 PrerenderLinkManager* prerender_link_manager = |
846 PrerenderLinkManagerFactory::GetForProfile( | 848 PrerenderLinkManagerFactory::GetForProfile( |
847 current_browser()->profile()); | 849 current_browser()->profile()); |
848 return prerender_link_manager; | 850 return prerender_link_manager; |
849 } | 851 } |
850 | 852 |
851 bool DidReceivePrerenderStartEventForLinkNumber(int index) const { | 853 bool DidReceivePrerenderStartEventForLinkNumber(int index) const { |
852 bool received_prerender_started; | 854 bool received_prerender_started; |
853 std::wstring expression = base::StringPrintf( | 855 std::string expression = base::StringPrintf( |
854 L"window.domAutomationController.send(Boolean(" | 856 "window.domAutomationController.send(Boolean(" |
855 L"receivedPrerenderStartEvents[%d]))", index); | 857 "receivedPrerenderStartEvents[%d]))", index); |
856 | 858 |
857 CHECK(content::ExecuteJavaScriptAndExtractBool( | 859 CHECK(content::ExecuteJavaScriptAndExtractBool( |
858 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), | 860 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), |
859 L"", expression, | 861 "", |
| 862 expression, |
860 &received_prerender_started)); | 863 &received_prerender_started)); |
861 return received_prerender_started; | 864 return received_prerender_started; |
862 } | 865 } |
863 | 866 |
864 bool DidReceivePrerenderStopEventForLinkNumber(int index) const { | 867 bool DidReceivePrerenderStopEventForLinkNumber(int index) const { |
865 bool received_prerender_stopped; | 868 bool received_prerender_stopped; |
866 std::wstring expression = base::StringPrintf( | 869 std::string expression = base::StringPrintf( |
867 L"window.domAutomationController.send(Boolean(" | 870 "window.domAutomationController.send(Boolean(" |
868 L"receivedPrerenderStopEvents[%d]))", index); | 871 "receivedPrerenderStopEvents[%d]))", index); |
869 | 872 |
870 CHECK(content::ExecuteJavaScriptAndExtractBool( | 873 CHECK(content::ExecuteJavaScriptAndExtractBool( |
871 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), | 874 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), |
872 L"", expression, | 875 "", |
| 876 expression, |
873 &received_prerender_stopped)); | 877 &received_prerender_stopped)); |
874 return received_prerender_stopped; | 878 return received_prerender_stopped; |
875 } | 879 } |
876 | 880 |
877 // Asserting on this can result in flaky tests. PrerenderHandles are | 881 // Asserting on this can result in flaky tests. PrerenderHandles are |
878 // removed from the PrerenderLinkManager when the prerender is canceled from | 882 // removed from the PrerenderLinkManager when the prerender is canceled from |
879 // the browser, when the prerenders are cancelled from the renderer process, | 883 // the browser, when the prerenders are cancelled from the renderer process, |
880 // or the channel for the renderer process is closed on the IO thread. In the | 884 // or the channel for the renderer process is closed on the IO thread. In the |
881 // last case, the code must be careful to wait for the channel to close, as it | 885 // last case, the code must be careful to wait for the channel to close, as it |
882 // is done asynchronously after swapping out the old process. See | 886 // is done asynchronously after swapping out the old process. See |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); | 1031 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); |
1028 | 1032 |
1029 if (call_javascript_ && expected_number_of_loads > 0) { | 1033 if (call_javascript_ && expected_number_of_loads > 0) { |
1030 // Wait for the prerendered page to change title to signal it is ready | 1034 // Wait for the prerendered page to change title to signal it is ready |
1031 // if required. | 1035 // if required. |
1032 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); | 1036 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); |
1033 | 1037 |
1034 // Check if page behaves as expected while in prerendered state. | 1038 // Check if page behaves as expected while in prerendered state. |
1035 bool prerender_test_result = false; | 1039 bool prerender_test_result = false; |
1036 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 1040 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
1037 prerender_contents->GetRenderViewHostMutable(), L"", | 1041 prerender_contents->GetRenderViewHostMutable(), |
1038 L"window.domAutomationController.send(DidPrerenderPass())", | 1042 "", |
| 1043 "window.domAutomationController.send(DidPrerenderPass())", |
1039 &prerender_test_result)); | 1044 &prerender_test_result)); |
1040 EXPECT_TRUE(prerender_test_result); | 1045 EXPECT_TRUE(prerender_test_result); |
1041 } | 1046 } |
1042 } else { | 1047 } else { |
1043 // 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 |
1044 // prerender_manager. We ignore dummy PrerenderContents (as indicated | 1049 // prerender_manager. We ignore dummy PrerenderContents (as indicated |
1045 // by not having started), and PrerenderContents that are expected to | 1050 // by not having started), and PrerenderContents that are expected to |
1046 // be left in the manager until the test finishes. | 1051 // be left in the manager until the test finishes. |
1047 EXPECT_TRUE(prerender_contents == NULL || | 1052 EXPECT_TRUE(prerender_contents == NULL || |
1048 !prerender_contents->prerendering_has_started()); | 1053 !prerender_contents->prerendering_has_started()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 | 1090 |
1086 // Make sure the PrerenderContents found earlier was used or removed. | 1091 // Make sure the PrerenderContents found earlier was used or removed. |
1087 EXPECT_EQ(static_cast<PrerenderContents*>(NULL), GetPrerenderContents()); | 1092 EXPECT_EQ(static_cast<PrerenderContents*>(NULL), GetPrerenderContents()); |
1088 | 1093 |
1089 if (call_javascript_ && web_contents) { | 1094 if (call_javascript_ && web_contents) { |
1090 if (page_load_observer.get()) | 1095 if (page_load_observer.get()) |
1091 page_load_observer->Wait(); | 1096 page_load_observer->Wait(); |
1092 | 1097 |
1093 bool display_test_result = false; | 1098 bool display_test_result = false; |
1094 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 1099 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
1095 web_contents->GetRenderViewHost(), L"", | 1100 web_contents->GetRenderViewHost(), |
1096 L"window.domAutomationController.send(DidDisplayPass())", | 1101 "", |
| 1102 "window.domAutomationController.send(DidDisplayPass())", |
1097 &display_test_result)); | 1103 &display_test_result)); |
1098 EXPECT_TRUE(display_test_result); | 1104 EXPECT_TRUE(display_test_result); |
1099 } | 1105 } |
1100 } | 1106 } |
1101 | 1107 |
1102 // Opens the prerendered page using javascript functions in the | 1108 // Opens the prerendered page using javascript functions in the |
1103 // loader page. |javascript_function_name| should be a 0 argument function | 1109 // loader page. |javascript_function_name| should be a 0 argument function |
1104 // which is invoked. | 1110 // which is invoked. |
1105 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) | 1111 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) |
1106 const { | 1112 const { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 // Run this check again. When we try to load aa ppapi plugin, the | 1399 // Run this check again. When we try to load aa ppapi plugin, the |
1394 // "loadstart" event is asynchronously posted to a message loop. | 1400 // "loadstart" event is asynchronously posted to a message loop. |
1395 // It's possible that earlier call could have been run before the | 1401 // It's possible that earlier call could have been run before the |
1396 // the "loadstart" event was posted. | 1402 // the "loadstart" event was posted. |
1397 // TODO(mmenke): While this should reliably fail on regressions, the | 1403 // TODO(mmenke): While this should reliably fail on regressions, the |
1398 // reliability depends on the specifics of ppapi plugin | 1404 // reliability depends on the specifics of ppapi plugin |
1399 // loading. It would be great if we could avoid that. | 1405 // loading. It would be great if we could avoid that. |
1400 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1406 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
1401 bool display_test_result = false; | 1407 bool display_test_result = false; |
1402 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 1408 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
1403 web_contents->GetRenderViewHost(), L"", | 1409 web_contents->GetRenderViewHost(), |
1404 L"window.domAutomationController.send(DidDisplayPass())", | 1410 "", |
| 1411 "window.domAutomationController.send(DidDisplayPass())", |
1405 &display_test_result)); | 1412 &display_test_result)); |
1406 EXPECT_TRUE(display_test_result); | 1413 EXPECT_TRUE(display_test_result); |
1407 } | 1414 } |
1408 | 1415 |
1409 // Checks that plugins in an iframe are not loaded while a page is | 1416 // Checks that plugins in an iframe are not loaded while a page is |
1410 // being preloaded, but are loaded when the page is displayed. | 1417 // being preloaded, but are loaded when the page is displayed. |
1411 #if defined(USE_AURA) | 1418 #if defined(USE_AURA) |
1412 // http://crbug.com/103496 | 1419 // http://crbug.com/103496 |
1413 #define MAYBE_PrerenderIframeDelayLoadPlugin \ | 1420 #define MAYBE_PrerenderIframeDelayLoadPlugin \ |
1414 DISABLED_PrerenderIframeDelayLoadPlugin | 1421 DISABLED_PrerenderIframeDelayLoadPlugin |
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 PrerenderTestURL("files/prerender/prerender_plugin_nacl_enabled.html", | 2567 PrerenderTestURL("files/prerender/prerender_plugin_nacl_enabled.html", |
2561 FINAL_STATUS_USED, | 2568 FINAL_STATUS_USED, |
2562 1); | 2569 1); |
2563 NavigateToDestURL(); | 2570 NavigateToDestURL(); |
2564 | 2571 |
2565 // To avoid any chance of a race, we have to let the script send its response | 2572 // To avoid any chance of a race, we have to let the script send its response |
2566 // asynchronously. | 2573 // asynchronously. |
2567 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 2574 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
2568 bool display_test_result = false; | 2575 bool display_test_result = false; |
2569 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 2576 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
2570 web_contents->GetRenderViewHost(), L"", | 2577 web_contents->GetRenderViewHost(), |
2571 L"DidDisplayReallyPass()", | 2578 "", |
| 2579 "DidDisplayReallyPass()", |
2572 &display_test_result)); | 2580 &display_test_result)); |
2573 ASSERT_TRUE(display_test_result); | 2581 ASSERT_TRUE(display_test_result); |
2574 } | 2582 } |
2575 | 2583 |
2576 // Checks that the referrer policy is used when prerendering. | 2584 // Checks that the referrer policy is used when prerendering. |
2577 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrerPolicy) { | 2585 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrerPolicy) { |
2578 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html"); | 2586 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html"); |
2579 PrerenderTestURL("files/prerender/prerender_referrer_policy.html", | 2587 PrerenderTestURL("files/prerender/prerender_referrer_policy.html", |
2580 FINAL_STATUS_USED, | 2588 FINAL_STATUS_USED, |
2581 1); | 2589 1); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2641 channel_close_watcher.WatchChannel( | 2649 channel_close_watcher.WatchChannel( |
2642 chrome::GetActiveWebContents(browser())->GetRenderProcessHost()); | 2650 chrome::GetActiveWebContents(browser())->GetRenderProcessHost()); |
2643 NavigateToDestURL(); | 2651 NavigateToDestURL(); |
2644 channel_close_watcher.WaitForChannelClose(); | 2652 channel_close_watcher.WaitForChannelClose(); |
2645 | 2653 |
2646 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); | 2654 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); |
2647 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 2655 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
2648 } | 2656 } |
2649 | 2657 |
2650 } // namespace prerender | 2658 } // namespace prerender |
OLD | NEW |