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

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: Changed namespace for MockFileStream. 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/base/mock_file_stream.cc » ('j') | no next file with comments »
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 net {
18
19 namespace testing {
20
21 class MockFileStream : public net::FileStream {
22 public:
23 MockFileStream() : forced_error_(net::OK) {}
24
25 MockFileStream(base::PlatformFile file, int flags)
26 : net::FileStream(file, flags), forced_error_(net::OK) {}
27
28 // FileStream methods.
29 virtual int Open(const FilePath& path, int open_flags) OVERRIDE;
30 virtual int64 Seek(net::Whence whence, int64 offset) OVERRIDE;
31 virtual int64 Available() OVERRIDE;
32 virtual int Read(char* buf,
33 int buf_len,
34 net::CompletionCallback* callback) OVERRIDE;
35 virtual int ReadUntilComplete(char *buf, int buf_len) OVERRIDE;
36 virtual int Write(const char* buf,
37 int buf_len,
38 net::CompletionCallback* callback) OVERRIDE;
39 virtual int64 Truncate(int64 bytes) OVERRIDE;
40 virtual int Flush() OVERRIDE;
41
42 void set_forced_error(int error) { forced_error_ = error; }
43 void clear_forced_error() { forced_error_ = net::OK; }
44 const FilePath& get_path() const { return path_; }
45
46 private:
47 int ReturnError(int function_error) {
48 if (forced_error_ != net::OK) {
49 int ret = forced_error_;
50 clear_forced_error();
51 return ret;
52 }
53
54 return function_error;
55 }
56
57 int64 ReturnError64(int64 function_error) {
58 if (forced_error_ != net::OK) {
59 int64 ret = forced_error_;
60 clear_forced_error();
61 return ret;
62 }
63
64 return function_error;
65 }
66
67 int forced_error_;
68 FilePath path_;
69 };
70
71 } // namespace testing
72
73 } // namespace net
74
75 #endif // NET_BASE_MOCK_FILE_STREAM_H_
OLDNEW
« no previous file with comments | « net/base/file_stream.h ('k') | net/base/mock_file_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698