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

Side by Side Diff: content/test/test_file_error_injector.h

Issue 9426029: Test file errors in downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed CLANG issue. Created 8 years, 9 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
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 #ifndef CONTENT_TEST_TEST_FILE_ERROR_INJECTOR_H_
6 #define CONTENT_TEST_TEST_FILE_ERROR_INJECTOR_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/memory/ref_counted.h"
12 #include "content/public/browser/download_id.h"
13 #include "net/base/net_errors.h"
14
15 class GURL;
16
17 namespace content {
18
19 // Test helper for injecting errors into download file operations.
20 // All errors for a download must be injected before it starts.
21 // This class needs to be |RefCountedThreadSafe| because the implementation
22 // is referenced by other classes that live past the time when the user is
23 // nominally done with it. These classes are internal to content/.
24 //
25 // NOTE: No more than one download with the same URL can be in progress at
26 // the same time. You can have multiple simultaneous downloads as long as the
27 // URLs are different.
Randy Smith (Not in Mondays) 2012/03/01 20:28:25 nit, suggestion: MIght be useful to explain why th
Randy Smith (Not in Mondays) 2012/03/01 20:28:25 Could you put in/have you put in a DCHECK() to con
ahendrickson 2012/03/02 21:58:47 Done.
ahendrickson 2012/03/02 21:58:47 Done.
28 class TestFileErrorInjector
29 : public base::RefCountedThreadSafe<TestFileErrorInjector> {
30 public:
31 enum FileOperationCode {
32 FILE_OPERATION_INITIALIZE,
33 FILE_OPERATION_WRITE,
34 FILE_OPERATION_RENAME
35 };
36
37 // Structure that encapsulates the information needed to inject a file error.
38 struct FileErrorInfo {
39 std::string url; // Full URL of the download. Identifies the download.
40 FileOperationCode code; // Operation to affect.
41 int operation_instance; // 0-based count of operation calls.
42 net::Error net_error; // Error to inject.
43 };
44
45 TestFileErrorInjector() {}
46
47 // Creates an instance.
48 static scoped_refptr<TestFileErrorInjector> Get();
49
50 // Adds an error.
51 // Must be called before |InjectErrors()| for a particular download file.
52 // Only one error per file will be used.
Randy Smith (Not in Mondays) 2012/03/01 20:28:25 So what happens if more than one AddError is calle
ahendrickson 2012/03/02 21:58:47 There's a DCHECK preventing it.
Randy Smith (Not in Mondays) 2012/03/06 23:05:19 So that means that it's an interface violation to
ahendrickson 2012/03/08 22:00:08 Done.
53 virtual bool AddError(const FileErrorInfo& error_info) = 0;
54
55 // Clears all errors.
56 // Doesn't affect files already created.
Randy Smith (Not in Mondays) 2012/03/01 20:28:25 Based on the implementation, I think this comment
ahendrickson 2012/03/02 21:58:47 Fixed comment.
57 virtual void ClearErrors() = 0;
Randy Smith (Not in Mondays) 2012/03/01 20:28:25 It might be illuminating to include a comment with
ahendrickson 2012/03/02 21:58:47 Done.
58
59 // Injects the errors.
60 // The download system must already be initialized before calling this.
61 virtual bool InjectErrors() = 0;
Randy Smith (Not in Mondays) 2012/03/01 20:28:25 It's not clear to me reading this header file how
ahendrickson 2012/03/02 21:58:47 Multiple calls are allowed. They replace the fact
62
63 // Get information about the DownloadFiles created.
64 virtual size_t CurrentFileCount() const = 0;
65 virtual size_t TotalFileCount() const = 0;
66 virtual bool HadFile(const GURL& url) const = 0;
67 virtual const content::DownloadId GetId(const GURL& url) const = 0;
68 virtual void ClearFoundFiles() = 0;
69
70 static std::string DebugString(FileOperationCode code);
71
72 protected:
73 virtual ~TestFileErrorInjector() {}
74
75 private:
76 friend class base::RefCountedThreadSafe<TestFileErrorInjector>;
77
78 DISALLOW_COPY_AND_ASSIGN(TestFileErrorInjector);
79 };
80
81 } // namespace content
82
83 #endif // CONTENT_TEST_TEST_FILE_ERROR_INJECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698