OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/scoped_temp_dir.h" | |
10 #include "base/string_util.h" | 9 #include "base/string_util.h" |
11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/prerender/prerender_contents.h" | 12 #include "chrome/browser/prerender/prerender_contents.h" |
14 #include "chrome/browser/prerender/prerender_manager.h" | 13 #include "chrome/browser/prerender/prerender_manager.h" |
15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/task_manager/task_manager.h" | 15 #include "chrome/browser/task_manager/task_manager.h" |
17 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // explicitly registered. | 234 // explicitly registered. |
236 FilePath app_dir; | 235 FilePath app_dir; |
237 PathService::Get(chrome::DIR_APP, &app_dir); | 236 PathService::Get(chrome::DIR_APP, &app_dir); |
238 command_line->AppendSwitchPath( | 237 command_line->AppendSwitchPath( |
239 switches::kExtraPluginDir, | 238 switches::kExtraPluginDir, |
240 app_dir.Append(FILE_PATH_LITERAL("plugins"))); | 239 app_dir.Append(FILE_PATH_LITERAL("plugins"))); |
241 #endif | 240 #endif |
242 } | 241 } |
243 | 242 |
244 virtual void SetUpOnMainThread() OVERRIDE { | 243 virtual void SetUpOnMainThread() OVERRIDE { |
245 // TODO(mmenke): Once downloading is stopped earlier, remove this. | |
246 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 244 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
247 false); | 245 false); |
248 | |
249 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); | |
250 | |
251 browser()->profile()->GetPrefs()->SetFilePath( | |
252 prefs::kDownloadDefaultDirectory, | |
253 downloads_directory_.path()); | |
254 } | 246 } |
255 | 247 |
256 // Overload for a single expected final status | 248 // Overload for a single expected final status |
257 void PrerenderTestURL(const std::string& html_file, | 249 void PrerenderTestURL(const std::string& html_file, |
258 FinalStatus expected_final_status, | 250 FinalStatus expected_final_status, |
259 int total_navigations) { | 251 int total_navigations) { |
260 std::deque<FinalStatus> expected_final_status_queue(1, | 252 std::deque<FinalStatus> expected_final_status_queue(1, |
261 expected_final_status); | 253 expected_final_status); |
262 PrerenderTestURL(html_file, | 254 PrerenderTestURL(html_file, |
263 expected_final_status_queue, | 255 expected_final_status_queue, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 L"window.domAutomationController.send(DidDisplayPass())", | 419 L"window.domAutomationController.send(DidDisplayPass())", |
428 &display_test_result)); | 420 &display_test_result)); |
429 EXPECT_TRUE(display_test_result); | 421 EXPECT_TRUE(display_test_result); |
430 } | 422 } |
431 } | 423 } |
432 | 424 |
433 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; | 425 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; |
434 GURL dest_url_; | 426 GURL dest_url_; |
435 bool use_https_src_server_; | 427 bool use_https_src_server_; |
436 bool call_javascript_; | 428 bool call_javascript_; |
437 | |
438 // Location of the downloads directory for these tests | |
439 ScopedTempDir downloads_directory_; | |
440 }; | 429 }; |
441 | 430 |
442 // Checks that a page is correctly prerendered in the case of a | 431 // Checks that a page is correctly prerendered in the case of a |
443 // <link rel=prefetch> tag and then loaded into a tab in response to a | 432 // <link rel=prefetch> tag and then loaded into a tab in response to a |
444 // navigation. | 433 // navigation. |
445 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { | 434 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { |
446 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 435 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
447 NavigateToDestURL(); | 436 NavigateToDestURL(); |
448 } | 437 } |
449 | 438 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 "files/prerender/prerender_with_iframe.html", | 652 "files/prerender/prerender_with_iframe.html", |
664 replacement_text, | 653 replacement_text, |
665 &replacement_path)); | 654 &replacement_path)); |
666 PrerenderTestURL(replacement_path, FINAL_STATUS_USED, 1); | 655 PrerenderTestURL(replacement_path, FINAL_STATUS_USED, 1); |
667 EXPECT_FALSE(UrlIsInPrerenderManager(https_url)); | 656 EXPECT_FALSE(UrlIsInPrerenderManager(https_url)); |
668 NavigateToDestURL(); | 657 NavigateToDestURL(); |
669 } | 658 } |
670 | 659 |
671 // Prerenders a page that contains an automatic download triggered through an | 660 // Prerenders a page that contains an automatic download triggered through an |
672 // iframe. This should not prerender successfully. | 661 // iframe. This should not prerender successfully. |
673 // Flaky: http://crbug.com/81985 | 662 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadIframe) { |
674 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, FLAKY_PrerenderDownloadIframe) { | |
675 PrerenderTestURL("files/prerender/prerender_download_iframe.html", | 663 PrerenderTestURL("files/prerender/prerender_download_iframe.html", |
676 FINAL_STATUS_DOWNLOAD, | 664 FINAL_STATUS_DOWNLOAD, |
677 1); | 665 1); |
678 } | 666 } |
679 | 667 |
680 // Prerenders a page that contains an automatic download triggered through | 668 // Prerenders a page that contains an automatic download triggered through |
681 // Javascript changing the window.location. This should not prerender | 669 // Javascript changing the window.location. This should not prerender |
682 // successfully | 670 // successfully |
683 // Flaky: http://crbug.com/81985 | 671 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadLocation) { |
684 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
685 FLAKY_PrerenderDownloadLocation) { | |
686 PrerenderTestURL(CreateClientRedirect("files/download-test1.lib"), | 672 PrerenderTestURL(CreateClientRedirect("files/download-test1.lib"), |
687 FINAL_STATUS_DOWNLOAD, | 673 FINAL_STATUS_DOWNLOAD, |
688 1); | 674 1); |
689 } | 675 } |
690 | 676 |
691 // Prerenders a page that contains an automatic download triggered through a | 677 // Prerenders a page that contains an automatic download triggered through a |
692 // client-issued redirect. This should not prerender successfully. | 678 // client-issued redirect. This should not prerender successfully. |
693 // Flaky: http://crbug.com/81985 | 679 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadClientRedirect) { |
694 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
695 FLAKY_PrerenderDownloadClientRedirect) { | |
696 PrerenderTestURL("files/prerender/prerender_download_refresh.html", | 680 PrerenderTestURL("files/prerender/prerender_download_refresh.html", |
697 FINAL_STATUS_DOWNLOAD, | 681 FINAL_STATUS_DOWNLOAD, |
698 1); | 682 1); |
699 } | 683 } |
700 | 684 |
701 // Checks that the referrer is set when prerendering. | 685 // Checks that the referrer is set when prerendering. |
702 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrer) { | 686 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrer) { |
703 PrerenderTestURL("files/prerender/prerender_referrer.html", | 687 PrerenderTestURL("files/prerender/prerender_referrer.html", |
704 FINAL_STATUS_USED, | 688 FINAL_STATUS_USED, |
705 1); | 689 1); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 945 |
962 // Checks that prerendering a JPG works correctly. | 946 // Checks that prerendering a JPG works correctly. |
963 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderImageJpeg) { | 947 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderImageJpeg) { |
964 DisableJavascriptCalls(); | 948 DisableJavascriptCalls(); |
965 PrerenderTestURL("files/prerender/image.jpeg", FINAL_STATUS_USED, 1); | 949 PrerenderTestURL("files/prerender/image.jpeg", FINAL_STATUS_USED, 1); |
966 NavigateToDestURL(); | 950 NavigateToDestURL(); |
967 } | 951 } |
968 | 952 |
969 // Checks that a prerender of a CRX will result in a cancellation due to | 953 // Checks that a prerender of a CRX will result in a cancellation due to |
970 // download. | 954 // download. |
971 // Flaky: http://crbug.com/81985 | 955 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCrx) { |
972 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, FLAKY_PrerenderCrx) { | |
973 PrerenderTestURL("files/prerender/extension.crx", FINAL_STATUS_DOWNLOAD, 1); | 956 PrerenderTestURL("files/prerender/extension.crx", FINAL_STATUS_DOWNLOAD, 1); |
974 } | 957 } |
975 | 958 |
976 // Checks that xhr GET requests allow prerenders. | 959 // Checks that xhr GET requests allow prerenders. |
977 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderXhrGet) { | 960 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderXhrGet) { |
978 PrerenderTestURL("files/prerender/prerender_xhr_get.html", | 961 PrerenderTestURL("files/prerender/prerender_xhr_get.html", |
979 FINAL_STATUS_USED, | 962 FINAL_STATUS_USED, |
980 1); | 963 1); |
981 NavigateToDestURL(); | 964 NavigateToDestURL(); |
982 } | 965 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 } | 1073 } |
1091 | 1074 |
1092 // Checks that we cancel correctly when window.print() is called. | 1075 // Checks that we cancel correctly when window.print() is called. |
1093 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPrint) { | 1076 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPrint) { |
1094 PrerenderTestURL("files/prerender/prerender_print.html", | 1077 PrerenderTestURL("files/prerender/prerender_print.html", |
1095 FINAL_STATUS_WINDOW_PRINT, | 1078 FINAL_STATUS_WINDOW_PRINT, |
1096 1); | 1079 1); |
1097 } | 1080 } |
1098 | 1081 |
1099 } // namespace prerender | 1082 } // namespace prerender |
OLD | NEW |