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

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: Removed illegal include from content. 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
« no previous file with comments | « net/base/file_stream.h ('k') | net/net.gyp » ('j') | net/net.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..fd79d89a8a53838740ec6088bc0176102e593094
--- /dev/null
+++ b/net/base/mock_file_stream.h
@@ -0,0 +1,93 @@
+// 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 {
+
+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) {}
+
+ void set_forced_error(int error) { forced_error_ = error; }
+ void clear_forced_error() { forced_error_ = net::OK; }
+
+ virtual int Open(const FilePath& path, int open_flags) OVERRIDE {
+ path_ = path;
+ return ReturnError(net::FileStream::Open(path, open_flags));
+ }
+
+ virtual int64 Seek(net::Whence whence, int64 offset) OVERRIDE {
+ return ReturnError64(net::FileStream::Seek(whence, offset));
+ }
+
+ virtual int64 Available() OVERRIDE {
+ return ReturnError64(net::FileStream::Available());
+ }
+
+ virtual int Read(char* buf, int buf_len, net::CompletionCallback* callback)
+ OVERRIDE {
wtc 2011/08/26 20:51:50 Nit: it may be better to list net::CompletionCallb
ahendrickson 2011/08/26 21:06:54 Done.
+ return ReturnError(net::FileStream::Read(buf, buf_len, callback));
+ }
+
+ virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE {
+ return ReturnError(net::FileStream::ReadUntilComplete(buf, buf_len));
+ }
+
+ virtual int Write(const char* buf,
+ int buf_len,
+ net::CompletionCallback* callback) OVERRIDE {
+ return ReturnError(net::FileStream::Write(buf, buf_len, callback));
+ }
+
+ virtual int64 Truncate(int64 bytes) OVERRIDE {
+ return ReturnError64(net::FileStream::Truncate(bytes));
+ }
+
+ virtual int Flush() OVERRIDE {
+ return ReturnError(net::FileStream::Flush());
+ }
+
+ const FilePath& get_path() const { return path_; }
wtc 2011/08/26 20:51:50 Nit: list get_path() along with the set_forced_err
ahendrickson 2011/08/26 21:06:54 Done.
+
+ 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_
« no previous file with comments | « net/base/file_stream.h ('k') | net/net.gyp » ('j') | net/net.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698