OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "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.h" | 10 #include "base/stl_util.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
49 // IDs and paths of CRX files used in tests. | 49 // IDs and paths of CRX files used in tests. |
50 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 50 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
51 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 51 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
52 | 52 |
53 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 53 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
54 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); | 54 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
55 | 55 |
| 56 // The contents of a downloaded file. |
| 57 const char kContentsOfTestFile[] = "abcdefghijklmnopqrstuvwxyz"; |
| 58 |
56 // Action a test should take if a dangerous download is encountered. | 59 // Action a test should take if a dangerous download is encountered. |
57 enum DangerousDownloadAction { | 60 enum DangerousDownloadAction { |
58 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download | 61 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download |
59 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download | 62 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download |
60 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen | 63 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen |
61 }; | 64 }; |
62 | 65 |
63 // Fake user click on "Accept". | 66 // Fake user click on "Accept". |
64 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, | 67 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
65 int32 download_id) { | 68 int32 download_id) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 ~DownloadsObserver() { | 124 ~DownloadsObserver() { |
122 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | 125 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); |
123 for (; it != downloads_observed_.end(); ++it) | 126 for (; it != downloads_observed_.end(); ++it) |
124 (*it)->RemoveObserver(this); | 127 (*it)->RemoveObserver(this); |
125 | 128 |
126 download_manager_->RemoveObserver(this); | 129 download_manager_->RemoveObserver(this); |
127 } | 130 } |
128 | 131 |
129 // State accessors. | 132 // State accessors. |
130 bool select_file_dialog_seen() { return select_file_dialog_seen_; } | 133 bool select_file_dialog_seen() { return select_file_dialog_seen_; } |
| 134 const FilePath& suggested_path() { return suggested_path_; } |
131 | 135 |
132 // Wait for whatever state was specified in the constructor. | 136 // Wait for whatever state was specified in the constructor. |
133 void WaitForFinished() { | 137 void WaitForFinished() { |
134 if (!IsFinished()) { | 138 if (!IsFinished()) { |
135 waiting_ = true; | 139 waiting_ = true; |
136 ui_test_utils::RunMessageLoop(); | 140 ui_test_utils::RunMessageLoop(); |
137 waiting_ = false; | 141 waiting_ = false; |
138 } | 142 } |
139 } | 143 } |
140 | 144 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // If it is finished and we are observing it, stop. | 237 // If it is finished and we are observing it, stop. |
234 if (finished_it != finished_downloads_.end() && | 238 if (finished_it != finished_downloads_.end() && |
235 observed_it != downloads_observed_.end()) { | 239 observed_it != downloads_observed_.end()) { |
236 (*it)->RemoveObserver(this); | 240 (*it)->RemoveObserver(this); |
237 downloads_observed_.erase(observed_it); | 241 downloads_observed_.erase(observed_it); |
238 continue; | 242 continue; |
239 } | 243 } |
240 } | 244 } |
241 } | 245 } |
242 | 246 |
243 virtual void SelectFileDialogDisplayed(int32 /* id */) { | 247 virtual void SelectFileDialogDisplayed( |
| 248 int32 /* id */, const FilePath& suggested_path) { |
244 select_file_dialog_seen_ = true; | 249 select_file_dialog_seen_ = true; |
| 250 suggested_path_ = suggested_path; |
245 SignalIfFinished(); | 251 SignalIfFinished(); |
246 } | 252 } |
247 | 253 |
248 virtual size_t NumDangerousDownloadsSeen() const { | 254 virtual size_t NumDangerousDownloadsSeen() const { |
249 return dangerous_downloads_seen_.size(); | 255 return dangerous_downloads_seen_.size(); |
250 } | 256 } |
251 | 257 |
252 private: | 258 private: |
253 // Called when we know that a download item is in a final state. | 259 // Called when we know that a download item is in a final state. |
254 // Note that this is not the same as it first transitioning in to the | 260 // 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 Loading... |
310 | 316 |
311 // True if we've seen the select file dialog. | 317 // True if we've seen the select file dialog. |
312 bool select_file_dialog_seen_; | 318 bool select_file_dialog_seen_; |
313 | 319 |
314 // Action to take if a dangerous download is encountered. | 320 // Action to take if a dangerous download is encountered. |
315 DangerousDownloadAction dangerous_download_action_; | 321 DangerousDownloadAction dangerous_download_action_; |
316 | 322 |
317 // Holds the download ids which were dangerous. | 323 // Holds the download ids which were dangerous. |
318 std::set<int32> dangerous_downloads_seen_; | 324 std::set<int32> dangerous_downloads_seen_; |
319 | 325 |
| 326 // The suggested file path in the select file dialog. |
| 327 FilePath suggested_path_; |
| 328 |
320 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); | 329 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); |
321 }; | 330 }; |
322 | 331 |
323 // WaitForFlush() returns after: | 332 // WaitForFlush() returns after: |
324 // * There are no IN_PROGRESS download items remaining on the | 333 // * There are no IN_PROGRESS download items remaining on the |
325 // DownloadManager. | 334 // DownloadManager. |
326 // * There have been two round trip messages through the file and | 335 // * There have been two round trip messages through the file and |
327 // IO threads. | 336 // IO threads. |
328 // This almost certainly means that a Download cancel has propagated through | 337 // This almost certainly means that a Download cancel has propagated through |
329 // the system. | 338 // the system. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 ResourceDispatcherHost* resource_dispatcher_host_; | 494 ResourceDispatcherHost* resource_dispatcher_host_; |
486 DownloadFileManager* download_file_manager_; | 495 DownloadFileManager* download_file_manager_; |
487 int rdh_pending_requests_; | 496 int rdh_pending_requests_; |
488 int dfm_pending_downloads_; | 497 int dfm_pending_downloads_; |
489 | 498 |
490 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); | 499 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); |
491 }; | 500 }; |
492 | 501 |
493 class DownloadTest : public InProcessBrowserTest { | 502 class DownloadTest : public InProcessBrowserTest { |
494 public: | 503 public: |
495 enum SelectExpectation { | |
496 EXPECT_NO_SELECT_DIALOG = -1, | |
497 EXPECT_NOTHING, | |
498 EXPECT_SELECT_DIALOG | |
499 }; | |
500 | |
501 DownloadTest() { | 504 DownloadTest() { |
502 EnableDOMAutomation(); | 505 EnableDOMAutomation(); |
503 } | 506 } |
504 | 507 |
505 // Returning false indicates a failure of the setup, and should be asserted | 508 // Returning false indicates a failure of the setup, and should be asserted |
506 // in the caller. | 509 // in the caller. |
507 virtual bool InitialSetup(bool prompt_for_download) { | 510 virtual bool InitialSetup(bool prompt_for_download) { |
508 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); | 511 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); |
509 EXPECT_TRUE(have_test_dir); | 512 EXPECT_TRUE(have_test_dir); |
510 if (!have_test_dir) | 513 if (!have_test_dir) |
(...skipping 27 matching lines...) Expand all Loading... |
538 SIZE_TEST_TYPE_UNKNOWN, | 541 SIZE_TEST_TYPE_UNKNOWN, |
539 }; | 542 }; |
540 | 543 |
541 // Location of the file source (the place from which it is downloaded). | 544 // Location of the file source (the place from which it is downloaded). |
542 FilePath OriginFile(FilePath file) { | 545 FilePath OriginFile(FilePath file) { |
543 return test_dir_.Append(file); | 546 return test_dir_.Append(file); |
544 } | 547 } |
545 | 548 |
546 // Location of the file destination (place to which it is downloaded). | 549 // Location of the file destination (place to which it is downloaded). |
547 FilePath DestinationFile(Browser* browser, FilePath file) { | 550 FilePath DestinationFile(Browser* browser, FilePath file) { |
548 return GetDownloadDirectory(browser).Append(file); | 551 return GetDownloadSaveDirectory(browser).Append(file); |
549 } | 552 } |
550 | 553 |
551 // Must be called after browser creation. Creates a temporary | 554 // Must be called after browser creation. Creates a temporary |
552 // directory for downloads that is auto-deleted on destruction. | 555 // directory for downloads that is auto-deleted on destruction. |
553 // Returning false indicates a failure of the function, and should be asserted | 556 // Returning false indicates a failure of the function, and should be asserted |
554 // in the caller. | 557 // in the caller. |
555 bool CreateAndSetDownloadsDirectory(Browser* browser) { | 558 bool CreateAndSetDownloadsDirectory(Browser* browser) { |
556 if (!browser) | 559 if (!browser) |
557 return false; | 560 return false; |
558 | 561 |
559 if (!downloads_directory_.CreateUniqueTempDir()) | 562 if (!downloads_directory_.CreateUniqueTempDir()) |
560 return false; | 563 return false; |
561 | 564 |
562 browser->profile()->GetPrefs()->SetFilePath( | 565 browser->profile()->GetPrefs()->SetFilePath( |
563 prefs::kDownloadDefaultDirectory, | 566 prefs::kDownloadDefaultDirectory, |
564 downloads_directory_.path()); | 567 downloads_directory_.path()); |
565 | 568 |
566 return true; | 569 return true; |
567 } | 570 } |
568 | 571 |
| 572 // Delete the default folder for downloaded files. |
| 573 bool DeleteDownloadsDirectory() { |
| 574 return downloads_directory_.Delete(); |
| 575 } |
| 576 |
569 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 577 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
570 return browser->profile()->GetDownloadManager()->download_prefs(); | 578 return browser->profile()->GetDownloadManager()->download_prefs(); |
571 } | 579 } |
572 | 580 |
573 FilePath GetDownloadDirectory(Browser* browser) { | 581 FilePath GetDownloadSaveDirectory(Browser* browser) { |
574 DownloadManager* download_mananger = | 582 DownloadManager* download_mananger = |
575 browser->profile()->GetDownloadManager(); | 583 browser->profile()->GetDownloadManager(); |
576 return download_mananger->download_prefs()->download_path(); | 584 return download_mananger->download_prefs()->download_path(); |
577 } | 585 } |
578 | 586 |
579 // Create a DownloadsObserver that will wait for the | 587 // Create a DownloadsObserver that will wait for the |
580 // specified number of downloads to finish. | 588 // specified number of downloads to finish. |
581 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { | 589 // If |finish_on_select_file| is true, the object will also be |
| 590 // considered finished when the select file dialog is displayed. |
| 591 DownloadsObserver* CreateWaiter(Browser* browser, |
| 592 int num_downloads, |
| 593 bool finish_on_select_file) { |
582 DownloadManager* download_manager = | 594 DownloadManager* download_manager = |
583 browser->profile()->GetDownloadManager(); | 595 browser->profile()->GetDownloadManager(); |
584 return new DownloadsObserver( | 596 return new DownloadsObserver( |
585 download_manager, num_downloads, | 597 download_manager, num_downloads, |
586 DownloadItem::COMPLETE, // Really done | 598 DownloadItem::COMPLETE, // Really done |
587 false, // Bail on select file | 599 finish_on_select_file, // Bail on select file |
588 ON_DANGEROUS_DOWNLOAD_FAIL); | 600 ON_DANGEROUS_DOWNLOAD_FAIL); |
589 } | 601 } |
590 | 602 |
591 // Create a DownloadsObserver that will wait for the | 603 // Create a DownloadsObserver that will wait for the |
592 // specified number of downloads to start. | 604 // specified number of downloads to start. |
593 DownloadsObserver* CreateInProgressWaiter(Browser* browser, | 605 DownloadsObserver* CreateInProgressWaiter(Browser* browser, |
594 int num_downloads) { | 606 int num_downloads) { |
595 DownloadManager* download_manager = | 607 DownloadManager* download_manager = |
596 browser->profile()->GetDownloadManager(); | 608 browser->profile()->GetDownloadManager(); |
597 return new DownloadsObserver( | 609 return new DownloadsObserver( |
(...skipping 16 matching lines...) Expand all Loading... |
614 return new DownloadsObserver( | 626 return new DownloadsObserver( |
615 download_manager, num_downloads, | 627 download_manager, num_downloads, |
616 final_state, | 628 final_state, |
617 true, // Bail on select file | 629 true, // Bail on select file |
618 dangerous_download_action); | 630 dangerous_download_action); |
619 } | 631 } |
620 | 632 |
621 // Download |url|, then wait for the download to finish. | 633 // Download |url|, then wait for the download to finish. |
622 // |disposition| indicates where the navigation occurs (current tab, new | 634 // |disposition| indicates where the navigation occurs (current tab, new |
623 // foreground tab, etc). | 635 // foreground tab, etc). |
624 // |expectation| indicates whether or not a Select File dialog should be | 636 // |expect_file_dialog| indicates whether a select file dialog should be |
625 // open when the download is finished, or if we don't care. | 637 // open when the download is finished, or if we don't care. |
626 // If the dialog appears, the routine exits. The only effect |expectation| | 638 // If the dialog appears, the routine exits. The only effect |
627 // has is whether or not the test succeeds. | 639 // |expect_file_dialog| has is whether or not the test succeeds. |
| 640 // |expected_suggested_path| is the path expected to be suggested in the |
| 641 // select file dialog. This |expected_suggested_path| must be specified |
| 642 // if |expect_file_dialog| is true. If |expect_file_dialog| is false, |
| 643 // |expected_suggested_path| is ignored. |
628 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 644 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
629 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 645 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
630 void DownloadAndWaitWithDisposition(Browser* browser, | 646 void DownloadAndWaitWithDisposition(Browser* browser, |
631 const GURL& url, | 647 const GURL& url, |
632 WindowOpenDisposition disposition, | 648 WindowOpenDisposition disposition, |
633 SelectExpectation expectation, | 649 bool expect_file_dialog, |
| 650 const FilePath& expected_suggested_path, |
634 int browser_test_flags) { | 651 int browser_test_flags) { |
635 // Setup notification, navigate, and block. | 652 // Setup notification, navigate, and block. |
636 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 653 scoped_ptr<DownloadsObserver> observer( |
| 654 CreateWaiter(browser, 1, expect_file_dialog)); |
637 // This call will block until the condition specified by | 655 // This call will block until the condition specified by |
638 // |browser_test_flags|, but will not wait for the download to finish. | 656 // |browser_test_flags|, but will not wait for the download to finish. |
639 ui_test_utils::NavigateToURLWithDisposition(browser, | 657 ui_test_utils::NavigateToURLWithDisposition(browser, |
640 url, | 658 url, |
641 disposition, | 659 disposition, |
642 browser_test_flags); | 660 browser_test_flags); |
643 // Waits for the download to complete. | 661 // Waits for the download to complete. |
644 observer->WaitForFinished(); | 662 observer->WaitForFinished(); |
645 | 663 |
646 // If specified, check the state of the select file dialog. | 664 // Checks if the select file dialog was displayed as expected. |
647 if (expectation != EXPECT_NOTHING) { | 665 // If displayed, checks the suggested path in the dialog. |
648 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, | 666 if (expect_file_dialog) { |
649 observer->select_file_dialog_seen()); | 667 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 668 EXPECT_EQ(observer->suggested_path(), expected_suggested_path); |
| 669 } else { |
| 670 EXPECT_FALSE(observer->select_file_dialog_seen()); |
650 } | 671 } |
651 } | 672 } |
652 | 673 |
653 // Download a file in the current tab, then wait for the download to finish. | 674 // Download a file in the current tab, then wait for the download to finish. |
654 void DownloadAndWait(Browser* browser, | 675 // Expect that no select file dialog is displayed. |
655 const GURL& url, | 676 void DownloadAndWait(Browser* browser, const GURL& url) { |
656 SelectExpectation expectation) { | |
657 DownloadAndWaitWithDisposition( | 677 DownloadAndWaitWithDisposition( |
658 browser, | 678 browser, url, CURRENT_TAB, false, FilePath(), |
659 url, | |
660 CURRENT_TAB, | |
661 expectation, | |
662 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 679 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
663 } | 680 } |
664 | 681 |
| 682 // Download a file in the current tab, then wait for the download to finish. |
| 683 // Expect that a select file dialog suggesting |expected_suggested_path| |
| 684 // is displayed. |
| 685 void DownloadAndWaitWithDialog(Browser* browser, const GURL& url, |
| 686 const FilePath& expected_suggested_path) { |
| 687 DownloadAndWaitWithDisposition( |
| 688 browser, url, CURRENT_TAB, true, expected_suggested_path, |
| 689 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 690 } |
| 691 |
665 // Should only be called when the download is known to have finished | 692 // Should only be called when the download is known to have finished |
666 // (in error or not). | 693 // (in error or not). |
667 // Returning false indicates a failure of the function, and should be asserted | 694 // Returning false indicates a failure of the function, and should be asserted |
668 // in the caller. | 695 // in the caller. |
669 bool CheckDownload(Browser* browser, | 696 bool CheckDownload(Browser* browser, |
670 const FilePath& downloaded_filename, | 697 const FilePath& downloaded_filename, |
671 const FilePath& origin_filename) { | 698 const FilePath& origin_filename) { |
672 // Find the path to which the data will be downloaded. | 699 // Find the path to which the data will be downloaded. |
673 FilePath downloaded_file(DestinationFile(browser, downloaded_filename)); | 700 FilePath downloaded_file(DestinationFile(browser, downloaded_filename)); |
674 | 701 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 // |expected_title_finished| need to be checked. | 744 // |expected_title_finished| need to be checked. |
718 FilePath filename; | 745 FilePath filename; |
719 net::FileURLToFilePath(url, &filename); | 746 net::FileURLToFilePath(url, &filename); |
720 string16 expected_title_in_progress( | 747 string16 expected_title_in_progress( |
721 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); | 748 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); |
722 string16 expected_title_finished( | 749 string16 expected_title_finished( |
723 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); | 750 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); |
724 | 751 |
725 // Download a partial web page in a background tab and wait. | 752 // Download a partial web page in a background tab and wait. |
726 // The mock system will not complete until it gets a special URL. | 753 // The mock system will not complete until it gets a special URL. |
727 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 754 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1, false)); |
728 ui_test_utils::NavigateToURL(browser, url); | 755 ui_test_utils::NavigateToURL(browser, url); |
729 | 756 |
730 // TODO(ahendrickson): check download status text before downloading. | 757 // TODO(ahendrickson): check download status text before downloading. |
731 // Need to: | 758 // Need to: |
732 // - Add a member function to the |DownloadShelf| interface class, that | 759 // - Add a member function to the |DownloadShelf| interface class, that |
733 // indicates how many members it has. | 760 // indicates how many members it has. |
734 // - Add a member function to |DownloadShelf| to get the status text | 761 // - Add a member function to |DownloadShelf| to get the status text |
735 // of a given member (for example, via the name in |DownloadItemView|'s | 762 // of a given member (for example, via the name in |DownloadItemView|'s |
736 // GetAccessibleState() member function), by index. | 763 // GetAccessibleState() member function), by index. |
737 // - Iterate over browser->window()->GetDownloadShelf()'s members | 764 // - Iterate over browser->window()->GetDownloadShelf()'s members |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 // Files for these tests are found in DIR_TEST_DATA (currently | 969 // Files for these tests are found in DIR_TEST_DATA (currently |
943 // "chrome\test\data\", see chrome_paths.cc). | 970 // "chrome\test\data\", see chrome_paths.cc). |
944 // Mock responses have extension .mock-http-headers appended to the file name. | 971 // Mock responses have extension .mock-http-headers appended to the file name. |
945 | 972 |
946 // Download a file due to the associated MIME type. | 973 // Download a file due to the associated MIME type. |
947 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 974 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
948 ASSERT_TRUE(InitialSetup(false)); | 975 ASSERT_TRUE(InitialSetup(false)); |
949 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 976 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
950 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 977 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
951 | 978 |
952 // Download the file and wait. We do not expect the Select File dialog. | 979 // Download the file and wait. |
953 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 980 DownloadAndWait(browser(), url); |
954 | 981 |
955 // Check state. | 982 // Check state. |
956 EXPECT_EQ(1, browser()->tab_count()); | 983 EXPECT_EQ(1, browser()->tab_count()); |
957 CheckDownload(browser(), file, file); | 984 CheckDownload(browser(), file, file); |
958 CheckDownloadUI(browser(), true, true, file); | 985 CheckDownloadUI(browser(), true, true, file); |
959 } | 986 } |
960 | 987 |
| 988 // Checks if a file is saved to the user's "Downloads" folder |
| 989 // in the following situation: |
| 990 // The default folder for downloaded files does not exist. |
| 991 // The user's "Downloads" folder exists. |
| 992 // |
| 993 // This test creates and deletes a file on the user's "Downloads" folder, |
| 994 // which is globally shared among all tests on the environment. Therefore, |
| 995 // if we run browser tests in parallel, the file created by one browser test |
| 996 // may be deleted by another brower test in case where the file name conflicts. |
| 997 // In order to avoid this problem, we create a temporary file with a unique name |
| 998 // in chrome/test/data/ folder and use the temporary file for this test. |
| 999 // |
| 1000 // Ideally, in the first place, we should not use the user's "Downloads" folder. |
| 1001 // Instead, we should create a temporary "Downloads" folder for each test. |
| 1002 // However, we concluded that creating temporary "Downloads" folder for each |
| 1003 // test requires very invasive code changes to many places. See also here: |
| 1004 // http://codereview.chromium.org/6973052/ |
| 1005 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadFolder) { |
| 1006 ASSERT_TRUE(InitialSetup(false)); |
| 1007 ScopedTempDir scoped_temp_dir; |
| 1008 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 1009 // Creates a temporary file with a unique name. |
| 1010 FilePath unique_file; |
| 1011 ASSERT_TRUE(file_util::CreateTemporaryFileInDir( |
| 1012 scoped_temp_dir.path(), &unique_file)); |
| 1013 // Adds "test" prefix to the temporary file, so that the file name starts |
| 1014 // with an ascii character and thus the file is handled as a normal file. |
| 1015 FilePath file = unique_file.DirName(). |
| 1016 Append(FILE_PATH_LITERAL("test") + unique_file.BaseName().value()); |
| 1017 ASSERT_TRUE(file_util::Move(unique_file, file)); |
| 1018 ASSERT_TRUE(file_util::WriteFile(file, |
| 1019 kContentsOfTestFile, |
| 1020 ARRAYSIZE_UNSAFE(kContentsOfTestFile))); |
| 1021 GURL url(URLRequestMockHTTPJob::GetMockUrlOfTempDir( |
| 1022 scoped_temp_dir.path().BaseName().Append(file.BaseName()))); |
| 1023 |
| 1024 FilePath default_download_dir = |
| 1025 download_util::GetDefaultDownloadDirectoryFromPathService(); |
| 1026 FilePath downloaded_file = default_download_dir.Append(file.BaseName()); |
| 1027 // Make sure that the target file does not exist. |
| 1028 file_util::Delete(downloaded_file, false); |
| 1029 // Make sure that the temporary file does not exist. |
| 1030 FilePath temporary_file = |
| 1031 downloaded_file.Append(FILE_PATH_LITERAL(".crdownload")); |
| 1032 file_util::Delete(temporary_file, false); |
| 1033 |
| 1034 // Delete the default folder for downloaded files. |
| 1035 ASSERT_TRUE(DeleteDownloadsDirectory()); |
| 1036 ASSERT_FALSE(file_util::PathExists(GetDownloadSaveDirectory(browser()))); |
| 1037 |
| 1038 // Download the file and wait. |
| 1039 DownloadAndWaitWithDialog(browser(), url, downloaded_file); |
| 1040 |
| 1041 EXPECT_FALSE(file_util::PathExists(downloaded_file)); |
| 1042 EXPECT_FALSE(file_util::PathExists(GetDownloadSaveDirectory(browser()))); |
| 1043 EXPECT_EQ(1, browser()->tab_count()); |
| 1044 |
| 1045 // Clean up the generated files. |
| 1046 file_util::Delete(downloaded_file, false); |
| 1047 file_util::Delete(temporary_file, false); |
| 1048 } |
| 1049 |
961 #if defined(OS_WIN) | 1050 #if defined(OS_WIN) |
962 // Download a file and confirm that the zone identifier (on windows) | 1051 // Download a file and confirm that the zone identifier (on windows) |
963 // is set to internet. | 1052 // is set to internet. |
964 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 1053 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
965 ASSERT_TRUE(InitialSetup(false)); | 1054 ASSERT_TRUE(InitialSetup(false)); |
966 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1055 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
967 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1056 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
968 | 1057 |
969 // Download the file and wait. We do not expect the Select File dialog. | 1058 // Download the file and wait. |
970 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1059 DownloadAndWait(browser(), url); |
971 | 1060 |
972 // Check state. Special file state must be checked before CheckDownload, | 1061 // Check state. Special file state must be checked before CheckDownload, |
973 // as CheckDownload will delete the output file. | 1062 // as CheckDownload will delete the output file. |
974 EXPECT_EQ(1, browser()->tab_count()); | 1063 EXPECT_EQ(1, browser()->tab_count()); |
975 FilePath downloaded_file(DestinationFile(browser(), file)); | 1064 FilePath downloaded_file(DestinationFile(browser(), file)); |
976 if (file_util::VolumeSupportsADS(downloaded_file)) | 1065 if (file_util::VolumeSupportsADS(downloaded_file)) |
977 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); | 1066 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
978 CheckDownload(browser(), file, file); | 1067 CheckDownload(browser(), file, file); |
979 CheckDownloadUI(browser(), true, true, file); | 1068 CheckDownloadUI(browser(), true, true, file); |
980 } | 1069 } |
981 #endif | 1070 #endif |
982 | 1071 |
983 // Put up a Select File dialog when the file is downloaded, due to its MIME | 1072 // Put up a select file dialog when the file is downloaded, due to its MIME |
984 // type. | 1073 // type. |
985 // | 1074 // |
986 // This test runs correctly, but leaves behind turds in the test user's | 1075 // This test runs correctly, but leaves behind turds in the test user's |
987 // download directory because of http://crbug.com/62099. No big loss; it | 1076 // download directory because of http://crbug.com/62099. No big loss; it |
988 // was primarily confirming DownloadsObserver wait on select file dialog | 1077 // was primarily confirming DownloadsObserver wait on select file dialog |
989 // functionality anyway. | 1078 // functionality anyway. |
990 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { | 1079 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { |
991 ASSERT_TRUE(InitialSetup(true)); | 1080 ASSERT_TRUE(InitialSetup(true)); |
992 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1081 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
993 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1082 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1083 FilePath file_path(DestinationFile(browser(), file)); |
994 | 1084 |
995 // Download the file and wait. We expect the Select File dialog to appear | 1085 // Download the file and wait. We expect the select file dialog to appear |
996 // due to the MIME type. | 1086 // due to the MIME type. |
997 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); | 1087 DownloadAndWaitWithDialog(browser(), url, file_path); |
998 | 1088 |
999 // Check state. | 1089 // Check state. |
1000 EXPECT_EQ(1, browser()->tab_count()); | 1090 EXPECT_EQ(1, browser()->tab_count()); |
1001 // Since we exited while the Select File dialog was visible, there should not | 1091 // Since we exited while the select file dialog was visible, there should not |
1002 // be anything in the download shelf and so it should not be visible. | 1092 // be anything in the download shelf and so it should not be visible. |
1003 CheckDownloadUI(browser(), false, false, FilePath()); | 1093 CheckDownloadUI(browser(), false, false, FilePath()); |
1004 } | 1094 } |
1005 | 1095 |
1006 // Access a file with a viewable mime-type, verify that a download | 1096 // Access a file with a viewable mime-type, verify that a download |
1007 // did not initiate. | 1097 // did not initiate. |
1008 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 1098 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
1009 ASSERT_TRUE(InitialSetup(false)); | 1099 ASSERT_TRUE(InitialSetup(false)); |
1010 FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 1100 FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
1011 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1101 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
(...skipping 14 matching lines...) Expand all Loading... |
1026 // download tab opened and the file exists as the filename specified in the | 1116 // download tab opened and the file exists as the filename specified in the |
1027 // header. This also ensures we properly handle empty file downloads. | 1117 // header. This also ensures we properly handle empty file downloads. |
1028 // The download shelf should be visible in the current tab. | 1118 // The download shelf should be visible in the current tab. |
1029 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 1119 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
1030 ASSERT_TRUE(InitialSetup(false)); | 1120 ASSERT_TRUE(InitialSetup(false)); |
1031 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1121 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
1032 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1122 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1033 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1123 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
1034 | 1124 |
1035 // Download a file and wait. | 1125 // Download a file and wait. |
1036 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1126 DownloadAndWait(browser(), url); |
1037 | 1127 |
1038 CheckDownload(browser(), download_file, file); | 1128 CheckDownload(browser(), download_file, file); |
1039 | 1129 |
1040 // Check state. | 1130 // Check state. |
1041 EXPECT_EQ(1, browser()->tab_count()); | 1131 EXPECT_EQ(1, browser()->tab_count()); |
1042 CheckDownloadUI(browser(), true, true, download_file); | 1132 CheckDownloadUI(browser(), true, true, download_file); |
1043 } | 1133 } |
1044 | 1134 |
1045 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. | 1135 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. |
1046 // Test that the download shelf is per-window by starting a download in one | 1136 // Test that the download shelf is per-window by starting a download in one |
1047 // tab, opening a second tab, closing the shelf, going back to the first tab, | 1137 // tab, opening a second tab, closing the shelf, going back to the first tab, |
1048 // and checking that the shelf is closed. | 1138 // and checking that the shelf is closed. |
1049 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { | 1139 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { |
1050 ASSERT_TRUE(InitialSetup(false)); | 1140 ASSERT_TRUE(InitialSetup(false)); |
1051 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1141 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
1052 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1142 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1053 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1143 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
1054 | 1144 |
1055 // Download a file and wait. | 1145 // Download a file and wait. |
1056 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1146 DownloadAndWait(browser(), url); |
1057 | 1147 |
1058 CheckDownload(browser(), download_file, file); | 1148 CheckDownload(browser(), download_file, file); |
1059 | 1149 |
1060 // Check state. | 1150 // Check state. |
1061 EXPECT_EQ(1, browser()->tab_count()); | 1151 EXPECT_EQ(1, browser()->tab_count()); |
1062 CheckDownloadUI(browser(), true, true, download_file); | 1152 CheckDownloadUI(browser(), true, true, download_file); |
1063 | 1153 |
1064 // Open a second tab and wait. | 1154 // Open a second tab and wait. |
1065 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), | 1155 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), |
1066 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); | 1156 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 int window_count = BrowserList::size(); | 1201 int window_count = BrowserList::size(); |
1112 EXPECT_EQ(2, window_count); | 1202 EXPECT_EQ(2, window_count); |
1113 | 1203 |
1114 // Download a file in the Incognito window and wait. | 1204 // Download a file in the Incognito window and wait. |
1115 CreateAndSetDownloadsDirectory(incognito); | 1205 CreateAndSetDownloadsDirectory(incognito); |
1116 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1206 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1117 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1207 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1118 // Since |incognito| is a separate browser, we have to set it up explicitly. | 1208 // Since |incognito| is a separate browser, we have to set it up explicitly. |
1119 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 1209 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
1120 false); | 1210 false); |
1121 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); | 1211 DownloadAndWait(incognito, url); |
1122 | 1212 |
1123 // We should still have 2 windows. | 1213 // We should still have 2 windows. |
1124 ExpectWindowCountAfterDownload(2); | 1214 ExpectWindowCountAfterDownload(2); |
1125 | 1215 |
1126 // Verify that the download shelf is showing for the Incognito window. | 1216 // Verify that the download shelf is showing for the Incognito window. |
1127 CheckDownloadUI(incognito, true, true, file); | 1217 CheckDownloadUI(incognito, true, true, file); |
1128 | 1218 |
1129 #if !defined(OS_MACOSX) | 1219 #if !defined(OS_MACOSX) |
1130 // On Mac OS X, the UI window close is delayed until the outermost | 1220 // On Mac OS X, the UI window close is delayed until the outermost |
1131 // message loop runs. So it isn't possible to get a BROWSER_CLOSED | 1221 // 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 Loading... |
1178 ASSERT_TRUE(InitialSetup(false)); | 1268 ASSERT_TRUE(InitialSetup(false)); |
1179 | 1269 |
1180 // Download a file in a new background tab and wait. The tab is automatically | 1270 // Download a file in a new background tab and wait. The tab is automatically |
1181 // closed when the download begins. | 1271 // closed when the download begins. |
1182 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1272 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1183 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1273 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1184 DownloadAndWaitWithDisposition( | 1274 DownloadAndWaitWithDisposition( |
1185 browser(), | 1275 browser(), |
1186 url, | 1276 url, |
1187 NEW_BACKGROUND_TAB, | 1277 NEW_BACKGROUND_TAB, |
1188 EXPECT_NO_SELECT_DIALOG, | 1278 false, |
| 1279 FilePath(), |
1189 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1280 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1190 | 1281 |
1191 // When the download finishes, we should still have one tab. | 1282 // When the download finishes, we should still have one tab. |
1192 CheckDownloadUI(browser(), true, true, file); | 1283 CheckDownloadUI(browser(), true, true, file); |
1193 EXPECT_EQ(1, browser()->tab_count()); | 1284 EXPECT_EQ(1, browser()->tab_count()); |
1194 | 1285 |
1195 CheckDownload(browser(), file, file); | 1286 CheckDownload(browser(), file, file); |
1196 } | 1287 } |
1197 | 1288 |
1198 // Open a web page in the current tab, then download a file in another tab via | 1289 // Open a web page in the current tab, then download a file in another tab via |
(...skipping 11 matching lines...) Expand all Loading... |
1210 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1301 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
1211 | 1302 |
1212 // Open a web page and wait. | 1303 // Open a web page and wait. |
1213 ui_test_utils::NavigateToURL(browser(), url); | 1304 ui_test_utils::NavigateToURL(browser(), url); |
1214 | 1305 |
1215 // Download a file in a new tab and wait (via Javascript). | 1306 // Download a file in a new tab and wait (via Javascript). |
1216 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1307 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1217 DownloadAndWaitWithDisposition(browser(), | 1308 DownloadAndWaitWithDisposition(browser(), |
1218 GURL("javascript:openNew()"), | 1309 GURL("javascript:openNew()"), |
1219 CURRENT_TAB, | 1310 CURRENT_TAB, |
1220 EXPECT_NO_SELECT_DIALOG, | 1311 false, |
| 1312 FilePath(), |
1221 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1313 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1222 | 1314 |
1223 // When the download finishes, we should have two tabs. | 1315 // When the download finishes, we should have two tabs. |
1224 CheckDownloadUI(browser(), true, true, file); | 1316 CheckDownloadUI(browser(), true, true, file); |
1225 EXPECT_EQ(2, browser()->tab_count()); | 1317 EXPECT_EQ(2, browser()->tab_count()); |
1226 | 1318 |
1227 CheckDownload(browser(), file, file); | 1319 CheckDownload(browser(), file, file); |
1228 } | 1320 } |
1229 | 1321 |
1230 // Open a web page in the current tab, open another tab via a Javascript call, | 1322 // Open a web page in the current tab, open another tab via a Javascript call, |
(...skipping 21 matching lines...) Expand all Loading... |
1252 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1344 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1253 | 1345 |
1254 EXPECT_EQ(2, browser()->tab_count()); | 1346 EXPECT_EQ(2, browser()->tab_count()); |
1255 | 1347 |
1256 // Download a file and wait. | 1348 // Download a file and wait. |
1257 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1349 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1258 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1350 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1259 DownloadAndWaitWithDisposition(browser(), | 1351 DownloadAndWaitWithDisposition(browser(), |
1260 url, | 1352 url, |
1261 CURRENT_TAB, | 1353 CURRENT_TAB, |
1262 EXPECT_NO_SELECT_DIALOG, | 1354 false, |
| 1355 FilePath(), |
1263 ui_test_utils::BROWSER_TEST_NONE); | 1356 ui_test_utils::BROWSER_TEST_NONE); |
1264 | 1357 |
1265 // When the download finishes, we should have two tabs. | 1358 // When the download finishes, we should have two tabs. |
1266 CheckDownloadUI(browser(), true, true, file); | 1359 CheckDownloadUI(browser(), true, true, file); |
1267 EXPECT_EQ(2, browser()->tab_count()); | 1360 EXPECT_EQ(2, browser()->tab_count()); |
1268 | 1361 |
1269 CheckDownload(browser(), file, file); | 1362 CheckDownload(browser(), file, file); |
1270 } | 1363 } |
1271 | 1364 |
1272 // Open a web page in the current tab, then download a file via Javascript, | 1365 // Open a web page in the current tab, then download a file via Javascript, |
(...skipping 12 matching lines...) Expand all Loading... |
1285 | 1378 |
1286 // Open a web page and wait. | 1379 // Open a web page and wait. |
1287 ui_test_utils::NavigateToURL(browser(), url); | 1380 ui_test_utils::NavigateToURL(browser(), url); |
1288 | 1381 |
1289 // Download a file and wait. | 1382 // Download a file and wait. |
1290 // The file to download is "download-test1.lib". | 1383 // The file to download is "download-test1.lib". |
1291 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1384 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1292 DownloadAndWaitWithDisposition(browser(), | 1385 DownloadAndWaitWithDisposition(browser(), |
1293 GURL("javascript:openNew()"), | 1386 GURL("javascript:openNew()"), |
1294 CURRENT_TAB, | 1387 CURRENT_TAB, |
1295 EXPECT_NO_SELECT_DIALOG, | 1388 false, |
| 1389 FilePath(), |
1296 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1390 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1297 | 1391 |
1298 // When the download finishes, we should still have one tab. | 1392 // When the download finishes, we should still have one tab. |
1299 CheckDownloadUI(browser(), true, true, file); | 1393 CheckDownloadUI(browser(), true, true, file); |
1300 EXPECT_EQ(1, browser()->tab_count()); | 1394 EXPECT_EQ(1, browser()->tab_count()); |
1301 | 1395 |
1302 CheckDownload(browser(), file, file); | 1396 CheckDownload(browser(), file, file); |
1303 } | 1397 } |
1304 | 1398 |
1305 // Open a web page in the current tab, then call Javascript via a button to | 1399 // Open a web page in the current tab, then call Javascript via a button to |
(...skipping 14 matching lines...) Expand all Loading... |
1320 ui_test_utils::NavigateToURL(browser(), url); | 1414 ui_test_utils::NavigateToURL(browser(), url); |
1321 | 1415 |
1322 // Download a file in a new tab and wait. The tab will automatically close | 1416 // Download a file in a new tab and wait. The tab will automatically close |
1323 // when the download begins. | 1417 // when the download begins. |
1324 // The file to download is "download-test1.lib". | 1418 // The file to download is "download-test1.lib". |
1325 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1419 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1326 DownloadAndWaitWithDisposition( | 1420 DownloadAndWaitWithDisposition( |
1327 browser(), | 1421 browser(), |
1328 GURL("javascript:document.getElementById('form').submit()"), | 1422 GURL("javascript:document.getElementById('form').submit()"), |
1329 CURRENT_TAB, | 1423 CURRENT_TAB, |
1330 EXPECT_NO_SELECT_DIALOG, | 1424 false, |
| 1425 FilePath(), |
1331 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1426 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1332 | 1427 |
1333 // When the download finishes, we should still have one tab. | 1428 // When the download finishes, we should still have one tab. |
1334 CheckDownloadUI(browser(), true, true, file); | 1429 CheckDownloadUI(browser(), true, true, file); |
1335 EXPECT_EQ(1, browser()->tab_count()); | 1430 EXPECT_EQ(1, browser()->tab_count()); |
1336 | 1431 |
1337 CheckDownload(browser(), file, file); | 1432 CheckDownload(browser(), file, file); |
1338 } | 1433 } |
1339 | 1434 |
1340 // Download a file in a new window. | 1435 // Download a file in a new window. |
1341 // Verify that we have 2 windows, and the download shelf is not visible in the | 1436 // Verify that we have 2 windows, and the download shelf is not visible in the |
1342 // first window, but is visible in the second window. | 1437 // first window, but is visible in the second window. |
1343 // Close the new window. | 1438 // Close the new window. |
1344 // Verify that we have 1 window, and the download shelf is not visible. | 1439 // Verify that we have 1 window, and the download shelf is not visible. |
1345 // | 1440 // |
1346 // Regression test for http://crbug.com/44454 | 1441 // Regression test for http://crbug.com/44454 |
1347 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { | 1442 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { |
1348 ASSERT_TRUE(InitialSetup(false)); | 1443 ASSERT_TRUE(InitialSetup(false)); |
1349 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1444 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1350 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1445 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1351 #if !defined(OS_MACOSX) | 1446 #if !defined(OS_MACOSX) |
1352 // See below. | 1447 // See below. |
1353 Browser* first_browser = browser(); | 1448 Browser* first_browser = browser(); |
1354 #endif | 1449 #endif |
1355 | 1450 |
1356 // Download a file in a new window and wait. | 1451 // Download a file in a new window and wait. |
1357 DownloadAndWaitWithDisposition(browser(), | 1452 DownloadAndWaitWithDisposition(browser(), |
1358 url, | 1453 url, |
1359 NEW_WINDOW, | 1454 NEW_WINDOW, |
1360 EXPECT_NO_SELECT_DIALOG, | 1455 false, |
| 1456 FilePath(), |
1361 ui_test_utils::BROWSER_TEST_NONE); | 1457 ui_test_utils::BROWSER_TEST_NONE); |
1362 | 1458 |
1363 // When the download finishes, the download shelf SHOULD NOT be visible in | 1459 // When the download finishes, the download shelf SHOULD NOT be visible in |
1364 // the first window. | 1460 // the first window. |
1365 ExpectWindowCountAfterDownload(2); | 1461 ExpectWindowCountAfterDownload(2); |
1366 EXPECT_EQ(1, browser()->tab_count()); | 1462 EXPECT_EQ(1, browser()->tab_count()); |
1367 // Download shelf should close. Download panel stays open on ChromeOS. | 1463 // Download shelf should close. Download panel stays open on ChromeOS. |
1368 CheckDownloadUI(browser(), false, true, file); | 1464 CheckDownloadUI(browser(), false, true, file); |
1369 | 1465 |
1370 // The download shelf SHOULD be visible in the second window. | 1466 // The download shelf SHOULD be visible in the second window. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 | 1553 |
1458 // Confirm a download makes it into the history properly. | 1554 // Confirm a download makes it into the history properly. |
1459 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1555 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
1460 ASSERT_TRUE(InitialSetup(false)); | 1556 ASSERT_TRUE(InitialSetup(false)); |
1461 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1557 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1462 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1558 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1463 FilePath origin_file(OriginFile(file)); | 1559 FilePath origin_file(OriginFile(file)); |
1464 int64 origin_size; | 1560 int64 origin_size; |
1465 file_util::GetFileSize(origin_file, &origin_size); | 1561 file_util::GetFileSize(origin_file, &origin_size); |
1466 | 1562 |
1467 // Download the file and wait. We do not expect the Select File dialog. | 1563 // Download the file and wait. |
1468 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1564 DownloadAndWait(browser(), url); |
1469 | 1565 |
1470 // Get details of what downloads have just happened. | 1566 // Get details of what downloads have just happened. |
1471 std::vector<DownloadItem*> downloads; | 1567 std::vector<DownloadItem*> downloads; |
1472 GetDownloads(browser(), &downloads); | 1568 GetDownloads(browser(), &downloads); |
1473 ASSERT_EQ(1u, downloads.size()); | 1569 ASSERT_EQ(1u, downloads.size()); |
1474 int64 db_handle = downloads[0]->db_handle(); | 1570 int64 db_handle = downloads[0]->db_handle(); |
1475 | 1571 |
1476 // Check state. | 1572 // Check state. |
1477 EXPECT_EQ(1, browser()->tab_count()); | 1573 EXPECT_EQ(1, browser()->tab_count()); |
1478 CheckDownload(browser(), file, file); | 1574 CheckDownload(browser(), file, file); |
(...skipping 16 matching lines...) Expand all Loading... |
1495 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1591 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
1496 // after download of a file while viewing another chrome://. | 1592 // after download of a file while viewing another chrome://. |
1497 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1593 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
1498 ASSERT_TRUE(InitialSetup(false)); | 1594 ASSERT_TRUE(InitialSetup(false)); |
1499 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1595 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1500 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1596 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1501 GURL flags_url(chrome::kChromeUIFlagsURL); | 1597 GURL flags_url(chrome::kChromeUIFlagsURL); |
1502 GURL extensions_url(chrome::kChromeUIExtensionsURL); | 1598 GURL extensions_url(chrome::kChromeUIExtensionsURL); |
1503 | 1599 |
1504 ui_test_utils::NavigateToURL(browser(), flags_url); | 1600 ui_test_utils::NavigateToURL(browser(), flags_url); |
1505 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1601 DownloadAndWait(browser(), download_url); |
1506 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1602 ui_test_utils::NavigateToURL(browser(), extensions_url); |
1507 TabContents* contents = browser()->GetSelectedTabContents(); | 1603 TabContents* contents = browser()->GetSelectedTabContents(); |
1508 ASSERT_TRUE(contents); | 1604 ASSERT_TRUE(contents); |
1509 bool webui_responded = false; | 1605 bool webui_responded = false; |
1510 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1606 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1511 contents->render_view_host(), | 1607 contents->render_view_host(), |
1512 L"", | 1608 L"", |
1513 L"window.domAutomationController.send(window.webui_responded_);", | 1609 L"window.domAutomationController.send(window.webui_responded_);", |
1514 &webui_responded)); | 1610 &webui_responded)); |
1515 EXPECT_TRUE(webui_responded); | 1611 EXPECT_TRUE(webui_responded); |
(...skipping 16 matching lines...) Expand all Loading... |
1532 ASSERT_TRUE(contents); | 1628 ASSERT_TRUE(contents); |
1533 bool result = false; | 1629 bool result = false; |
1534 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1630 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1535 contents->render_view_host(), | 1631 contents->render_view_host(), |
1536 L"", | 1632 L"", |
1537 L"window.onunload = function() { var do_nothing = 0; }; " | 1633 L"window.onunload = function() { var do_nothing = 0; }; " |
1538 L"window.domAutomationController.send(true);", | 1634 L"window.domAutomationController.send(true);", |
1539 &result)); | 1635 &result)); |
1540 EXPECT_TRUE(result); | 1636 EXPECT_TRUE(result); |
1541 | 1637 |
1542 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1638 DownloadAndWait(browser(), download_url); |
1543 | 1639 |
1544 ui_test_utils::WindowedNotificationObserver signal( | 1640 ui_test_utils::WindowedNotificationObserver signal( |
1545 chrome::NOTIFICATION_BROWSER_CLOSED, | 1641 chrome::NOTIFICATION_BROWSER_CLOSED, |
1546 Source<Browser>(browser())); | 1642 Source<Browser>(browser())); |
1547 browser()->CloseWindow(); | 1643 browser()->CloseWindow(); |
1548 signal.Wait(); | 1644 signal.Wait(); |
1549 } | 1645 } |
1550 | 1646 |
1551 // Test to make sure the 'download' attribute in anchor tag is respected. | 1647 // Test to make sure the 'download' attribute in anchor tag is respected. |
1552 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1648 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
1553 ASSERT_TRUE(InitialSetup(false)); | 1649 ASSERT_TRUE(InitialSetup(false)); |
1554 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1650 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
1555 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1651 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1556 | 1652 |
1557 // Create a download, wait until it's complete, and confirm | 1653 // Create a download, wait until it's complete, and confirm |
1558 // we're in the expected state. | 1654 // we're in the expected state. |
1559 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1)); | 1655 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1, false)); |
1560 ui_test_utils::NavigateToURL(browser(), url); | 1656 ui_test_utils::NavigateToURL(browser(), url); |
1561 observer->WaitForFinished(); | 1657 observer->WaitForFinished(); |
1562 | 1658 |
1563 // Confirm the downloaded data exists. | 1659 // Confirm the downloaded data exists. |
1564 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1660 FilePath downloaded_file( |
1565 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1661 DestinationFile(browser(), FilePath(FILE_PATH_LITERAL("a_red_dot.png")))); |
1566 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1662 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
1567 } | 1663 } |
1568 | 1664 |
1569 // Test to make sure auto-open works. | 1665 // Test to make sure auto-open works. |
1570 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1666 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
1571 ASSERT_TRUE(InitialSetup(false)); | 1667 ASSERT_TRUE(InitialSetup(false)); |
1572 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1668 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
1573 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1669 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1574 | 1670 |
1575 ASSERT_TRUE( | 1671 ASSERT_TRUE( |
1576 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1672 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
1577 | 1673 |
1578 // Mock out external opening on all downloads until end of test. | 1674 // Mock out external opening on all downloads until end of test. |
1579 MockDownloadOpeningObserver observer( | 1675 MockDownloadOpeningObserver observer( |
1580 browser()->profile()->GetDownloadManager()); | 1676 browser()->profile()->GetDownloadManager()); |
1581 | 1677 |
1582 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1678 DownloadAndWait(browser(), url); |
1583 | 1679 |
1584 // Find the download and confirm it was opened. | 1680 // Find the download and confirm it was opened. |
1585 std::vector<DownloadItem*> downloads; | 1681 std::vector<DownloadItem*> downloads; |
1586 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1682 browser()->profile()->GetDownloadManager()->SearchDownloads( |
1587 string16(), &downloads); | 1683 string16(), &downloads); |
1588 ASSERT_EQ(1u, downloads.size()); | 1684 ASSERT_EQ(1u, downloads.size()); |
1589 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); | 1685 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); |
1590 EXPECT_TRUE(downloads[0]->opened()); | 1686 EXPECT_TRUE(downloads[0]->opened()); |
1591 | 1687 |
1592 // As long as we're here, confirmed everything else is good. | 1688 // As long as we're here, confirmed everything else is good. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1825 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1730 | 1826 |
1731 // Download shelf should close. Download panel stays open on ChromeOS. | 1827 // Download shelf should close. Download panel stays open on ChromeOS. |
1732 CheckDownloadUI(browser(), false, true, FilePath()); | 1828 CheckDownloadUI(browser(), false, true, FilePath()); |
1733 | 1829 |
1734 // Check that the extension was installed. | 1830 // Check that the extension was installed. |
1735 ExtensionService* extension_service = | 1831 ExtensionService* extension_service = |
1736 browser()->profile()->GetExtensionService(); | 1832 browser()->profile()->GetExtensionService(); |
1737 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1833 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
1738 } | 1834 } |
OLD | NEW |