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

Unified Diff: chrome/browser/download/download_browsertest.cc

Issue 9355050: Added read-only file error test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk. Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/test_file_util_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_browsertest.cc
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index 4aa216d0f3d4e2e8305deaa4c588f4e8535cf026..455c2111d0cc336dbf431914630d81762583e360 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -250,6 +250,7 @@ class DownloadTest : public InProcessBrowserTest {
// Download interrupt reason (NONE is OK).
content::DownloadInterruptReason reason;
bool show_download_item; // True if the download item appears on the shelf.
+ bool should_redirect_to_documents; // True if we save it in "My Documents".
};
DownloadTest() {
@@ -641,6 +642,7 @@ class DownloadTest : public InProcessBrowserTest {
}
// Attempts to download a file, based on information in |download_info|.
+ // If a Select File dialog opens, will automatically choose the default.
void DownloadFileCheckErrors(const DownloadInfo& download_info) {
ASSERT_TRUE(test_server()->Start());
std::vector<DownloadItem*> download_items;
@@ -654,6 +656,8 @@ class DownloadTest : public InProcessBrowserTest {
GURL url = test_server()->GetURL(server_path);
ASSERT_TRUE(url.is_valid());
+ NullSelectFile(browser()); // Needed for read-only tests.
+
DownloadManager* download_manager = DownloadManagerForBrowser(browser());
scoped_ptr<DownloadTestObserver> observer(
new DownloadTestObserverTerminal(
@@ -717,9 +721,46 @@ class DownloadTest : public InProcessBrowserTest {
ASSERT_EQ(url, item->GetOriginalUrl());
ASSERT_EQ(download_info.reason, item->GetLastReason());
+
+ if (item->GetState() == content::DownloadItem::COMPLETE) {
+ // 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));
+
+ EXPECT_EQ(download_info.should_redirect_to_documents ?
+ std::string::npos :
+ 0u,
+ my_downloaded_file.value().find(destination_folder.value()));
+ if (download_info.should_redirect_to_documents) {
+ // If it's not where we asked it to be, it should be in the
+ // My Documents folder.
+ 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() << "'";
+ file_util::PermissionRestorer permission_restorer(destination_folder);
+ EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder));
+
+ DownloadFileCheckErrors(download_info);
+ }
+
bool EnsureNoPendingDownloads() {
bool result = true;
BrowserThread::PostTask(
@@ -2028,7 +2069,8 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadNavigate) {
"a_zip_file.zip",
DOWNLOAD_NAVIGATE,
content::DOWNLOAD_INTERRUPT_REASON_NONE,
- true
+ true,
+ false
};
// Do initial setup.
@@ -2041,7 +2083,8 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDirect) {
"a_zip_file.zip",
DOWNLOAD_DIRECT,
content::DOWNLOAD_INTERRUPT_REASON_NONE,
- true
+ true,
+ false
};
// Do initial setup.
@@ -2054,7 +2097,8 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Direct) {
"there_IS_no_spoon.zip",
DOWNLOAD_DIRECT,
content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
- true
+ true,
+ false
};
// Do initial setup.
@@ -2067,6 +2111,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError404Navigate) {
"there_IS_no_spoon.zip",
DOWNLOAD_NAVIGATE,
content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
+ false,
false
};
@@ -2080,7 +2125,8 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Direct) {
"zip_file_not_found.zip",
DOWNLOAD_DIRECT,
content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
- true
+ true,
+ false
};
// Do initial setup.
@@ -2093,6 +2139,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Navigate) {
"zip_file_not_found.zip",
DOWNLOAD_NAVIGATE,
content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
+ false,
false
};
@@ -2100,3 +2147,29 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Navigate) {
ASSERT_TRUE(InitialSetup(false));
DownloadFileCheckErrors(download_info);
}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolderDirect) {
+ DownloadInfo download_info = {
+ "a_zip_file.zip",
+ DOWNLOAD_DIRECT,
+ // This passes because we switch to the My Documents folder.
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
+ true,
+ 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.
+ content::DOWNLOAD_INTERRUPT_REASON_NONE,
+ true,
+ true
+ };
+
+ DownloadFileToReadonlyFolder(download_info);
+}
« no previous file with comments | « base/test/test_file_util_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698