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

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

Issue 7004039: Cancel downloads earlier when prerendering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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 | « no previous file | chrome/browser/prerender/prerender_contents.h » ('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) 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
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. 244 // TODO(mmenke): Once downloading is stopped earlier, remove this.
dominich 2011/05/20 17:42:35 still need this?
mmenke 2011/05/20 17:45:12 No. Thanks.
246 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, 245 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
247 false); 246 false);
248
249 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir());
250
251 browser()->profile()->GetPrefs()->SetFilePath(
252 prefs::kDownloadDefaultDirectory,
253 downloads_directory_.path());
254 } 247 }
255 248
256 // Overload for a single expected final status 249 // Overload for a single expected final status
257 void PrerenderTestURL(const std::string& html_file, 250 void PrerenderTestURL(const std::string& html_file,
258 FinalStatus expected_final_status, 251 FinalStatus expected_final_status,
259 int total_navigations) { 252 int total_navigations) {
260 std::deque<FinalStatus> expected_final_status_queue(1, 253 std::deque<FinalStatus> expected_final_status_queue(1,
261 expected_final_status); 254 expected_final_status);
262 PrerenderTestURL(html_file, 255 PrerenderTestURL(html_file,
263 expected_final_status_queue, 256 expected_final_status_queue,
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 L"window.domAutomationController.send(DidDisplayPass())", 420 L"window.domAutomationController.send(DidDisplayPass())",
428 &display_test_result)); 421 &display_test_result));
429 EXPECT_TRUE(display_test_result); 422 EXPECT_TRUE(display_test_result);
430 } 423 }
431 } 424 }
432 425
433 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; 426 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_;
434 GURL dest_url_; 427 GURL dest_url_;
435 bool use_https_src_server_; 428 bool use_https_src_server_;
436 bool call_javascript_; 429 bool call_javascript_;
437
438 // Location of the downloads directory for these tests
439 ScopedTempDir downloads_directory_;
440 }; 430 };
441 431
442 // Checks that a page is correctly prerendered in the case of a 432 // 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 433 // <link rel=prefetch> tag and then loaded into a tab in response to a
444 // navigation. 434 // navigation.
445 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { 435 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) {
446 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 436 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
447 NavigateToDestURL(); 437 NavigateToDestURL();
448 } 438 }
449 439
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 "files/prerender/prerender_with_iframe.html", 653 "files/prerender/prerender_with_iframe.html",
664 replacement_text, 654 replacement_text,
665 &replacement_path)); 655 &replacement_path));
666 PrerenderTestURL(replacement_path, FINAL_STATUS_USED, 1); 656 PrerenderTestURL(replacement_path, FINAL_STATUS_USED, 1);
667 EXPECT_FALSE(UrlIsInPrerenderManager(https_url)); 657 EXPECT_FALSE(UrlIsInPrerenderManager(https_url));
668 NavigateToDestURL(); 658 NavigateToDestURL();
669 } 659 }
670 660
671 // Prerenders a page that contains an automatic download triggered through an 661 // Prerenders a page that contains an automatic download triggered through an
672 // iframe. This should not prerender successfully. 662 // iframe. This should not prerender successfully.
673 // Flaky: http://crbug.com/81985 663 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadIframe) {
674 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, FLAKY_PrerenderDownloadIframe) {
675 PrerenderTestURL("files/prerender/prerender_download_iframe.html", 664 PrerenderTestURL("files/prerender/prerender_download_iframe.html",
676 FINAL_STATUS_DOWNLOAD, 665 FINAL_STATUS_DOWNLOAD,
677 1); 666 1);
678 } 667 }
679 668
680 // Prerenders a page that contains an automatic download triggered through 669 // Prerenders a page that contains an automatic download triggered through
681 // Javascript changing the window.location. This should not prerender 670 // Javascript changing the window.location. This should not prerender
682 // successfully 671 // successfully
683 // Flaky: http://crbug.com/81985 672 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDownloadLocation) {
684 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
685 FLAKY_PrerenderDownloadLocation) {
686 PrerenderTestURL(CreateClientRedirect("files/download-test1.lib"), 673 PrerenderTestURL(CreateClientRedirect("files/download-test1.lib"),
687 FINAL_STATUS_DOWNLOAD, 674 FINAL_STATUS_DOWNLOAD,
688 1); 675 1);
689 } 676 }
690 677
691 // Prerenders a page that contains an automatic download triggered through a 678 // Prerenders a page that contains an automatic download triggered through a
692 // client-issued redirect. This should not prerender successfully. 679 // client-issued redirect. This should not prerender successfully.
693 // Flaky: http://crbug.com/81985 680 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", 681 PrerenderTestURL("files/prerender/prerender_download_refresh.html",
697 FINAL_STATUS_DOWNLOAD, 682 FINAL_STATUS_DOWNLOAD,
698 1); 683 1);
699 } 684 }
700 685
701 // Checks that the referrer is set when prerendering. 686 // Checks that the referrer is set when prerendering.
702 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrer) { 687 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReferrer) {
703 PrerenderTestURL("files/prerender/prerender_referrer.html", 688 PrerenderTestURL("files/prerender/prerender_referrer.html",
704 FINAL_STATUS_USED, 689 FINAL_STATUS_USED,
705 1); 690 1);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 946
962 // Checks that prerendering a JPG works correctly. 947 // Checks that prerendering a JPG works correctly.
963 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderImageJpeg) { 948 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderImageJpeg) {
964 DisableJavascriptCalls(); 949 DisableJavascriptCalls();
965 PrerenderTestURL("files/prerender/image.jpeg", FINAL_STATUS_USED, 1); 950 PrerenderTestURL("files/prerender/image.jpeg", FINAL_STATUS_USED, 1);
966 NavigateToDestURL(); 951 NavigateToDestURL();
967 } 952 }
968 953
969 // Checks that a prerender of a CRX will result in a cancellation due to 954 // Checks that a prerender of a CRX will result in a cancellation due to
970 // download. 955 // download.
971 // Flaky: http://crbug.com/81985 956 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); 957 PrerenderTestURL("files/prerender/extension.crx", FINAL_STATUS_DOWNLOAD, 1);
974 } 958 }
975 959
976 // Checks that xhr GET requests allow prerenders. 960 // Checks that xhr GET requests allow prerenders.
977 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderXhrGet) { 961 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderXhrGet) {
978 PrerenderTestURL("files/prerender/prerender_xhr_get.html", 962 PrerenderTestURL("files/prerender/prerender_xhr_get.html",
979 FINAL_STATUS_USED, 963 FINAL_STATUS_USED,
980 1); 964 1);
981 NavigateToDestURL(); 965 NavigateToDestURL();
982 } 966 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 } 1074 }
1091 1075
1092 // Checks that we cancel correctly when window.print() is called. 1076 // Checks that we cancel correctly when window.print() is called.
1093 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPrint) { 1077 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPrint) {
1094 PrerenderTestURL("files/prerender/prerender_print.html", 1078 PrerenderTestURL("files/prerender/prerender_print.html",
1095 FINAL_STATUS_WINDOW_PRINT, 1079 FINAL_STATUS_WINDOW_PRINT,
1096 1); 1080 1);
1097 } 1081 }
1098 1082
1099 } // namespace prerender 1083 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698