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

Side by Side 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, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/file_stream.h ('k') | net/net.gyp » ('j') | net/net.gyp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file defines MockFileStream, a test class for FileStream.
6
7 #ifndef NET_BASE_MOCK_FILE_STREAM_H_
8 #define NET_BASE_MOCK_FILE_STREAM_H_
9 #pragma once
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/file_path.h"
14 #include "net/base/file_stream.h"
15 #include "net/base/net_errors.h"
16
17 namespace testing {
18
19 class MockFileStream : public net::FileStream {
20 public:
21 MockFileStream() : forced_error_(net::OK) {}
22 MockFileStream(base::PlatformFile file, int flags)
23 : net::FileStream(file, flags), forced_error_(net::OK) {}
24
25 void set_forced_error(int error) { forced_error_ = error; }
26 void clear_forced_error() { forced_error_ = net::OK; }
27
28 virtual int Open(const FilePath& path, int open_flags) OVERRIDE {
29 path_ = path;
30 return ReturnError(net::FileStream::Open(path, open_flags));
31 }
32
33 virtual int64 Seek(net::Whence whence, int64 offset) OVERRIDE {
34 return ReturnError64(net::FileStream::Seek(whence, offset));
35 }
36
37 virtual int64 Available() OVERRIDE {
38 return ReturnError64(net::FileStream::Available());
39 }
40
41 virtual int Read(char* buf, int buf_len, net::CompletionCallback* callback)
42 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.
43 return ReturnError(net::FileStream::Read(buf, buf_len, callback));
44 }
45
46 virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE {
47 return ReturnError(net::FileStream::ReadUntilComplete(buf, buf_len));
48 }
49
50 virtual int Write(const char* buf,
51 int buf_len,
52 net::CompletionCallback* callback) OVERRIDE {
53 return ReturnError(net::FileStream::Write(buf, buf_len, callback));
54 }
55
56 virtual int64 Truncate(int64 bytes) OVERRIDE {
57 return ReturnError64(net::FileStream::Truncate(bytes));
58 }
59
60 virtual int Flush() OVERRIDE {
61 return ReturnError(net::FileStream::Flush());
62 }
63
64 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.
65
66 private:
67 int ReturnError(int function_error) {
68 if (forced_error_ != net::OK) {
69 int ret = forced_error_;
70 clear_forced_error();
71 return ret;
72 }
73
74 return function_error;
75 }
76
77 int64 ReturnError64(int64 function_error) {
78 if (forced_error_ != net::OK) {
79 int64 ret = forced_error_;
80 clear_forced_error();
81 return ret;
82 }
83
84 return function_error;
85 }
86
87 int forced_error_;
88 FilePath path_;
89 };
90
91 } // namespace testing
92
93 #endif // NET_BASE_MOCK_FILE_STREAM_H_
OLDNEW
« 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