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

Unified Diff: net/base/mock_file_stream.h

Issue 7646025: Detect file system errors during downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor refactor of DownloadFileWithMockStream class. Created 9 years, 4 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: net/base/mock_file_stream.h
diff --git a/net/base/mock_file_stream.h b/net/base/mock_file_stream.h
new file mode 100755
index 0000000000000000000000000000000000000000..ab566c949035ddfa25f78e41778349f9374c6a0a
--- /dev/null
+++ b/net/base/mock_file_stream.h
@@ -0,0 +1,71 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file defines MockFileStream, a test class for FileStream.
+
+#ifndef NET_BASE_MOCK_FILE_STREAM_H_
+#define NET_BASE_MOCK_FILE_STREAM_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/file_path.h"
+#include "net/base/file_stream.h"
+#include "net/base/net_errors.h"
+
+namespace testing {
wtc 2011/08/29 18:17:05 IMPORTANT: I believe the top-level namespace "test
ahendrickson 2011/08/29 19:42:38 Now using the net::testing namespace.
+
+class MockFileStream : public net::FileStream {
+ public:
+ MockFileStream() : forced_error_(net::OK) {}
+
+ MockFileStream(base::PlatformFile file, int flags)
+ : net::FileStream(file, flags), forced_error_(net::OK) {}
+
+ // FileStream methods.
+ virtual int Open(const FilePath& path, int open_flags) OVERRIDE;
+ virtual int64 Seek(net::Whence whence, int64 offset) OVERRIDE;
+ virtual int64 Available() OVERRIDE;
+ virtual int Read(char* buf,
+ int buf_len,
+ net::CompletionCallback* callback) OVERRIDE;
+ virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE;
+ virtual int Write(const char* buf,
+ int buf_len,
+ net::CompletionCallback* callback) OVERRIDE;
+ virtual int64 Truncate(int64 bytes) OVERRIDE;
+ virtual int Flush() OVERRIDE;
wtc 2011/08/29 18:17:05 IMPORTANT: You didn't override the following metho
ahendrickson 2011/08/29 19:42:38 Yes. Close() does not return an error code, so it
wtc 2011/08/29 20:03:59 It seems that if MockFileStream::Open() fails, the
+
+ void set_forced_error(int error) { forced_error_ = error; }
+ void clear_forced_error() { forced_error_ = net::OK; }
+ const FilePath& get_path() const { return path_; }
+
+ private:
+ int ReturnError(int function_error) {
+ if (forced_error_ != net::OK) {
+ int ret = forced_error_;
+ clear_forced_error();
+ return ret;
+ }
+
+ return function_error;
+ }
+
+ int64 ReturnError64(int64 function_error) {
+ if (forced_error_ != net::OK) {
+ int64 ret = forced_error_;
+ clear_forced_error();
+ return ret;
+ }
+
+ return function_error;
+ }
+
+ int forced_error_;
+ FilePath path_;
+};
+
+} // namespace testing
+
+#endif // NET_BASE_MOCK_FILE_STREAM_H_

Powered by Google App Engine
This is Rietveld 408576698