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 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 int expected_number_of_loads) { | 694 int expected_number_of_loads) { |
695 std::deque<FinalStatus> expected_final_status_queue(1, | 695 std::deque<FinalStatus> expected_final_status_queue(1, |
696 expected_final_status); | 696 expected_final_status); |
697 PrerenderTestURLImpl(prerender_url, destination_url, | 697 PrerenderTestURLImpl(prerender_url, destination_url, |
698 expected_final_status_queue, | 698 expected_final_status_queue, |
699 expected_number_of_loads, | 699 expected_number_of_loads, |
700 false); | 700 false); |
701 } | 701 } |
702 | 702 |
703 void NavigateToDestURL() const { | 703 void NavigateToDestURL() const { |
704 NavigateToDestURLWithDisposition(CURRENT_TAB); | 704 NavigateToDestURLWithDisposition(CURRENT_TAB, true); |
705 } | 705 } |
706 | 706 |
707 // Opens the url in a new tab, with no opener. | 707 // Opens the url in a new tab, with no opener. |
708 void NavigateToDestURLWithDisposition( | 708 void NavigateToDestURLWithDisposition( |
709 WindowOpenDisposition disposition) const { | 709 WindowOpenDisposition disposition, |
710 NavigateToURLImpl(dest_url_, disposition); | 710 bool expect_swap_to_succeed) const { |
711 NavigateToURLImpl(dest_url_, disposition, expect_swap_to_succeed); | |
711 } | 712 } |
712 | 713 |
713 void OpenDestURLViaClick() const { | 714 void OpenDestURLViaClick() const { |
714 OpenDestURLWithJSImpl("Click()"); | 715 OpenDestURLWithJSImpl("Click()"); |
715 } | 716 } |
716 | 717 |
717 void OpenDestURLViaClickTarget() const { | 718 void OpenDestURLViaClickTarget() const { |
718 OpenDestURLWithJSImpl("ClickTarget()"); | 719 OpenDestURLWithJSImpl("ClickTarget()"); |
719 } | 720 } |
720 | 721 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 bool js_result; | 812 bool js_result; |
812 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 813 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
813 tab, | 814 tab, |
814 "window.domAutomationController.send(DidBackToOriginalPagePass())", | 815 "window.domAutomationController.send(DidBackToOriginalPagePass())", |
815 &js_result)); | 816 &js_result)); |
816 EXPECT_TRUE(js_result); | 817 EXPECT_TRUE(js_result); |
817 } | 818 } |
818 | 819 |
819 void NavigateToURL(const std::string& dest_html_file) const { | 820 void NavigateToURL(const std::string& dest_html_file) const { |
820 GURL dest_url = test_server()->GetURL(dest_html_file); | 821 GURL dest_url = test_server()->GetURL(dest_html_file); |
821 NavigateToURLImpl(dest_url, CURRENT_TAB); | 822 NavigateToURLImpl(dest_url, CURRENT_TAB, true); |
822 } | 823 } |
823 | 824 |
824 bool UrlIsInPrerenderManager(const std::string& html_file) const { | 825 bool UrlIsInPrerenderManager(const std::string& html_file) const { |
825 return UrlIsInPrerenderManager(test_server()->GetURL(html_file)); | 826 return UrlIsInPrerenderManager(test_server()->GetURL(html_file)); |
826 } | 827 } |
827 | 828 |
828 bool UrlIsInPrerenderManager(const GURL& url) const { | 829 bool UrlIsInPrerenderManager(const GURL& url) const { |
829 return GetPrerenderManager()->FindPrerenderData( | 830 return GetPrerenderManager()->FindPrerenderData( |
830 url, GetSessionStorageNamespace()) != NULL; | 831 url, GetSessionStorageNamespace()) != NULL; |
831 } | 832 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1078 // In the failure case, we should have removed |dest_url_| from the | 1079 // In the failure case, we should have removed |dest_url_| from the |
1079 // prerender_manager. We ignore dummy PrerenderContents (as indicated | 1080 // prerender_manager. We ignore dummy PrerenderContents (as indicated |
1080 // by not having started), and PrerenderContents that are expected to | 1081 // by not having started), and PrerenderContents that are expected to |
1081 // be left in the manager until the test finishes. | 1082 // be left in the manager until the test finishes. |
1082 EXPECT_TRUE(prerender_contents == NULL || | 1083 EXPECT_TRUE(prerender_contents == NULL || |
1083 !prerender_contents->prerendering_has_started()); | 1084 !prerender_contents->prerendering_has_started()); |
1084 } | 1085 } |
1085 } | 1086 } |
1086 | 1087 |
1087 void NavigateToURLImpl(const GURL& dest_url, | 1088 void NavigateToURLImpl(const GURL& dest_url, |
1088 WindowOpenDisposition disposition) const { | 1089 WindowOpenDisposition disposition, |
1090 bool expect_swap_to_succeed) const { | |
1089 ASSERT_NE(static_cast<PrerenderManager*>(NULL), GetPrerenderManager()); | 1091 ASSERT_NE(static_cast<PrerenderManager*>(NULL), GetPrerenderManager()); |
1090 // Make sure in navigating we have a URL to use in the PrerenderManager. | 1092 // Make sure in navigating we have a URL to use in the PrerenderManager. |
1091 ASSERT_NE(static_cast<PrerenderContents*>(NULL), GetPrerenderContents()); | 1093 ASSERT_NE(static_cast<PrerenderContents*>(NULL), GetPrerenderContents()); |
1092 | 1094 |
1093 // If opening the page in a background tab, it won't be shown when swapped | 1095 // If opening the page in a background tab, it won't be shown when swapped |
1094 // in. | 1096 // in. |
1095 if (disposition == NEW_BACKGROUND_TAB) | 1097 if (disposition == NEW_BACKGROUND_TAB) |
1096 GetPrerenderContents()->set_should_be_shown(false); | 1098 GetPrerenderContents()->set_should_be_shown(false); |
1097 | 1099 |
1098 scoped_ptr<content::WindowedNotificationObserver> page_load_observer; | 1100 scoped_ptr<content::WindowedNotificationObserver> page_load_observer; |
(...skipping 12 matching lines...) Expand all Loading... | |
1111 } | 1113 } |
1112 } | 1114 } |
1113 | 1115 |
1114 // Navigate to the prerendered URL, but don't run the message loop. Browser | 1116 // Navigate to the prerendered URL, but don't run the message loop. Browser |
1115 // issued navigations to prerendered pages will synchronously swap in the | 1117 // issued navigations to prerendered pages will synchronously swap in the |
1116 // prerendered page. | 1118 // prerendered page. |
1117 ui_test_utils::NavigateToURLWithDisposition( | 1119 ui_test_utils::NavigateToURLWithDisposition( |
1118 current_browser(), dest_url, disposition, | 1120 current_browser(), dest_url, disposition, |
1119 ui_test_utils::BROWSER_TEST_NONE); | 1121 ui_test_utils::BROWSER_TEST_NONE); |
1120 | 1122 |
1121 // Make sure the PrerenderContents found earlier was used or removed. | 1123 // Make sure the PrerenderContents found earlier was used or removed, |
1122 EXPECT_EQ(static_cast<PrerenderContents*>(NULL), GetPrerenderContents()); | 1124 // unless we expect the swap in to fail. |
1125 EXPECT_EQ(expect_swap_to_succeed, !GetPrerenderContents()); | |
1123 | 1126 |
1124 if (call_javascript_ && web_contents) { | 1127 if (call_javascript_ && web_contents && expect_swap_to_succeed) { |
1125 if (page_load_observer.get()) | 1128 if (page_load_observer.get()) |
1126 page_load_observer->Wait(); | 1129 page_load_observer->Wait(); |
1127 | 1130 |
1128 bool display_test_result = false; | 1131 bool display_test_result = false; |
1129 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 1132 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
1130 web_contents, | 1133 web_contents, |
1131 "window.domAutomationController.send(DidDisplayPass())", | 1134 "window.domAutomationController.send(DidDisplayPass())", |
1132 &display_test_result)); | 1135 &display_test_result)); |
1133 EXPECT_TRUE(display_test_result); | 1136 EXPECT_TRUE(display_test_result); |
1134 } | 1137 } |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1358 } | 1361 } |
1359 | 1362 |
1360 // Checks that the visibility API works. | 1363 // Checks that the visibility API works. |
1361 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibility) { | 1364 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibility) { |
1362 PrerenderTestURL("files/prerender/prerender_visibility.html", | 1365 PrerenderTestURL("files/prerender/prerender_visibility.html", |
1363 FINAL_STATUS_USED, | 1366 FINAL_STATUS_USED, |
1364 1); | 1367 1); |
1365 NavigateToDestURL(); | 1368 NavigateToDestURL(); |
1366 } | 1369 } |
1367 | 1370 |
1368 // Checks that the visibility API works when the prerender is quickly opened | 1371 // Checks that the prerendering of a page is canceled correctly if we try to |
1369 // in a new tab before it stops loading. | 1372 // swap it in before it commits. |
1370 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityQuickSwitch) { | 1373 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap) { |
1371 PrerenderTestURL("files/prerender/prerender_visibility_quick.html", | 1374 // Navigate to a page that triggers a prerender for a URL that never commits. |
1372 FINAL_STATUS_USED, 0); | 1375 // TODO(creis): Use a mock HTTP job for a URL that never commits. |
1373 NavigateToDestURL(); | 1376 const GURL no_commit_url = test_server()->GetURL("/slow?5"); |
Charlie Reis
2013/05/29 22:30:52
This needs to be replaced with a request that does
| |
1377 PrerenderTestURL(no_commit_url, | |
1378 FINAL_STATUS_CANCELLED, | |
1379 0); | |
1380 | |
1381 // Navigate to the URL, but assume the contents won't be swapped in. | |
1382 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | |
1383 | |
1384 // Confirm that the prerendered version of the URL is not swapped in, | |
1385 // since it never committed. | |
1386 EXPECT_TRUE(UrlIsInPrerenderManager(no_commit_url)); | |
1387 | |
1388 // Post a task to cancel all the prerenders, so that we don't wait further. | |
1389 base::MessageLoop::current()->PostTask( | |
1390 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager())); | |
1391 content::RunMessageLoop(); | |
1374 } | 1392 } |
1375 | 1393 |
1376 // Checks that the prerendering of a page is canceled correctly when a | 1394 // Checks that the prerendering of a page is canceled correctly when a |
1377 // Javascript alert is called. | 1395 // Javascript alert is called. |
1378 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertBeforeOnload) { | 1396 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertBeforeOnload) { |
1379 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", | 1397 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", |
1380 FINAL_STATUS_JAVASCRIPT_ALERT, | 1398 FINAL_STATUS_JAVASCRIPT_ALERT, |
1381 1); | 1399 1); |
1382 } | 1400 } |
1383 | 1401 |
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2788 // Checks that non-http/https main page redirects cancel the prerender. | 2806 // Checks that non-http/https main page redirects cancel the prerender. |
2789 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 2807 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
2790 PrerenderCancelMainFrameRedirectUnsupportedScheme) { | 2808 PrerenderCancelMainFrameRedirectUnsupportedScheme) { |
2791 GURL url = test_server()->GetURL( | 2809 GURL url = test_server()->GetURL( |
2792 CreateServerRedirect("invalidscheme://www.google.com/test.html")); | 2810 CreateServerRedirect("invalidscheme://www.google.com/test.html")); |
2793 PrerenderTestURL(url, FINAL_STATUS_UNSUPPORTED_SCHEME, 1); | 2811 PrerenderTestURL(url, FINAL_STATUS_UNSUPPORTED_SCHEME, 1); |
2794 NavigateToDestURL(); | 2812 NavigateToDestURL(); |
2795 } | 2813 } |
2796 | 2814 |
2797 } // namespace prerender | 2815 } // namespace prerender |
OLD | NEW |