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 DownloadAndWait(Browser* browser, const GURL& url) { |
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 DownloadAndWait(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, DownloadFolder1) { |
| 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::ScopedDefaultDownloadDirectory override_default_downloads; |
| 826 override_default_downloads.Override(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 |
| 841 // Checks if the default folder for downloaded files is created |
| 842 // and a file is saved to the folder in the following situation: |
| 843 // The default folder for downloaded files does not exist. |
| 844 // The user's "Downloads" folder does not exist. |
| 845 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadFolder2) { |
| 846 ASSERT_TRUE(InitialSetup(false)); |
| 847 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 848 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 849 FilePath downloaded_file(DestinationFile(browser(), file)); |
| 850 |
| 851 // Temporarily change the user's "Downloads" folder. |
| 852 FilePath nonexistent_dir("/tmp/koakuma_andre_moemoe_nyannyan"); |
| 853 download_util::ScopedDefaultDownloadDirectory override_default_downloads; |
| 854 override_default_downloads.Override(nonexistent_dir); |
| 855 |
| 856 // Delete the default folder for downloaded files. |
| 857 ASSERT_TRUE(DeleteDownloadsDirectory()); |
| 858 ASSERT_FALSE(file_util::PathExists(GetDownloadDirectory(browser()))); |
| 859 |
| 860 // Download the file and wait. We expect the select file dialog. |
| 861 DownloadAndWaitWithDialog(browser(), url, downloaded_file); |
| 862 |
| 863 EXPECT_FALSE(file_util::PathExists(downloaded_file)); |
| 864 EXPECT_FALSE(file_util::PathExists(nonexistent_dir)); |
| 865 EXPECT_TRUE(file_util::PathExists(GetDownloadDirectory(browser()))); |
| 866 EXPECT_EQ(1, browser()->tab_count()); |
| 867 } |
| 868 |
794 #if defined(OS_WIN) | 869 #if defined(OS_WIN) |
795 // Download a file and confirm that the zone identifier (on windows) | 870 // Download a file and confirm that the zone identifier (on windows) |
796 // is set to internet. | 871 // is set to internet. |
797 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 872 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
798 ASSERT_TRUE(InitialSetup(false)); | 873 ASSERT_TRUE(InitialSetup(false)); |
799 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 874 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
800 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 875 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
801 | 876 |
802 // Download the file and wait. We do not expect the Select File dialog. | 877 // Download the file and wait. We do not expect the select file dialog. |
803 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 878 DownloadAndWait(browser(), url); |
804 | 879 |
805 // Check state. Special file state must be checked before CheckDownload, | 880 // Check state. Special file state must be checked before CheckDownload, |
806 // as CheckDownload will delete the output file. | 881 // as CheckDownload will delete the output file. |
807 EXPECT_EQ(1, browser()->tab_count()); | 882 EXPECT_EQ(1, browser()->tab_count()); |
808 FilePath downloaded_file(DestinationFile(browser(), file)); | 883 FilePath downloaded_file(DestinationFile(browser(), file)); |
809 if (file_util::VolumeSupportsADS(downloaded_file)) | 884 if (file_util::VolumeSupportsADS(downloaded_file)) |
810 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); | 885 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
811 CheckDownload(browser(), file, file); | 886 CheckDownload(browser(), file, file); |
812 CheckDownloadUIVisible(browser(), true, true); | 887 CheckDownloadUIVisible(browser(), true, true); |
813 } | 888 } |
814 #endif | 889 #endif |
815 | 890 |
816 // Put up a Select File dialog when the file is downloaded, due to its MIME | 891 // Put up a select file dialog when the file is downloaded, due to its MIME |
817 // type. | 892 // type. |
818 // | 893 // |
819 // This test runs correctly, but leaves behind turds in the test user's | 894 // 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 | 895 // download directory because of http://crbug.com/62099. No big loss; it |
821 // was primarily confirming DownloadsObserver wait on select file dialog | 896 // was primarily confirming DownloadsObserver wait on select file dialog |
822 // functionality anyway. | 897 // functionality anyway. |
823 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { | 898 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { |
824 ASSERT_TRUE(InitialSetup(true)); | 899 ASSERT_TRUE(InitialSetup(true)); |
825 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 900 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
826 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 901 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 902 FilePath file_path(DestinationFile(browser(), file)); |
827 | 903 |
828 // Download the file and wait. We expect the Select File dialog to appear | 904 // Download the file and wait. We expect the select file dialog to appear |
829 // due to the MIME type. | 905 // due to the MIME type. |
830 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); | 906 DownloadAndWaitWithDialog(browser(), url, file_path); |
831 | 907 |
832 // Check state. | 908 // Check state. |
833 EXPECT_EQ(1, browser()->tab_count()); | 909 EXPECT_EQ(1, browser()->tab_count()); |
834 // Since we exited while the Select File dialog was visible, there should not | 910 // 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. | 911 // be anything in the download shelf and so it should not be visible. |
836 CheckDownloadUIVisible(browser(), false, false); | 912 CheckDownloadUIVisible(browser(), false, false); |
837 } | 913 } |
838 | 914 |
839 // Access a file with a viewable mime-type, verify that a download | 915 // Access a file with a viewable mime-type, verify that a download |
840 // did not initiate. | 916 // did not initiate. |
841 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 917 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
842 ASSERT_TRUE(InitialSetup(false)); | 918 ASSERT_TRUE(InitialSetup(false)); |
843 FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 919 FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
844 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 920 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 | 935 // download tab opened and the file exists as the filename specified in the |
860 // header. This also ensures we properly handle empty file downloads. | 936 // header. This also ensures we properly handle empty file downloads. |
861 // The download shelf should be visible in the current tab. | 937 // The download shelf should be visible in the current tab. |
862 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 938 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
863 ASSERT_TRUE(InitialSetup(false)); | 939 ASSERT_TRUE(InitialSetup(false)); |
864 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 940 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
865 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 941 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
866 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 942 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
867 | 943 |
868 // Download a file and wait. | 944 // Download a file and wait. |
869 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 945 DownloadAndWait(browser(), url); |
870 | 946 |
871 CheckDownload(browser(), download_file, file); | 947 CheckDownload(browser(), download_file, file); |
872 | 948 |
873 // Check state. | 949 // Check state. |
874 EXPECT_EQ(1, browser()->tab_count()); | 950 EXPECT_EQ(1, browser()->tab_count()); |
875 CheckDownloadUIVisible(browser(), true, true); | 951 CheckDownloadUIVisible(browser(), true, true); |
876 } | 952 } |
877 | 953 |
878 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. | 954 #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 | 955 // 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, | 956 // tab, opening a second tab, closing the shelf, going back to the first tab, |
881 // and checking that the shelf is closed. | 957 // and checking that the shelf is closed. |
882 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { | 958 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { |
883 ASSERT_TRUE(InitialSetup(false)); | 959 ASSERT_TRUE(InitialSetup(false)); |
884 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 960 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
885 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 961 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
886 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 962 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
887 | 963 |
888 // Download a file and wait. | 964 // Download a file and wait. |
889 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 965 DownloadAndWait(browser(), url); |
890 | 966 |
891 CheckDownload(browser(), download_file, file); | 967 CheckDownload(browser(), download_file, file); |
892 | 968 |
893 // Check state. | 969 // Check state. |
894 EXPECT_EQ(1, browser()->tab_count()); | 970 EXPECT_EQ(1, browser()->tab_count()); |
895 CheckDownloadUIVisible(browser(), true, true); | 971 CheckDownloadUIVisible(browser(), true, true); |
896 | 972 |
897 // Open a second tab and wait. | 973 // Open a second tab and wait. |
898 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), | 974 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), |
899 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); | 975 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 int window_count = BrowserList::size(); | 1020 int window_count = BrowserList::size(); |
945 EXPECT_EQ(2, window_count); | 1021 EXPECT_EQ(2, window_count); |
946 | 1022 |
947 // Download a file in the Incognito window and wait. | 1023 // Download a file in the Incognito window and wait. |
948 CreateAndSetDownloadsDirectory(incognito); | 1024 CreateAndSetDownloadsDirectory(incognito); |
949 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1025 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
950 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1026 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
951 // Since |incognito| is a separate browser, we have to set it up explicitly. | 1027 // Since |incognito| is a separate browser, we have to set it up explicitly. |
952 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 1028 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
953 false); | 1029 false); |
954 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); | 1030 DownloadAndWait(incognito, url); |
955 | 1031 |
956 // We should still have 2 windows. | 1032 // We should still have 2 windows. |
957 ExpectWindowCountAfterDownload(2); | 1033 ExpectWindowCountAfterDownload(2); |
958 | 1034 |
959 // Verify that the download shelf is showing for the Incognito window. | 1035 // Verify that the download shelf is showing for the Incognito window. |
960 CheckDownloadUIVisible(incognito, true, true); | 1036 CheckDownloadUIVisible(incognito, true, true); |
961 | 1037 |
962 #if !defined(OS_MACOSX) | 1038 #if !defined(OS_MACOSX) |
963 // On Mac OS X, the UI window close is delayed until the outermost | 1039 // 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 | 1040 // 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)); | 1087 ASSERT_TRUE(InitialSetup(false)); |
1012 | 1088 |
1013 // Download a file in a new background tab and wait. The tab is automatically | 1089 // Download a file in a new background tab and wait. The tab is automatically |
1014 // closed when the download begins. | 1090 // closed when the download begins. |
1015 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1091 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1016 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1092 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1017 DownloadAndWaitWithDisposition( | 1093 DownloadAndWaitWithDisposition( |
1018 browser(), | 1094 browser(), |
1019 url, | 1095 url, |
1020 NEW_BACKGROUND_TAB, | 1096 NEW_BACKGROUND_TAB, |
1021 EXPECT_NO_SELECT_DIALOG, | 1097 false, |
| 1098 FilePath(), |
1022 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1099 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1023 | 1100 |
1024 // When the download finishes, we should still have one tab. | 1101 // When the download finishes, we should still have one tab. |
1025 CheckDownloadUIVisible(browser(), true, true); | 1102 CheckDownloadUIVisible(browser(), true, true); |
1026 EXPECT_EQ(1, browser()->tab_count()); | 1103 EXPECT_EQ(1, browser()->tab_count()); |
1027 | 1104 |
1028 CheckDownload(browser(), file, file); | 1105 CheckDownload(browser(), file, file); |
1029 } | 1106 } |
1030 | 1107 |
1031 // Open a web page in the current tab, then download a file in another tab via | 1108 // 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)); | 1120 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
1044 | 1121 |
1045 // Open a web page and wait. | 1122 // Open a web page and wait. |
1046 ui_test_utils::NavigateToURL(browser(), url); | 1123 ui_test_utils::NavigateToURL(browser(), url); |
1047 | 1124 |
1048 // Download a file in a new tab and wait (via Javascript). | 1125 // Download a file in a new tab and wait (via Javascript). |
1049 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1126 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1050 DownloadAndWaitWithDisposition(browser(), | 1127 DownloadAndWaitWithDisposition(browser(), |
1051 GURL("javascript:openNew()"), | 1128 GURL("javascript:openNew()"), |
1052 CURRENT_TAB, | 1129 CURRENT_TAB, |
1053 EXPECT_NO_SELECT_DIALOG, | 1130 false, |
| 1131 FilePath(), |
1054 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1132 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1055 | 1133 |
1056 // When the download finishes, we should have two tabs. | 1134 // When the download finishes, we should have two tabs. |
1057 CheckDownloadUIVisible(browser(), true, true); | 1135 CheckDownloadUIVisible(browser(), true, true); |
1058 EXPECT_EQ(2, browser()->tab_count()); | 1136 EXPECT_EQ(2, browser()->tab_count()); |
1059 | 1137 |
1060 CheckDownload(browser(), file, file); | 1138 CheckDownload(browser(), file, file); |
1061 } | 1139 } |
1062 | 1140 |
1063 // Open a web page in the current tab, open another tab via a Javascript call, | 1141 // 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); | 1163 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1086 | 1164 |
1087 EXPECT_EQ(2, browser()->tab_count()); | 1165 EXPECT_EQ(2, browser()->tab_count()); |
1088 | 1166 |
1089 // Download a file and wait. | 1167 // Download a file and wait. |
1090 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1168 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1091 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1169 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1092 DownloadAndWaitWithDisposition(browser(), | 1170 DownloadAndWaitWithDisposition(browser(), |
1093 url, | 1171 url, |
1094 CURRENT_TAB, | 1172 CURRENT_TAB, |
1095 EXPECT_NO_SELECT_DIALOG, | 1173 false, |
| 1174 FilePath(), |
1096 ui_test_utils::BROWSER_TEST_NONE); | 1175 ui_test_utils::BROWSER_TEST_NONE); |
1097 | 1176 |
1098 // When the download finishes, we should have two tabs. | 1177 // When the download finishes, we should have two tabs. |
1099 CheckDownloadUIVisible(browser(), true, true); | 1178 CheckDownloadUIVisible(browser(), true, true); |
1100 EXPECT_EQ(2, browser()->tab_count()); | 1179 EXPECT_EQ(2, browser()->tab_count()); |
1101 | 1180 |
1102 CheckDownload(browser(), file, file); | 1181 CheckDownload(browser(), file, file); |
1103 } | 1182 } |
1104 | 1183 |
1105 // Open a web page in the current tab, then download a file via Javascript, | 1184 // Open a web page in the current tab, then download a file via Javascript, |
(...skipping 12 matching lines...) Expand all Loading... |
1118 | 1197 |
1119 // Open a web page and wait. | 1198 // Open a web page and wait. |
1120 ui_test_utils::NavigateToURL(browser(), url); | 1199 ui_test_utils::NavigateToURL(browser(), url); |
1121 | 1200 |
1122 // Download a file and wait. | 1201 // Download a file and wait. |
1123 // The file to download is "download-test1.lib". | 1202 // The file to download is "download-test1.lib". |
1124 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1203 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1125 DownloadAndWaitWithDisposition(browser(), | 1204 DownloadAndWaitWithDisposition(browser(), |
1126 GURL("javascript:openNew()"), | 1205 GURL("javascript:openNew()"), |
1127 CURRENT_TAB, | 1206 CURRENT_TAB, |
1128 EXPECT_NO_SELECT_DIALOG, | 1207 false, |
| 1208 FilePath(), |
1129 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1209 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1130 | 1210 |
1131 // When the download finishes, we should still have one tab. | 1211 // When the download finishes, we should still have one tab. |
1132 CheckDownloadUIVisible(browser(), true, true); | 1212 CheckDownloadUIVisible(browser(), true, true); |
1133 EXPECT_EQ(1, browser()->tab_count()); | 1213 EXPECT_EQ(1, browser()->tab_count()); |
1134 | 1214 |
1135 CheckDownload(browser(), file, file); | 1215 CheckDownload(browser(), file, file); |
1136 } | 1216 } |
1137 | 1217 |
1138 // Open a web page in the current tab, then call Javascript via a button to | 1218 // 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); | 1233 ui_test_utils::NavigateToURL(browser(), url); |
1154 | 1234 |
1155 // Download a file in a new tab and wait. The tab will automatically close | 1235 // Download a file in a new tab and wait. The tab will automatically close |
1156 // when the download begins. | 1236 // when the download begins. |
1157 // The file to download is "download-test1.lib". | 1237 // The file to download is "download-test1.lib". |
1158 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1238 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1159 DownloadAndWaitWithDisposition( | 1239 DownloadAndWaitWithDisposition( |
1160 browser(), | 1240 browser(), |
1161 GURL("javascript:document.getElementById('form').submit()"), | 1241 GURL("javascript:document.getElementById('form').submit()"), |
1162 CURRENT_TAB, | 1242 CURRENT_TAB, |
1163 EXPECT_NO_SELECT_DIALOG, | 1243 false, |
| 1244 FilePath(), |
1164 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1245 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1165 | 1246 |
1166 // When the download finishes, we should still have one tab. | 1247 // When the download finishes, we should still have one tab. |
1167 CheckDownloadUIVisible(browser(), true, true); | 1248 CheckDownloadUIVisible(browser(), true, true); |
1168 EXPECT_EQ(1, browser()->tab_count()); | 1249 EXPECT_EQ(1, browser()->tab_count()); |
1169 | 1250 |
1170 CheckDownload(browser(), file, file); | 1251 CheckDownload(browser(), file, file); |
1171 } | 1252 } |
1172 | 1253 |
1173 // Download a file in a new window. | 1254 // Download a file in a new window. |
1174 // Verify that we have 2 windows, and the download shelf is not visible in the | 1255 // 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. | 1256 // first window, but is visible in the second window. |
1176 // Close the new window. | 1257 // Close the new window. |
1177 // Verify that we have 1 window, and the download shelf is not visible. | 1258 // Verify that we have 1 window, and the download shelf is not visible. |
1178 // | 1259 // |
1179 // Regression test for http://crbug.com/44454 | 1260 // Regression test for http://crbug.com/44454 |
1180 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { | 1261 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { |
1181 ASSERT_TRUE(InitialSetup(false)); | 1262 ASSERT_TRUE(InitialSetup(false)); |
1182 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1263 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1183 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1264 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1184 #if !defined(OS_MACOSX) | 1265 #if !defined(OS_MACOSX) |
1185 // See below. | 1266 // See below. |
1186 Browser* first_browser = browser(); | 1267 Browser* first_browser = browser(); |
1187 #endif | 1268 #endif |
1188 | 1269 |
1189 // Download a file in a new window and wait. | 1270 // Download a file in a new window and wait. |
1190 DownloadAndWaitWithDisposition(browser(), | 1271 DownloadAndWaitWithDisposition(browser(), |
1191 url, | 1272 url, |
1192 NEW_WINDOW, | 1273 NEW_WINDOW, |
1193 EXPECT_NO_SELECT_DIALOG, | 1274 false, |
| 1275 FilePath(), |
1194 ui_test_utils::BROWSER_TEST_NONE); | 1276 ui_test_utils::BROWSER_TEST_NONE); |
1195 | 1277 |
1196 // When the download finishes, the download shelf SHOULD NOT be visible in | 1278 // When the download finishes, the download shelf SHOULD NOT be visible in |
1197 // the first window. | 1279 // the first window. |
1198 ExpectWindowCountAfterDownload(2); | 1280 ExpectWindowCountAfterDownload(2); |
1199 EXPECT_EQ(1, browser()->tab_count()); | 1281 EXPECT_EQ(1, browser()->tab_count()); |
1200 // Except on Chrome OS, where the download window sticks around. | 1282 // Except on Chrome OS, where the download window sticks around. |
1201 CheckDownloadUIVisible(browser(), false, true); | 1283 CheckDownloadUIVisible(browser(), false, true); |
1202 | 1284 |
1203 // The download shelf SHOULD be visible in the second window. | 1285 // The download shelf SHOULD be visible in the second window. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 | 1372 |
1291 // Confirm a download makes it into the history properly. | 1373 // Confirm a download makes it into the history properly. |
1292 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1374 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
1293 ASSERT_TRUE(InitialSetup(false)); | 1375 ASSERT_TRUE(InitialSetup(false)); |
1294 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1376 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1295 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1377 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1296 FilePath origin_file(OriginFile(file)); | 1378 FilePath origin_file(OriginFile(file)); |
1297 int64 origin_size; | 1379 int64 origin_size; |
1298 file_util::GetFileSize(origin_file, &origin_size); | 1380 file_util::GetFileSize(origin_file, &origin_size); |
1299 | 1381 |
1300 // Download the file and wait. We do not expect the Select File dialog. | 1382 // Download the file and wait. We do not expect the select file dialog. |
1301 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1383 DownloadAndWait(browser(), url); |
1302 | 1384 |
1303 // Get details of what downloads have just happened. | 1385 // Get details of what downloads have just happened. |
1304 std::vector<DownloadItem*> downloads; | 1386 std::vector<DownloadItem*> downloads; |
1305 GetDownloads(browser(), &downloads); | 1387 GetDownloads(browser(), &downloads); |
1306 ASSERT_EQ(1u, downloads.size()); | 1388 ASSERT_EQ(1u, downloads.size()); |
1307 int64 db_handle = downloads[0]->db_handle(); | 1389 int64 db_handle = downloads[0]->db_handle(); |
1308 | 1390 |
1309 // Check state. | 1391 // Check state. |
1310 EXPECT_EQ(1, browser()->tab_count()); | 1392 EXPECT_EQ(1, browser()->tab_count()); |
1311 CheckDownload(browser(), file, file); | 1393 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 | 1410 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
1329 // after download of a file while viewing another chrome://. | 1411 // after download of a file while viewing another chrome://. |
1330 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1412 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
1331 ASSERT_TRUE(InitialSetup(false)); | 1413 ASSERT_TRUE(InitialSetup(false)); |
1332 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1414 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1333 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1415 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1334 GURL flags_url(chrome::kAboutFlagsURL); | 1416 GURL flags_url(chrome::kAboutFlagsURL); |
1335 GURL extensions_url(chrome::kChromeUIExtensionsURL); | 1417 GURL extensions_url(chrome::kChromeUIExtensionsURL); |
1336 | 1418 |
1337 ui_test_utils::NavigateToURL(browser(), flags_url); | 1419 ui_test_utils::NavigateToURL(browser(), flags_url); |
1338 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1420 DownloadAndWait(browser(), download_url); |
1339 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1421 ui_test_utils::NavigateToURL(browser(), extensions_url); |
1340 TabContents* contents = browser()->GetSelectedTabContents(); | 1422 TabContents* contents = browser()->GetSelectedTabContents(); |
1341 ASSERT_TRUE(contents); | 1423 ASSERT_TRUE(contents); |
1342 bool webui_responded = false; | 1424 bool webui_responded = false; |
1343 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1425 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1344 contents->render_view_host(), | 1426 contents->render_view_host(), |
1345 L"", | 1427 L"", |
1346 L"window.domAutomationController.send(window.webui_responded_);", | 1428 L"window.domAutomationController.send(window.webui_responded_);", |
1347 &webui_responded)); | 1429 &webui_responded)); |
1348 EXPECT_TRUE(webui_responded); | 1430 EXPECT_TRUE(webui_responded); |
(...skipping 16 matching lines...) Expand all Loading... |
1365 ASSERT_TRUE(contents); | 1447 ASSERT_TRUE(contents); |
1366 bool result = false; | 1448 bool result = false; |
1367 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1449 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1368 contents->render_view_host(), | 1450 contents->render_view_host(), |
1369 L"", | 1451 L"", |
1370 L"window.onunload = function() { var do_nothing = 0; }; " | 1452 L"window.onunload = function() { var do_nothing = 0; }; " |
1371 L"window.domAutomationController.send(true);", | 1453 L"window.domAutomationController.send(true);", |
1372 &result)); | 1454 &result)); |
1373 EXPECT_TRUE(result); | 1455 EXPECT_TRUE(result); |
1374 | 1456 |
1375 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1457 DownloadAndWait(browser(), download_url); |
1376 | 1458 |
1377 ui_test_utils::WindowedNotificationObserver signal( | 1459 ui_test_utils::WindowedNotificationObserver signal( |
1378 NotificationType::BROWSER_CLOSED, | 1460 NotificationType::BROWSER_CLOSED, |
1379 Source<Browser>(browser())); | 1461 Source<Browser>(browser())); |
1380 browser()->CloseWindow(); | 1462 browser()->CloseWindow(); |
1381 signal.Wait(); | 1463 signal.Wait(); |
1382 } | 1464 } |
1383 | 1465 |
1384 // Test to make sure auto-open works. | 1466 // Test to make sure auto-open works. |
1385 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1467 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
1386 ASSERT_TRUE(InitialSetup(false)); | 1468 ASSERT_TRUE(InitialSetup(false)); |
1387 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1469 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
1388 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1470 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1389 | 1471 |
1390 ASSERT_TRUE( | 1472 ASSERT_TRUE( |
1391 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1473 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
1392 | 1474 |
1393 // Mokc out external opening on all downloads until end of test. | 1475 // Mokc out external opening on all downloads until end of test. |
1394 MockDownloadOpeningObserver observer( | 1476 MockDownloadOpeningObserver observer( |
1395 browser()->profile()->GetDownloadManager()); | 1477 browser()->profile()->GetDownloadManager()); |
1396 | 1478 |
1397 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1479 DownloadAndWait(browser(), url); |
1398 | 1480 |
1399 // Find the download and confirm it was opened. | 1481 // Find the download and confirm it was opened. |
1400 std::vector<DownloadItem*> downloads; | 1482 std::vector<DownloadItem*> downloads; |
1401 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1483 browser()->profile()->GetDownloadManager()->SearchDownloads( |
1402 string16(), &downloads); | 1484 string16(), &downloads); |
1403 ASSERT_EQ(1u, downloads.size()); | 1485 ASSERT_EQ(1u, downloads.size()); |
1404 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); | 1486 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); |
1405 EXPECT_TRUE(downloads[0]->opened()); | 1487 EXPECT_TRUE(downloads[0]->opened()); |
1406 | 1488 |
1407 // As long as we're here, confirmed everything else is good. | 1489 // As long as we're here, confirmed everything else is good. |
1408 EXPECT_EQ(1, browser()->tab_count()); | 1490 EXPECT_EQ(1, browser()->tab_count()); |
1409 CheckDownload(browser(), file, file); | 1491 CheckDownload(browser(), file, file); |
1410 // Dissapears on most UIs, but the download panel sticks around for | 1492 // Dissapears on most UIs, but the download panel sticks around for |
1411 // chrome os. | 1493 // chrome os. |
1412 CheckDownloadUIVisible(browser(), false, true); | 1494 CheckDownloadUIVisible(browser(), false, true); |
1413 } | 1495 } |
OLD | NEW |