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/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
37 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 37 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
38 #include "chrome/browser/task_manager/task_manager.h" | 38 #include "chrome/browser/task_manager/task_manager.h" |
39 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 39 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
40 #include "chrome/browser/ui/browser.h" | 40 #include "chrome/browser/ui/browser.h" |
41 #include "chrome/browser/ui/browser_commands.h" | 41 #include "chrome/browser/ui/browser_commands.h" |
42 #include "chrome/browser/ui/browser_finder.h" | 42 #include "chrome/browser/ui/browser_finder.h" |
43 #include "chrome/browser/ui/browser_navigator.h" | 43 #include "chrome/browser/ui/browser_navigator.h" |
44 #include "chrome/browser/ui/browser_window.h" | 44 #include "chrome/browser/ui/browser_window.h" |
45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 46 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
46 #include "chrome/common/chrome_paths.h" | 47 #include "chrome/common/chrome_paths.h" |
47 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
48 #include "chrome/common/extensions/extension_constants.h" | 49 #include "chrome/common/extensions/extension_constants.h" |
49 #include "chrome/common/pref_names.h" | 50 #include "chrome/common/pref_names.h" |
50 #include "chrome/test/base/in_process_browser_test.h" | 51 #include "chrome/test/base/in_process_browser_test.h" |
51 #include "chrome/test/base/test_switches.h" | 52 #include "chrome/test/base/test_switches.h" |
52 #include "chrome/test/base/ui_test_utils.h" | 53 #include "chrome/test/base/ui_test_utils.h" |
53 #include "content/public/browser/browser_message_filter.h" | 54 #include "content/public/browser/browser_message_filter.h" |
54 #include "content/public/browser/devtools_agent_host.h" | 55 #include "content/public/browser/devtools_agent_host.h" |
55 #include "content/public/browser/devtools_client_host.h" | 56 #include "content/public/browser/devtools_client_host.h" |
56 #include "content/public/browser/devtools_manager.h" | 57 #include "content/public/browser/devtools_manager.h" |
57 #include "content/public/browser/navigation_controller.h" | 58 #include "content/public/browser/navigation_controller.h" |
58 #include "content/public/browser/navigation_entry.h" | 59 #include "content/public/browser/navigation_entry.h" |
59 #include "content/public/browser/notification_service.h" | 60 #include "content/public/browser/notification_service.h" |
60 #include "content/public/browser/render_process_host.h" | 61 #include "content/public/browser/render_process_host.h" |
61 #include "content/public/browser/render_view_host.h" | 62 #include "content/public/browser/render_view_host.h" |
62 #include "content/public/browser/site_instance.h" | 63 #include "content/public/browser/site_instance.h" |
63 #include "content/public/browser/web_contents.h" | 64 #include "content/public/browser/web_contents.h" |
| 65 #include "content/public/browser/web_contents_observer.h" |
64 #include "content/public/common/url_constants.h" | 66 #include "content/public/common/url_constants.h" |
65 #include "content/public/test/browser_test_utils.h" | 67 #include "content/public/test/browser_test_utils.h" |
66 #include "content/public/test/test_navigation_observer.h" | 68 #include "content/public/test/test_navigation_observer.h" |
67 #include "content/public/test/test_utils.h" | 69 #include "content/public/test/test_utils.h" |
68 #include "content/test/net/url_request_mock_http_job.h" | 70 #include "content/test/net/url_request_mock_http_job.h" |
69 #include "extensions/common/switches.h" | 71 #include "extensions/common/switches.h" |
70 #include "grit/generated_resources.h" | 72 #include "grit/generated_resources.h" |
71 #include "net/base/escape.h" | 73 #include "net/base/escape.h" |
72 #include "net/dns/mock_host_resolver.h" | 74 #include "net/dns/mock_host_resolver.h" |
73 #include "net/url_request/url_request_context.h" | 75 #include "net/url_request/url_request_context.h" |
74 #include "net/url_request/url_request_context_getter.h" | 76 #include "net/url_request/url_request_context_getter.h" |
75 #include "net/url_request/url_request_filter.h" | 77 #include "net/url_request/url_request_filter.h" |
76 #include "net/url_request/url_request_job.h" | 78 #include "net/url_request/url_request_job.h" |
77 #include "ui/base/l10n/l10n_util.h" | 79 #include "ui/base/l10n/l10n_util.h" |
78 #include "url/gurl.h" | 80 #include "url/gurl.h" |
79 | 81 |
80 using content::BrowserThread; | 82 using content::BrowserThread; |
81 using content::DevToolsAgentHost; | 83 using content::DevToolsAgentHost; |
82 using content::DevToolsClientHost; | 84 using content::DevToolsClientHost; |
83 using content::DevToolsManager; | 85 using content::DevToolsManager; |
84 using content::NavigationController; | 86 using content::NavigationController; |
85 using content::OpenURLParams; | 87 using content::OpenURLParams; |
86 using content::Referrer; | 88 using content::Referrer; |
87 using content::RenderViewHost; | 89 using content::RenderViewHost; |
88 using content::RenderWidgetHost; | 90 using content::RenderWidgetHost; |
89 using content::WebContents; | 91 using content::WebContents; |
| 92 using content::WebContentsObserver; |
90 | 93 |
91 // Prerender tests work as follows: | 94 // Prerender tests work as follows: |
92 // | 95 // |
93 // A page with a prefetch link to the test page is loaded. Once prerendered, | 96 // A page with a prefetch link to the test page is loaded. Once prerendered, |
94 // its Javascript function DidPrerenderPass() is called, which returns true if | 97 // its Javascript function DidPrerenderPass() is called, which returns true if |
95 // the page behaves as expected when prerendered. | 98 // the page behaves as expected when prerendered. |
96 // | 99 // |
97 // The prerendered page is then displayed on a tab. The Javascript function | 100 // The prerendered page is then displayed on a tab. The Javascript function |
98 // DidDisplayPass() is called, and returns true if the page behaved as it | 101 // DidDisplayPass() is called, and returns true if the page behaved as it |
99 // should while being displayed. | 102 // should while being displayed. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 channel_destroyed_ = true; | 205 channel_destroyed_ = true; |
203 run_loop_.Quit(); | 206 run_loop_.Quit(); |
204 } | 207 } |
205 | 208 |
206 bool channel_destroyed_; | 209 bool channel_destroyed_; |
207 base::RunLoop run_loop_; | 210 base::RunLoop run_loop_; |
208 | 211 |
209 DISALLOW_COPY_AND_ASSIGN(ChannelDestructionWatcher); | 212 DISALLOW_COPY_AND_ASSIGN(ChannelDestructionWatcher); |
210 }; | 213 }; |
211 | 214 |
| 215 // A simple observer to wait on either a load or a swap of a WebContents. |
| 216 class NavigationOrSwapObserver : public WebContentsObserver, |
| 217 public TabStripModelObserver { |
| 218 public: |
| 219 // Waits for either a load or a swap of |tab_strip_model|'s active |
| 220 // WebContents. |
| 221 NavigationOrSwapObserver(TabStripModel* tab_strip_model, |
| 222 WebContents* web_contents) |
| 223 : WebContentsObserver(web_contents), |
| 224 tab_strip_model_(tab_strip_model) { |
| 225 CHECK_NE(TabStripModel::kNoTab, |
| 226 tab_strip_model->GetIndexOfWebContents(web_contents)); |
| 227 tab_strip_model_->AddObserver(this); |
| 228 } |
| 229 |
| 230 virtual ~NavigationOrSwapObserver() { |
| 231 tab_strip_model_->RemoveObserver(this); |
| 232 } |
| 233 |
| 234 void Wait() { |
| 235 loop_.Run(); |
| 236 } |
| 237 |
| 238 // WebContentsObserver implementation: |
| 239 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE { |
| 240 loop_.Quit(); |
| 241 } |
| 242 |
| 243 // TabStripModelObserver implementation: |
| 244 virtual void TabReplacedAt(TabStripModel* tab_strip_model, |
| 245 WebContents* old_contents, |
| 246 WebContents* new_contents, |
| 247 int index) OVERRIDE { |
| 248 if (old_contents != web_contents()) |
| 249 return; |
| 250 loop_.Quit(); |
| 251 } |
| 252 |
| 253 private: |
| 254 TabStripModel* tab_strip_model_; |
| 255 base::RunLoop loop_; |
| 256 }; |
| 257 |
212 // PrerenderContents that stops the UI message loop on DidStopLoading(). | 258 // PrerenderContents that stops the UI message loop on DidStopLoading(). |
213 class TestPrerenderContents : public PrerenderContents { | 259 class TestPrerenderContents : public PrerenderContents { |
214 public: | 260 public: |
215 TestPrerenderContents( | 261 TestPrerenderContents( |
216 PrerenderManager* prerender_manager, | 262 PrerenderManager* prerender_manager, |
217 Profile* profile, | 263 Profile* profile, |
218 const GURL& url, | 264 const GURL& url, |
219 const content::Referrer& referrer, | 265 const content::Referrer& referrer, |
220 Origin origin, | 266 Origin origin, |
221 int expected_number_of_loads, | 267 int expected_number_of_loads, |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 class RestorePrerenderMode { | 643 class RestorePrerenderMode { |
598 public: | 644 public: |
599 RestorePrerenderMode() : prev_mode_(PrerenderManager::GetMode()) { | 645 RestorePrerenderMode() : prev_mode_(PrerenderManager::GetMode()) { |
600 } | 646 } |
601 | 647 |
602 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); } | 648 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); } |
603 private: | 649 private: |
604 PrerenderManager::PrerenderManagerMode prev_mode_; | 650 PrerenderManager::PrerenderManagerMode prev_mode_; |
605 }; | 651 }; |
606 | 652 |
607 // URLRequestJob (and associated handler) which never starts. | 653 // URLRequestJob (and associated handler) which hangs. |
608 class NeverStartURLRequestJob : public net::URLRequestJob { | 654 class HangingURLRequestJob : public net::URLRequestJob { |
609 public: | 655 public: |
610 NeverStartURLRequestJob(net::URLRequest* request, | 656 HangingURLRequestJob(net::URLRequest* request, |
611 net::NetworkDelegate* network_delegate) | 657 net::NetworkDelegate* network_delegate) |
612 : net::URLRequestJob(request, network_delegate) { | 658 : net::URLRequestJob(request, network_delegate) { |
613 } | 659 } |
614 | 660 |
615 virtual void Start() OVERRIDE {} | 661 virtual void Start() OVERRIDE {} |
616 | 662 |
617 private: | 663 private: |
618 virtual ~NeverStartURLRequestJob() {} | 664 virtual ~HangingURLRequestJob() {} |
619 }; | 665 }; |
620 | 666 |
621 class NeverStartProtocolHandler | 667 class HangingFirstRequestProtocolHandler |
622 : public net::URLRequestJobFactory::ProtocolHandler { | 668 : public net::URLRequestJobFactory::ProtocolHandler { |
623 public: | 669 public: |
624 NeverStartProtocolHandler() {} | 670 explicit HangingFirstRequestProtocolHandler(const base::FilePath& file) |
625 virtual ~NeverStartProtocolHandler() {} | 671 : file_(file), |
| 672 first_run_(true) { |
| 673 } |
| 674 virtual ~HangingFirstRequestProtocolHandler() {} |
626 | 675 |
627 virtual net::URLRequestJob* MaybeCreateJob( | 676 virtual net::URLRequestJob* MaybeCreateJob( |
628 net::URLRequest* request, | 677 net::URLRequest* request, |
629 net::NetworkDelegate* network_delegate) const OVERRIDE { | 678 net::NetworkDelegate* network_delegate) const OVERRIDE { |
630 return new NeverStartURLRequestJob(request, network_delegate); | 679 if (first_run_) { |
| 680 first_run_ = false; |
| 681 return new HangingURLRequestJob(request, network_delegate); |
| 682 } |
| 683 return new content::URLRequestMockHTTPJob(request, network_delegate, file_); |
631 } | 684 } |
| 685 |
| 686 private: |
| 687 base::FilePath file_; |
| 688 mutable bool first_run_; |
632 }; | 689 }; |
633 | 690 |
634 void CreateNeverStartProtocolHandlerOnIO(const GURL& url) { | 691 // Makes |url| never respond on the first load, and then with the contents of |
| 692 // |file| afterwards. |
| 693 void CreateHangingFirstRequestProtocolHandlerOnIO(const GURL& url, |
| 694 const base::FilePath& file) { |
635 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 695 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
636 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> never_respond_handler( | 696 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> never_respond_handler( |
637 new NeverStartProtocolHandler()); | 697 new HangingFirstRequestProtocolHandler(file)); |
638 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( | 698 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( |
639 url, never_respond_handler.Pass()); | 699 url, never_respond_handler.Pass()); |
640 } | 700 } |
641 | 701 |
642 // Makes |url| respond to requests with the contents of |file|. | 702 // Makes |url| respond to requests with the contents of |file|. |
643 void CreateMockProtocolHandlerOnIO(const GURL& url, | 703 void CreateMockProtocolHandlerOnIO(const GURL& url, |
644 const base::FilePath& file) { | 704 const base::FilePath& file) { |
645 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 705 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
646 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( | 706 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( |
647 url, content::URLRequestMockHTTPJob::CreateProtocolHandlerForSingleFile( | 707 url, content::URLRequestMockHTTPJob::CreateProtocolHandlerForSingleFile( |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 void NavigateToDestURLInNewTab() const { | 891 void NavigateToDestURLInNewTab() const { |
832 // First, open a new tab. | 892 // First, open a new tab. |
833 ui_test_utils::NavigateToURLWithDisposition( | 893 ui_test_utils::NavigateToURLWithDisposition( |
834 current_browser(), GURL(content::kAboutBlankURL), | 894 current_browser(), GURL(content::kAboutBlankURL), |
835 NEW_FOREGROUND_TAB, | 895 NEW_FOREGROUND_TAB, |
836 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 896 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
837 // Next, navigate to the destination URL. The swap-in will not succeed, | 897 // Next, navigate to the destination URL. The swap-in will not succeed, |
838 // due to session storage namespace mismatch. The merge is only kicked off | 898 // due to session storage namespace mismatch. The merge is only kicked off |
839 // asynchronously. | 899 // asynchronously. |
840 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | 900 NavigateToDestURLWithDisposition(CURRENT_TAB, false); |
841 // Run the message loop, waiting for the merge to complete, the swapin to | |
842 // be reattempted, and to eventually succeed. | |
843 content::RunMessageLoop(); | |
844 } | 901 } |
845 | 902 |
846 // Opens the url in a new tab, with no opener. | 903 // Opens the url in a new tab, with no opener. |
847 void NavigateToDestURLWithDisposition( | 904 void NavigateToDestURLWithDisposition( |
848 WindowOpenDisposition disposition, | 905 WindowOpenDisposition disposition, |
849 bool expect_swap_to_succeed) const { | 906 bool expect_swap_to_succeed) const { |
850 NavigateToURLWithParams( | 907 NavigateToURLWithParams( |
851 content::OpenURLParams(dest_url_, Referrer(), disposition, | 908 content::OpenURLParams(dest_url_, Referrer(), disposition, |
852 content::PAGE_TRANSITION_TYPED, false), | 909 content::PAGE_TRANSITION_TYPED, false), |
853 expect_swap_to_succeed); | 910 expect_swap_to_succeed); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 } | 1202 } |
1146 | 1203 |
1147 void IncreasePrerenderMemory() { | 1204 void IncreasePrerenderMemory() { |
1148 // Increase the memory allowed in a prerendered page above normal settings. | 1205 // Increase the memory allowed in a prerendered page above normal settings. |
1149 // Debug build bots occasionally run against the default limit, and tests | 1206 // Debug build bots occasionally run against the default limit, and tests |
1150 // were failing because the prerender was canceled due to memory exhaustion. | 1207 // were failing because the prerender was canceled due to memory exhaustion. |
1151 // http://crbug.com/93076 | 1208 // http://crbug.com/93076 |
1152 GetPrerenderManager()->mutable_config().max_bytes = 1000 * 1024 * 1024; | 1209 GetPrerenderManager()->mutable_config().max_bytes = 1000 * 1024 * 1024; |
1153 } | 1210 } |
1154 | 1211 |
| 1212 bool DidPrerenderPass(WebContents* web_contents) const { |
| 1213 bool prerender_test_result = false; |
| 1214 if (!content::ExecuteScriptAndExtractBool( |
| 1215 web_contents, |
| 1216 "window.domAutomationController.send(DidPrerenderPass())", |
| 1217 &prerender_test_result)) |
| 1218 return false; |
| 1219 return prerender_test_result; |
| 1220 } |
| 1221 |
| 1222 bool DidDisplayPass(WebContents* web_contents) const { |
| 1223 bool display_test_result = false; |
| 1224 if (!content::ExecuteScriptAndExtractBool( |
| 1225 web_contents, |
| 1226 "window.domAutomationController.send(DidDisplayPass())", |
| 1227 &display_test_result)) |
| 1228 return false; |
| 1229 return display_test_result; |
| 1230 } |
| 1231 |
1155 protected: | 1232 protected: |
1156 bool autostart_test_server_; | 1233 bool autostart_test_server_; |
1157 | 1234 |
1158 private: | 1235 private: |
1159 void PrerenderTestURLImpl( | 1236 void PrerenderTestURLImpl( |
1160 const GURL& prerender_url, | 1237 const GURL& prerender_url, |
1161 const GURL& destination_url, | 1238 const GURL& destination_url, |
1162 const std::deque<FinalStatus>& expected_final_status_queue, | 1239 const std::deque<FinalStatus>& expected_final_status_queue, |
1163 int expected_number_of_loads, | 1240 int expected_number_of_loads, |
1164 bool prerender_should_wait_for_ready_title) { | 1241 bool prerender_should_wait_for_ready_title) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { | 1308 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { |
1232 ASSERT_NE(static_cast<PrerenderContents*>(NULL), prerender_contents); | 1309 ASSERT_NE(static_cast<PrerenderContents*>(NULL), prerender_contents); |
1233 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); | 1310 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); |
1234 | 1311 |
1235 if (call_javascript_) { | 1312 if (call_javascript_) { |
1236 // Wait for the prerendered page to change title to signal it is ready | 1313 // Wait for the prerendered page to change title to signal it is ready |
1237 // if required. | 1314 // if required. |
1238 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); | 1315 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); |
1239 | 1316 |
1240 // Check if page behaves as expected while in prerendered state. | 1317 // Check if page behaves as expected while in prerendered state. |
1241 bool prerender_test_result = false; | 1318 EXPECT_TRUE(DidPrerenderPass(prerender_contents->prerender_contents())); |
1242 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
1243 prerender_contents->GetRenderViewHostMutable(), | |
1244 "window.domAutomationController.send(DidPrerenderPass())", | |
1245 &prerender_test_result)); | |
1246 EXPECT_TRUE(prerender_test_result); | |
1247 } | 1319 } |
1248 | 1320 |
1249 // Test that the referring page received events. | 1321 // Test that the referring page received events. |
1250 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0)); | 1322 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0)); |
1251 if (check_load_events_) { | 1323 if (check_load_events_) { |
1252 EXPECT_EQ(expected_number_of_loads, | 1324 EXPECT_EQ(expected_number_of_loads, |
1253 GetPrerenderLoadEventCountForLinkNumber(0)); | 1325 GetPrerenderLoadEventCountForLinkNumber(0)); |
1254 } | 1326 } |
1255 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0)); | 1327 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0)); |
1256 } else { | 1328 } else { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 web_contents = GetPrerenderContents()->prerender_contents(); | 1367 web_contents = GetPrerenderContents()->prerender_contents(); |
1296 if (GetPrerenderContents()->number_of_loads() == 0) { | 1368 if (GetPrerenderContents()->number_of_loads() == 0) { |
1297 page_load_observer.reset( | 1369 page_load_observer.reset( |
1298 new content::WindowedNotificationObserver( | 1370 new content::WindowedNotificationObserver( |
1299 content::NOTIFICATION_LOAD_STOP, | 1371 content::NOTIFICATION_LOAD_STOP, |
1300 content::Source<NavigationController>( | 1372 content::Source<NavigationController>( |
1301 &web_contents->GetController()))); | 1373 &web_contents->GetController()))); |
1302 } | 1374 } |
1303 } | 1375 } |
1304 | 1376 |
1305 // Navigate to the prerendered URL, but don't run the message loop. Browser | 1377 // Navigate and wait for either the load to finish normally or for a swap to |
1306 // issued navigations to prerendered pages will synchronously swap in the | 1378 // occur. |
1307 // prerendered page. | 1379 // TODO(davidben): The only handles CURRENT_TAB navigations, which is the |
| 1380 // only case tested or prerendered right now. |
| 1381 CHECK_EQ(CURRENT_TAB, params.disposition); |
| 1382 NavigationOrSwapObserver swap_observer( |
| 1383 current_browser()->tab_strip_model(), |
| 1384 current_browser()->tab_strip_model()->GetActiveWebContents()); |
1308 WebContents* target_web_contents = current_browser()->OpenURL(params); | 1385 WebContents* target_web_contents = current_browser()->OpenURL(params); |
| 1386 swap_observer.Wait(); |
1309 | 1387 |
1310 if (web_contents && expect_swap_to_succeed) { | 1388 if (web_contents && expect_swap_to_succeed) { |
1311 EXPECT_EQ(web_contents, target_web_contents); | 1389 EXPECT_EQ(web_contents, target_web_contents); |
1312 if (call_javascript_) { | 1390 if (call_javascript_) { |
1313 if (page_load_observer.get()) | 1391 if (page_load_observer.get()) |
1314 page_load_observer->Wait(); | 1392 page_load_observer->Wait(); |
1315 | 1393 |
1316 bool display_test_result = false; | 1394 EXPECT_TRUE(DidDisplayPass(web_contents)); |
1317 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
1318 web_contents, | |
1319 "window.domAutomationController.send(DidDisplayPass())", | |
1320 &display_test_result)); | |
1321 EXPECT_TRUE(display_test_result); | |
1322 } | 1395 } |
1323 } | 1396 } |
1324 } | 1397 } |
1325 | 1398 |
1326 // Opens the prerendered page using javascript functions in the | 1399 // Opens the prerendered page using javascript functions in the |
1327 // loader page. |javascript_function_name| should be a 0 argument function | 1400 // loader page. |javascript_function_name| should be a 0 argument function |
1328 // which is invoked. | 1401 // which is invoked. |
1329 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) | 1402 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) |
1330 const { | 1403 const { |
1331 TestPrerenderContents* prerender_contents = GetPrerenderContents(); | 1404 TestPrerenderContents* prerender_contents = GetPrerenderContents(); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 FINAL_STATUS_USED, | 1618 FINAL_STATUS_USED, |
1546 1); | 1619 1); |
1547 NavigateToDestURL(); | 1620 NavigateToDestURL(); |
1548 } | 1621 } |
1549 | 1622 |
1550 // Checks that the prerendering of a page is canceled correctly if we try to | 1623 // Checks that the prerendering of a page is canceled correctly if we try to |
1551 // swap it in before it commits. | 1624 // swap it in before it commits. |
1552 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap) { | 1625 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap) { |
1553 // Navigate to a page that triggers a prerender for a URL that never commits. | 1626 // Navigate to a page that triggers a prerender for a URL that never commits. |
1554 const GURL kNoCommitUrl("http://never-respond.example.com"); | 1627 const GURL kNoCommitUrl("http://never-respond.example.com"); |
| 1628 base::FilePath file(FILE_PATH_LITERAL( |
| 1629 "chrome/test/data/prerender/prerender_page.html")); |
1555 BrowserThread::PostTask( | 1630 BrowserThread::PostTask( |
1556 BrowserThread::IO, FROM_HERE, | 1631 BrowserThread::IO, FROM_HERE, |
1557 base::Bind(&CreateNeverStartProtocolHandlerOnIO, kNoCommitUrl)); | 1632 base::Bind(&CreateHangingFirstRequestProtocolHandlerOnIO, |
| 1633 kNoCommitUrl, file)); |
1558 DisableJavascriptCalls(); | 1634 DisableJavascriptCalls(); |
1559 PrerenderTestURL(kNoCommitUrl, | 1635 PrerenderTestURL(kNoCommitUrl, |
1560 FINAL_STATUS_NAVIGATION_UNCOMMITTED, | 1636 FINAL_STATUS_NAVIGATION_UNCOMMITTED, |
1561 0); | 1637 0); |
1562 | 1638 |
1563 // Navigate to the URL, but assume the contents won't be swapped in. | 1639 // Navigate to the URL, but assume the contents won't be swapped in. |
1564 NavigateToDestURLWithDisposition(CURRENT_TAB, false); | 1640 NavigateToDestURLWithDisposition(CURRENT_TAB, false); |
1565 } | 1641 } |
1566 | 1642 |
1567 // Checks that client redirects don't add alias URLs until after they commit. | 1643 // Checks that client redirects don't add alias URLs until after they commit. |
1568 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap2) { | 1644 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap2) { |
1569 // Navigate to a page that then navigates to a URL that never commits. | 1645 // Navigate to a page that then navigates to a URL that never commits. |
1570 const GURL kNoCommitUrl("http://never-respond.example.com"); | 1646 const GURL kNoCommitUrl("http://never-respond.example.com"); |
| 1647 base::FilePath file(FILE_PATH_LITERAL( |
| 1648 "chrome/test/data/prerender/prerender_page.html")); |
1571 BrowserThread::PostTask( | 1649 BrowserThread::PostTask( |
1572 BrowserThread::IO, FROM_HERE, | 1650 BrowserThread::IO, FROM_HERE, |
1573 base::Bind(&CreateNeverStartProtocolHandlerOnIO, kNoCommitUrl)); | 1651 base::Bind(&CreateHangingFirstRequestProtocolHandlerOnIO, |
| 1652 kNoCommitUrl, file)); |
1574 DisableJavascriptCalls(); | 1653 DisableJavascriptCalls(); |
1575 PrerenderTestURL(CreateClientRedirect(kNoCommitUrl.spec()), | 1654 PrerenderTestURL(CreateClientRedirect(kNoCommitUrl.spec()), |
1576 FINAL_STATUS_APP_TERMINATING, 1); | 1655 FINAL_STATUS_APP_TERMINATING, 1); |
1577 | 1656 |
1578 // Navigating to the second URL should not swap. | 1657 // Navigating to the second URL should not swap. |
1579 NavigateToURLWithDisposition(kNoCommitUrl, CURRENT_TAB, false); | 1658 NavigateToURLWithDisposition(kNoCommitUrl, CURRENT_TAB, false); |
1580 } | 1659 } |
1581 | 1660 |
1582 // Checks that the prerendering of a page is canceled correctly when a | 1661 // Checks that the prerendering of a page is canceled correctly when a |
1583 // Javascript alert is called. | 1662 // Javascript alert is called. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 | 1724 |
1646 // Run this check again. When we try to load aa ppapi plugin, the | 1725 // Run this check again. When we try to load aa ppapi plugin, the |
1647 // "loadstart" event is asynchronously posted to a message loop. | 1726 // "loadstart" event is asynchronously posted to a message loop. |
1648 // It's possible that earlier call could have been run before the | 1727 // It's possible that earlier call could have been run before the |
1649 // the "loadstart" event was posted. | 1728 // the "loadstart" event was posted. |
1650 // TODO(mmenke): While this should reliably fail on regressions, the | 1729 // TODO(mmenke): While this should reliably fail on regressions, the |
1651 // reliability depends on the specifics of ppapi plugin | 1730 // reliability depends on the specifics of ppapi plugin |
1652 // loading. It would be great if we could avoid that. | 1731 // loading. It would be great if we could avoid that. |
1653 WebContents* web_contents = | 1732 WebContents* web_contents = |
1654 browser()->tab_strip_model()->GetActiveWebContents(); | 1733 browser()->tab_strip_model()->GetActiveWebContents(); |
1655 bool display_test_result = false; | 1734 EXPECT_TRUE(DidDisplayPass(web_contents)); |
1656 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
1657 web_contents, | |
1658 "window.domAutomationController.send(DidDisplayPass())", | |
1659 &display_test_result)); | |
1660 EXPECT_TRUE(display_test_result); | |
1661 } | 1735 } |
1662 | 1736 |
1663 // Checks that plugins in an iframe are not loaded while a page is | 1737 // Checks that plugins in an iframe are not loaded while a page is |
1664 // being preloaded, but are loaded when the page is displayed. | 1738 // being preloaded, but are loaded when the page is displayed. |
1665 #if defined(USE_AURA) && !defined(OS_WIN) | 1739 #if defined(USE_AURA) && !defined(OS_WIN) |
1666 // http://crbug.com/103496 | 1740 // http://crbug.com/103496 |
1667 #define MAYBE_PrerenderIframeDelayLoadPlugin \ | 1741 #define MAYBE_PrerenderIframeDelayLoadPlugin \ |
1668 DISABLED_PrerenderIframeDelayLoadPlugin | 1742 DISABLED_PrerenderIframeDelayLoadPlugin |
1669 #elif defined(OS_MACOSX) | 1743 #elif defined(OS_MACOSX) |
1670 // http://crbug.com/100514 | 1744 // http://crbug.com/100514 |
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3360 const NavigationController& controller = web_contents->GetController(); | 3434 const NavigationController& controller = web_contents->GetController(); |
3361 // First entry is about:blank, second is prerender_page.html. | 3435 // First entry is about:blank, second is prerender_page.html. |
3362 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 3436 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
3363 EXPECT_EQ(2, controller.GetEntryCount()); | 3437 EXPECT_EQ(2, controller.GetEntryCount()); |
3364 EXPECT_EQ(GURL(content::kAboutBlankURL), | 3438 EXPECT_EQ(GURL(content::kAboutBlankURL), |
3365 controller.GetEntryAtIndex(0)->GetURL()); | 3439 controller.GetEntryAtIndex(0)->GetURL()); |
3366 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); | 3440 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); |
3367 } | 3441 } |
3368 | 3442 |
3369 } // namespace prerender | 3443 } // namespace prerender |
OLD | NEW |