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

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: Refactored per Chris' comments 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 "base/memory/ref_counted.h"
10 #include "net/base/net_errors.h"
11
12 namespace content {
13
14 // Test helper for injecting errors into |DownloadFile| operations.
15 // All errors must be injected before download starts.
16 class TestFileErrorInjector
17 : public base::RefCountedThreadSafe<TestFileErrorInjector> {
Randy Smith (Not in Mondays) 2012/02/28 22:06:13 I'd like some documentation as to why this class i
ahendrickson 2012/03/01 09:17:32 Done.
18 public:
19 enum FileOperationCode {
20 FILE_OPERATION_INITIALIZE,
21 FILE_OPERATION_WRITE,
22 FILE_OPERATION_RENAME
23 };
24
25 // Structure that encapsulates the information needed to inject a file error.
26 struct FileErrorInfo {
27 int file_index; // 0-based index into created DownloadFile instances.
Randy Smith (Not in Mondays) 2012/02/28 22:06:13 I don't like references to DownloadFile in this fi
Randy Smith (Not in Mondays) 2012/02/28 22:06:13 I don't like 0 based indices, because they presume
ahendrickson 2012/03/01 09:17:32 Done.
ahendrickson 2012/03/01 09:17:32 There will be multiple calls with the same URL, an
ahendrickson 2012/03/01 09:21:15 Now using the URL as the distinguishing value, all
28 FileOperationCode code; // Operation to affect.
29 int operation_instance; // 0-based count of operation calls.
Randy Smith (Not in Mondays) 2012/02/28 22:06:13 These two options strike me as having some redunda
ahendrickson 2012/03/01 09:17:32 No, they're not redundant. The code specifies the
Randy Smith (Not in Mondays) 2012/03/01 20:28:24 Ah, got it. The key point I was missing was that
ahendrickson 2012/03/02 21:58:47 Done.
30 net::Error net_error; // Error to inject.
31 };
32
33 TestFileErrorInjector() {}
34
35 // Creates an instance.
36 static scoped_refptr<TestFileErrorInjector> Create();
Randy Smith (Not in Mondays) 2012/02/28 22:06:13 Could you specify whether this has singleton seman
ahendrickson 2012/03/01 09:17:32 Hmm, I suppose it should have singleton semantics.
37
38 // Adds an error. Must be called before InjectErrors().
cbentzel 2012/02/28 14:51:41 Nit: |InjectErrors()|
ahendrickson 2012/03/01 09:17:32 Done.
39 virtual bool AddError(const FileErrorInfo& error_info) = 0;
40
41 // Injects the errors. Can be called only once.
cbentzel 2012/02/28 14:51:41 Nit: Comment more about how this impacts the Downl
Randy Smith (Not in Mondays) 2012/02/28 22:06:13 In an ideal world, comments in this file would not
ahendrickson 2012/03/01 09:17:32 Done.
ahendrickson 2012/03/01 09:17:32 Done.
42 virtual bool InjectErrors() = 0;
43
44 // Get information about the DownloadFiles created.
45 virtual size_t CurrentFileCount() const = 0;
46 virtual size_t FileCreationCount() const = 0;
cbentzel 2012/02/28 14:51:41 Nit: Perhaps TotalFileCount to match CurrentFileCo
ahendrickson 2012/03/01 09:17:32 Done.
47 virtual bool HasFile(int file_index) const = 0;
48
49 // Debugging only.
cbentzel 2012/02/28 14:51:41 This isn't needed - or at least needed for public
ahendrickson 2012/03/01 09:17:32 It's used now.
50 static std::string DebugString(FileOperationCode code);
51
52 protected:
53 virtual ~TestFileErrorInjector() {}
54
55 private:
56 friend class base::RefCountedThreadSafe<TestFileErrorInjector>;
57
58 DISALLOW_COPY_AND_ASSIGN(TestFileErrorInjector);
59 };
60
61 } // namespace content
62
63 #endif // CONTENT_TEST_TEST_FILE_ERROR_INJECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698