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..ca0c322ff510b9b1d0eac08ff0e133fb3dd940eb 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,9 @@ class DownloadsObserver : public DownloadManager::Observer, |
} |
} |
- virtual void SelectFileDialogDisplayed(int32 /* id */) { |
+ virtual void SelectFileDialogDisplayed(int32 /* id */, FilePath& path) { |
select_file_dialog_seen_ = true; |
+ suggested_path_ = path; |
SignalIfFinished(); |
} |
@@ -218,6 +224,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 +476,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 +517,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 +792,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 +801,44 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
EXPECT_TRUE(IsDownloadUIVisible(browser())); |
} |
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadedDirectory) { |
+ ASSERT_TRUE(InitialSetup(false)); |
+ 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. |
+ DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
+ |
+ FilePath file_path(DestinationFile(browser(), file)); |
+ EXPECT_TRUE(file_util::PathExists(file_path)); |
+ CheckDownload(browser(), file, file); |
+ EXPECT_EQ(1, browser()->tab_count()); |
+ EXPECT_TRUE(IsDownloadUIVisible(browser())); |
+ |
+ // Delete the default folder for downloaded files. |
Paweł Hajdan Jr.
2011/05/31 17:15:53
Do we only need to do the setup above to get the f
haraken1
2011/06/02 09:13:22
Done.
|
+ ASSERT_TRUE(DeleteDownloadsDirectory()); |
+ ASSERT_FALSE(file_util::PathExists(file_path)); |
+ |
+ // Download the file and wait. We expect the select file dialog. |
+ DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); |
+ |
+ FilePath default_downloads_path; |
+ PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &default_downloads_path); |
Paweł Hajdan Jr.
2011/05/31 17:15:53
Please check the return value.
haraken1
2011/06/02 09:13:22
Done.
|
+ file_path = default_downloads_path.Append(file); |
+ EXPECT_FALSE(file_util::PathExists(file_path)); |
Randy Smith (Not in Mondays)
2011/05/31 23:03:10
Would it be also appropriate to confirm that we di
haraken1
2011/06/02 09:13:22
Done.
|
+ EXPECT_EQ(1, browser()->tab_count()); |
+ |
+ scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1)); |
+ ui_test_utils::NavigateToURLWithDisposition( |
Paweł Hajdan Jr.
2011/05/31 17:15:53
Why do we have a second navigation to |url|? By "f
haraken1
2011/06/02 09:13:22
I cannot yet say the exact reason but this Navigat
Randy Smith (Not in Mondays)
2011/06/02 19:13:57
Haraken: Let's figure out why the test isn't behav
haraken1
2011/06/03 06:50:26
Ahh, I got it. Thank you.
After all, for simplic
|
+ 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 +847,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 +861,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 +873,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 +1358,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. |