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" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "chrome/test/ui_test_utils.h" | 32 #include "chrome/test/ui_test_utils.h" |
33 #include "content/browser/cancelable_request.h" | 33 #include "content/browser/cancelable_request.h" |
34 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 34 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
35 #include "content/browser/tab_contents/tab_contents.h" | 35 #include "content/browser/tab_contents/tab_contents.h" |
36 #include "content/common/page_transition_types.h" | 36 #include "content/common/page_transition_types.h" |
37 #include "net/base/net_util.h" | 37 #include "net/base/net_util.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 enum SelectExpectation { | |
43 EXPECT_NO_SELECT_DIALOG = -1, | |
44 EXPECT_NOTHING, | |
45 EXPECT_SELECT_DIALOG | |
46 }; | |
47 | |
42 // Construction of this class defines a system state, based on some number | 48 // Construction of this class defines a system state, based on some number |
43 // of downloads being seen in a particular state + other events that | 49 // of downloads being seen in a particular state + other events that |
44 // may occur in the download system. That state will be recorded if it | 50 // may occur in the download system. That state will be recorded if it |
45 // occurs at any point after construction. When that state occurs, the class | 51 // occurs at any point after construction. When that state occurs, the class |
46 // is considered finished. Callers may either probe for the finished state, or | 52 // is considered finished. Callers may either probe for the finished state, or |
47 // wait on it. | 53 // wait on it. |
48 // | 54 // |
49 // TODO(rdsmith): Detect manager going down, remove pointer to | 55 // TODO(rdsmith): Detect manager going down, remove pointer to |
50 // DownloadManager, transition to finished. (For right now we | 56 // DownloadManager, transition to finished. (For right now we |
51 // just use a scoped_refptr<> to keep it around, but that may cause | 57 // just use a scoped_refptr<> to keep it around, but that may cause |
(...skipping 29 matching lines...) Expand all Loading... | |
81 } | 87 } |
82 | 88 |
83 ~DownloadsObserver() { | 89 ~DownloadsObserver() { |
84 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | 90 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); |
85 for (; it != downloads_observed_.end(); ++it) { | 91 for (; it != downloads_observed_.end(); ++it) { |
86 (*it)->RemoveObserver(this); | 92 (*it)->RemoveObserver(this); |
87 } | 93 } |
88 download_manager_->RemoveObserver(this); | 94 download_manager_->RemoveObserver(this); |
89 } | 95 } |
90 | 96 |
91 // State accessors. | 97 // Checks if the select file dialog was displayed as we expected. |
92 bool select_file_dialog_seen() { return select_file_dialog_seen_; } | 98 // If displayed, checks the suggested path in the dialog. |
99 bool CheckSelectFileDialogState(SelectExpectation expectation, | |
100 const FilePath& expected_suggested_path) { | |
101 if (expectation == EXPECT_NO_SELECT_DIALOG) { | |
102 return !select_file_dialog_seen_; | |
103 } else if (expectation == EXPECT_SELECT_DIALOG) { | |
104 return select_file_dialog_seen_ && | |
105 suggested_path_ == expected_suggested_path; | |
106 } | |
107 return true; | |
108 } | |
93 | 109 |
94 // Wait for whatever state was specified in the constructor. | 110 // Wait for whatever state was specified in the constructor. |
95 void WaitForFinished() { | 111 void WaitForFinished() { |
96 if (!IsFinished()) { | 112 if (!IsFinished()) { |
97 waiting_ = true; | 113 waiting_ = true; |
98 ui_test_utils::RunMessageLoop(); | 114 ui_test_utils::RunMessageLoop(); |
99 waiting_ = false; | 115 waiting_ = false; |
100 } | 116 } |
101 } | 117 } |
102 | 118 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 // If it is finished and we are observing it, stop. | 160 // If it is finished and we are observing it, stop. |
145 if (finished_it != finished_downloads_.end() && | 161 if (finished_it != finished_downloads_.end() && |
146 observed_it != downloads_observed_.end()) { | 162 observed_it != downloads_observed_.end()) { |
147 (*it)->RemoveObserver(this); | 163 (*it)->RemoveObserver(this); |
148 downloads_observed_.erase(observed_it); | 164 downloads_observed_.erase(observed_it); |
149 continue; | 165 continue; |
150 } | 166 } |
151 } | 167 } |
152 } | 168 } |
153 | 169 |
154 virtual void SelectFileDialogDisplayed(int32 /* id */) { | 170 virtual void SelectFileDialogDisplayed( |
171 int32 /* id */, const FilePath& suggested_path) { | |
155 select_file_dialog_seen_ = true; | 172 select_file_dialog_seen_ = true; |
173 suggested_path_ = suggested_path; | |
156 SignalIfFinished(); | 174 SignalIfFinished(); |
157 } | 175 } |
158 | 176 |
159 private: | 177 private: |
160 // Called when we know that a download item is in a final state. | 178 // 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 | 179 // 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 | 180 // final state; multiple notifications may occur once the item is in |
163 // that state. So we keep our own track of transitions into final. | 181 // that state. So we keep our own track of transitions into final. |
164 void DownloadInFinalState(DownloadItem* download) { | 182 void DownloadInFinalState(DownloadItem* download) { |
165 if (finished_downloads_.find(download) != finished_downloads_.end()) { | 183 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. | 229 // The state on which to consider the DownloadItem finished. |
212 DownloadItem::DownloadState download_finished_state_; | 230 DownloadItem::DownloadState download_finished_state_; |
213 | 231 |
214 // True if we should transition the DownloadsObserver to finished if | 232 // True if we should transition the DownloadsObserver to finished if |
215 // the select file dialog comes up. | 233 // the select file dialog comes up. |
216 bool finish_on_select_file_; | 234 bool finish_on_select_file_; |
217 | 235 |
218 // True if we've seen the select file dialog. | 236 // True if we've seen the select file dialog. |
219 bool select_file_dialog_seen_; | 237 bool select_file_dialog_seen_; |
220 | 238 |
239 // The suggested file path in the select file dialog. | |
240 FilePath suggested_path_; | |
241 | |
221 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); | 242 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); |
222 }; | 243 }; |
223 | 244 |
224 // WaitForFlush() returns after: | 245 // WaitForFlush() returns after: |
225 // * There are no IN_PROGRESS download items remaining on the | 246 // * There are no IN_PROGRESS download items remaining on the |
226 // DownloadManager. | 247 // DownloadManager. |
227 // * There have been two round trip messages through the file and | 248 // * There have been two round trip messages through the file and |
228 // IO threads. | 249 // IO threads. |
229 // This almost certainly means that a Download cancel has propagated through | 250 // This almost certainly means that a Download cancel has propagated through |
230 // the system. | 251 // the system. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 ResourceDispatcherHost* resource_dispatcher_host_; | 407 ResourceDispatcherHost* resource_dispatcher_host_; |
387 DownloadFileManager* download_file_manager_; | 408 DownloadFileManager* download_file_manager_; |
388 int rdh_pending_requests_; | 409 int rdh_pending_requests_; |
389 int dfm_pending_downloads_; | 410 int dfm_pending_downloads_; |
390 | 411 |
391 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); | 412 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); |
392 }; | 413 }; |
393 | 414 |
394 class DownloadTest : public InProcessBrowserTest { | 415 class DownloadTest : public InProcessBrowserTest { |
395 public: | 416 public: |
396 enum SelectExpectation { | |
397 EXPECT_NO_SELECT_DIALOG = -1, | |
398 EXPECT_NOTHING, | |
399 EXPECT_SELECT_DIALOG | |
400 }; | |
401 | |
402 DownloadTest() { | 417 DownloadTest() { |
403 EnableDOMAutomation(); | 418 EnableDOMAutomation(); |
404 } | 419 } |
405 | 420 |
406 // Returning false indicates a failure of the setup, and should be asserted | 421 // Returning false indicates a failure of the setup, and should be asserted |
407 // in the caller. | 422 // in the caller. |
408 virtual bool InitialSetup(bool prompt_for_download) { | 423 virtual bool InitialSetup(bool prompt_for_download) { |
409 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); | 424 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); |
410 EXPECT_TRUE(have_test_dir); | 425 EXPECT_TRUE(have_test_dir); |
411 if (!have_test_dir) | 426 if (!have_test_dir) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 if (!downloads_directory_.CreateUniqueTempDir()) | 475 if (!downloads_directory_.CreateUniqueTempDir()) |
461 return false; | 476 return false; |
462 | 477 |
463 browser->profile()->GetPrefs()->SetFilePath( | 478 browser->profile()->GetPrefs()->SetFilePath( |
464 prefs::kDownloadDefaultDirectory, | 479 prefs::kDownloadDefaultDirectory, |
465 downloads_directory_.path()); | 480 downloads_directory_.path()); |
466 | 481 |
467 return true; | 482 return true; |
468 } | 483 } |
469 | 484 |
485 // Delete the default folder for downloaded files. | |
486 bool DeleteDownloadsDirectory() { | |
487 return downloads_directory_.Delete(); | |
488 } | |
489 | |
470 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 490 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
471 return browser->profile()->GetDownloadManager()->download_prefs(); | 491 return browser->profile()->GetDownloadManager()->download_prefs(); |
472 } | 492 } |
473 | 493 |
474 FilePath GetDownloadDirectory(Browser* browser) { | 494 FilePath GetDownloadDirectory(Browser* browser) { |
475 DownloadManager* download_mananger = | 495 DownloadManager* download_mananger = |
476 browser->profile()->GetDownloadManager(); | 496 browser->profile()->GetDownloadManager(); |
477 return download_mananger->download_prefs()->download_path(); | 497 return download_mananger->download_prefs()->download_path(); |
478 } | 498 } |
479 | 499 |
(...skipping 16 matching lines...) Expand all Loading... | |
496 browser->profile()->GetDownloadManager(); | 516 browser->profile()->GetDownloadManager(); |
497 return new DownloadsObserver( | 517 return new DownloadsObserver( |
498 download_manager, num_downloads, | 518 download_manager, num_downloads, |
499 DownloadItem::IN_PROGRESS, // Has started | 519 DownloadItem::IN_PROGRESS, // Has started |
500 true); // Bail on select file | 520 true); // Bail on select file |
501 } | 521 } |
502 | 522 |
503 // Download |url|, then wait for the download to finish. | 523 // Download |url|, then wait for the download to finish. |
504 // |disposition| indicates where the navigation occurs (current tab, new | 524 // |disposition| indicates where the navigation occurs (current tab, new |
505 // foreground tab, etc). | 525 // foreground tab, etc). |
506 // |expectation| indicates whether or not a Select File dialog should be | 526 // |expectation| indicates whether or not a select file dialog should be |
507 // open when the download is finished, or if we don't care. | 527 // open when the download is finished, or if we don't care. |
508 // If the dialog appears, the routine exits. The only effect |expectation| | 528 // If the dialog appears, the routine exits. The only effect |expectation| |
509 // has is whether or not the test succeeds. | 529 // has is whether or not the test succeeds. |
530 // |expected_suggested_path| is the path expected to be suggested in the | |
531 // select file dialog. This |expected_suggested_path| must be specified | |
532 // if |expectation| is EXPECT_SELECT_DIALOG. If |expectation| is | |
533 // not EXPECT_SELECT_DIALOG, |expected_suggested_path| is ignored. | |
510 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 534 // |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. | 535 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
512 void DownloadAndWaitWithDisposition(Browser* browser, | 536 void DownloadAndWaitWithDisposition(Browser* browser, |
513 const GURL& url, | 537 const GURL& url, |
514 WindowOpenDisposition disposition, | 538 WindowOpenDisposition disposition, |
515 SelectExpectation expectation, | 539 SelectExpectation expectation, |
540 const FilePath& expected_suggested_path, | |
516 int browser_test_flags) { | 541 int browser_test_flags) { |
517 // Setup notification, navigate, and block. | 542 // Setup notification, navigate, and block. |
518 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 543 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); |
519 // This call will block until the condition specified by | 544 // This call will block until the condition specified by |
520 // |browser_test_flags|, but will not wait for the download to finish. | 545 // |browser_test_flags|, but will not wait for the download to finish. |
521 ui_test_utils::NavigateToURLWithDisposition(browser, | 546 ui_test_utils::NavigateToURLWithDisposition(browser, |
522 url, | 547 url, |
523 disposition, | 548 disposition, |
524 browser_test_flags); | 549 browser_test_flags); |
525 // Waits for the download to complete. | 550 // Waits for the download to complete. |
526 observer->WaitForFinished(); | 551 observer->WaitForFinished(); |
527 | 552 |
528 // If specified, check the state of the select file dialog. | 553 // Checks the state of the select file dialog. |
529 if (expectation != EXPECT_NOTHING) { | 554 EXPECT_TRUE(observer->CheckSelectFileDialogState(expectation, |
530 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, | 555 expected_suggested_path)); |
Randy Smith (Not in Mondays)
2011/06/06 15:31:29
I'd suggest (i.e. I don't feel very strongly) that
haraken1
2011/06/08 04:12:08
Done.
| |
531 observer->select_file_dialog_seen()); | |
532 } | |
533 } | 556 } |
534 | 557 |
535 // Download a file in the current tab, then wait for the download to finish. | 558 // Download a file in the current tab, then wait for the download to finish. |
536 void DownloadAndWait(Browser* browser, | 559 void DownloadAndWait(Browser* browser, |
537 const GURL& url, | 560 const GURL& url, |
538 SelectExpectation expectation) { | 561 SelectExpectation expectation, |
562 const FilePath& expected_suggested_path) { | |
Randy Smith (Not in Mondays)
2011/06/06 15:31:29
I'm inclined to say you should make a new variant
haraken1
2011/06/08 04:12:08
I made DownloadAndWaitWithoutDialog() and Download
| |
539 DownloadAndWaitWithDisposition( | 563 DownloadAndWaitWithDisposition( |
540 browser, | 564 browser, |
541 url, | 565 url, |
542 CURRENT_TAB, | 566 CURRENT_TAB, |
543 expectation, | 567 expectation, |
568 expected_suggested_path, | |
544 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 569 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
545 } | 570 } |
546 | 571 |
547 // Should only be called when the download is known to have finished | 572 // Should only be called when the download is known to have finished |
548 // (in error or not). | 573 // (in error or not). |
549 // Returning false indicates a failure of the function, and should be asserted | 574 // Returning false indicates a failure of the function, and should be asserted |
550 // in the caller. | 575 // in the caller. |
551 bool CheckDownload(Browser* browser, | 576 bool CheckDownload(Browser* browser, |
552 const FilePath& downloaded_filename, | 577 const FilePath& downloaded_filename, |
553 const FilePath& origin_filename) { | 578 const FilePath& origin_filename) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 // Files for these tests are found in DIR_TEST_DATA (currently | 796 // Files for these tests are found in DIR_TEST_DATA (currently |
772 // "chrome\test\data\", see chrome_paths.cc). | 797 // "chrome\test\data\", see chrome_paths.cc). |
773 // Mock responses have extension .mock-http-headers appended to the file name. | 798 // Mock responses have extension .mock-http-headers appended to the file name. |
774 | 799 |
775 // Download a file due to the associated MIME type. | 800 // Download a file due to the associated MIME type. |
776 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 801 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
777 ASSERT_TRUE(InitialSetup(false)); | 802 ASSERT_TRUE(InitialSetup(false)); |
778 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 803 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
779 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 804 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
780 | 805 |
781 // Download the file and wait. We do not expect the Select File dialog. | 806 // Download the file and wait. We do not expect the select file dialog. |
782 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 807 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
783 | 808 |
784 // Check state. | 809 // Check state. |
785 EXPECT_EQ(1, browser()->tab_count()); | 810 EXPECT_EQ(1, browser()->tab_count()); |
786 CheckDownload(browser(), file, file); | 811 CheckDownload(browser(), file, file); |
787 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 812 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
788 } | 813 } |
789 | 814 |
815 // Checks if a file is saved to the user's "Downloads" folder | |
816 // in the following situation: | |
817 // The default folder for downloaded files does not exist. | |
818 // The user's "Downloads" folder exists. | |
819 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadedFolder1) { | |
820 ASSERT_TRUE(InitialSetup(false)); | |
821 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
822 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
823 | |
824 // Temporarily change the user's "Downloads" folder. | |
825 FilePath prev_default_downloads_dir; | |
826 ASSERT_TRUE(PathService::Get( | |
827 chrome::DIR_DEFAULT_DOWNLOADS, &prev_default_downloads_dir)); | |
828 ScopedTempDir default_downloads_dir; | |
829 ASSERT_TRUE(default_downloads_dir.CreateUniqueTempDir()); | |
830 PathService::Set(chrome::DIR_DEFAULT_DOWNLOADS, default_downloads_dir.path()); | |
831 FilePath downloaded_file = default_downloads_dir.path().Append(file); | |
832 | |
833 // Delete the default folder for downloaded files. | |
834 ASSERT_TRUE(DeleteDownloadsDirectory()); | |
835 ASSERT_FALSE(file_util::PathExists(GetDownloadDirectory(browser()))); | |
836 | |
837 // Download the file and wait. We expect the select file dialog. | |
838 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG, downloaded_file); | |
839 | |
840 EXPECT_FALSE(file_util::PathExists(downloaded_file)); | |
841 EXPECT_FALSE(file_util::PathExists(GetDownloadDirectory(browser()))); | |
842 EXPECT_EQ(1, browser()->tab_count()); | |
843 | |
844 // Restore the user's "Downloads" folder. | |
845 PathService::Set(chrome::DIR_DEFAULT_DOWNLOADS, prev_default_downloads_dir); | |
846 } | |
847 | |
848 // Checks if the default folder for downloaded files is created | |
849 // and a file is saved to the folder in the following situation: | |
850 // The default folder for downloaded files does not exist. | |
851 // The user's "Downloads" folder does not exist. | |
852 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadedFolder2) { | |
853 ASSERT_TRUE(InitialSetup(false)); | |
854 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
855 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
856 FilePath downloaded_file(DestinationFile(browser(), file)); | |
857 | |
858 // Temporarily change the user's "Downloads" folder. | |
859 FilePath prev_default_downloads_dir; | |
860 ASSERT_TRUE(PathService::Get( | |
861 chrome::DIR_DEFAULT_DOWNLOADS, &prev_default_downloads_dir)); | |
862 FilePath nonexistent_dir("/tmp/koakuma_andre_moemoe_nyannyannyan"); | |
863 PathService::Set(chrome::DIR_DEFAULT_DOWNLOADS, nonexistent_dir); | |
864 | |
865 // Delete the default folder for downloaded files. | |
866 ASSERT_TRUE(DeleteDownloadsDirectory()); | |
867 ASSERT_FALSE(file_util::PathExists(GetDownloadDirectory(browser()))); | |
868 | |
869 // Download the file and wait. We expect the select file dialog. | |
870 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG, downloaded_file); | |
871 | |
872 EXPECT_FALSE(file_util::PathExists(downloaded_file)); | |
873 EXPECT_FALSE(file_util::PathExists(nonexistent_dir)); | |
874 EXPECT_TRUE(file_util::PathExists(GetDownloadDirectory(browser()))); | |
875 EXPECT_EQ(1, browser()->tab_count()); | |
876 | |
877 // Restore the user's "Downloads" folder. | |
878 PathService::Set(chrome::DIR_DEFAULT_DOWNLOADS, prev_default_downloads_dir); | |
879 } | |
880 | |
790 #if defined(OS_WIN) | 881 #if defined(OS_WIN) |
791 // Download a file and confirm that the zone identifier (on windows) | 882 // Download a file and confirm that the zone identifier (on windows) |
792 // is set to internet. | 883 // is set to internet. |
793 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 884 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
794 ASSERT_TRUE(InitialSetup(false)); | 885 ASSERT_TRUE(InitialSetup(false)); |
795 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 886 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
796 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 887 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
797 | 888 |
798 // Download the file and wait. We do not expect the Select File dialog. | 889 // Download the file and wait. We do not expect the select file dialog. |
799 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 890 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
800 | 891 |
801 // Check state. Special file state must be checked before CheckDownload, | 892 // Check state. Special file state must be checked before CheckDownload, |
802 // as CheckDownload will delete the output file. | 893 // as CheckDownload will delete the output file. |
803 EXPECT_EQ(1, browser()->tab_count()); | 894 EXPECT_EQ(1, browser()->tab_count()); |
804 FilePath downloaded_file(DestinationFile(browser(), file)); | 895 FilePath downloaded_file(DestinationFile(browser(), file)); |
805 if (file_util::VolumeSupportsADS(downloaded_file)) | 896 if (file_util::VolumeSupportsADS(downloaded_file)) |
806 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); | 897 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
807 CheckDownload(browser(), file, file); | 898 CheckDownload(browser(), file, file); |
808 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 899 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
809 } | 900 } |
810 #endif | 901 #endif |
811 | 902 |
812 // Put up a Select File dialog when the file is downloaded, due to its MIME | 903 // Put up a select file dialog when the file is downloaded, due to its MIME |
813 // type. | 904 // type. |
814 // | 905 // |
815 // This test runs correctly, but leaves behind turds in the test user's | 906 // This test runs correctly, but leaves behind turds in the test user's |
816 // download directory because of http://crbug.com/62099. No big loss; it | 907 // download directory because of http://crbug.com/62099. No big loss; it |
817 // was primarily confirming DownloadsObserver wait on select file dialog | 908 // was primarily confirming DownloadsObserver wait on select file dialog |
818 // functionality anyway. | 909 // functionality anyway. |
819 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { | 910 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { |
820 ASSERT_TRUE(InitialSetup(true)); | 911 ASSERT_TRUE(InitialSetup(true)); |
821 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 912 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
822 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 913 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
914 FilePath file_path(DestinationFile(browser(), file)); | |
823 | 915 |
824 // Download the file and wait. We expect the Select File dialog to appear | 916 // Download the file and wait. We expect the select file dialog to appear |
825 // due to the MIME type. | 917 // due to the MIME type. |
826 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); | 918 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG, file_path); |
827 | 919 |
828 // Check state. | 920 // Check state. |
829 EXPECT_EQ(1, browser()->tab_count()); | 921 EXPECT_EQ(1, browser()->tab_count()); |
830 // Since we exited while the Select File dialog was visible, there should not | 922 // Since we exited while the select file dialog was visible, there should not |
831 // be anything in the download shelf and so it should not be visible. | 923 // be anything in the download shelf and so it should not be visible. |
832 EXPECT_FALSE(IsDownloadUIVisible(browser())); | 924 EXPECT_FALSE(IsDownloadUIVisible(browser())); |
833 } | 925 } |
834 | 926 |
835 // Access a file with a viewable mime-type, verify that a download | 927 // Access a file with a viewable mime-type, verify that a download |
836 // did not initiate. | 928 // did not initiate. |
837 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 929 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
838 ASSERT_TRUE(InitialSetup(false)); | 930 ASSERT_TRUE(InitialSetup(false)); |
839 FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 931 FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
840 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 932 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
(...skipping 14 matching lines...) Expand all Loading... | |
855 // download tab opened and the file exists as the filename specified in the | 947 // download tab opened and the file exists as the filename specified in the |
856 // header. This also ensures we properly handle empty file downloads. | 948 // header. This also ensures we properly handle empty file downloads. |
857 // The download shelf should be visible in the current tab. | 949 // The download shelf should be visible in the current tab. |
858 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 950 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
859 ASSERT_TRUE(InitialSetup(false)); | 951 ASSERT_TRUE(InitialSetup(false)); |
860 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 952 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
861 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 953 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
862 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 954 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
863 | 955 |
864 // Download a file and wait. | 956 // Download a file and wait. |
865 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 957 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
866 | 958 |
867 CheckDownload(browser(), download_file, file); | 959 CheckDownload(browser(), download_file, file); |
868 | 960 |
869 // Check state. | 961 // Check state. |
870 EXPECT_EQ(1, browser()->tab_count()); | 962 EXPECT_EQ(1, browser()->tab_count()); |
871 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 963 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
872 } | 964 } |
873 | 965 |
874 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. | 966 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. |
875 // Test that the download shelf is per-window by starting a download in one | 967 // Test that the download shelf is per-window by starting a download in one |
876 // tab, opening a second tab, closing the shelf, going back to the first tab, | 968 // tab, opening a second tab, closing the shelf, going back to the first tab, |
877 // and checking that the shelf is closed. | 969 // and checking that the shelf is closed. |
878 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { | 970 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { |
879 ASSERT_TRUE(InitialSetup(false)); | 971 ASSERT_TRUE(InitialSetup(false)); |
880 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 972 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
881 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 973 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
882 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 974 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
883 | 975 |
884 // Download a file and wait. | 976 // Download a file and wait. |
885 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 977 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
886 | 978 |
887 CheckDownload(browser(), download_file, file); | 979 CheckDownload(browser(), download_file, file); |
888 | 980 |
889 // Check state. | 981 // Check state. |
890 EXPECT_EQ(1, browser()->tab_count()); | 982 EXPECT_EQ(1, browser()->tab_count()); |
891 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 983 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
892 | 984 |
893 // Open a second tab and wait. | 985 // Open a second tab and wait. |
894 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), | 986 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), |
895 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); | 987 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
940 int window_count = BrowserList::size(); | 1032 int window_count = BrowserList::size(); |
941 EXPECT_EQ(2, window_count); | 1033 EXPECT_EQ(2, window_count); |
942 | 1034 |
943 // Download a file in the Incognito window and wait. | 1035 // Download a file in the Incognito window and wait. |
944 CreateAndSetDownloadsDirectory(incognito); | 1036 CreateAndSetDownloadsDirectory(incognito); |
945 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1037 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
946 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1038 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
947 // Since |incognito| is a separate browser, we have to set it up explicitly. | 1039 // Since |incognito| is a separate browser, we have to set it up explicitly. |
948 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 1040 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
949 false); | 1041 false); |
950 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); | 1042 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
951 | 1043 |
952 // We should still have 2 windows. | 1044 // We should still have 2 windows. |
953 ExpectWindowCountAfterDownload(2); | 1045 ExpectWindowCountAfterDownload(2); |
954 | 1046 |
955 // Verify that the download shelf is showing for the Incognito window. | 1047 // Verify that the download shelf is showing for the Incognito window. |
956 EXPECT_TRUE(IsDownloadUIVisible(incognito)); | 1048 EXPECT_TRUE(IsDownloadUIVisible(incognito)); |
957 | 1049 |
958 #if !defined(OS_MACOSX) | 1050 #if !defined(OS_MACOSX) |
959 // On Mac OS X, the UI window close is delayed until the outermost | 1051 // On Mac OS X, the UI window close is delayed until the outermost |
960 // message loop runs. So it isn't possible to get a BROWSER_CLOSED | 1052 // message loop runs. So it isn't possible to get a BROWSER_CLOSED |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 | 1098 |
1007 // Download a file in a new background tab and wait. The tab is automatically | 1099 // Download a file in a new background tab and wait. The tab is automatically |
1008 // closed when the download begins. | 1100 // closed when the download begins. |
1009 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1101 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1010 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1102 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1011 DownloadAndWaitWithDisposition( | 1103 DownloadAndWaitWithDisposition( |
1012 browser(), | 1104 browser(), |
1013 url, | 1105 url, |
1014 NEW_BACKGROUND_TAB, | 1106 NEW_BACKGROUND_TAB, |
1015 EXPECT_NO_SELECT_DIALOG, | 1107 EXPECT_NO_SELECT_DIALOG, |
1108 FilePath(), | |
1016 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1109 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1017 | 1110 |
1018 // When the download finishes, we should still have one tab. | 1111 // When the download finishes, we should still have one tab. |
1019 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 1112 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
1020 EXPECT_EQ(1, browser()->tab_count()); | 1113 EXPECT_EQ(1, browser()->tab_count()); |
1021 | 1114 |
1022 CheckDownload(browser(), file, file); | 1115 CheckDownload(browser(), file, file); |
1023 } | 1116 } |
1024 | 1117 |
1025 // Open a web page in the current tab, then download a file in another tab via | 1118 // Open a web page in the current tab, then download a file in another tab via |
(...skipping 12 matching lines...) Expand all Loading... | |
1038 | 1131 |
1039 // Open a web page and wait. | 1132 // Open a web page and wait. |
1040 ui_test_utils::NavigateToURL(browser(), url); | 1133 ui_test_utils::NavigateToURL(browser(), url); |
1041 | 1134 |
1042 // Download a file in a new tab and wait (via Javascript). | 1135 // Download a file in a new tab and wait (via Javascript). |
1043 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1136 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1044 DownloadAndWaitWithDisposition(browser(), | 1137 DownloadAndWaitWithDisposition(browser(), |
1045 GURL("javascript:openNew()"), | 1138 GURL("javascript:openNew()"), |
1046 CURRENT_TAB, | 1139 CURRENT_TAB, |
1047 EXPECT_NO_SELECT_DIALOG, | 1140 EXPECT_NO_SELECT_DIALOG, |
1141 FilePath(), | |
1048 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1142 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1049 | 1143 |
1050 // When the download finishes, we should have two tabs. | 1144 // When the download finishes, we should have two tabs. |
1051 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 1145 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
1052 EXPECT_EQ(2, browser()->tab_count()); | 1146 EXPECT_EQ(2, browser()->tab_count()); |
1053 | 1147 |
1054 CheckDownload(browser(), file, file); | 1148 CheckDownload(browser(), file, file); |
1055 } | 1149 } |
1056 | 1150 |
1057 // Open a web page in the current tab, open another tab via a Javascript call, | 1151 // Open a web page in the current tab, open another tab via a Javascript call, |
(...skipping 22 matching lines...) Expand all Loading... | |
1080 | 1174 |
1081 EXPECT_EQ(2, browser()->tab_count()); | 1175 EXPECT_EQ(2, browser()->tab_count()); |
1082 | 1176 |
1083 // Download a file and wait. | 1177 // Download a file and wait. |
1084 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1178 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1085 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1179 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1086 DownloadAndWaitWithDisposition(browser(), | 1180 DownloadAndWaitWithDisposition(browser(), |
1087 url, | 1181 url, |
1088 CURRENT_TAB, | 1182 CURRENT_TAB, |
1089 EXPECT_NO_SELECT_DIALOG, | 1183 EXPECT_NO_SELECT_DIALOG, |
1184 FilePath(), | |
1090 ui_test_utils::BROWSER_TEST_NONE); | 1185 ui_test_utils::BROWSER_TEST_NONE); |
1091 | 1186 |
1092 // When the download finishes, we should have two tabs. | 1187 // When the download finishes, we should have two tabs. |
1093 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 1188 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
1094 EXPECT_EQ(2, browser()->tab_count()); | 1189 EXPECT_EQ(2, browser()->tab_count()); |
1095 | 1190 |
1096 CheckDownload(browser(), file, file); | 1191 CheckDownload(browser(), file, file); |
1097 } | 1192 } |
1098 | 1193 |
1099 // Open a web page in the current tab, then download a file via Javascript, | 1194 // Open a web page in the current tab, then download a file via Javascript, |
(...skipping 13 matching lines...) Expand all Loading... | |
1113 // Open a web page and wait. | 1208 // Open a web page and wait. |
1114 ui_test_utils::NavigateToURL(browser(), url); | 1209 ui_test_utils::NavigateToURL(browser(), url); |
1115 | 1210 |
1116 // Download a file and wait. | 1211 // Download a file and wait. |
1117 // The file to download is "download-test1.lib". | 1212 // The file to download is "download-test1.lib". |
1118 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1213 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1119 DownloadAndWaitWithDisposition(browser(), | 1214 DownloadAndWaitWithDisposition(browser(), |
1120 GURL("javascript:openNew()"), | 1215 GURL("javascript:openNew()"), |
1121 CURRENT_TAB, | 1216 CURRENT_TAB, |
1122 EXPECT_NO_SELECT_DIALOG, | 1217 EXPECT_NO_SELECT_DIALOG, |
1218 FilePath(), | |
1123 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1219 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1124 | 1220 |
1125 // When the download finishes, we should still have one tab. | 1221 // When the download finishes, we should still have one tab. |
1126 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 1222 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
1127 EXPECT_EQ(1, browser()->tab_count()); | 1223 EXPECT_EQ(1, browser()->tab_count()); |
1128 | 1224 |
1129 CheckDownload(browser(), file, file); | 1225 CheckDownload(browser(), file, file); |
1130 } | 1226 } |
1131 | 1227 |
1132 // Open a web page in the current tab, then call Javascript via a button to | 1228 // Open a web page in the current tab, then call Javascript via a button to |
(...skipping 15 matching lines...) Expand all Loading... | |
1148 | 1244 |
1149 // Download a file in a new tab and wait. The tab will automatically close | 1245 // Download a file in a new tab and wait. The tab will automatically close |
1150 // when the download begins. | 1246 // when the download begins. |
1151 // The file to download is "download-test1.lib". | 1247 // The file to download is "download-test1.lib". |
1152 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1248 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1153 DownloadAndWaitWithDisposition( | 1249 DownloadAndWaitWithDisposition( |
1154 browser(), | 1250 browser(), |
1155 GURL("javascript:document.getElementById('form').submit()"), | 1251 GURL("javascript:document.getElementById('form').submit()"), |
1156 CURRENT_TAB, | 1252 CURRENT_TAB, |
1157 EXPECT_NO_SELECT_DIALOG, | 1253 EXPECT_NO_SELECT_DIALOG, |
1254 FilePath(), | |
1158 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1255 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1159 | 1256 |
1160 // When the download finishes, we should still have one tab. | 1257 // When the download finishes, we should still have one tab. |
1161 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 1258 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
1162 EXPECT_EQ(1, browser()->tab_count()); | 1259 EXPECT_EQ(1, browser()->tab_count()); |
1163 | 1260 |
1164 CheckDownload(browser(), file, file); | 1261 CheckDownload(browser(), file, file); |
1165 } | 1262 } |
1166 | 1263 |
1167 // Download a file in a new window. | 1264 // Download a file in a new window. |
(...skipping 10 matching lines...) Expand all Loading... | |
1178 #if !defined(OS_MACOSX) | 1275 #if !defined(OS_MACOSX) |
1179 // See below. | 1276 // See below. |
1180 Browser* first_browser = browser(); | 1277 Browser* first_browser = browser(); |
1181 #endif | 1278 #endif |
1182 | 1279 |
1183 // Download a file in a new window and wait. | 1280 // Download a file in a new window and wait. |
1184 DownloadAndWaitWithDisposition(browser(), | 1281 DownloadAndWaitWithDisposition(browser(), |
1185 url, | 1282 url, |
1186 NEW_WINDOW, | 1283 NEW_WINDOW, |
1187 EXPECT_NO_SELECT_DIALOG, | 1284 EXPECT_NO_SELECT_DIALOG, |
1285 FilePath(), | |
1188 ui_test_utils::BROWSER_TEST_NONE); | 1286 ui_test_utils::BROWSER_TEST_NONE); |
1189 | 1287 |
1190 // When the download finishes, the download shelf SHOULD NOT be visible in | 1288 // When the download finishes, the download shelf SHOULD NOT be visible in |
1191 // the first window. | 1289 // the first window. |
1192 ExpectWindowCountAfterDownload(2); | 1290 ExpectWindowCountAfterDownload(2); |
1193 EXPECT_EQ(1, browser()->tab_count()); | 1291 EXPECT_EQ(1, browser()->tab_count()); |
1194 #if defined(OS_CHROMEOS) | 1292 #if defined(OS_CHROMEOS) |
1195 // Except on chromeos the download UI isn't window-specific. | 1293 // Except on chromeos the download UI isn't window-specific. |
1196 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 1294 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
1197 #else | 1295 #else |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1299 | 1397 |
1300 // Confirm a download makes it into the history properly. | 1398 // Confirm a download makes it into the history properly. |
1301 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1399 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
1302 ASSERT_TRUE(InitialSetup(false)); | 1400 ASSERT_TRUE(InitialSetup(false)); |
1303 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1401 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1304 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1402 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1305 FilePath origin_file(OriginFile(file)); | 1403 FilePath origin_file(OriginFile(file)); |
1306 int64 origin_size; | 1404 int64 origin_size; |
1307 file_util::GetFileSize(origin_file, &origin_size); | 1405 file_util::GetFileSize(origin_file, &origin_size); |
1308 | 1406 |
1309 // Download the file and wait. We do not expect the Select File dialog. | 1407 // Download the file and wait. We do not expect the select file dialog. |
1310 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1408 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
1311 | 1409 |
1312 // Get details of what downloads have just happened. | 1410 // Get details of what downloads have just happened. |
1313 std::vector<DownloadItem*> downloads; | 1411 std::vector<DownloadItem*> downloads; |
1314 GetDownloads(browser(), &downloads); | 1412 GetDownloads(browser(), &downloads); |
1315 ASSERT_EQ(1u, downloads.size()); | 1413 ASSERT_EQ(1u, downloads.size()); |
1316 int64 db_handle = downloads[0]->db_handle(); | 1414 int64 db_handle = downloads[0]->db_handle(); |
1317 | 1415 |
1318 // Check state. | 1416 // Check state. |
1319 EXPECT_EQ(1, browser()->tab_count()); | 1417 EXPECT_EQ(1, browser()->tab_count()); |
1320 CheckDownload(browser(), file, file); | 1418 CheckDownload(browser(), file, file); |
(...skipping 16 matching lines...) Expand all Loading... | |
1337 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1435 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
1338 // after download of a file while viewing another chrome://. | 1436 // after download of a file while viewing another chrome://. |
1339 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1437 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
1340 ASSERT_TRUE(InitialSetup(false)); | 1438 ASSERT_TRUE(InitialSetup(false)); |
1341 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1439 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1342 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1440 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1343 GURL flags_url(chrome::kAboutFlagsURL); | 1441 GURL flags_url(chrome::kAboutFlagsURL); |
1344 GURL extensions_url(chrome::kChromeUIExtensionsURL); | 1442 GURL extensions_url(chrome::kChromeUIExtensionsURL); |
1345 | 1443 |
1346 ui_test_utils::NavigateToURL(browser(), flags_url); | 1444 ui_test_utils::NavigateToURL(browser(), flags_url); |
1347 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1445 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
1348 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1446 ui_test_utils::NavigateToURL(browser(), extensions_url); |
1349 TabContents* contents = browser()->GetSelectedTabContents(); | 1447 TabContents* contents = browser()->GetSelectedTabContents(); |
1350 ASSERT_TRUE(contents); | 1448 ASSERT_TRUE(contents); |
1351 bool webui_responded = false; | 1449 bool webui_responded = false; |
1352 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1450 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1353 contents->render_view_host(), | 1451 contents->render_view_host(), |
1354 L"", | 1452 L"", |
1355 L"window.domAutomationController.send(window.webui_responded_);", | 1453 L"window.domAutomationController.send(window.webui_responded_);", |
1356 &webui_responded)); | 1454 &webui_responded)); |
1357 EXPECT_TRUE(webui_responded); | 1455 EXPECT_TRUE(webui_responded); |
(...skipping 16 matching lines...) Expand all Loading... | |
1374 ASSERT_TRUE(contents); | 1472 ASSERT_TRUE(contents); |
1375 bool result = false; | 1473 bool result = false; |
1376 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1474 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1377 contents->render_view_host(), | 1475 contents->render_view_host(), |
1378 L"", | 1476 L"", |
1379 L"window.onunload = function() { var do_nothing = 0; }; " | 1477 L"window.onunload = function() { var do_nothing = 0; }; " |
1380 L"window.domAutomationController.send(true);", | 1478 L"window.domAutomationController.send(true);", |
1381 &result)); | 1479 &result)); |
1382 EXPECT_TRUE(result); | 1480 EXPECT_TRUE(result); |
1383 | 1481 |
1384 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1482 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
1385 | 1483 |
1386 ui_test_utils::WindowedNotificationObserver signal( | 1484 ui_test_utils::WindowedNotificationObserver signal( |
1387 NotificationType::BROWSER_CLOSED, | 1485 NotificationType::BROWSER_CLOSED, |
1388 Source<Browser>(browser())); | 1486 Source<Browser>(browser())); |
1389 browser()->CloseWindow(); | 1487 browser()->CloseWindow(); |
1390 signal.Wait(); | 1488 signal.Wait(); |
1391 } | 1489 } |
1392 | 1490 |
1393 // Test to make sure auto-open works. | 1491 // Test to make sure auto-open works. |
1394 #if defined(OS_CHROMEOS) | 1492 #if defined(OS_CHROMEOS) |
1395 // Always fails on Chrome OS: crbug.com/84058 | 1493 // Always fails on Chrome OS: crbug.com/84058 |
1396 #define MAYBE_AutoOpen FAILS_AutoOpen | 1494 #define MAYBE_AutoOpen FAILS_AutoOpen |
1397 #else | 1495 #else |
1398 #define MAYBE_AutoOpen AutoOpen | 1496 #define MAYBE_AutoOpen AutoOpen |
1399 #endif | 1497 #endif |
1400 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_AutoOpen) { | 1498 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_AutoOpen) { |
1401 ASSERT_TRUE(InitialSetup(false)); | 1499 ASSERT_TRUE(InitialSetup(false)); |
1402 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1500 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
1403 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1501 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1404 | 1502 |
1405 ASSERT_TRUE( | 1503 ASSERT_TRUE( |
1406 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1504 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
1407 | 1505 |
1408 // Mokc out external opening on all downloads until end of test. | 1506 // Mokc out external opening on all downloads until end of test. |
1409 MockDownloadOpeningObserver observer( | 1507 MockDownloadOpeningObserver observer( |
1410 browser()->profile()->GetDownloadManager()); | 1508 browser()->profile()->GetDownloadManager()); |
1411 | 1509 |
1412 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1510 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG, FilePath()); |
1413 | 1511 |
1414 // Find the download and confirm it was opened. | 1512 // Find the download and confirm it was opened. |
1415 std::vector<DownloadItem*> downloads; | 1513 std::vector<DownloadItem*> downloads; |
1416 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1514 browser()->profile()->GetDownloadManager()->SearchDownloads( |
1417 string16(), &downloads); | 1515 string16(), &downloads); |
1418 ASSERT_EQ(1u, downloads.size()); | 1516 ASSERT_EQ(1u, downloads.size()); |
1419 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); | 1517 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); |
1420 EXPECT_TRUE(downloads[0]->opened()); | 1518 EXPECT_TRUE(downloads[0]->opened()); |
1421 | 1519 |
1422 // As long as we're here, confirmed everything else is good. | 1520 // As long as we're here, confirmed everything else is good. |
1423 EXPECT_EQ(1, browser()->tab_count()); | 1521 EXPECT_EQ(1, browser()->tab_count()); |
1424 CheckDownload(browser(), file, file); | 1522 CheckDownload(browser(), file, file); |
1425 EXPECT_FALSE(IsDownloadUIVisible(browser())); // Auto-opened. | 1523 EXPECT_FALSE(IsDownloadUIVisible(browser())); // Auto-opened. |
1426 } | 1524 } |
OLD | NEW |