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

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 7294013: Modified cancel and interrupt processing to avoid race with history. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 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
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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 49 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
50 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); 50 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx"));
51 51
52 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; 52 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
53 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); 53 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx"));
54 54
55 // Action a test should take if a dangerous download is encountered. 55 // Action a test should take if a dangerous download is encountered.
56 enum DangerousDownloadAction { 56 enum DangerousDownloadAction {
57 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download 57 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download
58 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download 58 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download
59 ON_DANGEROUS_DOWNLOAD_IGNORE, // Don't do anything; calling code will handle.
59 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen 60 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen
60 }; 61 };
61 62
62 // Fake user click on "Accept". 63 // Fake user click on "Accept".
63 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, 64 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager,
64 int32 download_id) { 65 int32 download_id) {
65 DownloadItem* download = download_manager->GetDownloadItem(download_id); 66 DownloadItem* download = download_manager->GetDownloadItem(download_id);
66 download->DangerousDownloadValidated(); 67 download->DangerousDownloadValidated();
67 } 68 }
68 69
69 // Fake user click on "Deny". 70 // Fake user click on "Deny".
70 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, 71 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager,
71 int32 download_id) { 72 int32 download_id) {
72 DownloadItem* download = download_manager->GetDownloadItem(download_id); 73 DownloadItem* download = download_manager->GetDownloadItem(download_id);
73 ASSERT_TRUE(download->IsPartialDownload()); 74 ASSERT_TRUE(download->IsPartialDownload());
74 download->Cancel(true); 75 download->Cancel();
75 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 76 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
76 } 77 }
77 78
78 // Construction of this class defines a system state, based on some number 79 // Construction of this class defines a system state, based on some number
79 // of downloads being seen in a particular state + other events that 80 // of downloads being seen in a particular state + other events that
80 // may occur in the download system. That state will be recorded if it 81 // may occur in the download system. That state will be recorded if it
81 // occurs at any point after construction. When that state occurs, the class 82 // occurs at any point after construction. When that state occurs, the class
82 // is considered finished. Callers may either probe for the finished state, or 83 // is considered finished. Callers may either probe for the finished state, or
83 // wait on it. 84 // wait on it.
84 // 85 //
85 // TODO(rdsmith): Detect manager going down, remove pointer to 86 // TODO(rdsmith): Detect manager going down, remove pointer to
86 // DownloadManager, transition to finished. (For right now we 87 // DownloadManager, transition to finished. (For right now we
87 // just use a scoped_refptr<> to keep it around, but that may cause 88 // just use a scoped_refptr<> to keep it around, but that may cause
88 // timeouts on waiting if a DownloadManager::Shutdown() occurs which 89 // timeouts on waiting if a DownloadManager::Shutdown() occurs which
89 // cancels our in-progress downloads.) 90 // cancels our in-progress downloads.)
90 class DownloadsObserver : public DownloadManager::Observer, 91 class DownloadsObserver : public DownloadManager::Observer,
91 public DownloadItem::Observer { 92 public DownloadItem::Observer {
92 public: 93 public:
94 typedef std::set<DownloadItem::DownloadState> StateSet;
95
93 // Create an object that will be considered finished when |wait_count| 96 // Create an object that will be considered finished when |wait_count|
94 // download items have entered state |download_finished_state|. 97 // download items have entered any states in |download_finished_states|.
95 // If |finish_on_select_file| is true, the object will also be 98 // If |finish_on_select_file| is true, the object will also be
96 // considered finished if the DownloadManager raises a 99 // considered finished if the DownloadManager raises a
97 // SelectFileDialogDisplayed() notification. 100 // SelectFileDialogDisplayed() notification.
98 101
99 // TODO(rdsmith): Consider rewriting the interface to take a list of events 102 // TODO(rdsmith): Consider rewriting the interface to take a list of events
100 // to treat as completion events. 103 // to treat as completion events.
101 DownloadsObserver(DownloadManager* download_manager, 104 DownloadsObserver(DownloadManager* download_manager,
102 size_t wait_count, 105 size_t wait_count,
103 DownloadItem::DownloadState download_finished_state, 106 StateSet download_finished_states,
104 bool finish_on_select_file, 107 bool finish_on_select_file,
105 DangerousDownloadAction dangerous_download_action) 108 DangerousDownloadAction dangerous_download_action)
106 : download_manager_(download_manager), 109 : download_manager_(download_manager),
107 wait_count_(wait_count), 110 wait_count_(wait_count),
108 finished_downloads_at_construction_(0), 111 finished_downloads_at_construction_(0),
109 waiting_(false), 112 waiting_(false),
110 download_finished_state_(download_finished_state), 113 download_finished_states_(download_finished_states),
111 finish_on_select_file_(finish_on_select_file), 114 finish_on_select_file_(finish_on_select_file),
112 select_file_dialog_seen_(false), 115 select_file_dialog_seen_(false),
113 dangerous_download_action_(dangerous_download_action) { 116 dangerous_download_action_(dangerous_download_action) {
114 download_manager_->AddObserver(this); // Will call initial ModelChanged(). 117 download_manager_->AddObserver(this); // Will call initial ModelChanged().
115 finished_downloads_at_construction_ = finished_downloads_.size(); 118 finished_downloads_at_construction_ = finished_downloads_.size();
116 EXPECT_NE(DownloadItem::REMOVING, download_finished_state) 119 EXPECT_TRUE(download_finished_states.find(DownloadItem::REMOVING) ==
120 download_finished_states.end())
117 << "Waiting for REMOVING is not supported. Try COMPLETE."; 121 << "Waiting for REMOVING is not supported. Try COMPLETE.";
118 } 122 }
119 123
120 ~DownloadsObserver() { 124 ~DownloadsObserver() {
121 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); 125 std::set<DownloadItem*>::iterator it = downloads_observed_.begin();
122 for (; it != downloads_observed_.end(); ++it) 126 for (; it != downloads_observed_.end(); ++it)
123 (*it)->RemoveObserver(this); 127 (*it)->RemoveObserver(this);
124 128
125 download_manager_->RemoveObserver(this); 129 download_manager_->RemoveObserver(this);
126 } 130 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 NewRunnableFunction( 189 NewRunnableFunction(
186 &DenyDangerousDownload, 190 &DenyDangerousDownload,
187 download_manager_, 191 download_manager_,
188 download->id())); 192 download->id()));
189 break; 193 break;
190 194
191 case ON_DANGEROUS_DOWNLOAD_FAIL: 195 case ON_DANGEROUS_DOWNLOAD_FAIL:
192 ADD_FAILURE() << "Unexpected dangerous download item."; 196 ADD_FAILURE() << "Unexpected dangerous download item.";
193 break; 197 break;
194 198
199 case ON_DANGEROUS_DOWNLOAD_IGNORE:
200 break;
201
195 default: 202 default:
196 NOTREACHED(); 203 NOTREACHED();
197 } 204 }
198 } 205 }
199 206
200 if (download->state() == download_finished_state_) { 207 if (download_finished_states_.find(download->state()) !=
208 download_finished_states_.end()) {
201 DownloadInFinalState(download); 209 DownloadInFinalState(download);
202 } 210 }
203 } 211 }
204 212
205 virtual void OnDownloadOpened(DownloadItem* download) {} 213 virtual void OnDownloadOpened(DownloadItem* download) {}
206 214
207 // DownloadManager::Observer 215 // DownloadManager::Observer
208 virtual void ModelChanged() { 216 virtual void ModelChanged() {
209 // Regenerate DownloadItem observers. If there are any download items 217 // Regenerate DownloadItem observers. If there are any download items
210 // in our final state, note them in |finished_downloads_| 218 // in our final state, note them in |finished_downloads_|
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // construction and return from wait. But some downloads may be in our 301 // construction and return from wait. But some downloads may be in our
294 // final state (and thus be entered into |finished_downloads_|) when we 302 // final state (and thus be entered into |finished_downloads_|) when we
295 // construct this class. We don't want to count those in our transition 303 // construct this class. We don't want to count those in our transition
296 // to finished. 304 // to finished.
297 int finished_downloads_at_construction_; 305 int finished_downloads_at_construction_;
298 306
299 // Whether an internal message loop has been started and must be quit upon 307 // Whether an internal message loop has been started and must be quit upon
300 // all downloads completing. 308 // all downloads completing.
301 bool waiting_; 309 bool waiting_;
302 310
303 // The state on which to consider the DownloadItem finished. 311 // The states on which to consider the DownloadItem finished.
304 DownloadItem::DownloadState download_finished_state_; 312 StateSet download_finished_states_;
305 313
306 // True if we should transition the DownloadsObserver to finished if 314 // True if we should transition the DownloadsObserver to finished if
307 // the select file dialog comes up. 315 // the select file dialog comes up.
308 bool finish_on_select_file_; 316 bool finish_on_select_file_;
309 317
310 // True if we've seen the select file dialog. 318 // True if we've seen the select file dialog.
311 bool select_file_dialog_seen_; 319 bool select_file_dialog_seen_;
312 320
313 // Action to take if a dangerous download is encountered. 321 // Action to take if a dangerous download is encountered.
314 DangerousDownloadAction dangerous_download_action_; 322 DangerousDownloadAction dangerous_download_action_;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 490 }
483 491
484 ResourceDispatcherHost* resource_dispatcher_host_; 492 ResourceDispatcherHost* resource_dispatcher_host_;
485 DownloadFileManager* download_file_manager_; 493 DownloadFileManager* download_file_manager_;
486 int rdh_pending_requests_; 494 int rdh_pending_requests_;
487 int dfm_pending_downloads_; 495 int dfm_pending_downloads_;
488 496
489 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); 497 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector);
490 }; 498 };
491 499
500 static const DownloadItem::DownloadState kTerminalStates[] = {
501 DownloadItem::CANCELLED,
502 DownloadItem::INTERRUPTED,
503 DownloadItem::COMPLETE,
504 };
505
506 static const DownloadItem::DownloadState kInProgressStates[] = {
507 DownloadItem::IN_PROGRESS,
508 };
509
492 class DownloadTest : public InProcessBrowserTest { 510 class DownloadTest : public InProcessBrowserTest {
493 public: 511 public:
494 enum SelectExpectation { 512 enum SelectExpectation {
495 EXPECT_NO_SELECT_DIALOG = -1, 513 EXPECT_NO_SELECT_DIALOG = -1,
496 EXPECT_NOTHING, 514 EXPECT_NOTHING,
497 EXPECT_SELECT_DIALOG 515 EXPECT_SELECT_DIALOG
498 }; 516 };
499 517
500 DownloadTest() { 518 DownloadTest() {
501 EnableDOMAutomation(); 519 EnableDOMAutomation();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if (!downloads_directory_.CreateUniqueTempDir()) 576 if (!downloads_directory_.CreateUniqueTempDir())
559 return false; 577 return false;
560 578
561 browser->profile()->GetPrefs()->SetFilePath( 579 browser->profile()->GetPrefs()->SetFilePath(
562 prefs::kDownloadDefaultDirectory, 580 prefs::kDownloadDefaultDirectory,
563 downloads_directory_.path()); 581 downloads_directory_.path());
564 582
565 return true; 583 return true;
566 } 584 }
567 585
586 // For tests that want to test system reaction to files
587 // going away underneath them.
588 void DeleteDownloadsDirectory() {
589 EXPECT_TRUE(downloads_directory_.Delete());
590 }
591
568 DownloadPrefs* GetDownloadPrefs(Browser* browser) { 592 DownloadPrefs* GetDownloadPrefs(Browser* browser) {
569 return browser->profile()->GetDownloadManager()->download_prefs(); 593 return browser->profile()->GetDownloadManager()->download_prefs();
570 } 594 }
571 595
572 FilePath GetDownloadDirectory(Browser* browser) { 596 FilePath GetDownloadDirectory(Browser* browser) {
573 DownloadManager* download_mananger = 597 DownloadManager* download_mananger =
574 browser->profile()->GetDownloadManager(); 598 browser->profile()->GetDownloadManager();
575 return download_mananger->download_prefs()->download_path(); 599 return download_mananger->download_prefs()->download_path();
576 } 600 }
577 601
578 // Create a DownloadsObserver that will wait for the 602 // Create a DownloadsObserver that will wait for the
579 // specified number of downloads to finish. 603 // specified number of downloads to finish.
580 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { 604 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) {
581 DownloadManager* download_manager = 605 DownloadManager* download_manager =
582 browser->profile()->GetDownloadManager(); 606 browser->profile()->GetDownloadManager();
583 return new DownloadsObserver( 607 return new DownloadsObserver(
584 download_manager, num_downloads, 608 download_manager, num_downloads,
585 DownloadItem::COMPLETE, // Really done 609 DownloadsObserver::StateSet(
586 false, // Bail on select file 610 kTerminalStates, kTerminalStates + arraysize(kTerminalStates)),
611 true, // Bail on select file
587 ON_DANGEROUS_DOWNLOAD_FAIL); 612 ON_DANGEROUS_DOWNLOAD_FAIL);
588 } 613 }
589 614
590 // Create a DownloadsObserver that will wait for the 615 // Create a DownloadsObserver that will wait for the
616 // specified number of downloads to finish, and is
617 // ok with dangerous downloads. Note that use of this
618 // waiter is conditional on accepting the dangerous download.
619 DownloadsObserver* CreateDangerousWaiter(
620 Browser* browser, int num_downloads) {
621 DownloadManager* download_manager =
622 browser->profile()->GetDownloadManager();
623 return new DownloadsObserver(
624 download_manager, num_downloads,
625 DownloadsObserver::StateSet(
626 kTerminalStates, kTerminalStates + arraysize(kTerminalStates)),
627 true, // Bail on select file
628 ON_DANGEROUS_DOWNLOAD_IGNORE);
629 }
630
631 // Create a DownloadsObserver that will wait for the
591 // specified number of downloads to start. 632 // specified number of downloads to start.
592 DownloadsObserver* CreateInProgressWaiter(Browser* browser, 633 DownloadsObserver* CreateInProgressWaiter(Browser* browser,
593 int num_downloads) { 634 int num_downloads) {
594 DownloadManager* download_manager = 635 DownloadManager* download_manager =
595 browser->profile()->GetDownloadManager(); 636 browser->profile()->GetDownloadManager();
596 return new DownloadsObserver( 637 return new DownloadsObserver(
597 download_manager, num_downloads, 638 download_manager, num_downloads,
598 DownloadItem::IN_PROGRESS, // Has started 639 DownloadsObserver::StateSet(
640 kInProgressStates,
641 kInProgressStates + arraysize(kInProgressStates)),
599 true, // Bail on select file 642 true, // Bail on select file
600 ON_DANGEROUS_DOWNLOAD_FAIL); 643 ON_DANGEROUS_DOWNLOAD_IGNORE);
601 } 644 }
602 645
603 // Create a DownloadsObserver that will wait for the 646 // Create a DownloadsObserver that will wait for the
604 // specified number of downloads to finish, or for 647 // specified number of downloads to finish, or for
605 // a dangerous download warning to be shown. 648 // a dangerous download warning to be shown.
606 DownloadsObserver* DangerousInstallWaiter( 649 DownloadsObserver* DangerousInstallWaiter(
607 Browser* browser, 650 Browser* browser,
608 int num_downloads, 651 int num_downloads,
609 DownloadItem::DownloadState final_state, 652 DownloadItem::DownloadState final_state,
610 DangerousDownloadAction dangerous_download_action) { 653 DangerousDownloadAction dangerous_download_action) {
611 654
655 DownloadsObserver::StateSet states;
656 states.insert(final_state);
657
612 DownloadManager* download_manager = 658 DownloadManager* download_manager =
613 browser->profile()->GetDownloadManager(); 659 browser->profile()->GetDownloadManager();
614 return new DownloadsObserver( 660 return new DownloadsObserver(
615 download_manager, num_downloads, 661 download_manager, num_downloads,
616 final_state, 662 states,
617 true, // Bail on select file 663 true, // Bail on select file
618 dangerous_download_action); 664 dangerous_download_action);
619 } 665 }
620 666
621 // Download |url|, then wait for the download to finish. 667 // Download |url|, then wait for the download to finish.
622 // |disposition| indicates where the navigation occurs (current tab, new 668 // |disposition| indicates where the navigation occurs (current tab, new
623 // foreground tab, etc). 669 // foreground tab, etc).
624 // |expectation| indicates whether or not a Select File dialog should be 670 // |expectation| indicates whether or not a Select File dialog should be
625 // open when the download is finished, or if we don't care. 671 // open when the download is finished, or if we don't care.
626 // If the dialog appears, the routine exits. The only effect |expectation| 672 // If the dialog appears, the routine exits. The only effect |expectation|
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 EXPECT_EQ(1, browser()->tab_count()); 1004 EXPECT_EQ(1, browser()->tab_count());
959 FilePath downloaded_file(DestinationFile(browser(), file)); 1005 FilePath downloaded_file(DestinationFile(browser(), file));
960 if (file_util::VolumeSupportsADS(downloaded_file)) 1006 if (file_util::VolumeSupportsADS(downloaded_file))
961 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); 1007 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file));
962 CheckDownload(browser(), file, file); 1008 CheckDownload(browser(), file, file);
963 CheckDownloadUIVisible(browser(), true, true); 1009 CheckDownloadUIVisible(browser(), true, true);
964 } 1010 }
965 #endif 1011 #endif
966 1012
967 // Put up a Select File dialog when the file is downloaded, due to its MIME 1013 // Put up a Select File dialog when the file is downloaded, due to its MIME
968 // type. 1014 // type. Confirm that we can cancel the download in that state.
969 // 1015 IN_PROC_BROWSER_TEST_F(DownloadTest, CancelFromFileSelection) {
970 // This test runs correctly, but leaves behind turds in the test user's
971 // download directory because of http://crbug.com/62099. No big loss; it
972 // was primarily confirming DownloadsObserver wait on select file dialog
973 // functionality anyway.
974 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) {
975 ASSERT_TRUE(InitialSetup(true)); 1016 ASSERT_TRUE(InitialSetup(true));
976 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1017 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
977 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1018 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
978 1019
979 // Download the file and wait. We expect the Select File dialog to appear 1020 // Download the file and wait. We expect the Select File dialog to appear
980 // due to the MIME type. 1021 // due to the MIME type.
981 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); 1022 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG);
982 1023
1024 std::vector<DownloadItem*> active_downloads, history_downloads;
1025 browser()->profile()->GetDownloadManager()->GetInProgressDownloads(
1026 &active_downloads);
1027 ASSERT_EQ(1u, active_downloads.size());
1028 EXPECT_EQ(DownloadItem::IN_PROGRESS, active_downloads[0]->state());
1029 browser()->profile()->GetDownloadManager()->SearchDownloads(
1030 string16(), &history_downloads);
1031 EXPECT_EQ(0u, history_downloads.size());
1032
1033 // This should remove the download as it hasn't yet been entered into
1034 // the history.
1035 active_downloads[0]->Cancel();
1036
1037 active_downloads.clear();
1038 history_downloads.clear();
1039 browser()->profile()->GetDownloadManager()->GetInProgressDownloads(
1040 &active_downloads);
1041 EXPECT_EQ(0u, active_downloads.size());
1042 browser()->profile()->GetDownloadManager()->SearchDownloads(
1043 string16(), &history_downloads);
1044 EXPECT_EQ(0u, history_downloads.size());
1045
983 // Check state. 1046 // Check state.
984 EXPECT_EQ(1, browser()->tab_count()); 1047 EXPECT_EQ(1, browser()->tab_count());
985 // Since we exited while the Select File dialog was visible, there should not 1048 // Since we exited while the Select File dialog was visible, there should not
1049 // be anything in the download shelf and so it should not be visible.
1050 CheckDownloadUIVisible(browser(), false, false);
1051 }
1052
1053 // Put up a Select File dialog when the file is downloaded, due to its MIME
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 These comments about select file dialog appearing
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1054 // type. Confirm that we can remove the download in that state.
1055 IN_PROC_BROWSER_TEST_F(DownloadTest, RemoveFromFileSelection) {
1056 ASSERT_TRUE(InitialSetup(true));
1057 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1058 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1059
1060 // Download the file and wait. We expect the Select File dialog to appear
1061 // due to the MIME type.
1062 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG);
1063
1064 std::vector<DownloadItem*> active_downloads, history_downloads;
1065 browser()->profile()->GetDownloadManager()->GetInProgressDownloads(
1066 &active_downloads);
1067 ASSERT_EQ(1u, active_downloads.size());
1068 EXPECT_EQ(DownloadItem::IN_PROGRESS, active_downloads[0]->state());
1069 browser()->profile()->GetDownloadManager()->SearchDownloads(
1070 string16(), &history_downloads);
1071 EXPECT_EQ(0u, history_downloads.size());
1072
1073 active_downloads[0]->Remove();
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Comment: Confirm the file can be successfully remo
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1074
1075 active_downloads.clear();
1076 history_downloads.clear();
1077 browser()->profile()->GetDownloadManager()->GetInProgressDownloads(
1078 &active_downloads);
1079 EXPECT_EQ(0u, active_downloads.size());
1080 browser()->profile()->GetDownloadManager()->SearchDownloads(
1081 string16(), &history_downloads);
1082 EXPECT_EQ(0u, history_downloads.size());
1083
1084 // Check state.
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Remove comment.
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1085 EXPECT_EQ(1, browser()->tab_count());
1086 // Since we exited while the Select File dialog was visible, there should not
1087 // be anything in the download shelf and so it should not be visible.
1088 CheckDownloadUIVisible(browser(), false, false);
1089 }
1090
1091 // Put up a Select File dialog when the file is downloaded, due to its MIME
1092 // type. Confirm that an error coming in from the network works properly
1093 // when in that state.
1094 IN_PROC_BROWSER_TEST_F(DownloadTest, InterruptFromFileSelection) {
1095 ASSERT_TRUE(InitialSetup(true));
1096 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl);
1097
1098 // Download the file and wait. We expect the Select File dialog to appear
1099 // due to the MIME type.
1100 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG);
1101
1102 std::vector<DownloadItem*> active_downloads, history_downloads;
1103 browser()->profile()->GetDownloadManager()->GetInProgressDownloads(
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Consider making a download manager accessor. A bi
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Created new and used existing accessors for what I
1104 &active_downloads);
1105 ASSERT_EQ(1u, active_downloads.size());
1106 EXPECT_EQ(DownloadItem::IN_PROGRESS, active_downloads[0]->state());
1107 browser()->profile()->GetDownloadManager()->SearchDownloads(
1108 string16(), &history_downloads);
1109 EXPECT_EQ(0u, history_downloads.size());
1110
1111 // Complete the download with error.
1112 GURL error_url(URLRequestSlowDownloadJob::kErrorFinishDownloadUrl);
1113 ui_test_utils::NavigateToURL(browser(), error_url);
1114 MessageLoopForUI::current()->RunAllPending();
1115
1116 active_downloads.clear();
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Comment: Confirm that a download error before entr
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1117 history_downloads.clear();
1118 browser()->profile()->GetDownloadManager()->GetInProgressDownloads(
1119 &active_downloads);
1120 EXPECT_EQ(0u, active_downloads.size());
1121 browser()->profile()->GetDownloadManager()->SearchDownloads(
1122 string16(), &history_downloads);
1123 EXPECT_EQ(0u, history_downloads.size());
1124
1125 // Check state.
1126 EXPECT_EQ(1, browser()->tab_count());
1127 // Since we exited while the Select File dialog was visible, there should not
986 // be anything in the download shelf and so it should not be visible. 1128 // be anything in the download shelf and so it should not be visible.
987 CheckDownloadUIVisible(browser(), false, false); 1129 CheckDownloadUIVisible(browser(), false, false);
988 } 1130 }
989 1131
990 // Access a file with a viewable mime-type, verify that a download 1132 // Access a file with a viewable mime-type, verify that a download
991 // did not initiate. 1133 // did not initiate.
992 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { 1134 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
993 ASSERT_TRUE(InitialSetup(false)); 1135 ASSERT_TRUE(InitialSetup(false));
994 FilePath file(FILE_PATH_LITERAL("download-test2.html")); 1136 FilePath file(FILE_PATH_LITERAL("download-test2.html"));
995 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1137 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 EXPECT_EQ(0, info->rdh_pending_requests()); 1575 EXPECT_EQ(0, info->rdh_pending_requests());
1434 EXPECT_EQ(0, info->dfm_pending_downloads()); 1576 EXPECT_EQ(0, info->dfm_pending_downloads());
1435 1577
1436 // Using "DownloadItem::Remove" follows the discard dangerous download path, 1578 // Using "DownloadItem::Remove" follows the discard dangerous download path,
1437 // which completely removes the browser from the shelf and closes the shelf 1579 // which completely removes the browser from the shelf and closes the shelf
1438 // if it was there. Chrome OS is an exception to this, where if we 1580 // if it was there. Chrome OS is an exception to this, where if we
1439 // bring up the downloads panel, it stays there. 1581 // bring up the downloads panel, it stays there.
1440 CheckDownloadUIVisible(browser(), false, true); 1582 CheckDownloadUIVisible(browser(), false, true);
1441 } 1583 }
1442 1584
1585 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerous) {
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Comment explaining test.
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1586 ASSERT_TRUE(InitialSetup(false));
1587 FilePath file(FILE_PATH_LITERAL("download-dangerous.jar"));
1588 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1589
1590 EXPECT_EQ(1, browser()->tab_count());
1591
1592 scoped_ptr<DownloadsObserver> observer(
1593 CreateInProgressWaiter(browser(), 1));
1594 ui_test_utils::NavigateToURL(browser(), url);
1595 observer->WaitForFinished();
1596
1597 // We should have one download, in history, and it should
1598 // still be dangerous.
1599 std::vector<DownloadItem*> downloads;
1600 browser()->profile()->GetDownloadManager()->SearchDownloads(
1601 string16(), &downloads);
1602 ASSERT_EQ(1u, downloads.size());
1603 DownloadItem* download = downloads[0];
1604 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state());
1605 EXPECT_EQ(DownloadItem::DANGEROUS, download->safety_state());
1606 EXPECT_EQ(DownloadItem::DANGEROUS_FILE, download->GetDangerType());
1607 CheckDownloadUIVisible(browser(), true, true);
1608
1609 // See if accepting it does the right thing.
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Specify what the right thing is.
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1610 scoped_ptr<DownloadsObserver> completion_observer(
1611 CreateDangerousWaiter(browser(), 1));
1612 AcceptDangerousDownload(browser()->profile()->GetDownloadManager(),
1613 download->id());
1614 completion_observer->WaitForFinished();
1615
1616 downloads.clear();
1617 browser()->profile()->GetDownloadManager()->SearchDownloads(
1618 string16(), &downloads);
1619 ASSERT_EQ(1u, downloads.size());
1620 ASSERT_EQ(downloads[0], download);
1621 EXPECT_EQ(DownloadItem::COMPLETE, download->state());
1622 EXPECT_EQ(DownloadItem::DANGEROUS_BUT_VALIDATED, download->safety_state());
1623 CheckDownloadUIVisible(browser(), true, true);
1624 }
1625
1626 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousFileError) {
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Comment describing test.
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1627 ASSERT_TRUE(InitialSetup(false));
1628 FilePath file(FILE_PATH_LITERAL("download-dangerous.jar"));
1629 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1630
1631 EXPECT_EQ(1, browser()->tab_count());
1632
1633 scoped_ptr<DownloadsObserver> observer(
1634 CreateInProgressWaiter(browser(), 1));
1635 ui_test_utils::NavigateToURL(browser(), url);
1636 observer->WaitForFinished();
1637
1638 // We should have one download, in history, and it should
1639 // still be dangerous.
1640 std::vector<DownloadItem*> downloads;
1641 browser()->profile()->GetDownloadManager()->SearchDownloads(
1642 string16(), &downloads);
1643 ASSERT_EQ(1u, downloads.size());
1644 DownloadItem* download = downloads[0];
1645 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state());
1646 EXPECT_EQ(DownloadItem::DANGEROUS, download->safety_state());
1647 EXPECT_EQ(DownloadItem::DANGEROUS_FILE, download->GetDangerType());
1648 CheckDownloadUIVisible(browser(), true, true);
1649
1650 // Accept it after nuking the directory into which it's being downloaded;
1651 // that should complete the download with an error.
1652 DeleteDownloadsDirectory();
1653 scoped_ptr<DownloadsObserver> completion_observer(
1654 CreateDangerousWaiter(browser(), 1));
1655 AcceptDangerousDownload(browser()->profile()->GetDownloadManager(),
1656 download->id());
1657 completion_observer->WaitForFinished();
1658
1659 downloads.clear();
1660 browser()->profile()->GetDownloadManager()->SearchDownloads(
1661 string16(), &downloads);
1662 ASSERT_EQ(1u, downloads.size());
1663 ASSERT_EQ(downloads[0], download);
1664 // Persistent errors currently -> CANCELLED.
1665 EXPECT_EQ(DownloadItem::CANCELLED, download->state());
1666 EXPECT_EQ(DownloadItem::DANGEROUS_BUT_VALIDATED, download->safety_state());
1667 CheckDownloadUIVisible(browser(), true, true);
1668 }
1669
1670 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousDecline) {
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Comment explaining test.
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1671 ASSERT_TRUE(InitialSetup(false));
1672 FilePath file(FILE_PATH_LITERAL("download-dangerous.jar"));
1673 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1674
1675 EXPECT_EQ(1, browser()->tab_count());
1676
1677 scoped_ptr<DownloadsObserver> observer(
1678 CreateInProgressWaiter(browser(), 1));
1679 ui_test_utils::NavigateToURL(browser(), url);
1680 observer->WaitForFinished();
1681
1682 // We should have one download, in history, and it should
1683 // still be dangerous.
1684 std::vector<DownloadItem*> downloads;
1685 browser()->profile()->GetDownloadManager()->SearchDownloads(
1686 string16(), &downloads);
1687 ASSERT_EQ(1u, downloads.size());
1688 DownloadItem* download = downloads[0];
1689 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state());
1690 EXPECT_EQ(DownloadItem::DANGEROUS, download->safety_state());
1691 EXPECT_EQ(DownloadItem::DANGEROUS_FILE, download->GetDangerType());
1692 CheckDownloadUIVisible(browser(), true, true);
1693
1694 // See if declining it does the right thing.
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 Specify what the right thing is.
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Just deleted comment; initial comment has all need
1695 DenyDangerousDownload(browser()->profile()->GetDownloadManager(),
1696 download->id());
1697
1698 downloads.clear();
1699 browser()->profile()->GetDownloadManager()->SearchDownloads(
1700 string16(), &downloads);
1701 ASSERT_EQ(0u, downloads.size());
1702 CheckDownloadUIVisible(browser(), false, true);
1703 }
1704
1705
1706
1707 // Fail a download with a network error partway through, and make sure the
1708 // correct things happen.
Randy Smith (Not in Mondays) 2011/06/30 23:05:13 More specific about what the correct things are.
Randy Smith (Not in Mondays) 2011/07/05 20:28:44 Done.
1709 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadInterrupted) {
1710 ASSERT_TRUE(InitialSetup(false));
1711 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl);
1712
1713 scoped_ptr<DownloadsObserver> observer(
1714 CreateInProgressWaiter(browser(), 1));
1715 ui_test_utils::NavigateToURL(browser(), url);
1716 observer->WaitForFinished();
1717
1718 std::vector<DownloadItem*> downloads;
1719 browser()->profile()->GetDownloadManager()->SearchDownloads(
1720 string16(), &downloads);
1721 ASSERT_EQ(1u, downloads.size());
1722 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state());
1723 CheckDownloadUIVisible(browser(), true, true);
1724
1725 // Fail the download
1726 GURL error_url(URLRequestSlowDownloadJob::kErrorFinishDownloadUrl);
1727 ui_test_utils::NavigateToURL(browser(), error_url);
1728 MessageLoopForUI::current()->RunAllPending();
1729
1730 // Should still be visible, with INTERRUPTED state.
1731 downloads.clear();
1732 browser()->profile()->GetDownloadManager()->SearchDownloads(
1733 string16(), &downloads);
1734 ASSERT_EQ(1u, downloads.size());
1735 DownloadItem* download = downloads[0];
1736 ASSERT_EQ(DownloadItem::INTERRUPTED, download->state());
1737 CheckDownloadUIVisible(browser(), true, true);
1738
1739 // Confirm cancel does nothing.
1740 download->Cancel();
1741 MessageLoopForUI::current()->RunAllPending();
1742
1743 downloads.clear();
1744 browser()->profile()->GetDownloadManager()->SearchDownloads(
1745 string16(), &downloads);
1746 ASSERT_EQ(1u, downloads.size());
1747 ASSERT_EQ(download, downloads[0]);
1748 ASSERT_EQ(DownloadItem::INTERRUPTED, download->state());
1749 CheckDownloadUIVisible(browser(), true, true);
1750
1751 // Confirm remove gets rid of it.
1752 download->Remove();
1753 download = NULL;
1754 MessageLoopForUI::current()->RunAllPending();
1755
1756 downloads.clear();
1757 browser()->profile()->GetDownloadManager()->SearchDownloads(
1758 string16(), &downloads);
1759 ASSERT_EQ(0u, downloads.size());
1760 CheckDownloadUIVisible(browser(), false, true);
1761 }
1762
1443 // Confirm a download makes it into the history properly. 1763 // Confirm a download makes it into the history properly.
1444 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { 1764 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
1445 ASSERT_TRUE(InitialSetup(false)); 1765 ASSERT_TRUE(InitialSetup(false));
1446 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1766 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1447 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1767 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1448 FilePath origin_file(OriginFile(file)); 1768 FilePath origin_file(OriginFile(file));
1449 int64 origin_size; 1769 int64 origin_size;
1450 file_util::GetFileSize(origin_file, &origin_size); 1770 file_util::GetFileSize(origin_file, &origin_size);
1451 1771
1452 // Download the file and wait. We do not expect the Select File dialog. 1772 // Download the file and wait. We do not expect the Select File dialog.
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 2016 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1697 2017
1698 // DL Shelf should close. Download panel sticks around on ChromeOS. 2018 // DL Shelf should close. Download panel sticks around on ChromeOS.
1699 CheckDownloadUIVisible(browser(), false, true); 2019 CheckDownloadUIVisible(browser(), false, true);
1700 2020
1701 // Check that the extension was installed. 2021 // Check that the extension was installed.
1702 ExtensionService* extension_service = 2022 ExtensionService* extension_service =
1703 browser()->profile()->GetExtensionService(); 2023 browser()->profile()->GetExtensionService();
1704 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 2024 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1705 } 2025 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698