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/test/test_file_util.h" | 10 #include "base/test/test_file_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/download/download_file_manager.h" | 13 #include "chrome/browser/download/download_file_manager.h" |
14 #include "chrome/browser/download/download_item.h" | 14 #include "chrome/browser/download/download_item.h" |
15 #include "chrome/browser/download/download_manager.h" | 15 #include "chrome/browser/download/download_manager.h" |
16 #include "chrome/browser/download/download_prefs.h" | 16 #include "chrome/browser/download/download_prefs.h" |
17 #include "chrome/browser/download/download_shelf.h" | 17 #include "chrome/browser/download/download_shelf.h" |
18 #include "chrome/browser/download/download_util.h" | |
18 #include "chrome/browser/history/download_history_info.h" | 19 #include "chrome/browser/history/download_history_info.h" |
19 #include "chrome/browser/history/history.h" | 20 #include "chrome/browser/history/history.h" |
20 #include "chrome/browser/net/url_request_mock_http_job.h" | 21 #include "chrome/browser/net/url_request_mock_http_job.h" |
21 #include "chrome/browser/net/url_request_slow_download_job.h" | 22 #include "chrome/browser/net/url_request_slow_download_job.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/webui/active_downloads_ui.h" | 28 #include "chrome/browser/ui/webui/active_downloads_ui.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 ~DownloadsObserver() { | 84 ~DownloadsObserver() { |
84 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | 85 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); |
85 for (; it != downloads_observed_.end(); ++it) { | 86 for (; it != downloads_observed_.end(); ++it) { |
86 (*it)->RemoveObserver(this); | 87 (*it)->RemoveObserver(this); |
87 } | 88 } |
88 download_manager_->RemoveObserver(this); | 89 download_manager_->RemoveObserver(this); |
89 } | 90 } |
90 | 91 |
91 // State accessors. | 92 // State accessors. |
92 bool select_file_dialog_seen() { return select_file_dialog_seen_; } | 93 bool select_file_dialog_seen() { return select_file_dialog_seen_; } |
94 const FilePath& suggested_path() { return suggested_path_; } | |
93 | 95 |
94 // Wait for whatever state was specified in the constructor. | 96 // Wait for whatever state was specified in the constructor. |
95 void WaitForFinished() { | 97 void WaitForFinished() { |
96 if (!IsFinished()) { | 98 if (!IsFinished()) { |
97 waiting_ = true; | 99 waiting_ = true; |
98 ui_test_utils::RunMessageLoop(); | 100 ui_test_utils::RunMessageLoop(); |
99 waiting_ = false; | 101 waiting_ = false; |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 // If it is finished and we are observing it, stop. | 146 // If it is finished and we are observing it, stop. |
145 if (finished_it != finished_downloads_.end() && | 147 if (finished_it != finished_downloads_.end() && |
146 observed_it != downloads_observed_.end()) { | 148 observed_it != downloads_observed_.end()) { |
147 (*it)->RemoveObserver(this); | 149 (*it)->RemoveObserver(this); |
148 downloads_observed_.erase(observed_it); | 150 downloads_observed_.erase(observed_it); |
149 continue; | 151 continue; |
150 } | 152 } |
151 } | 153 } |
152 } | 154 } |
153 | 155 |
154 virtual void SelectFileDialogDisplayed(int32 /* id */) { | 156 virtual void SelectFileDialogDisplayed( |
157 int32 /* id */, const FilePath& suggested_path) { | |
155 select_file_dialog_seen_ = true; | 158 select_file_dialog_seen_ = true; |
159 suggested_path_ = suggested_path; | |
156 SignalIfFinished(); | 160 SignalIfFinished(); |
157 } | 161 } |
158 | 162 |
159 private: | 163 private: |
160 // Called when we know that a download item is in a final state. | 164 // Called when we know that a download item is in a final state. |
161 // Note that this is not the same as it first transitioning in to the | 165 // Note that this is not the same as it first transitioning in to the |
162 // final state; multiple notifications may occur once the item is in | 166 // final state; multiple notifications may occur once the item is in |
163 // that state. So we keep our own track of transitions into final. | 167 // that state. So we keep our own track of transitions into final. |
164 void DownloadInFinalState(DownloadItem* download) { | 168 void DownloadInFinalState(DownloadItem* download) { |
165 if (finished_downloads_.find(download) != finished_downloads_.end()) { | 169 if (finished_downloads_.find(download) != finished_downloads_.end()) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 // The state on which to consider the DownloadItem finished. | 215 // The state on which to consider the DownloadItem finished. |
212 DownloadItem::DownloadState download_finished_state_; | 216 DownloadItem::DownloadState download_finished_state_; |
213 | 217 |
214 // True if we should transition the DownloadsObserver to finished if | 218 // True if we should transition the DownloadsObserver to finished if |
215 // the select file dialog comes up. | 219 // the select file dialog comes up. |
216 bool finish_on_select_file_; | 220 bool finish_on_select_file_; |
217 | 221 |
218 // True if we've seen the select file dialog. | 222 // True if we've seen the select file dialog. |
219 bool select_file_dialog_seen_; | 223 bool select_file_dialog_seen_; |
220 | 224 |
225 // The suggested file path in the select file dialog. | |
226 FilePath suggested_path_; | |
227 | |
221 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); | 228 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); |
222 }; | 229 }; |
223 | 230 |
224 // WaitForFlush() returns after: | 231 // WaitForFlush() returns after: |
225 // * There are no IN_PROGRESS download items remaining on the | 232 // * There are no IN_PROGRESS download items remaining on the |
226 // DownloadManager. | 233 // DownloadManager. |
227 // * There have been two round trip messages through the file and | 234 // * There have been two round trip messages through the file and |
228 // IO threads. | 235 // IO threads. |
229 // This almost certainly means that a Download cancel has propagated through | 236 // This almost certainly means that a Download cancel has propagated through |
230 // the system. | 237 // the system. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 ResourceDispatcherHost* resource_dispatcher_host_; | 393 ResourceDispatcherHost* resource_dispatcher_host_; |
387 DownloadFileManager* download_file_manager_; | 394 DownloadFileManager* download_file_manager_; |
388 int rdh_pending_requests_; | 395 int rdh_pending_requests_; |
389 int dfm_pending_downloads_; | 396 int dfm_pending_downloads_; |
390 | 397 |
391 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); | 398 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); |
392 }; | 399 }; |
393 | 400 |
394 class DownloadTest : public InProcessBrowserTest { | 401 class DownloadTest : public InProcessBrowserTest { |
395 public: | 402 public: |
396 enum SelectExpectation { | |
397 EXPECT_NO_SELECT_DIALOG = -1, | |
398 EXPECT_NOTHING, | |
399 EXPECT_SELECT_DIALOG | |
400 }; | |
401 | |
402 DownloadTest() { | 403 DownloadTest() { |
403 EnableDOMAutomation(); | 404 EnableDOMAutomation(); |
404 } | 405 } |
405 | 406 |
406 // Returning false indicates a failure of the setup, and should be asserted | 407 // Returning false indicates a failure of the setup, and should be asserted |
407 // in the caller. | 408 // in the caller. |
408 virtual bool InitialSetup(bool prompt_for_download) { | 409 virtual bool InitialSetup(bool prompt_for_download) { |
409 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); | 410 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); |
410 EXPECT_TRUE(have_test_dir); | 411 EXPECT_TRUE(have_test_dir); |
411 if (!have_test_dir) | 412 if (!have_test_dir) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 if (!downloads_directory_.CreateUniqueTempDir()) | 461 if (!downloads_directory_.CreateUniqueTempDir()) |
461 return false; | 462 return false; |
462 | 463 |
463 browser->profile()->GetPrefs()->SetFilePath( | 464 browser->profile()->GetPrefs()->SetFilePath( |
464 prefs::kDownloadDefaultDirectory, | 465 prefs::kDownloadDefaultDirectory, |
465 downloads_directory_.path()); | 466 downloads_directory_.path()); |
466 | 467 |
467 return true; | 468 return true; |
468 } | 469 } |
469 | 470 |
471 // Delete the default folder for downloaded files. | |
472 bool DeleteDownloadsDirectory() { | |
473 return downloads_directory_.Delete(); | |
474 } | |
475 | |
470 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 476 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
471 return browser->profile()->GetDownloadManager()->download_prefs(); | 477 return browser->profile()->GetDownloadManager()->download_prefs(); |
472 } | 478 } |
473 | 479 |
474 FilePath GetDownloadDirectory(Browser* browser) { | 480 FilePath GetDownloadDirectory(Browser* browser) { |
475 DownloadManager* download_mananger = | 481 DownloadManager* download_mananger = |
476 browser->profile()->GetDownloadManager(); | 482 browser->profile()->GetDownloadManager(); |
477 return download_mananger->download_prefs()->download_path(); | 483 return download_mananger->download_prefs()->download_path(); |
478 } | 484 } |
479 | 485 |
(...skipping 16 matching lines...) Expand all Loading... | |
496 browser->profile()->GetDownloadManager(); | 502 browser->profile()->GetDownloadManager(); |
497 return new DownloadsObserver( | 503 return new DownloadsObserver( |
498 download_manager, num_downloads, | 504 download_manager, num_downloads, |
499 DownloadItem::IN_PROGRESS, // Has started | 505 DownloadItem::IN_PROGRESS, // Has started |
500 true); // Bail on select file | 506 true); // Bail on select file |
501 } | 507 } |
502 | 508 |
503 // Download |url|, then wait for the download to finish. | 509 // Download |url|, then wait for the download to finish. |
504 // |disposition| indicates where the navigation occurs (current tab, new | 510 // |disposition| indicates where the navigation occurs (current tab, new |
505 // foreground tab, etc). | 511 // foreground tab, etc). |
506 // |expectation| indicates whether or not a Select File dialog should be | 512 // |expect_file_dialog| indicates whether a select file dialog should be |
507 // open when the download is finished, or if we don't care. | 513 // open when the download is finished, or if we don't care. |
508 // If the dialog appears, the routine exits. The only effect |expectation| | 514 // If the dialog appears, the routine exits. The only effect |
509 // has is whether or not the test succeeds. | 515 // |expect_file_dialog| has is whether or not the test succeeds. |
516 // |expected_suggested_path| is the path expected to be suggested in the | |
517 // select file dialog. This |expected_suggested_path| must be specified | |
518 // if |expect_file_dialog| is true. If |expect_file_dialog| is false, | |
519 // |expected_suggested_path| is ignored. | |
510 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 520 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
511 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 521 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
512 void DownloadAndWaitWithDisposition(Browser* browser, | 522 void DownloadAndWaitWithDisposition(Browser* browser, |
513 const GURL& url, | 523 const GURL& url, |
514 WindowOpenDisposition disposition, | 524 WindowOpenDisposition disposition, |
515 SelectExpectation expectation, | 525 bool expect_file_dialog, |
526 const FilePath& expected_suggested_path, | |
516 int browser_test_flags) { | 527 int browser_test_flags) { |
517 // Setup notification, navigate, and block. | 528 // Setup notification, navigate, and block. |
518 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 529 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); |
519 // This call will block until the condition specified by | 530 // This call will block until the condition specified by |
520 // |browser_test_flags|, but will not wait for the download to finish. | 531 // |browser_test_flags|, but will not wait for the download to finish. |
521 ui_test_utils::NavigateToURLWithDisposition(browser, | 532 ui_test_utils::NavigateToURLWithDisposition(browser, |
522 url, | 533 url, |
523 disposition, | 534 disposition, |
524 browser_test_flags); | 535 browser_test_flags); |
525 // Waits for the download to complete. | 536 // Waits for the download to complete. |
526 observer->WaitForFinished(); | 537 observer->WaitForFinished(); |
527 | 538 |
528 // If specified, check the state of the select file dialog. | 539 // Checks if the select file dialog was displayed as we expected. |
529 if (expectation != EXPECT_NOTHING) { | 540 // If displayed, checks the suggested path in the dialog. |
530 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, | 541 if (expect_file_dialog) { |
531 observer->select_file_dialog_seen()); | 542 EXPECT_TRUE(observer->select_file_dialog_seen()); |
543 EXPECT_EQ(observer->suggested_path(), expected_suggested_path); | |
544 } else { | |
545 EXPECT_FALSE(observer->select_file_dialog_seen()); | |
532 } | 546 } |
533 } | 547 } |
534 | 548 |
535 // Download a file in the current tab, then wait for the download to finish. | 549 // Download a file in the current tab, then wait for the download to finish. |
536 void DownloadAndWait(Browser* browser, | 550 // Expect that no select file dialog is displayed. |
537 const GURL& url, | 551 void DownloadAndWaitWithoutDialog(Browser* browser, const GURL& url) { |
Randy Smith (Not in Mondays)
2011/06/08 22:31:18
I think that this is the common case, so I'd leave
haraken1
2011/06/09 10:16:56
Done.
| |
538 SelectExpectation expectation) { | |
539 DownloadAndWaitWithDisposition( | 552 DownloadAndWaitWithDisposition( |
540 browser, | 553 browser, url, CURRENT_TAB, false, FilePath(), |
541 url, | |
542 CURRENT_TAB, | |
543 expectation, | |
544 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 554 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
545 } | 555 } |
546 | 556 |
557 // Download a file in the current tab, then wait for the download to finish. | |
558 // Expect that a select file dialog suggesting || is displayed. | |
559 void DownloadAndWaitWithDialog(Browser* browser, const GURL& url, | |
560 const FilePath& expected_suggested_path) { | |
561 DownloadAndWaitWithDisposition( | |
562 browser, url, CURRENT_TAB, true, expected_suggested_path, | |
563 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
564 } | |
565 | |
547 // Should only be called when the download is known to have finished | 566 // Should only be called when the download is known to have finished |
548 // (in error or not). | 567 // (in error or not). |
549 // Returning false indicates a failure of the function, and should be asserted | 568 // Returning false indicates a failure of the function, and should be asserted |
550 // in the caller. | 569 // in the caller. |
551 bool CheckDownload(Browser* browser, | 570 bool CheckDownload(Browser* browser, |
552 const FilePath& downloaded_filename, | 571 const FilePath& downloaded_filename, |
553 const FilePath& origin_filename) { | 572 const FilePath& origin_filename) { |
554 // Find the path to which the data will be downloaded. | 573 // Find the path to which the data will be downloaded. |
555 FilePath downloaded_file(DestinationFile(browser, downloaded_filename)); | 574 FilePath downloaded_file(DestinationFile(browser, downloaded_filename)); |
556 | 575 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 // Files for these tests are found in DIR_TEST_DATA (currently | 794 // Files for these tests are found in DIR_TEST_DATA (currently |
776 // "chrome\test\data\", see chrome_paths.cc). | 795 // "chrome\test\data\", see chrome_paths.cc). |
777 // Mock responses have extension .mock-http-headers appended to the file name. | 796 // Mock responses have extension .mock-http-headers appended to the file name. |
778 | 797 |
779 // Download a file due to the associated MIME type. | 798 // Download a file due to the associated MIME type. |
780 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 799 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
781 ASSERT_TRUE(InitialSetup(false)); | 800 ASSERT_TRUE(InitialSetup(false)); |
782 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 801 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
783 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 802 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
784 | 803 |
785 // Download the file and wait. We do not expect the Select File dialog. | 804 // Download the file and wait. We do not expect the select file dialog. |
786 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 805 DownloadAndWaitWithoutDialog(browser(), url); |
787 | 806 |
788 // Check state. | 807 // Check state. |
789 EXPECT_EQ(1, browser()->tab_count()); | 808 EXPECT_EQ(1, browser()->tab_count()); |
790 CheckDownload(browser(), file, file); | 809 CheckDownload(browser(), file, file); |
791 CheckDownloadUIVisible(browser(), true, true); | 810 CheckDownloadUIVisible(browser(), true, true); |
792 } | 811 } |
793 | 812 |
813 // Checks if a file is saved to the user's "Downloads" folder | |
814 // in the following situation: | |
815 // The default folder for downloaded files does not exist. | |
816 // The user's "Downloads" folder exists. | |
817 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadedFolder1) { | |
818 ASSERT_TRUE(InitialSetup(false)); | |
819 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
820 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
821 | |
822 // Temporarily change the user's "Downloads" folder. | |
823 ScopedTempDir default_downloads_dir; | |
824 ASSERT_TRUE(default_downloads_dir.CreateUniqueTempDir()); | |
825 download_util::DefaultDownloadDirectory::Override( | |
826 default_downloads_dir.path()); | |
827 FilePath downloaded_file = default_downloads_dir.path().Append(file); | |
828 | |
829 // Delete the default folder for downloaded files. | |
830 ASSERT_TRUE(DeleteDownloadsDirectory()); | |
831 ASSERT_FALSE(file_util::PathExists(GetDownloadDirectory(browser()))); | |
832 | |
833 // Download the file and wait. We expect the select file dialog. | |
834 DownloadAndWaitWithDialog(browser(), url, downloaded_file); | |
835 | |
836 EXPECT_FALSE(file_util::PathExists(downloaded_file)); | |
837 EXPECT_FALSE(file_util::PathExists(GetDownloadDirectory(browser()))); | |
838 EXPECT_EQ(1, browser()->tab_count()); | |
839 | |
840 // Restore the user's "Downloads" folder. | |
841 download_util::DefaultDownloadDirectory::UnOverride(); | |
Paweł Hajdan Jr.
2011/06/08 09:50:23
I think this should be handled by a scoped object
haraken1
2011/06/09 10:16:56
Done. I created a new class ScopedDefaultDownloadD
| |
842 } | |
843 | |
844 // Checks if the default folder for downloaded files is created | |
845 // and a file is saved to the folder in the following situation: | |
846 // The default folder for downloaded files does not exist. | |
847 // The user's "Downloads" folder does not exist. | |
848 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadedFolder2) { | |
849 ASSERT_TRUE(InitialSetup(false)); | |
850 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
851 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
852 FilePath downloaded_file(DestinationFile(browser(), file)); | |
853 | |
854 // Temporarily change the user's "Downloads" folder. | |
855 FilePath nonexistent_dir("/tmp/koakuma_andre_moemoe_nyannyan"); | |
856 download_util::DefaultDownloadDirectory::Override(nonexistent_dir); | |
857 | |
858 // Delete the default folder for downloaded files. | |
859 ASSERT_TRUE(DeleteDownloadsDirectory()); | |
860 ASSERT_FALSE(file_util::PathExists(GetDownloadDirectory(browser()))); | |
861 | |
862 // Download the file and wait. We expect the select file dialog. | |
863 DownloadAndWaitWithDialog(browser(), url, downloaded_file); | |
864 | |
865 EXPECT_FALSE(file_util::PathExists(downloaded_file)); | |
866 EXPECT_FALSE(file_util::PathExists(nonexistent_dir)); | |
867 EXPECT_TRUE(file_util::PathExists(GetDownloadDirectory(browser()))); | |
868 EXPECT_EQ(1, browser()->tab_count()); | |
869 | |
870 // Restore the user's "Downloads" folder. | |
871 download_util::DefaultDownloadDirectory::UnOverride(); | |
872 } | |
873 | |
794 #if defined(OS_WIN) | 874 #if defined(OS_WIN) |
795 // Download a file and confirm that the zone identifier (on windows) | 875 // Download a file and confirm that the zone identifier (on windows) |
796 // is set to internet. | 876 // is set to internet. |
797 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 877 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
798 ASSERT_TRUE(InitialSetup(false)); | 878 ASSERT_TRUE(InitialSetup(false)); |
799 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 879 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
800 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 880 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
801 | 881 |
802 // Download the file and wait. We do not expect the Select File dialog. | 882 // Download the file and wait. We do not expect the select file dialog. |
803 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 883 DownloadAndWaitWithoutDialog(browser(), url); |
804 | 884 |
805 // Check state. Special file state must be checked before CheckDownload, | 885 // Check state. Special file state must be checked before CheckDownload, |
806 // as CheckDownload will delete the output file. | 886 // as CheckDownload will delete the output file. |
807 EXPECT_EQ(1, browser()->tab_count()); | 887 EXPECT_EQ(1, browser()->tab_count()); |
808 FilePath downloaded_file(DestinationFile(browser(), file)); | 888 FilePath downloaded_file(DestinationFile(browser(), file)); |
809 if (file_util::VolumeSupportsADS(downloaded_file)) | 889 if (file_util::VolumeSupportsADS(downloaded_file)) |
810 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); | 890 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
811 CheckDownload(browser(), file, file); | 891 CheckDownload(browser(), file, file); |
812 CheckDownloadUIVisible(browser(), true, true); | 892 CheckDownloadUIVisible(browser(), true, true); |
813 } | 893 } |
814 #endif | 894 #endif |
815 | 895 |
816 // Put up a Select File dialog when the file is downloaded, due to its MIME | 896 // Put up a select file dialog when the file is downloaded, due to its MIME |
817 // type. | 897 // type. |
818 // | 898 // |
819 // This test runs correctly, but leaves behind turds in the test user's | 899 // This test runs correctly, but leaves behind turds in the test user's |
820 // download directory because of http://crbug.com/62099. No big loss; it | 900 // download directory because of http://crbug.com/62099. No big loss; it |
821 // was primarily confirming DownloadsObserver wait on select file dialog | 901 // was primarily confirming DownloadsObserver wait on select file dialog |
822 // functionality anyway. | 902 // functionality anyway. |
823 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { | 903 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { |
824 ASSERT_TRUE(InitialSetup(true)); | 904 ASSERT_TRUE(InitialSetup(true)); |
825 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 905 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
826 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 906 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
907 FilePath file_path(DestinationFile(browser(), file)); | |
827 | 908 |
828 // Download the file and wait. We expect the Select File dialog to appear | 909 // Download the file and wait. We expect the select file dialog to appear |
829 // due to the MIME type. | 910 // due to the MIME type. |
830 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); | 911 DownloadAndWaitWithDialog(browser(), url, file_path); |
831 | 912 |
832 // Check state. | 913 // Check state. |
833 EXPECT_EQ(1, browser()->tab_count()); | 914 EXPECT_EQ(1, browser()->tab_count()); |
834 // Since we exited while the Select File dialog was visible, there should not | 915 // Since we exited while the select file dialog was visible, there should not |
835 // be anything in the download shelf and so it should not be visible. | 916 // be anything in the download shelf and so it should not be visible. |
836 CheckDownloadUIVisible(browser(), false, false); | 917 CheckDownloadUIVisible(browser(), false, false); |
837 } | 918 } |
838 | 919 |
839 // Access a file with a viewable mime-type, verify that a download | 920 // Access a file with a viewable mime-type, verify that a download |
840 // did not initiate. | 921 // did not initiate. |
841 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 922 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
842 ASSERT_TRUE(InitialSetup(false)); | 923 ASSERT_TRUE(InitialSetup(false)); |
843 FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 924 FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
844 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 925 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
(...skipping 14 matching lines...) Expand all Loading... | |
859 // download tab opened and the file exists as the filename specified in the | 940 // download tab opened and the file exists as the filename specified in the |
860 // header. This also ensures we properly handle empty file downloads. | 941 // header. This also ensures we properly handle empty file downloads. |
861 // The download shelf should be visible in the current tab. | 942 // The download shelf should be visible in the current tab. |
862 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 943 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
863 ASSERT_TRUE(InitialSetup(false)); | 944 ASSERT_TRUE(InitialSetup(false)); |
864 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 945 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
865 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 946 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
866 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 947 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
867 | 948 |
868 // Download a file and wait. | 949 // Download a file and wait. |
869 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 950 DownloadAndWaitWithoutDialog(browser(), url); |
870 | 951 |
871 CheckDownload(browser(), download_file, file); | 952 CheckDownload(browser(), download_file, file); |
872 | 953 |
873 // Check state. | 954 // Check state. |
874 EXPECT_EQ(1, browser()->tab_count()); | 955 EXPECT_EQ(1, browser()->tab_count()); |
875 CheckDownloadUIVisible(browser(), true, true); | 956 CheckDownloadUIVisible(browser(), true, true); |
876 } | 957 } |
877 | 958 |
878 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. | 959 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. |
879 // Test that the download shelf is per-window by starting a download in one | 960 // Test that the download shelf is per-window by starting a download in one |
880 // tab, opening a second tab, closing the shelf, going back to the first tab, | 961 // tab, opening a second tab, closing the shelf, going back to the first tab, |
881 // and checking that the shelf is closed. | 962 // and checking that the shelf is closed. |
882 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { | 963 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { |
883 ASSERT_TRUE(InitialSetup(false)); | 964 ASSERT_TRUE(InitialSetup(false)); |
884 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 965 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
885 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 966 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
886 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 967 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
887 | 968 |
888 // Download a file and wait. | 969 // Download a file and wait. |
889 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 970 DownloadAndWaitWithoutDialog(browser(), url); |
890 | 971 |
891 CheckDownload(browser(), download_file, file); | 972 CheckDownload(browser(), download_file, file); |
892 | 973 |
893 // Check state. | 974 // Check state. |
894 EXPECT_EQ(1, browser()->tab_count()); | 975 EXPECT_EQ(1, browser()->tab_count()); |
895 CheckDownloadUIVisible(browser(), true, true); | 976 CheckDownloadUIVisible(browser(), true, true); |
896 | 977 |
897 // Open a second tab and wait. | 978 // Open a second tab and wait. |
898 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), | 979 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), |
899 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); | 980 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 int window_count = BrowserList::size(); | 1025 int window_count = BrowserList::size(); |
945 EXPECT_EQ(2, window_count); | 1026 EXPECT_EQ(2, window_count); |
946 | 1027 |
947 // Download a file in the Incognito window and wait. | 1028 // Download a file in the Incognito window and wait. |
948 CreateAndSetDownloadsDirectory(incognito); | 1029 CreateAndSetDownloadsDirectory(incognito); |
949 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1030 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
950 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1031 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
951 // Since |incognito| is a separate browser, we have to set it up explicitly. | 1032 // Since |incognito| is a separate browser, we have to set it up explicitly. |
952 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 1033 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
953 false); | 1034 false); |
954 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); | 1035 DownloadAndWaitWithoutDialog(incognito, url); |
955 | 1036 |
956 // We should still have 2 windows. | 1037 // We should still have 2 windows. |
957 ExpectWindowCountAfterDownload(2); | 1038 ExpectWindowCountAfterDownload(2); |
958 | 1039 |
959 // Verify that the download shelf is showing for the Incognito window. | 1040 // Verify that the download shelf is showing for the Incognito window. |
960 CheckDownloadUIVisible(incognito, true, true); | 1041 CheckDownloadUIVisible(incognito, true, true); |
961 | 1042 |
962 #if !defined(OS_MACOSX) | 1043 #if !defined(OS_MACOSX) |
963 // On Mac OS X, the UI window close is delayed until the outermost | 1044 // On Mac OS X, the UI window close is delayed until the outermost |
964 // message loop runs. So it isn't possible to get a BROWSER_CLOSED | 1045 // 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... | |
1011 ASSERT_TRUE(InitialSetup(false)); | 1092 ASSERT_TRUE(InitialSetup(false)); |
1012 | 1093 |
1013 // Download a file in a new background tab and wait. The tab is automatically | 1094 // Download a file in a new background tab and wait. The tab is automatically |
1014 // closed when the download begins. | 1095 // closed when the download begins. |
1015 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1096 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1016 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1097 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1017 DownloadAndWaitWithDisposition( | 1098 DownloadAndWaitWithDisposition( |
1018 browser(), | 1099 browser(), |
1019 url, | 1100 url, |
1020 NEW_BACKGROUND_TAB, | 1101 NEW_BACKGROUND_TAB, |
1021 EXPECT_NO_SELECT_DIALOG, | 1102 false, |
1103 FilePath(), | |
1022 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1104 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1023 | 1105 |
1024 // When the download finishes, we should still have one tab. | 1106 // When the download finishes, we should still have one tab. |
1025 CheckDownloadUIVisible(browser(), true, true); | 1107 CheckDownloadUIVisible(browser(), true, true); |
1026 EXPECT_EQ(1, browser()->tab_count()); | 1108 EXPECT_EQ(1, browser()->tab_count()); |
1027 | 1109 |
1028 CheckDownload(browser(), file, file); | 1110 CheckDownload(browser(), file, file); |
1029 } | 1111 } |
1030 | 1112 |
1031 // Open a web page in the current tab, then download a file in another tab via | 1113 // Open a web page in the current tab, then download a file in another tab via |
(...skipping 11 matching lines...) Expand all Loading... | |
1043 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1125 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
1044 | 1126 |
1045 // Open a web page and wait. | 1127 // Open a web page and wait. |
1046 ui_test_utils::NavigateToURL(browser(), url); | 1128 ui_test_utils::NavigateToURL(browser(), url); |
1047 | 1129 |
1048 // Download a file in a new tab and wait (via Javascript). | 1130 // Download a file in a new tab and wait (via Javascript). |
1049 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1131 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1050 DownloadAndWaitWithDisposition(browser(), | 1132 DownloadAndWaitWithDisposition(browser(), |
1051 GURL("javascript:openNew()"), | 1133 GURL("javascript:openNew()"), |
1052 CURRENT_TAB, | 1134 CURRENT_TAB, |
1053 EXPECT_NO_SELECT_DIALOG, | 1135 false, |
1136 FilePath(), | |
1054 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1137 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1055 | 1138 |
1056 // When the download finishes, we should have two tabs. | 1139 // When the download finishes, we should have two tabs. |
1057 CheckDownloadUIVisible(browser(), true, true); | 1140 CheckDownloadUIVisible(browser(), true, true); |
1058 EXPECT_EQ(2, browser()->tab_count()); | 1141 EXPECT_EQ(2, browser()->tab_count()); |
1059 | 1142 |
1060 CheckDownload(browser(), file, file); | 1143 CheckDownload(browser(), file, file); |
1061 } | 1144 } |
1062 | 1145 |
1063 // Open a web page in the current tab, open another tab via a Javascript call, | 1146 // Open a web page in the current tab, open another tab via a Javascript call, |
(...skipping 21 matching lines...) Expand all Loading... | |
1085 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1168 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1086 | 1169 |
1087 EXPECT_EQ(2, browser()->tab_count()); | 1170 EXPECT_EQ(2, browser()->tab_count()); |
1088 | 1171 |
1089 // Download a file and wait. | 1172 // Download a file and wait. |
1090 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1173 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1091 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1174 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1092 DownloadAndWaitWithDisposition(browser(), | 1175 DownloadAndWaitWithDisposition(browser(), |
1093 url, | 1176 url, |
1094 CURRENT_TAB, | 1177 CURRENT_TAB, |
1095 EXPECT_NO_SELECT_DIALOG, | 1178 false, |
1179 FilePath(), | |
1096 ui_test_utils::BROWSER_TEST_NONE); | 1180 ui_test_utils::BROWSER_TEST_NONE); |
1097 | 1181 |
1098 // When the download finishes, we should have two tabs. | 1182 // When the download finishes, we should have two tabs. |
1099 CheckDownloadUIVisible(browser(), true, true); | 1183 CheckDownloadUIVisible(browser(), true, true); |
1100 EXPECT_EQ(2, browser()->tab_count()); | 1184 EXPECT_EQ(2, browser()->tab_count()); |
1101 | 1185 |
1102 CheckDownload(browser(), file, file); | 1186 CheckDownload(browser(), file, file); |
1103 } | 1187 } |
1104 | 1188 |
1105 // Open a web page in the current tab, then download a file via Javascript, | 1189 // Open a web page in the current tab, then download a file via Javascript, |
(...skipping 12 matching lines...) Expand all Loading... | |
1118 | 1202 |
1119 // Open a web page and wait. | 1203 // Open a web page and wait. |
1120 ui_test_utils::NavigateToURL(browser(), url); | 1204 ui_test_utils::NavigateToURL(browser(), url); |
1121 | 1205 |
1122 // Download a file and wait. | 1206 // Download a file and wait. |
1123 // The file to download is "download-test1.lib". | 1207 // The file to download is "download-test1.lib". |
1124 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1208 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1125 DownloadAndWaitWithDisposition(browser(), | 1209 DownloadAndWaitWithDisposition(browser(), |
1126 GURL("javascript:openNew()"), | 1210 GURL("javascript:openNew()"), |
1127 CURRENT_TAB, | 1211 CURRENT_TAB, |
1128 EXPECT_NO_SELECT_DIALOG, | 1212 false, |
1213 FilePath(), | |
1129 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1214 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1130 | 1215 |
1131 // When the download finishes, we should still have one tab. | 1216 // When the download finishes, we should still have one tab. |
1132 CheckDownloadUIVisible(browser(), true, true); | 1217 CheckDownloadUIVisible(browser(), true, true); |
1133 EXPECT_EQ(1, browser()->tab_count()); | 1218 EXPECT_EQ(1, browser()->tab_count()); |
1134 | 1219 |
1135 CheckDownload(browser(), file, file); | 1220 CheckDownload(browser(), file, file); |
1136 } | 1221 } |
1137 | 1222 |
1138 // Open a web page in the current tab, then call Javascript via a button to | 1223 // Open a web page in the current tab, then call Javascript via a button to |
(...skipping 14 matching lines...) Expand all Loading... | |
1153 ui_test_utils::NavigateToURL(browser(), url); | 1238 ui_test_utils::NavigateToURL(browser(), url); |
1154 | 1239 |
1155 // Download a file in a new tab and wait. The tab will automatically close | 1240 // Download a file in a new tab and wait. The tab will automatically close |
1156 // when the download begins. | 1241 // when the download begins. |
1157 // The file to download is "download-test1.lib". | 1242 // The file to download is "download-test1.lib". |
1158 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1243 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1159 DownloadAndWaitWithDisposition( | 1244 DownloadAndWaitWithDisposition( |
1160 browser(), | 1245 browser(), |
1161 GURL("javascript:document.getElementById('form').submit()"), | 1246 GURL("javascript:document.getElementById('form').submit()"), |
1162 CURRENT_TAB, | 1247 CURRENT_TAB, |
1163 EXPECT_NO_SELECT_DIALOG, | 1248 false, |
1249 FilePath(), | |
1164 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1250 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1165 | 1251 |
1166 // When the download finishes, we should still have one tab. | 1252 // When the download finishes, we should still have one tab. |
1167 CheckDownloadUIVisible(browser(), true, true); | 1253 CheckDownloadUIVisible(browser(), true, true); |
1168 EXPECT_EQ(1, browser()->tab_count()); | 1254 EXPECT_EQ(1, browser()->tab_count()); |
1169 | 1255 |
1170 CheckDownload(browser(), file, file); | 1256 CheckDownload(browser(), file, file); |
1171 } | 1257 } |
1172 | 1258 |
1173 // Download a file in a new window. | 1259 // Download a file in a new window. |
1174 // Verify that we have 2 windows, and the download shelf is not visible in the | 1260 // Verify that we have 2 windows, and the download shelf is not visible in the |
1175 // first window, but is visible in the second window. | 1261 // first window, but is visible in the second window. |
1176 // Close the new window. | 1262 // Close the new window. |
1177 // Verify that we have 1 window, and the download shelf is not visible. | 1263 // Verify that we have 1 window, and the download shelf is not visible. |
1178 // | 1264 // |
1179 // Regression test for http://crbug.com/44454 | 1265 // Regression test for http://crbug.com/44454 |
1180 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { | 1266 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { |
1181 ASSERT_TRUE(InitialSetup(false)); | 1267 ASSERT_TRUE(InitialSetup(false)); |
1182 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1268 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1183 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1269 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1184 #if !defined(OS_MACOSX) | 1270 #if !defined(OS_MACOSX) |
1185 // See below. | 1271 // See below. |
1186 Browser* first_browser = browser(); | 1272 Browser* first_browser = browser(); |
1187 #endif | 1273 #endif |
1188 | 1274 |
1189 // Download a file in a new window and wait. | 1275 // Download a file in a new window and wait. |
1190 DownloadAndWaitWithDisposition(browser(), | 1276 DownloadAndWaitWithDisposition(browser(), |
1191 url, | 1277 url, |
1192 NEW_WINDOW, | 1278 NEW_WINDOW, |
1193 EXPECT_NO_SELECT_DIALOG, | 1279 false, |
1280 FilePath(), | |
1194 ui_test_utils::BROWSER_TEST_NONE); | 1281 ui_test_utils::BROWSER_TEST_NONE); |
1195 | 1282 |
1196 // When the download finishes, the download shelf SHOULD NOT be visible in | 1283 // When the download finishes, the download shelf SHOULD NOT be visible in |
1197 // the first window. | 1284 // the first window. |
1198 ExpectWindowCountAfterDownload(2); | 1285 ExpectWindowCountAfterDownload(2); |
1199 EXPECT_EQ(1, browser()->tab_count()); | 1286 EXPECT_EQ(1, browser()->tab_count()); |
1200 // Except on Chrome OS, where the download window sticks around. | 1287 // Except on Chrome OS, where the download window sticks around. |
1201 CheckDownloadUIVisible(browser(), false, true); | 1288 CheckDownloadUIVisible(browser(), false, true); |
1202 | 1289 |
1203 // The download shelf SHOULD be visible in the second window. | 1290 // The download shelf SHOULD be visible in the second window. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 | 1377 |
1291 // Confirm a download makes it into the history properly. | 1378 // Confirm a download makes it into the history properly. |
1292 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1379 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
1293 ASSERT_TRUE(InitialSetup(false)); | 1380 ASSERT_TRUE(InitialSetup(false)); |
1294 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1381 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1295 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1382 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1296 FilePath origin_file(OriginFile(file)); | 1383 FilePath origin_file(OriginFile(file)); |
1297 int64 origin_size; | 1384 int64 origin_size; |
1298 file_util::GetFileSize(origin_file, &origin_size); | 1385 file_util::GetFileSize(origin_file, &origin_size); |
1299 | 1386 |
1300 // Download the file and wait. We do not expect the Select File dialog. | 1387 // Download the file and wait. We do not expect the select file dialog. |
1301 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1388 DownloadAndWaitWithoutDialog(browser(), url); |
1302 | 1389 |
1303 // Get details of what downloads have just happened. | 1390 // Get details of what downloads have just happened. |
1304 std::vector<DownloadItem*> downloads; | 1391 std::vector<DownloadItem*> downloads; |
1305 GetDownloads(browser(), &downloads); | 1392 GetDownloads(browser(), &downloads); |
1306 ASSERT_EQ(1u, downloads.size()); | 1393 ASSERT_EQ(1u, downloads.size()); |
1307 int64 db_handle = downloads[0]->db_handle(); | 1394 int64 db_handle = downloads[0]->db_handle(); |
1308 | 1395 |
1309 // Check state. | 1396 // Check state. |
1310 EXPECT_EQ(1, browser()->tab_count()); | 1397 EXPECT_EQ(1, browser()->tab_count()); |
1311 CheckDownload(browser(), file, file); | 1398 CheckDownload(browser(), file, file); |
(...skipping 16 matching lines...) Expand all Loading... | |
1328 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1415 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
1329 // after download of a file while viewing another chrome://. | 1416 // after download of a file while viewing another chrome://. |
1330 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1417 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
1331 ASSERT_TRUE(InitialSetup(false)); | 1418 ASSERT_TRUE(InitialSetup(false)); |
1332 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1419 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1333 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1420 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1334 GURL flags_url(chrome::kAboutFlagsURL); | 1421 GURL flags_url(chrome::kAboutFlagsURL); |
1335 GURL extensions_url(chrome::kChromeUIExtensionsURL); | 1422 GURL extensions_url(chrome::kChromeUIExtensionsURL); |
1336 | 1423 |
1337 ui_test_utils::NavigateToURL(browser(), flags_url); | 1424 ui_test_utils::NavigateToURL(browser(), flags_url); |
1338 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1425 DownloadAndWaitWithoutDialog(browser(), download_url); |
1339 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1426 ui_test_utils::NavigateToURL(browser(), extensions_url); |
1340 TabContents* contents = browser()->GetSelectedTabContents(); | 1427 TabContents* contents = browser()->GetSelectedTabContents(); |
1341 ASSERT_TRUE(contents); | 1428 ASSERT_TRUE(contents); |
1342 bool webui_responded = false; | 1429 bool webui_responded = false; |
1343 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1430 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1344 contents->render_view_host(), | 1431 contents->render_view_host(), |
1345 L"", | 1432 L"", |
1346 L"window.domAutomationController.send(window.webui_responded_);", | 1433 L"window.domAutomationController.send(window.webui_responded_);", |
1347 &webui_responded)); | 1434 &webui_responded)); |
1348 EXPECT_TRUE(webui_responded); | 1435 EXPECT_TRUE(webui_responded); |
(...skipping 16 matching lines...) Expand all Loading... | |
1365 ASSERT_TRUE(contents); | 1452 ASSERT_TRUE(contents); |
1366 bool result = false; | 1453 bool result = false; |
1367 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1454 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1368 contents->render_view_host(), | 1455 contents->render_view_host(), |
1369 L"", | 1456 L"", |
1370 L"window.onunload = function() { var do_nothing = 0; }; " | 1457 L"window.onunload = function() { var do_nothing = 0; }; " |
1371 L"window.domAutomationController.send(true);", | 1458 L"window.domAutomationController.send(true);", |
1372 &result)); | 1459 &result)); |
1373 EXPECT_TRUE(result); | 1460 EXPECT_TRUE(result); |
1374 | 1461 |
1375 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1462 DownloadAndWaitWithoutDialog(browser(), download_url); |
1376 | 1463 |
1377 ui_test_utils::WindowedNotificationObserver signal( | 1464 ui_test_utils::WindowedNotificationObserver signal( |
1378 NotificationType::BROWSER_CLOSED, | 1465 NotificationType::BROWSER_CLOSED, |
1379 Source<Browser>(browser())); | 1466 Source<Browser>(browser())); |
1380 browser()->CloseWindow(); | 1467 browser()->CloseWindow(); |
1381 signal.Wait(); | 1468 signal.Wait(); |
1382 } | 1469 } |
1383 | 1470 |
1384 // Test to make sure auto-open works. | 1471 // Test to make sure auto-open works. |
1385 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1472 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
1386 ASSERT_TRUE(InitialSetup(false)); | 1473 ASSERT_TRUE(InitialSetup(false)); |
1387 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1474 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
1388 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1475 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1389 | 1476 |
1390 ASSERT_TRUE( | 1477 ASSERT_TRUE( |
1391 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1478 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
1392 | 1479 |
1393 // Mokc out external opening on all downloads until end of test. | 1480 // Mokc out external opening on all downloads until end of test. |
1394 MockDownloadOpeningObserver observer( | 1481 MockDownloadOpeningObserver observer( |
1395 browser()->profile()->GetDownloadManager()); | 1482 browser()->profile()->GetDownloadManager()); |
1396 | 1483 |
1397 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1484 DownloadAndWaitWithoutDialog(browser(), url); |
1398 | 1485 |
1399 // Find the download and confirm it was opened. | 1486 // Find the download and confirm it was opened. |
1400 std::vector<DownloadItem*> downloads; | 1487 std::vector<DownloadItem*> downloads; |
1401 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1488 browser()->profile()->GetDownloadManager()->SearchDownloads( |
1402 string16(), &downloads); | 1489 string16(), &downloads); |
1403 ASSERT_EQ(1u, downloads.size()); | 1490 ASSERT_EQ(1u, downloads.size()); |
1404 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); | 1491 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); |
1405 EXPECT_TRUE(downloads[0]->opened()); | 1492 EXPECT_TRUE(downloads[0]->opened()); |
1406 | 1493 |
1407 // As long as we're here, confirmed everything else is good. | 1494 // As long as we're here, confirmed everything else is good. |
1408 EXPECT_EQ(1, browser()->tab_count()); | 1495 EXPECT_EQ(1, browser()->tab_count()); |
1409 CheckDownload(browser(), file, file); | 1496 CheckDownload(browser(), file, file); |
1410 // Dissapears on most UIs, but the download panel sticks around for | 1497 // Dissapears on most UIs, but the download panel sticks around for |
1411 // chrome os. | 1498 // chrome os. |
1412 CheckDownloadUIVisible(browser(), false, true); | 1499 CheckDownloadUIVisible(browser(), false, true); |
1413 } | 1500 } |
OLD | NEW |