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

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

Issue 7324031: Revert 91861 - When the download folder does not exist, change the download folder to a user's "D... (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
« no previous file with comments | « chrome/browser/download/base_file.cc ('k') | chrome/browser/download/download_file_manager.cc » ('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 "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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ~DownloadsObserver() { 120 ~DownloadsObserver() {
121 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); 121 std::set<DownloadItem*>::iterator it = downloads_observed_.begin();
122 for (; it != downloads_observed_.end(); ++it) 122 for (; it != downloads_observed_.end(); ++it)
123 (*it)->RemoveObserver(this); 123 (*it)->RemoveObserver(this);
124 124
125 download_manager_->RemoveObserver(this); 125 download_manager_->RemoveObserver(this);
126 } 126 }
127 127
128 // State accessors. 128 // State accessors.
129 bool select_file_dialog_seen() { return select_file_dialog_seen_; } 129 bool select_file_dialog_seen() { return select_file_dialog_seen_; }
130 const FilePath& suggested_path() { return suggested_path_; }
131 130
132 // Wait for whatever state was specified in the constructor. 131 // Wait for whatever state was specified in the constructor.
133 void WaitForFinished() { 132 void WaitForFinished() {
134 if (!IsFinished()) { 133 if (!IsFinished()) {
135 waiting_ = true; 134 waiting_ = true;
136 ui_test_utils::RunMessageLoop(); 135 ui_test_utils::RunMessageLoop();
137 waiting_ = false; 136 waiting_ = false;
138 } 137 }
139 } 138 }
140 139
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // If it is finished and we are observing it, stop. 232 // If it is finished and we are observing it, stop.
234 if (finished_it != finished_downloads_.end() && 233 if (finished_it != finished_downloads_.end() &&
235 observed_it != downloads_observed_.end()) { 234 observed_it != downloads_observed_.end()) {
236 (*it)->RemoveObserver(this); 235 (*it)->RemoveObserver(this);
237 downloads_observed_.erase(observed_it); 236 downloads_observed_.erase(observed_it);
238 continue; 237 continue;
239 } 238 }
240 } 239 }
241 } 240 }
242 241
243 virtual void SelectFileDialogDisplayed( 242 virtual void SelectFileDialogDisplayed(int32 /* id */) {
244 int32 /* id */, const FilePath& suggested_path) {
245 select_file_dialog_seen_ = true; 243 select_file_dialog_seen_ = true;
246 suggested_path_ = suggested_path;
247 SignalIfFinished(); 244 SignalIfFinished();
248 } 245 }
249 246
250 virtual size_t NumDangerousDownloadsSeen() const { 247 virtual size_t NumDangerousDownloadsSeen() const {
251 return dangerous_downloads_seen_.size(); 248 return dangerous_downloads_seen_.size();
252 } 249 }
253 250
254 private: 251 private:
255 // Called when we know that a download item is in a final state. 252 // Called when we know that a download item is in a final state.
256 // Note that this is not the same as it first transitioning in to the 253 // Note that this is not the same as it first transitioning in to the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 309
313 // True if we've seen the select file dialog. 310 // True if we've seen the select file dialog.
314 bool select_file_dialog_seen_; 311 bool select_file_dialog_seen_;
315 312
316 // Action to take if a dangerous download is encountered. 313 // Action to take if a dangerous download is encountered.
317 DangerousDownloadAction dangerous_download_action_; 314 DangerousDownloadAction dangerous_download_action_;
318 315
319 // Holds the download ids which were dangerous. 316 // Holds the download ids which were dangerous.
320 std::set<int32> dangerous_downloads_seen_; 317 std::set<int32> dangerous_downloads_seen_;
321 318
322 // The suggested file path in the select file dialog.
323 FilePath suggested_path_;
324
325 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); 319 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver);
326 }; 320 };
327 321
328 // WaitForFlush() returns after: 322 // WaitForFlush() returns after:
329 // * There are no IN_PROGRESS download items remaining on the 323 // * There are no IN_PROGRESS download items remaining on the
330 // DownloadManager. 324 // DownloadManager.
331 // * There have been two round trip messages through the file and 325 // * There have been two round trip messages through the file and
332 // IO threads. 326 // IO threads.
333 // This almost certainly means that a Download cancel has propagated through 327 // This almost certainly means that a Download cancel has propagated through
334 // the system. 328 // the system.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 ResourceDispatcherHost* resource_dispatcher_host_; 484 ResourceDispatcherHost* resource_dispatcher_host_;
491 DownloadFileManager* download_file_manager_; 485 DownloadFileManager* download_file_manager_;
492 int rdh_pending_requests_; 486 int rdh_pending_requests_;
493 int dfm_pending_downloads_; 487 int dfm_pending_downloads_;
494 488
495 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); 489 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector);
496 }; 490 };
497 491
498 class DownloadTest : public InProcessBrowserTest { 492 class DownloadTest : public InProcessBrowserTest {
499 public: 493 public:
494 enum SelectExpectation {
495 EXPECT_NO_SELECT_DIALOG = -1,
496 EXPECT_NOTHING,
497 EXPECT_SELECT_DIALOG
498 };
499
500 DownloadTest() { 500 DownloadTest() {
501 EnableDOMAutomation(); 501 EnableDOMAutomation();
502 } 502 }
503 503
504 // Returning false indicates a failure of the setup, and should be asserted 504 // Returning false indicates a failure of the setup, and should be asserted
505 // in the caller. 505 // in the caller.
506 virtual bool InitialSetup(bool prompt_for_download) { 506 virtual bool InitialSetup(bool prompt_for_download) {
507 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); 507 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_);
508 EXPECT_TRUE(have_test_dir); 508 EXPECT_TRUE(have_test_dir);
509 if (!have_test_dir) 509 if (!have_test_dir)
(...skipping 27 matching lines...) Expand all
537 SIZE_TEST_TYPE_UNKNOWN, 537 SIZE_TEST_TYPE_UNKNOWN,
538 }; 538 };
539 539
540 // Location of the file source (the place from which it is downloaded). 540 // Location of the file source (the place from which it is downloaded).
541 FilePath OriginFile(FilePath file) { 541 FilePath OriginFile(FilePath file) {
542 return test_dir_.Append(file); 542 return test_dir_.Append(file);
543 } 543 }
544 544
545 // Location of the file destination (place to which it is downloaded). 545 // Location of the file destination (place to which it is downloaded).
546 FilePath DestinationFile(Browser* browser, FilePath file) { 546 FilePath DestinationFile(Browser* browser, FilePath file) {
547 return GetDownloadSaveDirectory(browser).Append(file); 547 return GetDownloadDirectory(browser).Append(file);
548 } 548 }
549 549
550 // Must be called after browser creation. Creates a temporary 550 // Must be called after browser creation. Creates a temporary
551 // directory for downloads that is auto-deleted on destruction. 551 // directory for downloads that is auto-deleted on destruction.
552 // Returning false indicates a failure of the function, and should be asserted 552 // Returning false indicates a failure of the function, and should be asserted
553 // in the caller. 553 // in the caller.
554 bool CreateAndSetDownloadsDirectory(Browser* browser) { 554 bool CreateAndSetDownloadsDirectory(Browser* browser) {
555 if (!browser) 555 if (!browser)
556 return false; 556 return false;
557 557
558 if (!downloads_directory_.CreateUniqueTempDir()) 558 if (!downloads_directory_.CreateUniqueTempDir())
559 return false; 559 return false;
560 560
561 browser->profile()->GetPrefs()->SetFilePath( 561 browser->profile()->GetPrefs()->SetFilePath(
562 prefs::kDownloadDefaultDirectory, 562 prefs::kDownloadDefaultDirectory,
563 downloads_directory_.path()); 563 downloads_directory_.path());
564 564
565 return true; 565 return true;
566 } 566 }
567 567
568 // Delete the default folder for downloaded files.
569 bool DeleteDownloadsDirectory() {
570 return downloads_directory_.Delete();
571 }
572
573 DownloadPrefs* GetDownloadPrefs(Browser* browser) { 568 DownloadPrefs* GetDownloadPrefs(Browser* browser) {
574 return browser->profile()->GetDownloadManager()->download_prefs(); 569 return browser->profile()->GetDownloadManager()->download_prefs();
575 } 570 }
576 571
577 FilePath GetDownloadSaveDirectory(Browser* browser) { 572 FilePath GetDownloadDirectory(Browser* browser) {
578 DownloadManager* download_mananger = 573 DownloadManager* download_mananger =
579 browser->profile()->GetDownloadManager(); 574 browser->profile()->GetDownloadManager();
580 return download_mananger->download_prefs()->download_path(); 575 return download_mananger->download_prefs()->download_path();
581 } 576 }
582 577
583 // Create a DownloadsObserver that will wait for the 578 // Create a DownloadsObserver that will wait for the
584 // specified number of downloads to finish. 579 // specified number of downloads to finish.
585 // If |finish_on_select_file| is true, the object will also be 580 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) {
586 // considered finished when the select file dialog is displayed.
587 DownloadsObserver* CreateWaiter(Browser* browser,
588 int num_downloads,
589 bool finish_on_select_file) {
590 DownloadManager* download_manager = 581 DownloadManager* download_manager =
591 browser->profile()->GetDownloadManager(); 582 browser->profile()->GetDownloadManager();
592 return new DownloadsObserver( 583 return new DownloadsObserver(
593 download_manager, num_downloads, 584 download_manager, num_downloads,
594 DownloadItem::COMPLETE, // Really done 585 DownloadItem::COMPLETE, // Really done
595 finish_on_select_file, // Bail on select file 586 false, // Bail on select file
596 ON_DANGEROUS_DOWNLOAD_FAIL); 587 ON_DANGEROUS_DOWNLOAD_FAIL);
597 } 588 }
598 589
599 // Create a DownloadsObserver that will wait for the 590 // Create a DownloadsObserver that will wait for the
600 // specified number of downloads to start. 591 // specified number of downloads to start.
601 DownloadsObserver* CreateInProgressWaiter(Browser* browser, 592 DownloadsObserver* CreateInProgressWaiter(Browser* browser,
602 int num_downloads) { 593 int num_downloads) {
603 DownloadManager* download_manager = 594 DownloadManager* download_manager =
604 browser->profile()->GetDownloadManager(); 595 browser->profile()->GetDownloadManager();
605 return new DownloadsObserver( 596 return new DownloadsObserver(
(...skipping 16 matching lines...) Expand all
622 return new DownloadsObserver( 613 return new DownloadsObserver(
623 download_manager, num_downloads, 614 download_manager, num_downloads,
624 final_state, 615 final_state,
625 true, // Bail on select file 616 true, // Bail on select file
626 dangerous_download_action); 617 dangerous_download_action);
627 } 618 }
628 619
629 // Download |url|, then wait for the download to finish. 620 // Download |url|, then wait for the download to finish.
630 // |disposition| indicates where the navigation occurs (current tab, new 621 // |disposition| indicates where the navigation occurs (current tab, new
631 // foreground tab, etc). 622 // foreground tab, etc).
632 // |expect_file_dialog| indicates whether a select file dialog should be 623 // |expectation| indicates whether or not a Select File dialog should be
633 // open when the download is finished, or if we don't care. 624 // open when the download is finished, or if we don't care.
634 // If the dialog appears, the routine exits. The only effect 625 // If the dialog appears, the routine exits. The only effect |expectation|
635 // |expect_file_dialog| has is whether or not the test succeeds. 626 // has is whether or not the test succeeds.
636 // |expected_suggested_path| is the path expected to be suggested in the
637 // select file dialog. This |expected_suggested_path| must be specified
638 // if |expect_file_dialog| is true. If |expect_file_dialog| is false,
639 // |expected_suggested_path| is ignored.
640 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more 627 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more
641 // values in the ui_test_utils::BrowserTestWaitFlags enum. 628 // values in the ui_test_utils::BrowserTestWaitFlags enum.
642 void DownloadAndWaitWithDisposition(Browser* browser, 629 void DownloadAndWaitWithDisposition(Browser* browser,
643 const GURL& url, 630 const GURL& url,
644 WindowOpenDisposition disposition, 631 WindowOpenDisposition disposition,
645 bool expect_file_dialog, 632 SelectExpectation expectation,
646 const FilePath& expected_suggested_path,
647 int browser_test_flags) { 633 int browser_test_flags) {
648 // Setup notification, navigate, and block. 634 // Setup notification, navigate, and block.
649 scoped_ptr<DownloadsObserver> observer( 635 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1));
650 CreateWaiter(browser, 1, expect_file_dialog));
651 // This call will block until the condition specified by 636 // This call will block until the condition specified by
652 // |browser_test_flags|, but will not wait for the download to finish. 637 // |browser_test_flags|, but will not wait for the download to finish.
653 ui_test_utils::NavigateToURLWithDisposition(browser, 638 ui_test_utils::NavigateToURLWithDisposition(browser,
654 url, 639 url,
655 disposition, 640 disposition,
656 browser_test_flags); 641 browser_test_flags);
657 // Waits for the download to complete. 642 // Waits for the download to complete.
658 observer->WaitForFinished(); 643 observer->WaitForFinished();
659 644
660 // Checks if the select file dialog was displayed as expected. 645 // If specified, check the state of the select file dialog.
661 // If displayed, checks the suggested path in the dialog. 646 if (expectation != EXPECT_NOTHING) {
662 if (expect_file_dialog) { 647 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG,
663 EXPECT_TRUE(observer->select_file_dialog_seen()); 648 observer->select_file_dialog_seen());
664 EXPECT_EQ(observer->suggested_path(), expected_suggested_path);
665 } else {
666 EXPECT_FALSE(observer->select_file_dialog_seen());
667 } 649 }
668 } 650 }
669 651
670 // Download a file in the current tab, then wait for the download to finish. 652 // Download a file in the current tab, then wait for the download to finish.
671 // Expect that no select file dialog is displayed. 653 void DownloadAndWait(Browser* browser,
672 void DownloadAndWait(Browser* browser, const GURL& url) { 654 const GURL& url,
655 SelectExpectation expectation) {
673 DownloadAndWaitWithDisposition( 656 DownloadAndWaitWithDisposition(
674 browser, url, CURRENT_TAB, false, FilePath(), 657 browser,
675 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 658 url,
676 } 659 CURRENT_TAB,
677 660 expectation,
678 // Download a file in the current tab, then wait for the download to finish.
679 // Expect that a select file dialog suggesting |expected_suggested_path|
680 // is displayed.
681 void DownloadAndWaitWithDialog(Browser* browser, const GURL& url,
682 const FilePath& expected_suggested_path) {
683 DownloadAndWaitWithDisposition(
684 browser, url, CURRENT_TAB, true, expected_suggested_path,
685 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 661 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
686 } 662 }
687 663
688 // Should only be called when the download is known to have finished 664 // Should only be called when the download is known to have finished
689 // (in error or not). 665 // (in error or not).
690 // Returning false indicates a failure of the function, and should be asserted 666 // Returning false indicates a failure of the function, and should be asserted
691 // in the caller. 667 // in the caller.
692 bool CheckDownload(Browser* browser, 668 bool CheckDownload(Browser* browser,
693 const FilePath& downloaded_filename, 669 const FilePath& downloaded_filename,
694 const FilePath& origin_filename) { 670 const FilePath& origin_filename) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 // |expected_title_finished| need to be checked. 716 // |expected_title_finished| need to be checked.
741 FilePath filename; 717 FilePath filename;
742 net::FileURLToFilePath(url, &filename); 718 net::FileURLToFilePath(url, &filename);
743 string16 expected_title_in_progress( 719 string16 expected_title_in_progress(
744 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); 720 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName());
745 string16 expected_title_finished( 721 string16 expected_title_finished(
746 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); 722 ASCIIToUTF16(total_indication) + filename.LossyDisplayName());
747 723
748 // Download a partial web page in a background tab and wait. 724 // Download a partial web page in a background tab and wait.
749 // The mock system will not complete until it gets a special URL. 725 // The mock system will not complete until it gets a special URL.
750 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1, false)); 726 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1));
751 ui_test_utils::NavigateToURL(browser, url); 727 ui_test_utils::NavigateToURL(browser, url);
752 728
753 // TODO(ahendrickson): check download status text before downloading. 729 // TODO(ahendrickson): check download status text before downloading.
754 // Need to: 730 // Need to:
755 // - Add a member function to the |DownloadShelf| interface class, that 731 // - Add a member function to the |DownloadShelf| interface class, that
756 // indicates how many members it has. 732 // indicates how many members it has.
757 // - Add a member function to |DownloadShelf| to get the status text 733 // - Add a member function to |DownloadShelf| to get the status text
758 // of a given member (for example, via the name in |DownloadItemView|'s 734 // of a given member (for example, via the name in |DownloadItemView|'s
759 // GetAccessibleState() member function), by index. 735 // GetAccessibleState() member function), by index.
760 // - Iterate over browser->window()->GetDownloadShelf()'s members 736 // - Iterate over browser->window()->GetDownloadShelf()'s members
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 // Files for these tests are found in DIR_TEST_DATA (currently 941 // Files for these tests are found in DIR_TEST_DATA (currently
966 // "chrome\test\data\", see chrome_paths.cc). 942 // "chrome\test\data\", see chrome_paths.cc).
967 // Mock responses have extension .mock-http-headers appended to the file name. 943 // Mock responses have extension .mock-http-headers appended to the file name.
968 944
969 // Download a file due to the associated MIME type. 945 // Download a file due to the associated MIME type.
970 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { 946 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) {
971 ASSERT_TRUE(InitialSetup(false)); 947 ASSERT_TRUE(InitialSetup(false));
972 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 948 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
973 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 949 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
974 950
975 // Download the file and wait. 951 // Download the file and wait. We do not expect the Select File dialog.
976 DownloadAndWait(browser(), url); 952 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
977 953
978 // Check state. 954 // Check state.
979 EXPECT_EQ(1, browser()->tab_count()); 955 EXPECT_EQ(1, browser()->tab_count());
980 CheckDownload(browser(), file, file); 956 CheckDownload(browser(), file, file);
981 CheckDownloadUI(browser(), true, true, file); 957 CheckDownloadUI(browser(), true, true, file);
982 } 958 }
983 959
984 // Checks if a file is saved to the user's "Downloads" folder
985 // in the following situation:
986 // The default folder for downloaded files does not exist.
987 // The user's "Downloads" folder exists.
988 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadFolder) {
989 ASSERT_TRUE(InitialSetup(false));
990 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
991 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
992
993 FilePath default_download_dir =
994 download_util::GetDefaultDownloadDirectoryFromPathService();
995 FilePath downloaded_file = default_download_dir.Append(file);
996
997 // Delete the default folder for downloaded files.
998 ASSERT_TRUE(DeleteDownloadsDirectory());
999 ASSERT_FALSE(file_util::PathExists(GetDownloadSaveDirectory(browser())));
1000
1001 // Download the file and wait.
1002 DownloadAndWaitWithDialog(browser(), url, downloaded_file);
1003
1004 EXPECT_FALSE(file_util::PathExists(downloaded_file));
1005 EXPECT_FALSE(file_util::PathExists(GetDownloadSaveDirectory(browser())));
1006 EXPECT_EQ(1, browser()->tab_count());
1007 }
1008
1009 #if defined(OS_WIN) 960 #if defined(OS_WIN)
1010 // Download a file and confirm that the zone identifier (on windows) 961 // Download a file and confirm that the zone identifier (on windows)
1011 // is set to internet. 962 // is set to internet.
1012 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { 963 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) {
1013 ASSERT_TRUE(InitialSetup(false)); 964 ASSERT_TRUE(InitialSetup(false));
1014 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 965 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1015 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 966 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1016 967
1017 // Download the file and wait. 968 // Download the file and wait. We do not expect the Select File dialog.
1018 DownloadAndWait(browser(), url); 969 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1019 970
1020 // Check state. Special file state must be checked before CheckDownload, 971 // Check state. Special file state must be checked before CheckDownload,
1021 // as CheckDownload will delete the output file. 972 // as CheckDownload will delete the output file.
1022 EXPECT_EQ(1, browser()->tab_count()); 973 EXPECT_EQ(1, browser()->tab_count());
1023 FilePath downloaded_file(DestinationFile(browser(), file)); 974 FilePath downloaded_file(DestinationFile(browser(), file));
1024 if (file_util::VolumeSupportsADS(downloaded_file)) 975 if (file_util::VolumeSupportsADS(downloaded_file))
1025 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); 976 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file));
1026 CheckDownload(browser(), file, file); 977 CheckDownload(browser(), file, file);
1027 CheckDownloadUI(browser(), true, true, file); 978 CheckDownloadUI(browser(), true, true, file);
1028 } 979 }
1029 #endif 980 #endif
1030 981
1031 // Put up a select file dialog when the file is downloaded, due to its MIME 982 // Put up a Select File dialog when the file is downloaded, due to its MIME
1032 // type. 983 // type.
1033 // 984 //
1034 // This test runs correctly, but leaves behind turds in the test user's 985 // This test runs correctly, but leaves behind turds in the test user's
1035 // download directory because of http://crbug.com/62099. No big loss; it 986 // download directory because of http://crbug.com/62099. No big loss; it
1036 // was primarily confirming DownloadsObserver wait on select file dialog 987 // was primarily confirming DownloadsObserver wait on select file dialog
1037 // functionality anyway. 988 // functionality anyway.
1038 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { 989 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) {
1039 ASSERT_TRUE(InitialSetup(true)); 990 ASSERT_TRUE(InitialSetup(true));
1040 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 991 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1041 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 992 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1042 FilePath file_path(DestinationFile(browser(), file));
1043 993
1044 // Download the file and wait. We expect the select file dialog to appear 994 // Download the file and wait. We expect the Select File dialog to appear
1045 // due to the MIME type. 995 // due to the MIME type.
1046 DownloadAndWaitWithDialog(browser(), url, file_path); 996 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG);
1047 997
1048 // Check state. 998 // Check state.
1049 EXPECT_EQ(1, browser()->tab_count()); 999 EXPECT_EQ(1, browser()->tab_count());
1050 // Since we exited while the select file dialog was visible, there should not 1000 // Since we exited while the Select File dialog was visible, there should not
1051 // be anything in the download shelf and so it should not be visible. 1001 // be anything in the download shelf and so it should not be visible.
1052 CheckDownloadUI(browser(), false, false, FilePath()); 1002 CheckDownloadUI(browser(), false, false, FilePath());
1053 } 1003 }
1054 1004
1055 // Access a file with a viewable mime-type, verify that a download 1005 // Access a file with a viewable mime-type, verify that a download
1056 // did not initiate. 1006 // did not initiate.
1057 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { 1007 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
1058 ASSERT_TRUE(InitialSetup(false)); 1008 ASSERT_TRUE(InitialSetup(false));
1059 FilePath file(FILE_PATH_LITERAL("download-test2.html")); 1009 FilePath file(FILE_PATH_LITERAL("download-test2.html"));
1060 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1010 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
(...skipping 14 matching lines...) Expand all
1075 // download tab opened and the file exists as the filename specified in the 1025 // download tab opened and the file exists as the filename specified in the
1076 // header. This also ensures we properly handle empty file downloads. 1026 // header. This also ensures we properly handle empty file downloads.
1077 // The download shelf should be visible in the current tab. 1027 // The download shelf should be visible in the current tab.
1078 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { 1028 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) {
1079 ASSERT_TRUE(InitialSetup(false)); 1029 ASSERT_TRUE(InitialSetup(false));
1080 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1030 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1081 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1031 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1082 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1032 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
1083 1033
1084 // Download a file and wait. 1034 // Download a file and wait.
1085 DownloadAndWait(browser(), url); 1035 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1086 1036
1087 CheckDownload(browser(), download_file, file); 1037 CheckDownload(browser(), download_file, file);
1088 1038
1089 // Check state. 1039 // Check state.
1090 EXPECT_EQ(1, browser()->tab_count()); 1040 EXPECT_EQ(1, browser()->tab_count());
1091 CheckDownloadUI(browser(), true, true, download_file); 1041 CheckDownloadUI(browser(), true, true, download_file);
1092 } 1042 }
1093 1043
1094 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. 1044 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS.
1095 // Test that the download shelf is per-window by starting a download in one 1045 // Test that the download shelf is per-window by starting a download in one
1096 // tab, opening a second tab, closing the shelf, going back to the first tab, 1046 // tab, opening a second tab, closing the shelf, going back to the first tab,
1097 // and checking that the shelf is closed. 1047 // and checking that the shelf is closed.
1098 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { 1048 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) {
1099 ASSERT_TRUE(InitialSetup(false)); 1049 ASSERT_TRUE(InitialSetup(false));
1100 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1050 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1101 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1051 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1102 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1052 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
1103 1053
1104 // Download a file and wait. 1054 // Download a file and wait.
1105 DownloadAndWait(browser(), url); 1055 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1106 1056
1107 CheckDownload(browser(), download_file, file); 1057 CheckDownload(browser(), download_file, file);
1108 1058
1109 // Check state. 1059 // Check state.
1110 EXPECT_EQ(1, browser()->tab_count()); 1060 EXPECT_EQ(1, browser()->tab_count());
1111 CheckDownloadUI(browser(), true, true, download_file); 1061 CheckDownloadUI(browser(), true, true, download_file);
1112 1062
1113 // Open a second tab and wait. 1063 // Open a second tab and wait.
1114 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), 1064 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL),
1115 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); 1065 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 int window_count = BrowserList::size(); 1110 int window_count = BrowserList::size();
1161 EXPECT_EQ(2, window_count); 1111 EXPECT_EQ(2, window_count);
1162 1112
1163 // Download a file in the Incognito window and wait. 1113 // Download a file in the Incognito window and wait.
1164 CreateAndSetDownloadsDirectory(incognito); 1114 CreateAndSetDownloadsDirectory(incognito);
1165 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1115 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1166 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1116 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1167 // Since |incognito| is a separate browser, we have to set it up explicitly. 1117 // Since |incognito| is a separate browser, we have to set it up explicitly.
1168 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, 1118 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
1169 false); 1119 false);
1170 DownloadAndWait(incognito, url); 1120 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG);
1171 1121
1172 // We should still have 2 windows. 1122 // We should still have 2 windows.
1173 ExpectWindowCountAfterDownload(2); 1123 ExpectWindowCountAfterDownload(2);
1174 1124
1175 // Verify that the download shelf is showing for the Incognito window. 1125 // Verify that the download shelf is showing for the Incognito window.
1176 CheckDownloadUI(incognito, true, true, file); 1126 CheckDownloadUI(incognito, true, true, file);
1177 1127
1178 #if !defined(OS_MACOSX) 1128 #if !defined(OS_MACOSX)
1179 // On Mac OS X, the UI window close is delayed until the outermost 1129 // On Mac OS X, the UI window close is delayed until the outermost
1180 // message loop runs. So it isn't possible to get a BROWSER_CLOSED 1130 // message loop runs. So it isn't possible to get a BROWSER_CLOSED
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 ASSERT_TRUE(InitialSetup(false)); 1177 ASSERT_TRUE(InitialSetup(false));
1228 1178
1229 // Download a file in a new background tab and wait. The tab is automatically 1179 // Download a file in a new background tab and wait. The tab is automatically
1230 // closed when the download begins. 1180 // closed when the download begins.
1231 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1181 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1232 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1182 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1233 DownloadAndWaitWithDisposition( 1183 DownloadAndWaitWithDisposition(
1234 browser(), 1184 browser(),
1235 url, 1185 url,
1236 NEW_BACKGROUND_TAB, 1186 NEW_BACKGROUND_TAB,
1237 false, 1187 EXPECT_NO_SELECT_DIALOG,
1238 FilePath(),
1239 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1188 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1240 1189
1241 // When the download finishes, we should still have one tab. 1190 // When the download finishes, we should still have one tab.
1242 CheckDownloadUI(browser(), true, true, file); 1191 CheckDownloadUI(browser(), true, true, file);
1243 EXPECT_EQ(1, browser()->tab_count()); 1192 EXPECT_EQ(1, browser()->tab_count());
1244 1193
1245 CheckDownload(browser(), file, file); 1194 CheckDownload(browser(), file, file);
1246 } 1195 }
1247 1196
1248 // Open a web page in the current tab, then download a file in another tab via 1197 // Open a web page in the current tab, then download a file in another tab via
(...skipping 11 matching lines...) Expand all
1260 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); 1209 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
1261 1210
1262 // Open a web page and wait. 1211 // Open a web page and wait.
1263 ui_test_utils::NavigateToURL(browser(), url); 1212 ui_test_utils::NavigateToURL(browser(), url);
1264 1213
1265 // Download a file in a new tab and wait (via Javascript). 1214 // Download a file in a new tab and wait (via Javascript).
1266 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1215 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1267 DownloadAndWaitWithDisposition(browser(), 1216 DownloadAndWaitWithDisposition(browser(),
1268 GURL("javascript:openNew()"), 1217 GURL("javascript:openNew()"),
1269 CURRENT_TAB, 1218 CURRENT_TAB,
1270 false, 1219 EXPECT_NO_SELECT_DIALOG,
1271 FilePath(),
1272 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1220 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1273 1221
1274 // When the download finishes, we should have two tabs. 1222 // When the download finishes, we should have two tabs.
1275 CheckDownloadUI(browser(), true, true, file); 1223 CheckDownloadUI(browser(), true, true, file);
1276 EXPECT_EQ(2, browser()->tab_count()); 1224 EXPECT_EQ(2, browser()->tab_count());
1277 1225
1278 CheckDownload(browser(), file, file); 1226 CheckDownload(browser(), file, file);
1279 } 1227 }
1280 1228
1281 // Open a web page in the current tab, open another tab via a Javascript call, 1229 // Open a web page in the current tab, open another tab via a Javascript call,
(...skipping 21 matching lines...) Expand all
1303 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1251 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1304 1252
1305 EXPECT_EQ(2, browser()->tab_count()); 1253 EXPECT_EQ(2, browser()->tab_count());
1306 1254
1307 // Download a file and wait. 1255 // Download a file and wait.
1308 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1256 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1309 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1257 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1310 DownloadAndWaitWithDisposition(browser(), 1258 DownloadAndWaitWithDisposition(browser(),
1311 url, 1259 url,
1312 CURRENT_TAB, 1260 CURRENT_TAB,
1313 false, 1261 EXPECT_NO_SELECT_DIALOG,
1314 FilePath(),
1315 ui_test_utils::BROWSER_TEST_NONE); 1262 ui_test_utils::BROWSER_TEST_NONE);
1316 1263
1317 // When the download finishes, we should have two tabs. 1264 // When the download finishes, we should have two tabs.
1318 CheckDownloadUI(browser(), true, true, file); 1265 CheckDownloadUI(browser(), true, true, file);
1319 EXPECT_EQ(2, browser()->tab_count()); 1266 EXPECT_EQ(2, browser()->tab_count());
1320 1267
1321 CheckDownload(browser(), file, file); 1268 CheckDownload(browser(), file, file);
1322 } 1269 }
1323 1270
1324 // Open a web page in the current tab, then download a file via Javascript, 1271 // Open a web page in the current tab, then download a file via Javascript,
(...skipping 12 matching lines...) Expand all
1337 1284
1338 // Open a web page and wait. 1285 // Open a web page and wait.
1339 ui_test_utils::NavigateToURL(browser(), url); 1286 ui_test_utils::NavigateToURL(browser(), url);
1340 1287
1341 // Download a file and wait. 1288 // Download a file and wait.
1342 // The file to download is "download-test1.lib". 1289 // The file to download is "download-test1.lib".
1343 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1290 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1344 DownloadAndWaitWithDisposition(browser(), 1291 DownloadAndWaitWithDisposition(browser(),
1345 GURL("javascript:openNew()"), 1292 GURL("javascript:openNew()"),
1346 CURRENT_TAB, 1293 CURRENT_TAB,
1347 false, 1294 EXPECT_NO_SELECT_DIALOG,
1348 FilePath(),
1349 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1295 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1350 1296
1351 // When the download finishes, we should still have one tab. 1297 // When the download finishes, we should still have one tab.
1352 CheckDownloadUI(browser(), true, true, file); 1298 CheckDownloadUI(browser(), true, true, file);
1353 EXPECT_EQ(1, browser()->tab_count()); 1299 EXPECT_EQ(1, browser()->tab_count());
1354 1300
1355 CheckDownload(browser(), file, file); 1301 CheckDownload(browser(), file, file);
1356 } 1302 }
1357 1303
1358 // Open a web page in the current tab, then call Javascript via a button to 1304 // Open a web page in the current tab, then call Javascript via a button to
(...skipping 14 matching lines...) Expand all
1373 ui_test_utils::NavigateToURL(browser(), url); 1319 ui_test_utils::NavigateToURL(browser(), url);
1374 1320
1375 // Download a file in a new tab and wait. The tab will automatically close 1321 // Download a file in a new tab and wait. The tab will automatically close
1376 // when the download begins. 1322 // when the download begins.
1377 // The file to download is "download-test1.lib". 1323 // The file to download is "download-test1.lib".
1378 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1324 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1379 DownloadAndWaitWithDisposition( 1325 DownloadAndWaitWithDisposition(
1380 browser(), 1326 browser(),
1381 GURL("javascript:document.getElementById('form').submit()"), 1327 GURL("javascript:document.getElementById('form').submit()"),
1382 CURRENT_TAB, 1328 CURRENT_TAB,
1383 false, 1329 EXPECT_NO_SELECT_DIALOG,
1384 FilePath(),
1385 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1330 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1386 1331
1387 // When the download finishes, we should still have one tab. 1332 // When the download finishes, we should still have one tab.
1388 CheckDownloadUI(browser(), true, true, file); 1333 CheckDownloadUI(browser(), true, true, file);
1389 EXPECT_EQ(1, browser()->tab_count()); 1334 EXPECT_EQ(1, browser()->tab_count());
1390 1335
1391 CheckDownload(browser(), file, file); 1336 CheckDownload(browser(), file, file);
1392 } 1337 }
1393 1338
1394 // Download a file in a new window. 1339 // Download a file in a new window.
1395 // Verify that we have 2 windows, and the download shelf is not visible in the 1340 // Verify that we have 2 windows, and the download shelf is not visible in the
1396 // first window, but is visible in the second window. 1341 // first window, but is visible in the second window.
1397 // Close the new window. 1342 // Close the new window.
1398 // Verify that we have 1 window, and the download shelf is not visible. 1343 // Verify that we have 1 window, and the download shelf is not visible.
1399 // 1344 //
1400 // Regression test for http://crbug.com/44454 1345 // Regression test for http://crbug.com/44454
1401 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { 1346 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) {
1402 ASSERT_TRUE(InitialSetup(false)); 1347 ASSERT_TRUE(InitialSetup(false));
1403 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1348 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1404 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1349 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1405 #if !defined(OS_MACOSX) 1350 #if !defined(OS_MACOSX)
1406 // See below. 1351 // See below.
1407 Browser* first_browser = browser(); 1352 Browser* first_browser = browser();
1408 #endif 1353 #endif
1409 1354
1410 // Download a file in a new window and wait. 1355 // Download a file in a new window and wait.
1411 DownloadAndWaitWithDisposition(browser(), 1356 DownloadAndWaitWithDisposition(browser(),
1412 url, 1357 url,
1413 NEW_WINDOW, 1358 NEW_WINDOW,
1414 false, 1359 EXPECT_NO_SELECT_DIALOG,
1415 FilePath(),
1416 ui_test_utils::BROWSER_TEST_NONE); 1360 ui_test_utils::BROWSER_TEST_NONE);
1417 1361
1418 // When the download finishes, the download shelf SHOULD NOT be visible in 1362 // When the download finishes, the download shelf SHOULD NOT be visible in
1419 // the first window. 1363 // the first window.
1420 ExpectWindowCountAfterDownload(2); 1364 ExpectWindowCountAfterDownload(2);
1421 EXPECT_EQ(1, browser()->tab_count()); 1365 EXPECT_EQ(1, browser()->tab_count());
1422 // Download shelf should close. Download panel stays open on ChromeOS. 1366 // Download shelf should close. Download panel stays open on ChromeOS.
1423 CheckDownloadUI(browser(), false, true, file); 1367 CheckDownloadUI(browser(), false, true, file);
1424 1368
1425 // The download shelf SHOULD be visible in the second window. 1369 // The download shelf SHOULD be visible in the second window.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 1456
1513 // Confirm a download makes it into the history properly. 1457 // Confirm a download makes it into the history properly.
1514 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { 1458 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
1515 ASSERT_TRUE(InitialSetup(false)); 1459 ASSERT_TRUE(InitialSetup(false));
1516 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1460 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1517 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1461 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1518 FilePath origin_file(OriginFile(file)); 1462 FilePath origin_file(OriginFile(file));
1519 int64 origin_size; 1463 int64 origin_size;
1520 file_util::GetFileSize(origin_file, &origin_size); 1464 file_util::GetFileSize(origin_file, &origin_size);
1521 1465
1522 // Download the file and wait. 1466 // Download the file and wait. We do not expect the Select File dialog.
1523 DownloadAndWait(browser(), url); 1467 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1524 1468
1525 // Get details of what downloads have just happened. 1469 // Get details of what downloads have just happened.
1526 std::vector<DownloadItem*> downloads; 1470 std::vector<DownloadItem*> downloads;
1527 GetDownloads(browser(), &downloads); 1471 GetDownloads(browser(), &downloads);
1528 ASSERT_EQ(1u, downloads.size()); 1472 ASSERT_EQ(1u, downloads.size());
1529 int64 db_handle = downloads[0]->db_handle(); 1473 int64 db_handle = downloads[0]->db_handle();
1530 1474
1531 // Check state. 1475 // Check state.
1532 EXPECT_EQ(1, browser()->tab_count()); 1476 EXPECT_EQ(1, browser()->tab_count());
1533 CheckDownload(browser(), file, file); 1477 CheckDownload(browser(), file, file);
(...skipping 16 matching lines...) Expand all
1550 // Test for crbug.com/14505. This tests that chrome:// urls are still functional 1494 // Test for crbug.com/14505. This tests that chrome:// urls are still functional
1551 // after download of a file while viewing another chrome://. 1495 // after download of a file while viewing another chrome://.
1552 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { 1496 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) {
1553 ASSERT_TRUE(InitialSetup(false)); 1497 ASSERT_TRUE(InitialSetup(false));
1554 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1498 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1555 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1499 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1556 GURL flags_url(chrome::kChromeUIFlagsURL); 1500 GURL flags_url(chrome::kChromeUIFlagsURL);
1557 GURL extensions_url(chrome::kChromeUIExtensionsURL); 1501 GURL extensions_url(chrome::kChromeUIExtensionsURL);
1558 1502
1559 ui_test_utils::NavigateToURL(browser(), flags_url); 1503 ui_test_utils::NavigateToURL(browser(), flags_url);
1560 DownloadAndWait(browser(), download_url); 1504 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
1561 ui_test_utils::NavigateToURL(browser(), extensions_url); 1505 ui_test_utils::NavigateToURL(browser(), extensions_url);
1562 TabContents* contents = browser()->GetSelectedTabContents(); 1506 TabContents* contents = browser()->GetSelectedTabContents();
1563 ASSERT_TRUE(contents); 1507 ASSERT_TRUE(contents);
1564 bool webui_responded = false; 1508 bool webui_responded = false;
1565 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1509 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
1566 contents->render_view_host(), 1510 contents->render_view_host(),
1567 L"", 1511 L"",
1568 L"window.domAutomationController.send(window.webui_responded_);", 1512 L"window.domAutomationController.send(window.webui_responded_);",
1569 &webui_responded)); 1513 &webui_responded));
1570 EXPECT_TRUE(webui_responded); 1514 EXPECT_TRUE(webui_responded);
(...skipping 16 matching lines...) Expand all
1587 ASSERT_TRUE(contents); 1531 ASSERT_TRUE(contents);
1588 bool result = false; 1532 bool result = false;
1589 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1533 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
1590 contents->render_view_host(), 1534 contents->render_view_host(),
1591 L"", 1535 L"",
1592 L"window.onunload = function() { var do_nothing = 0; }; " 1536 L"window.onunload = function() { var do_nothing = 0; }; "
1593 L"window.domAutomationController.send(true);", 1537 L"window.domAutomationController.send(true);",
1594 &result)); 1538 &result));
1595 EXPECT_TRUE(result); 1539 EXPECT_TRUE(result);
1596 1540
1597 DownloadAndWait(browser(), download_url); 1541 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
1598 1542
1599 ui_test_utils::WindowedNotificationObserver signal( 1543 ui_test_utils::WindowedNotificationObserver signal(
1600 NotificationType::BROWSER_CLOSED, 1544 NotificationType::BROWSER_CLOSED,
1601 Source<Browser>(browser())); 1545 Source<Browser>(browser()));
1602 browser()->CloseWindow(); 1546 browser()->CloseWindow();
1603 signal.Wait(); 1547 signal.Wait();
1604 } 1548 }
1605 1549
1606 // Test to make sure auto-open works. 1550 // Test to make sure auto-open works.
1607 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { 1551 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) {
1608 ASSERT_TRUE(InitialSetup(false)); 1552 ASSERT_TRUE(InitialSetup(false));
1609 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); 1553 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt"));
1610 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1554 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1611 1555
1612 ASSERT_TRUE( 1556 ASSERT_TRUE(
1613 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); 1557 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file));
1614 1558
1615 // Mock out external opening on all downloads until end of test. 1559 // Mock out external opening on all downloads until end of test.
1616 MockDownloadOpeningObserver observer( 1560 MockDownloadOpeningObserver observer(
1617 browser()->profile()->GetDownloadManager()); 1561 browser()->profile()->GetDownloadManager());
1618 1562
1619 DownloadAndWait(browser(), url); 1563 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1620 1564
1621 // Find the download and confirm it was opened. 1565 // Find the download and confirm it was opened.
1622 std::vector<DownloadItem*> downloads; 1566 std::vector<DownloadItem*> downloads;
1623 browser()->profile()->GetDownloadManager()->SearchDownloads( 1567 browser()->profile()->GetDownloadManager()->SearchDownloads(
1624 string16(), &downloads); 1568 string16(), &downloads);
1625 ASSERT_EQ(1u, downloads.size()); 1569 ASSERT_EQ(1u, downloads.size());
1626 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); 1570 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state());
1627 EXPECT_TRUE(downloads[0]->opened()); 1571 EXPECT_TRUE(downloads[0]->opened());
1628 1572
1629 // As long as we're here, confirmed everything else is good. 1573 // As long as we're here, confirmed everything else is good.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1710 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1767 1711
1768 // Download shelf should close. Download panel stays open on ChromeOS. 1712 // Download shelf should close. Download panel stays open on ChromeOS.
1769 CheckDownloadUI(browser(), false, true, FilePath()); 1713 CheckDownloadUI(browser(), false, true, FilePath());
1770 1714
1771 // Check that the extension was installed. 1715 // Check that the extension was installed.
1772 ExtensionService* extension_service = 1716 ExtensionService* extension_service =
1773 browser()->profile()->GetExtensionService(); 1717 browser()->profile()->GetExtensionService();
1774 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 1718 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1775 } 1719 }
OLDNEW
« no previous file with comments | « chrome/browser/download/base_file.cc ('k') | chrome/browser/download/download_file_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698