| Index: chrome/browser/download/download_browsertest.cc
|
| diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
|
| index e5826c9d8a52474d6a5cc7d2a29be648361cacbb..650198fe29d611095238a2f2102e7fac9a3a685c 100644
|
| --- a/chrome/browser/download/download_browsertest.cc
|
| +++ b/chrome/browser/download/download_browsertest.cc
|
| @@ -91,6 +91,11 @@ class DownloadsObserver : public DownloadManager::Observer,
|
| // State accessors.
|
| bool select_file_dialog_seen() { return select_file_dialog_seen_; }
|
|
|
| + // Checks if the select file dialog suggesting |path| was displayed.
|
| + bool IsSeenSelectFileDialogWithPath(FilePath& path) {
|
| + return select_file_dialog_seen_ && suggested_path_ == path;
|
| + }
|
| +
|
| // Wait for whatever state was specified in the constructor.
|
| void WaitForFinished() {
|
| if (!IsFinished()) {
|
| @@ -151,8 +156,10 @@ class DownloadsObserver : public DownloadManager::Observer,
|
| }
|
| }
|
|
|
| - virtual void SelectFileDialogDisplayed(int32 /* id */) {
|
| + virtual void SelectFileDialogDisplayed(
|
| + int32 /* id */, FilePath& suggested_path) {
|
| select_file_dialog_seen_ = true;
|
| + suggested_path_ = suggested_path;
|
| SignalIfFinished();
|
| }
|
|
|
| @@ -218,6 +225,9 @@ class DownloadsObserver : public DownloadManager::Observer,
|
| // True if we've seen the select file dialog.
|
| bool select_file_dialog_seen_;
|
|
|
| + // The suggested file path in the select file dialog.
|
| + FilePath suggested_path_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(DownloadsObserver);
|
| };
|
|
|
| @@ -467,6 +477,11 @@ class DownloadTest : public InProcessBrowserTest {
|
| return true;
|
| }
|
|
|
| + // Delete the default folder for downloaded files.
|
| + bool DeleteDownloadsDirectory() {
|
| + return downloads_directory_.Delete();
|
| + }
|
| +
|
| DownloadPrefs* GetDownloadPrefs(Browser* browser) {
|
| return browser->profile()->GetDownloadManager()->download_prefs();
|
| }
|
| @@ -503,7 +518,7 @@ class DownloadTest : public InProcessBrowserTest {
|
| // Download |url|, then wait for the download to finish.
|
| // |disposition| indicates where the navigation occurs (current tab, new
|
| // foreground tab, etc).
|
| - // |expectation| indicates whether or not a Select File dialog should be
|
| + // |expectation| indicates whether or not a select file dialog should be
|
| // open when the download is finished, or if we don't care.
|
| // If the dialog appears, the routine exits. The only effect |expectation|
|
| // has is whether or not the test succeeds.
|
| @@ -778,7 +793,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) {
|
| FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
|
| GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
|
|
|
| - // Download the file and wait. We do not expect the Select File dialog.
|
| + // Download the file and wait. We do not expect the select file dialog.
|
| DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
|
|
|
| // Check state.
|
| @@ -787,6 +802,38 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) {
|
| EXPECT_TRUE(IsDownloadUIVisible(browser()));
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadedFolder) {
|
| + ASSERT_TRUE(InitialSetup(false));
|
| + FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
|
| + GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
|
| + FilePath file_path(DestinationFile(browser(), file));
|
| +
|
| + // Delete the default folder for downloaded files.
|
| + ASSERT_TRUE(DeleteDownloadsDirectory());
|
| + ASSERT_FALSE(file_util::PathExists(GetDownloadDirectory(browser())));
|
| +
|
| + // Download the file and wait. We expect the select file dialog.
|
| + DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG);
|
| +
|
| + FilePath default_downloads_path;
|
| + ASSERT_TRUE(PathService::Get(
|
| + chrome::DIR_DEFAULT_DOWNLOADS, &default_downloads_path));
|
| + file_path = default_downloads_path.Append(file);
|
| + EXPECT_FALSE(file_util::PathExists(file_path));
|
| + EXPECT_FALSE(file_util::PathExists(GetDownloadDirectory(browser())));
|
| + EXPECT_EQ(1, browser()->tab_count());
|
| +
|
| + scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1));
|
| + ui_test_utils::NavigateToURLWithDisposition(
|
| + browser(), url, CURRENT_TAB,
|
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
|
| +
|
| + // Waits for the download to complete.
|
| + observer->WaitForFinished();
|
| +
|
| + EXPECT_TRUE(observer->IsSeenSelectFileDialogWithPath(file_path));
|
| +}
|
| +
|
| #if defined(OS_WIN)
|
| // Download a file and confirm that the zone identifier (on windows)
|
| // is set to internet.
|
| @@ -795,7 +842,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) {
|
| FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
|
| GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
|
|
|
| - // Download the file and wait. We do not expect the Select File dialog.
|
| + // Download the file and wait. We do not expect the select file dialog.
|
| DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
|
|
|
| // Check state. Special file state must be checked before CheckDownload,
|
| @@ -809,7 +856,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) {
|
| }
|
| #endif
|
|
|
| -// Put up a Select File dialog when the file is downloaded, due to its MIME
|
| +// Put up a select file dialog when the file is downloaded, due to its MIME
|
| // type.
|
| //
|
| // This test runs correctly, but leaves behind turds in the test user's
|
| @@ -821,13 +868,13 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) {
|
| FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
|
| GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
|
|
|
| - // Download the file and wait. We expect the Select File dialog to appear
|
| + // Download the file and wait. We expect the select file dialog to appear
|
| // due to the MIME type.
|
| DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG);
|
|
|
| // Check state.
|
| EXPECT_EQ(1, browser()->tab_count());
|
| - // Since we exited while the Select File dialog was visible, there should not
|
| + // Since we exited while the select file dialog was visible, there should not
|
| // be anything in the download shelf and so it should not be visible.
|
| EXPECT_FALSE(IsDownloadUIVisible(browser()));
|
| }
|
| @@ -1306,7 +1353,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
|
| int64 origin_size;
|
| file_util::GetFileSize(origin_file, &origin_size);
|
|
|
| - // Download the file and wait. We do not expect the Select File dialog.
|
| + // Download the file and wait. We do not expect the select file dialog.
|
| DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
|
|
|
| // Get details of what downloads have just happened.
|
|
|