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