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

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

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

Powered by Google App Engine
This is Rietveld 408576698