Chromium Code Reviews| Index: chrome/browser/download/download_browsertest.cc |
| diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc |
| index 98ba3a57129a220da104232a1b65dc58e73d9e5f..e7f102806fc1a87419eb6b0caeacc9f0037609de 100644 |
| --- a/chrome/browser/download/download_browsertest.cc |
| +++ b/chrome/browser/download/download_browsertest.cc |
| @@ -690,6 +690,8 @@ class DownloadTest : public InProcessBrowserTest { |
| GURL url = test_server()->GetURL(server_path); |
| ASSERT_TRUE(url.is_valid()); |
| + NullSelectFile(browser()); // Needed for read-only tests. |
|
Randy Smith (Not in Mondays)
2012/02/24 19:16:15
This makes me uncomfortable, as it changes the beh
ahendrickson
2012/02/25 01:05:17
This makes the behavior what I wanted it to be in
Randy Smith (Not in Mondays)
2012/02/27 21:06:03
I don't see the comment; did you mean you'd add it
ahendrickson
2012/02/28 03:59:25
Yes, it got added after a merge with the parent.
I
Randy Smith (Not in Mondays)
2012/03/01 20:37:14
Got it--thanks.
|
| + |
| DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| scoped_ptr<DownloadTestObserver> observer( |
| new DownloadTestObserver( |
| @@ -698,7 +700,7 @@ class DownloadTest : public InProcessBrowserTest { |
| download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? |
| DownloadItem::COMPLETE : // Really done |
| DownloadItem::INTERRUPTED, |
| - true, // Bail on select file |
| + false, // Don't finish on select file |
| DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| if (download_info.download_method == DOWNLOAD_DIRECT) { |
| @@ -731,9 +733,49 @@ class DownloadTest : public InProcessBrowserTest { |
| ASSERT_EQ(url, item->GetOriginalUrl()); |
| ASSERT_EQ(download_info.reason, item->GetLastReason()); |
| + |
| + if (item->GetLastReason() == DOWNLOAD_INTERRUPT_REASON_NONE) { |
|
Randy Smith (Not in Mondays)
2012/02/27 21:06:03
What does this test mean? That we weren't interru
ahendrickson
2012/02/28 03:59:25
It means that the download succeeded in the end.
Randy Smith (Not in Mondays)
2012/03/01 20:37:14
Why not test against state COMPLETED? It seems cl
ahendrickson
2012/03/02 17:51:57
Done.
|
| + // Clean up the file, in case it ended up in the My Documents folder. |
| + FilePath destination_folder = GetDownloadDirectory(browser()); |
| + FilePath my_downloaded_file = item->GetTargetFilePath(); |
| + EXPECT_TRUE(file_util::PathExists(my_downloaded_file)); |
| + EXPECT_TRUE(file_util::Delete(my_downloaded_file, false)); |
| + |
| + // If it's not where we asked it to be, it should be in the |
| + // My Documents folder. |
| + if (my_downloaded_file.value().find(destination_folder.value()) == |
| + std::string::npos) { |
| + FilePath my_docs_folder; |
| + EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DOCUMENTS, |
| + &my_docs_folder)); |
| + EXPECT_EQ(0u, |
| + my_downloaded_file.value().find(my_docs_folder.value())); |
| + } |
| + } |
| } |
| } |
| + // Attempts to download a file to a read-only folder, based on information |
| + // in |download_info|. |
| + void DownloadFileToReadonlyFolder(const DownloadInfo& download_info) { |
| + ASSERT_TRUE(InitialSetup(false)); // Creates temporary download folder. |
| + |
| + // Make the test folder unwritable. |
| + FilePath destination_folder = GetDownloadDirectory(browser()); |
| + DVLOG(1) << " " << __FUNCTION__ << "()" |
| + << " folder = '" << destination_folder.value() << "'"; |
| + size_t perm_length = 0; |
| + void* original_permissions = |
| + file_util::GetPermissionInfo(destination_folder, &perm_length); |
| + EXPECT_TRUE(original_permissions != NULL); |
| + EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder)); |
| + |
| + DownloadFileCheckErrors(download_info); |
| + |
| + EXPECT_TRUE(file_util::RestorePermissionInfo(destination_folder, |
| + original_permissions, |
| + perm_length)); |
| + } |
| private: |
| // Location of the test data. |
| FilePath test_dir_; |
| @@ -2018,3 +2060,27 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Navigate) { |
| ASSERT_TRUE(InitialSetup(false)); |
| DownloadFileCheckErrors(download_info); |
| } |
| + |
| +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolderDirect) { |
|
Randy Smith (Not in Mondays)
2012/02/24 19:16:15
Shouldn't both of these tests actively confirm tha
ahendrickson
2012/02/25 01:05:17
They do, in line 751.
Randy Smith (Not in Mondays)
2012/02/27 21:06:03
That test (presuming I'm reading it correctly) is
ahendrickson
2012/02/28 03:59:25
Ah, I see. I don't have access to the information
|
| + DownloadInfo download_info = { |
| + "a_zip_file.zip", |
| + DOWNLOAD_DIRECT, |
| + // This passes because we switch to the My Documents folder. |
| + DOWNLOAD_INTERRUPT_REASON_NONE, |
| + true |
| + }; |
| + |
| + DownloadFileToReadonlyFolder(download_info); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolderNavigate) { |
| + DownloadInfo download_info = { |
| + "a_zip_file.zip", |
| + DOWNLOAD_NAVIGATE, |
| + // This passes because we switch to the My Documents folder. |
| + DOWNLOAD_INTERRUPT_REASON_NONE, |
| + true |
| + }; |
| + |
| + DownloadFileToReadonlyFolder(download_info); |
| +} |