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

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

Issue 9426029: Test file errors in downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplified injector classes further. Created 8 years, 10 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
Index: chrome/browser/download/download_browsertest.cc
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index d3e0f19b564e8f9199c44fae8e5114aab17c18bb..f18f09c61bb1e6a858438c161d3ef33fa94c1fc9 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -55,6 +55,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/context_menu_params.h"
#include "content/public/common/page_transition_types.h"
+#include "content/test/test_file_error_injector.h"
#include "content/test/test_navigation_observer.h"
#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -306,6 +307,14 @@ class DownloadTest : public InProcessBrowserTest {
bool show_download_item; // True if the download item appears on the shelf.
};
+ struct FileErrorInjectInfo {
+ DownloadInfo download_info; // See above.
+ content::FileOperationCode code; // A code indicating what file operation
+ // to affect.
+ int operation_index; // The number of the operation to affect (0 = first).
+ net::Error error_to_inject; // The net error to inject into the file op.
+ };
+
DownloadTest() {
EnableDOMAutomation();
}
@@ -736,6 +745,25 @@ class DownloadTest : public InProcessBrowserTest {
}
}
+ void DownloadInsertFileErrorCheckErrors(const FileErrorInjectInfo& info) {
+ // Do initial setup.
+ ASSERT_TRUE(InitialSetup(false));
+
+ // Set up file failures.
+ // |injector| will be owned by the DownloadFileManager (indirectly).
cbentzel 2012/02/27 02:18:54 How hard would it be to change this so the injecto
ahendrickson 2012/02/28 03:28:56 Switched to using RefCountedThreadSafe for the inj
+ content::TestFileErrorInjector* injector =
+ content::TestFileErrorInjector::Create();
+ injector->InjectError(0, // First DownloadFile created.
cbentzel 2012/02/27 02:18:54 I'd remove this argument for now.
ahendrickson 2012/02/28 03:28:56 How strongly do you feel about that?
cbentzel 2012/02/28 10:57:29 Pretty strongly. I don't like adding arguments tha
+ info.code,
+ info.operation_index,
cbentzel 2012/02/27 02:18:54 Do you need operation_index? It looks like it's al
ahendrickson 2012/02/28 03:28:56 Right now the unit tests only try to download smal
cbentzel 2012/02/28 10:57:29 Again, I'd hold off until you have concrete need f
+ info.error_to_inject);
+
+ DownloadFileCheckErrors(info.download_info);
+
+ EXPECT_EQ(1u, injector->FileCreationCount());
+ EXPECT_EQ(0u, injector->CurrentFileCount());
+ }
+
private:
// Location of the test data.
FilePath test_dir_;
@@ -2081,3 +2109,185 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadError400Navigate) {
ASSERT_TRUE(InitialSetup(false));
DownloadFileCheckErrors(download_info);
}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceOpenNavigate) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_NAVIGATE,
+ DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
+ 1
+ },
+ content::FILE_OPERATION_INITIALIZE,
+ 0,
+ net::ERR_FILE_NO_SPACE
cbentzel 2012/02/27 02:18:54 Why would we get NO_SPACE on INITIALIZE?
ahendrickson 2012/02/28 03:28:56 Wouldn't we get that if there are no bytes availab
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceOpenDirect) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_DIRECT,
+ DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
+ 1
+ },
+ content::FILE_OPERATION_INITIALIZE,
+ 0,
+ net::ERR_FILE_NO_SPACE
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceWriteNavigate) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_NAVIGATE,
+ DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
+ 1
+ },
+ content::FILE_OPERATION_WRITE,
+ 0,
+ net::ERR_FILE_NO_SPACE
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNoSpaceWriteDirect) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_DIRECT,
+ DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
+ 1
+ },
+ content::FILE_OPERATION_WRITE,
+ 0,
+ net::ERR_FILE_NO_SPACE
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedOpenNavigate) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_NAVIGATE,
+ DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
+ 1
+ },
+ content::FILE_OPERATION_INITIALIZE,
+ 0,
+ net::ERR_FAILED
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedOpenDirect) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_DIRECT,
+ DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
+ 1
+ },
+ content::FILE_OPERATION_INITIALIZE,
+ 0,
+ net::ERR_FAILED
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedWriteNavigate) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_NAVIGATE,
+ DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
+ 1
+ },
+ content::FILE_OPERATION_WRITE,
+ 0,
+ net::ERR_FAILED
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileFailedWriteDirect) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_DIRECT,
+ DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
+ 1
+ },
+ content::FILE_OPERATION_WRITE,
+ 0,
+ net::ERR_FAILED
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNameTooLongOpenNavigate) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_NAVIGATE,
+ DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
+ 1
+ },
+ content::FILE_OPERATION_INITIALIZE,
+ 0,
+ net::ERR_FILE_PATH_TOO_LONG
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorFileNameTooLongOpenDirect) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_DIRECT,
+ DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG,
+ 1
+ },
+ content::FILE_OPERATION_INITIALIZE,
+ 0,
+ net::ERR_FILE_PATH_TOO_LONG
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest,
+ DownloadErrorFileInvalidHandleWriteNavigate) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_NAVIGATE,
+ DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
+ 1
+ },
+ content::FILE_OPERATION_WRITE,
+ 0,
+ net::ERR_INVALID_HANDLE
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest,
+ DownloadErrorFileInvalidHandleWriteDirect) {
+ FileErrorInjectInfo error_info = {
+ { "a_zip_file.zip",
+ DOWNLOAD_DIRECT,
+ DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
+ 1
+ },
+ content::FILE_OPERATION_WRITE,
+ 0,
+ net::ERR_INVALID_HANDLE
+ };
+
+ DownloadInsertFileErrorCheckErrors(error_info);
+}
« no previous file with comments | « no previous file | content/browser/download/download_file_manager.h » ('j') | content/test/test_file_error_injector.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698