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

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: Remove DownloadTest.DownloadFolder2 and SavePageBrowserTest.SaveFolder4 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/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_list.h" 25 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/webui/active_downloads_ui.h" 27 #include "chrome/browser/ui/webui/active_downloads_ui.h"
26 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.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, DownloadFolder) {
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
794 #if defined(OS_WIN) 843 #if defined(OS_WIN)
795 // Download a file and confirm that the zone identifier (on windows) 844 // Download a file and confirm that the zone identifier (on windows)
796 // is set to internet. 845 // is set to internet.
797 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { 846 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) {
798 ASSERT_TRUE(InitialSetup(false)); 847 ASSERT_TRUE(InitialSetup(false));
799 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 848 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
800 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 849 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
801 850
802 // Download the file and wait. We do not expect the Select File dialog. 851 // Download the file and wait. We do not expect the select file dialog.
803 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 852 DownloadAndWait(browser(), url);
804 853
805 // Check state. Special file state must be checked before CheckDownload, 854 // Check state. Special file state must be checked before CheckDownload,
806 // as CheckDownload will delete the output file. 855 // as CheckDownload will delete the output file.
807 EXPECT_EQ(1, browser()->tab_count()); 856 EXPECT_EQ(1, browser()->tab_count());
808 FilePath downloaded_file(DestinationFile(browser(), file)); 857 FilePath downloaded_file(DestinationFile(browser(), file));
809 if (file_util::VolumeSupportsADS(downloaded_file)) 858 if (file_util::VolumeSupportsADS(downloaded_file))
810 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); 859 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file));
811 CheckDownload(browser(), file, file); 860 CheckDownload(browser(), file, file);
812 CheckDownloadUIVisible(browser(), true, true); 861 CheckDownloadUIVisible(browser(), true, true);
813 } 862 }
814 #endif 863 #endif
815 864
816 // Put up a Select File dialog when the file is downloaded, due to its MIME 865 // Put up a select file dialog when the file is downloaded, due to its MIME
817 // type. 866 // type.
818 // 867 //
819 // This test runs correctly, but leaves behind turds in the test user's 868 // 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 869 // download directory because of http://crbug.com/62099. No big loss; it
821 // was primarily confirming DownloadsObserver wait on select file dialog 870 // was primarily confirming DownloadsObserver wait on select file dialog
822 // functionality anyway. 871 // functionality anyway.
823 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { 872 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) {
824 ASSERT_TRUE(InitialSetup(true)); 873 ASSERT_TRUE(InitialSetup(true));
825 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 874 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
826 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 875 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
876 FilePath file_path(DestinationFile(browser(), file));
827 877
828 // Download the file and wait. We expect the Select File dialog to appear 878 // Download the file and wait. We expect the select file dialog to appear
829 // due to the MIME type. 879 // due to the MIME type.
830 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); 880 DownloadAndWaitWithDialog(browser(), url, file_path);
831 881
832 // Check state. 882 // Check state.
833 EXPECT_EQ(1, browser()->tab_count()); 883 EXPECT_EQ(1, browser()->tab_count());
834 // Since we exited while the Select File dialog was visible, there should not 884 // 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. 885 // be anything in the download shelf and so it should not be visible.
836 CheckDownloadUIVisible(browser(), false, false); 886 CheckDownloadUIVisible(browser(), false, false);
837 } 887 }
838 888
839 // Access a file with a viewable mime-type, verify that a download 889 // Access a file with a viewable mime-type, verify that a download
840 // did not initiate. 890 // did not initiate.
841 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { 891 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
842 ASSERT_TRUE(InitialSetup(false)); 892 ASSERT_TRUE(InitialSetup(false));
843 FilePath file(FILE_PATH_LITERAL("download-test2.html")); 893 FilePath file(FILE_PATH_LITERAL("download-test2.html"));
844 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 894 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 909 // download tab opened and the file exists as the filename specified in the
860 // header. This also ensures we properly handle empty file downloads. 910 // header. This also ensures we properly handle empty file downloads.
861 // The download shelf should be visible in the current tab. 911 // The download shelf should be visible in the current tab.
862 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { 912 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) {
863 ASSERT_TRUE(InitialSetup(false)); 913 ASSERT_TRUE(InitialSetup(false));
864 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 914 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
865 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 915 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
866 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 916 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
867 917
868 // Download a file and wait. 918 // Download a file and wait.
869 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 919 DownloadAndWait(browser(), url);
870 920
871 CheckDownload(browser(), download_file, file); 921 CheckDownload(browser(), download_file, file);
872 922
873 // Check state. 923 // Check state.
874 EXPECT_EQ(1, browser()->tab_count()); 924 EXPECT_EQ(1, browser()->tab_count());
875 CheckDownloadUIVisible(browser(), true, true); 925 CheckDownloadUIVisible(browser(), true, true);
876 } 926 }
877 927
878 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. 928 #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 929 // 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, 930 // tab, opening a second tab, closing the shelf, going back to the first tab,
881 // and checking that the shelf is closed. 931 // and checking that the shelf is closed.
882 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { 932 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) {
883 ASSERT_TRUE(InitialSetup(false)); 933 ASSERT_TRUE(InitialSetup(false));
884 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 934 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
885 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 935 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
886 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 936 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
887 937
888 // Download a file and wait. 938 // Download a file and wait.
889 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 939 DownloadAndWait(browser(), url);
890 940
891 CheckDownload(browser(), download_file, file); 941 CheckDownload(browser(), download_file, file);
892 942
893 // Check state. 943 // Check state.
894 EXPECT_EQ(1, browser()->tab_count()); 944 EXPECT_EQ(1, browser()->tab_count());
895 CheckDownloadUIVisible(browser(), true, true); 945 CheckDownloadUIVisible(browser(), true, true);
896 946
897 // Open a second tab and wait. 947 // Open a second tab and wait.
898 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), 948 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL),
899 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); 949 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 int window_count = BrowserList::size(); 994 int window_count = BrowserList::size();
945 EXPECT_EQ(2, window_count); 995 EXPECT_EQ(2, window_count);
946 996
947 // Download a file in the Incognito window and wait. 997 // Download a file in the Incognito window and wait.
948 CreateAndSetDownloadsDirectory(incognito); 998 CreateAndSetDownloadsDirectory(incognito);
949 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 999 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
950 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1000 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
951 // Since |incognito| is a separate browser, we have to set it up explicitly. 1001 // Since |incognito| is a separate browser, we have to set it up explicitly.
952 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, 1002 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
953 false); 1003 false);
954 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); 1004 DownloadAndWait(incognito, url);
955 1005
956 // We should still have 2 windows. 1006 // We should still have 2 windows.
957 ExpectWindowCountAfterDownload(2); 1007 ExpectWindowCountAfterDownload(2);
958 1008
959 // Verify that the download shelf is showing for the Incognito window. 1009 // Verify that the download shelf is showing for the Incognito window.
960 CheckDownloadUIVisible(incognito, true, true); 1010 CheckDownloadUIVisible(incognito, true, true);
961 1011
962 #if !defined(OS_MACOSX) 1012 #if !defined(OS_MACOSX)
963 // On Mac OS X, the UI window close is delayed until the outermost 1013 // 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 1014 // 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)); 1061 ASSERT_TRUE(InitialSetup(false));
1012 1062
1013 // Download a file in a new background tab and wait. The tab is automatically 1063 // Download a file in a new background tab and wait. The tab is automatically
1014 // closed when the download begins. 1064 // closed when the download begins.
1015 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1065 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1016 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1066 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1017 DownloadAndWaitWithDisposition( 1067 DownloadAndWaitWithDisposition(
1018 browser(), 1068 browser(),
1019 url, 1069 url,
1020 NEW_BACKGROUND_TAB, 1070 NEW_BACKGROUND_TAB,
1021 EXPECT_NO_SELECT_DIALOG, 1071 false,
1072 FilePath(),
1022 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1073 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1023 1074
1024 // When the download finishes, we should still have one tab. 1075 // When the download finishes, we should still have one tab.
1025 CheckDownloadUIVisible(browser(), true, true); 1076 CheckDownloadUIVisible(browser(), true, true);
1026 EXPECT_EQ(1, browser()->tab_count()); 1077 EXPECT_EQ(1, browser()->tab_count());
1027 1078
1028 CheckDownload(browser(), file, file); 1079 CheckDownload(browser(), file, file);
1029 } 1080 }
1030 1081
1031 // Open a web page in the current tab, then download a file in another tab via 1082 // 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)); 1094 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
1044 1095
1045 // Open a web page and wait. 1096 // Open a web page and wait.
1046 ui_test_utils::NavigateToURL(browser(), url); 1097 ui_test_utils::NavigateToURL(browser(), url);
1047 1098
1048 // Download a file in a new tab and wait (via Javascript). 1099 // Download a file in a new tab and wait (via Javascript).
1049 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1100 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1050 DownloadAndWaitWithDisposition(browser(), 1101 DownloadAndWaitWithDisposition(browser(),
1051 GURL("javascript:openNew()"), 1102 GURL("javascript:openNew()"),
1052 CURRENT_TAB, 1103 CURRENT_TAB,
1053 EXPECT_NO_SELECT_DIALOG, 1104 false,
1105 FilePath(),
1054 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1106 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1055 1107
1056 // When the download finishes, we should have two tabs. 1108 // When the download finishes, we should have two tabs.
1057 CheckDownloadUIVisible(browser(), true, true); 1109 CheckDownloadUIVisible(browser(), true, true);
1058 EXPECT_EQ(2, browser()->tab_count()); 1110 EXPECT_EQ(2, browser()->tab_count());
1059 1111
1060 CheckDownload(browser(), file, file); 1112 CheckDownload(browser(), file, file);
1061 } 1113 }
1062 1114
1063 // Open a web page in the current tab, open another tab via a Javascript call, 1115 // 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); 1137 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1086 1138
1087 EXPECT_EQ(2, browser()->tab_count()); 1139 EXPECT_EQ(2, browser()->tab_count());
1088 1140
1089 // Download a file and wait. 1141 // Download a file and wait.
1090 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1142 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1091 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1143 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1092 DownloadAndWaitWithDisposition(browser(), 1144 DownloadAndWaitWithDisposition(browser(),
1093 url, 1145 url,
1094 CURRENT_TAB, 1146 CURRENT_TAB,
1095 EXPECT_NO_SELECT_DIALOG, 1147 false,
1148 FilePath(),
1096 ui_test_utils::BROWSER_TEST_NONE); 1149 ui_test_utils::BROWSER_TEST_NONE);
1097 1150
1098 // When the download finishes, we should have two tabs. 1151 // When the download finishes, we should have two tabs.
1099 CheckDownloadUIVisible(browser(), true, true); 1152 CheckDownloadUIVisible(browser(), true, true);
1100 EXPECT_EQ(2, browser()->tab_count()); 1153 EXPECT_EQ(2, browser()->tab_count());
1101 1154
1102 CheckDownload(browser(), file, file); 1155 CheckDownload(browser(), file, file);
1103 } 1156 }
1104 1157
1105 // Open a web page in the current tab, then download a file via Javascript, 1158 // Open a web page in the current tab, then download a file via Javascript,
(...skipping 12 matching lines...) Expand all
1118 1171
1119 // Open a web page and wait. 1172 // Open a web page and wait.
1120 ui_test_utils::NavigateToURL(browser(), url); 1173 ui_test_utils::NavigateToURL(browser(), url);
1121 1174
1122 // Download a file and wait. 1175 // Download a file and wait.
1123 // The file to download is "download-test1.lib". 1176 // The file to download is "download-test1.lib".
1124 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1177 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1125 DownloadAndWaitWithDisposition(browser(), 1178 DownloadAndWaitWithDisposition(browser(),
1126 GURL("javascript:openNew()"), 1179 GURL("javascript:openNew()"),
1127 CURRENT_TAB, 1180 CURRENT_TAB,
1128 EXPECT_NO_SELECT_DIALOG, 1181 false,
1182 FilePath(),
1129 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1183 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1130 1184
1131 // When the download finishes, we should still have one tab. 1185 // When the download finishes, we should still have one tab.
1132 CheckDownloadUIVisible(browser(), true, true); 1186 CheckDownloadUIVisible(browser(), true, true);
1133 EXPECT_EQ(1, browser()->tab_count()); 1187 EXPECT_EQ(1, browser()->tab_count());
1134 1188
1135 CheckDownload(browser(), file, file); 1189 CheckDownload(browser(), file, file);
1136 } 1190 }
1137 1191
1138 // Open a web page in the current tab, then call Javascript via a button to 1192 // 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); 1207 ui_test_utils::NavigateToURL(browser(), url);
1154 1208
1155 // Download a file in a new tab and wait. The tab will automatically close 1209 // Download a file in a new tab and wait. The tab will automatically close
1156 // when the download begins. 1210 // when the download begins.
1157 // The file to download is "download-test1.lib". 1211 // The file to download is "download-test1.lib".
1158 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1212 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1159 DownloadAndWaitWithDisposition( 1213 DownloadAndWaitWithDisposition(
1160 browser(), 1214 browser(),
1161 GURL("javascript:document.getElementById('form').submit()"), 1215 GURL("javascript:document.getElementById('form').submit()"),
1162 CURRENT_TAB, 1216 CURRENT_TAB,
1163 EXPECT_NO_SELECT_DIALOG, 1217 false,
1218 FilePath(),
1164 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1219 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1165 1220
1166 // When the download finishes, we should still have one tab. 1221 // When the download finishes, we should still have one tab.
1167 CheckDownloadUIVisible(browser(), true, true); 1222 CheckDownloadUIVisible(browser(), true, true);
1168 EXPECT_EQ(1, browser()->tab_count()); 1223 EXPECT_EQ(1, browser()->tab_count());
1169 1224
1170 CheckDownload(browser(), file, file); 1225 CheckDownload(browser(), file, file);
1171 } 1226 }
1172 1227
1173 // Download a file in a new window. 1228 // Download a file in a new window.
1174 // Verify that we have 2 windows, and the download shelf is not visible in the 1229 // 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. 1230 // first window, but is visible in the second window.
1176 // Close the new window. 1231 // Close the new window.
1177 // Verify that we have 1 window, and the download shelf is not visible. 1232 // Verify that we have 1 window, and the download shelf is not visible.
1178 // 1233 //
1179 // Regression test for http://crbug.com/44454 1234 // Regression test for http://crbug.com/44454
1180 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { 1235 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) {
1181 ASSERT_TRUE(InitialSetup(false)); 1236 ASSERT_TRUE(InitialSetup(false));
1182 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1237 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1183 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1238 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1184 #if !defined(OS_MACOSX) 1239 #if !defined(OS_MACOSX)
1185 // See below. 1240 // See below.
1186 Browser* first_browser = browser(); 1241 Browser* first_browser = browser();
1187 #endif 1242 #endif
1188 1243
1189 // Download a file in a new window and wait. 1244 // Download a file in a new window and wait.
1190 DownloadAndWaitWithDisposition(browser(), 1245 DownloadAndWaitWithDisposition(browser(),
1191 url, 1246 url,
1192 NEW_WINDOW, 1247 NEW_WINDOW,
1193 EXPECT_NO_SELECT_DIALOG, 1248 false,
1249 FilePath(),
1194 ui_test_utils::BROWSER_TEST_NONE); 1250 ui_test_utils::BROWSER_TEST_NONE);
1195 1251
1196 // When the download finishes, the download shelf SHOULD NOT be visible in 1252 // When the download finishes, the download shelf SHOULD NOT be visible in
1197 // the first window. 1253 // the first window.
1198 ExpectWindowCountAfterDownload(2); 1254 ExpectWindowCountAfterDownload(2);
1199 EXPECT_EQ(1, browser()->tab_count()); 1255 EXPECT_EQ(1, browser()->tab_count());
1200 // Except on Chrome OS, where the download window sticks around. 1256 // Except on Chrome OS, where the download window sticks around.
1201 CheckDownloadUIVisible(browser(), false, true); 1257 CheckDownloadUIVisible(browser(), false, true);
1202 1258
1203 // The download shelf SHOULD be visible in the second window. 1259 // The download shelf SHOULD be visible in the second window.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 1346
1291 // Confirm a download makes it into the history properly. 1347 // Confirm a download makes it into the history properly.
1292 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { 1348 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
1293 ASSERT_TRUE(InitialSetup(false)); 1349 ASSERT_TRUE(InitialSetup(false));
1294 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1350 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1295 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1351 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1296 FilePath origin_file(OriginFile(file)); 1352 FilePath origin_file(OriginFile(file));
1297 int64 origin_size; 1353 int64 origin_size;
1298 file_util::GetFileSize(origin_file, &origin_size); 1354 file_util::GetFileSize(origin_file, &origin_size);
1299 1355
1300 // Download the file and wait. We do not expect the Select File dialog. 1356 // Download the file and wait. We do not expect the select file dialog.
1301 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1357 DownloadAndWait(browser(), url);
1302 1358
1303 // Get details of what downloads have just happened. 1359 // Get details of what downloads have just happened.
1304 std::vector<DownloadItem*> downloads; 1360 std::vector<DownloadItem*> downloads;
1305 GetDownloads(browser(), &downloads); 1361 GetDownloads(browser(), &downloads);
1306 ASSERT_EQ(1u, downloads.size()); 1362 ASSERT_EQ(1u, downloads.size());
1307 int64 db_handle = downloads[0]->db_handle(); 1363 int64 db_handle = downloads[0]->db_handle();
1308 1364
1309 // Check state. 1365 // Check state.
1310 EXPECT_EQ(1, browser()->tab_count()); 1366 EXPECT_EQ(1, browser()->tab_count());
1311 CheckDownload(browser(), file, file); 1367 CheckDownload(browser(), file, file);
(...skipping 16 matching lines...) Expand all
1328 // Test for crbug.com/14505. This tests that chrome:// urls are still functional 1384 // Test for crbug.com/14505. This tests that chrome:// urls are still functional
1329 // after download of a file while viewing another chrome://. 1385 // after download of a file while viewing another chrome://.
1330 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { 1386 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) {
1331 ASSERT_TRUE(InitialSetup(false)); 1387 ASSERT_TRUE(InitialSetup(false));
1332 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1388 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1333 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1389 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1334 GURL flags_url(chrome::kChromeUIFlagsURL); 1390 GURL flags_url(chrome::kChromeUIFlagsURL);
1335 GURL extensions_url(chrome::kChromeUIExtensionsURL); 1391 GURL extensions_url(chrome::kChromeUIExtensionsURL);
1336 1392
1337 ui_test_utils::NavigateToURL(browser(), flags_url); 1393 ui_test_utils::NavigateToURL(browser(), flags_url);
1338 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); 1394 DownloadAndWait(browser(), download_url);
1339 ui_test_utils::NavigateToURL(browser(), extensions_url); 1395 ui_test_utils::NavigateToURL(browser(), extensions_url);
1340 TabContents* contents = browser()->GetSelectedTabContents(); 1396 TabContents* contents = browser()->GetSelectedTabContents();
1341 ASSERT_TRUE(contents); 1397 ASSERT_TRUE(contents);
1342 bool webui_responded = false; 1398 bool webui_responded = false;
1343 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1399 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
1344 contents->render_view_host(), 1400 contents->render_view_host(),
1345 L"", 1401 L"",
1346 L"window.domAutomationController.send(window.webui_responded_);", 1402 L"window.domAutomationController.send(window.webui_responded_);",
1347 &webui_responded)); 1403 &webui_responded));
1348 EXPECT_TRUE(webui_responded); 1404 EXPECT_TRUE(webui_responded);
(...skipping 16 matching lines...) Expand all
1365 ASSERT_TRUE(contents); 1421 ASSERT_TRUE(contents);
1366 bool result = false; 1422 bool result = false;
1367 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1423 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
1368 contents->render_view_host(), 1424 contents->render_view_host(),
1369 L"", 1425 L"",
1370 L"window.onunload = function() { var do_nothing = 0; }; " 1426 L"window.onunload = function() { var do_nothing = 0; }; "
1371 L"window.domAutomationController.send(true);", 1427 L"window.domAutomationController.send(true);",
1372 &result)); 1428 &result));
1373 EXPECT_TRUE(result); 1429 EXPECT_TRUE(result);
1374 1430
1375 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); 1431 DownloadAndWait(browser(), download_url);
1376 1432
1377 ui_test_utils::WindowedNotificationObserver signal( 1433 ui_test_utils::WindowedNotificationObserver signal(
1378 NotificationType::BROWSER_CLOSED, 1434 NotificationType::BROWSER_CLOSED,
1379 Source<Browser>(browser())); 1435 Source<Browser>(browser()));
1380 browser()->CloseWindow(); 1436 browser()->CloseWindow();
1381 signal.Wait(); 1437 signal.Wait();
1382 } 1438 }
1383 1439
1384 // Test to make sure auto-open works. 1440 // Test to make sure auto-open works.
1385 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { 1441 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) {
1386 ASSERT_TRUE(InitialSetup(false)); 1442 ASSERT_TRUE(InitialSetup(false));
1387 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); 1443 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt"));
1388 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1444 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1389 1445
1390 ASSERT_TRUE( 1446 ASSERT_TRUE(
1391 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); 1447 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file));
1392 1448
1393 // Mokc out external opening on all downloads until end of test. 1449 // Mokc out external opening on all downloads until end of test.
1394 MockDownloadOpeningObserver observer( 1450 MockDownloadOpeningObserver observer(
1395 browser()->profile()->GetDownloadManager()); 1451 browser()->profile()->GetDownloadManager());
1396 1452
1397 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1453 DownloadAndWait(browser(), url);
1398 1454
1399 // Find the download and confirm it was opened. 1455 // Find the download and confirm it was opened.
1400 std::vector<DownloadItem*> downloads; 1456 std::vector<DownloadItem*> downloads;
1401 browser()->profile()->GetDownloadManager()->SearchDownloads( 1457 browser()->profile()->GetDownloadManager()->SearchDownloads(
1402 string16(), &downloads); 1458 string16(), &downloads);
1403 ASSERT_EQ(1u, downloads.size()); 1459 ASSERT_EQ(1u, downloads.size());
1404 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); 1460 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state());
1405 EXPECT_TRUE(downloads[0]->opened()); 1461 EXPECT_TRUE(downloads[0]->opened());
1406 1462
1407 // As long as we're here, confirmed everything else is good. 1463 // As long as we're here, confirmed everything else is good.
1408 EXPECT_EQ(1, browser()->tab_count()); 1464 EXPECT_EQ(1, browser()->tab_count());
1409 CheckDownload(browser(), file, file); 1465 CheckDownload(browser(), file, file);
1410 // Dissapears on most UIs, but the download panel sticks around for 1466 // Dissapears on most UIs, but the download panel sticks around for
1411 // chrome os. 1467 // chrome os.
1412 CheckDownloadUIVisible(browser(), false, true); 1468 CheckDownloadUIVisible(browser(), false, true);
1413 } 1469 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698