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

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

Issue 11753009: Simplify ExecuteJavaScript* functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update prerender_browsertest.cc. Created 7 years, 11 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
« no previous file with comments | « chrome/browser/popup_blocker_browsertest.cc ('k') | chrome/browser/ssl/ssl_browser_tests.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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 775
776 // Called after the prerendered page has been navigated to and then away from. 776 // Called after the prerendered page has been navigated to and then away from.
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::ExecuteScriptAndExtractBool(
786 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), 786 chrome::GetActiveWebContents(current_browser()),
787 "",
788 "window.domAutomationController.send(IsOriginalPrerenderPage())", 787 "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::ExecuteScriptAndExtractBool(
807 tab->GetRenderViewHost(), 806 tab,
808 "",
809 "window.domAutomationController.send(DidBackToOriginalPagePass())", 807 "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
(...skipping 30 matching lines...) Expand all
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::string expression = base::StringPrintf(
856 "window.domAutomationController.send(Boolean(" 854 "window.domAutomationController.send(Boolean("
857 "receivedPrerenderStartEvents[%d]))", index); 855 "receivedPrerenderStartEvents[%d]))", index);
858 856
859 CHECK(content::ExecuteJavaScriptAndExtractBool( 857 CHECK(content::ExecuteScriptAndExtractBool(
860 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), 858 chrome::GetActiveWebContents(current_browser()),
861 "",
862 expression, 859 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 DidReceivePrerenderLoadEventForLinkNumber(int index) const { 864 bool DidReceivePrerenderLoadEventForLinkNumber(int index) const {
868 bool received_prerender_loaded; 865 bool received_prerender_loaded;
869 std::string expression = base::StringPrintf( 866 std::string expression = base::StringPrintf(
870 "window.domAutomationController.send(Boolean(" 867 "window.domAutomationController.send(Boolean("
871 "receivedPrerenderLoadEvents[%d]))", index); 868 "receivedPrerenderLoadEvents[%d]))", index);
872 869
873 CHECK(content::ExecuteJavaScriptAndExtractBool( 870 CHECK(content::ExecuteScriptAndExtractBool(
874 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), 871 chrome::GetActiveWebContents(current_browser()),
875 "", expression, 872 expression,
876 &received_prerender_loaded)); 873 &received_prerender_loaded));
877 return received_prerender_loaded; 874 return received_prerender_loaded;
878 } 875 }
879 876
880 bool DidReceivePrerenderStopEventForLinkNumber(int index) const { 877 bool DidReceivePrerenderStopEventForLinkNumber(int index) const {
881 bool received_prerender_stopped; 878 bool received_prerender_stopped;
882 std::string expression = base::StringPrintf( 879 std::string expression = base::StringPrintf(
883 "window.domAutomationController.send(Boolean(" 880 "window.domAutomationController.send(Boolean("
884 "receivedPrerenderStopEvents[%d]))", index); 881 "receivedPrerenderStopEvents[%d]))", index);
885 882
886 CHECK(content::ExecuteJavaScriptAndExtractBool( 883 CHECK(content::ExecuteScriptAndExtractBool(
887 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), 884 chrome::GetActiveWebContents(current_browser()),
888 "",
889 expression, 885 expression,
890 &received_prerender_stopped)); 886 &received_prerender_stopped));
891 return received_prerender_stopped; 887 return received_prerender_stopped;
892 } 888 }
893 889
894 bool HadPrerenderEventErrors() const { 890 bool HadPrerenderEventErrors() const {
895 bool had_prerender_event_errors; 891 bool had_prerender_event_errors;
896 CHECK(content::ExecuteJavaScriptAndExtractBool( 892 CHECK(content::ExecuteScriptAndExtractBool(
897 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), 893 chrome::GetActiveWebContents(current_browser()),
898 "", "window.domAutomationController.send(Boolean(" 894 "window.domAutomationController.send(Boolean("
899 "hadPrerenderEventErrors))", &had_prerender_event_errors)); 895 " hadPrerenderEventErrors))",
896 &had_prerender_event_errors));
900 return had_prerender_event_errors; 897 return had_prerender_event_errors;
901 } 898 }
902 899
903 // Asserting on this can result in flaky tests. PrerenderHandles are 900 // Asserting on this can result in flaky tests. PrerenderHandles are
904 // removed from the PrerenderLinkManager when the prerender is canceled from 901 // removed from the PrerenderLinkManager when the prerender is canceled from
905 // the browser, when the prerenders are cancelled from the renderer process, 902 // the browser, when the prerenders are cancelled from the renderer process,
906 // or the channel for the renderer process is closed on the IO thread. In the 903 // or the channel for the renderer process is closed on the IO thread. In the
907 // last case, the code must be careful to wait for the channel to close, as it 904 // last case, the code must be careful to wait for the channel to close, as it
908 // is done asynchronously after swapping out the old process. See 905 // is done asynchronously after swapping out the old process. See
909 // ChannelDestructionWatcher. 906 // ChannelDestructionWatcher.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 ASSERT_NE(static_cast<PrerenderContents*>(NULL), prerender_contents); 1049 ASSERT_NE(static_cast<PrerenderContents*>(NULL), prerender_contents);
1053 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); 1050 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status());
1054 1051
1055 if (call_javascript_ && expected_number_of_loads > 0) { 1052 if (call_javascript_ && expected_number_of_loads > 0) {
1056 // Wait for the prerendered page to change title to signal it is ready 1053 // Wait for the prerendered page to change title to signal it is ready
1057 // if required. 1054 // if required.
1058 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); 1055 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired();
1059 1056
1060 // Check if page behaves as expected while in prerendered state. 1057 // Check if page behaves as expected while in prerendered state.
1061 bool prerender_test_result = false; 1058 bool prerender_test_result = false;
1062 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 1059 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1063 prerender_contents->GetRenderViewHostMutable(), 1060 prerender_contents->GetRenderViewHostMutable(),
1064 "",
1065 "window.domAutomationController.send(DidPrerenderPass())", 1061 "window.domAutomationController.send(DidPrerenderPass())",
1066 &prerender_test_result)); 1062 &prerender_test_result));
1067 EXPECT_TRUE(prerender_test_result); 1063 EXPECT_TRUE(prerender_test_result);
1068 } 1064 }
1069 } else { 1065 } else {
1070 // In the failure case, we should have removed |dest_url_| from the 1066 // In the failure case, we should have removed |dest_url_| from the
1071 // prerender_manager. We ignore dummy PrerenderContents (as indicated 1067 // prerender_manager. We ignore dummy PrerenderContents (as indicated
1072 // by not having started), and PrerenderContents that are expected to 1068 // by not having started), and PrerenderContents that are expected to
1073 // be left in the manager until the test finishes. 1069 // be left in the manager until the test finishes.
1074 EXPECT_TRUE(prerender_contents == NULL || 1070 EXPECT_TRUE(prerender_contents == NULL ||
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 ui_test_utils::BROWSER_TEST_NONE); 1107 ui_test_utils::BROWSER_TEST_NONE);
1112 1108
1113 // Make sure the PrerenderContents found earlier was used or removed. 1109 // Make sure the PrerenderContents found earlier was used or removed.
1114 EXPECT_EQ(static_cast<PrerenderContents*>(NULL), GetPrerenderContents()); 1110 EXPECT_EQ(static_cast<PrerenderContents*>(NULL), GetPrerenderContents());
1115 1111
1116 if (call_javascript_ && web_contents) { 1112 if (call_javascript_ && web_contents) {
1117 if (page_load_observer.get()) 1113 if (page_load_observer.get())
1118 page_load_observer->Wait(); 1114 page_load_observer->Wait();
1119 1115
1120 bool display_test_result = false; 1116 bool display_test_result = false;
1121 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 1117 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1122 web_contents->GetRenderViewHost(), 1118 web_contents,
1123 "",
1124 "window.domAutomationController.send(DidDisplayPass())", 1119 "window.domAutomationController.send(DidDisplayPass())",
1125 &display_test_result)); 1120 &display_test_result));
1126 EXPECT_TRUE(display_test_result); 1121 EXPECT_TRUE(display_test_result);
1127 } 1122 }
1128 } 1123 }
1129 1124
1130 // Opens the prerendered page using javascript functions in the 1125 // Opens the prerendered page using javascript functions in the
1131 // loader page. |javascript_function_name| should be a 0 argument function 1126 // loader page. |javascript_function_name| should be a 0 argument function
1132 // which is invoked. 1127 // which is invoked.
1133 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) 1128 void OpenDestURLWithJSImpl(const std::string& javascript_function_name)
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 1420
1426 // Run this check again. When we try to load aa ppapi plugin, the 1421 // Run this check again. When we try to load aa ppapi plugin, the
1427 // "loadstart" event is asynchronously posted to a message loop. 1422 // "loadstart" event is asynchronously posted to a message loop.
1428 // It's possible that earlier call could have been run before the 1423 // It's possible that earlier call could have been run before the
1429 // the "loadstart" event was posted. 1424 // the "loadstart" event was posted.
1430 // TODO(mmenke): While this should reliably fail on regressions, the 1425 // TODO(mmenke): While this should reliably fail on regressions, the
1431 // reliability depends on the specifics of ppapi plugin 1426 // reliability depends on the specifics of ppapi plugin
1432 // loading. It would be great if we could avoid that. 1427 // loading. It would be great if we could avoid that.
1433 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 1428 WebContents* web_contents = chrome::GetActiveWebContents(browser());
1434 bool display_test_result = false; 1429 bool display_test_result = false;
1435 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 1430 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1436 web_contents->GetRenderViewHost(), 1431 web_contents,
1437 "",
1438 "window.domAutomationController.send(DidDisplayPass())", 1432 "window.domAutomationController.send(DidDisplayPass())",
1439 &display_test_result)); 1433 &display_test_result));
1440 EXPECT_TRUE(display_test_result); 1434 EXPECT_TRUE(display_test_result);
1441 } 1435 }
1442 1436
1443 // Checks that plugins in an iframe are not loaded while a page is 1437 // Checks that plugins in an iframe are not loaded while a page is
1444 // being preloaded, but are loaded when the page is displayed. 1438 // being preloaded, but are loaded when the page is displayed.
1445 #if defined(USE_AURA) 1439 #if defined(USE_AURA)
1446 // http://crbug.com/103496 1440 // http://crbug.com/103496
1447 #define MAYBE_PrerenderIframeDelayLoadPlugin \ 1441 #define MAYBE_PrerenderIframeDelayLoadPlugin \
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2608 PrerenderNaClPluginEnabled) { 2602 PrerenderNaClPluginEnabled) {
2609 PrerenderTestURL("files/prerender/prerender_plugin_nacl_enabled.html", 2603 PrerenderTestURL("files/prerender/prerender_plugin_nacl_enabled.html",
2610 FINAL_STATUS_USED, 2604 FINAL_STATUS_USED,
2611 1); 2605 1);
2612 NavigateToDestURL(); 2606 NavigateToDestURL();
2613 2607
2614 // To avoid any chance of a race, we have to let the script send its response 2608 // To avoid any chance of a race, we have to let the script send its response
2615 // asynchronously. 2609 // asynchronously.
2616 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 2610 WebContents* web_contents = chrome::GetActiveWebContents(browser());
2617 bool display_test_result = false; 2611 bool display_test_result = false;
2618 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 2612 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents,
2619 web_contents->GetRenderViewHost(), 2613 "DidDisplayReallyPass()",
2620 "", 2614 &display_test_result));
2621 "DidDisplayReallyPass()",
2622 &display_test_result));
2623 ASSERT_TRUE(display_test_result); 2615 ASSERT_TRUE(display_test_result);
2624 } 2616 }
2625 2617
2626 // Checks that the referrer policy is used when prerendering. 2618 // Checks that the referrer policy is used when prerendering.
2627 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrerPolicy) { 2619 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrerPolicy) {
2628 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html"); 2620 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html");
2629 PrerenderTestURL("files/prerender/prerender_referrer_policy.html", 2621 PrerenderTestURL("files/prerender/prerender_referrer_policy.html",
2630 FINAL_STATUS_USED, 2622 FINAL_STATUS_USED,
2631 1); 2623 1);
2632 NavigateToDestURL(); 2624 NavigateToDestURL();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2691 channel_close_watcher.WatchChannel( 2683 channel_close_watcher.WatchChannel(
2692 chrome::GetActiveWebContents(browser())->GetRenderProcessHost()); 2684 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
2693 NavigateToDestURL(); 2685 NavigateToDestURL();
2694 channel_close_watcher.WaitForChannelClose(); 2686 channel_close_watcher.WaitForChannelClose();
2695 2687
2696 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 2688 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
2697 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 2689 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
2698 } 2690 }
2699 2691
2700 } // namespace prerender 2692 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/popup_blocker_browsertest.cc ('k') | chrome/browser/ssl/ssl_browser_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698