Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "net/base/net_errors.h" | |
| 13 | |
| 14 class GURL; | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 class DownloadId; | |
| 19 | |
| 20 // Test helper for injecting errors into download file operations. | |
| 21 // All errors for a download must be injected before it starts. | |
| 22 // This class needs to be |RefCountedThreadSafe| because the implementation | |
| 23 // is referenced by other classes that live past the time when the user is | |
| 24 // nominally done with it. These classes are internal to content/. | |
| 25 // | |
| 26 // NOTE: No more than one download with the same URL can be in progress at | |
| 27 // the same time. You can have multiple simultaneous downloads as long as the | |
| 28 // URLs are different, as the URLs are used as keys to get information about | |
| 29 // the download. | |
| 30 // | |
| 31 // Example: | |
| 32 // | |
| 33 // FileErrorInfo a = { url1, ... }; | |
| 34 // FileErrorInfo b = { url2, ... }; | |
| 35 // | |
| 36 // scoped_refptr<TestFileErrorInjector> injector = | |
| 37 // TestFileErrorInjector::Create(); | |
| 38 // | |
| 39 // injector->AddError(); | |
| 40 // injector->AddError(); | |
|
Randy Smith (Not in Mondays)
2012/03/06 23:05:19
Shouldn't these refer to a & b?
ahendrickson
2012/03/08 22:00:08
Done.
| |
| 41 // injector->InjectErrors(); | |
| 42 // | |
| 43 // download_manager->DownloadUrl(url1, ...); | |
| 44 // download_manager->DownloadUrl(url2, ...); | |
| 45 // ... wait for downloads to finish or get an injected error ... | |
|
Randy Smith (Not in Mondays)
2012/03/06 23:05:19
Thank you--I think this comment makes this class m
| |
| 46 // | |
| 47 class TestFileErrorInjector | |
| 48 : public base::RefCountedThreadSafe<TestFileErrorInjector> { | |
| 49 public: | |
| 50 enum FileOperationCode { | |
| 51 FILE_OPERATION_INITIALIZE, | |
| 52 FILE_OPERATION_WRITE, | |
| 53 FILE_OPERATION_RENAME | |
| 54 }; | |
| 55 | |
| 56 // Structure that encapsulates the information needed to inject a file error. | |
| 57 struct FileErrorInfo { | |
| 58 std::string url; // Full URL of the download. Identifies the download. | |
| 59 FileOperationCode code; // Operation to affect. | |
| 60 int operation_instance; // 0-based count of operation calls, for each code. | |
| 61 net::Error net_error; // Error to inject. | |
| 62 }; | |
| 63 | |
| 64 TestFileErrorInjector() {} | |
|
Randy Smith (Not in Mondays)
2012/03/06 23:05:19
If you want all instances of this class to be crea
ahendrickson
2012/03/08 22:00:08
Made it protected, as another class inherits from
Randy Smith (Not in Mondays)
2012/03/12 01:44:50
Good point; oops on my part.
| |
| 65 | |
| 66 // Creates an instance. May only be called once. | |
|
Randy Smith (Not in Mondays)
2012/03/06 23:05:19
I'd say something about lifetime here, since many
ahendrickson
2012/03/08 22:00:08
Done.
| |
| 67 static scoped_refptr<TestFileErrorInjector> Create(); | |
| 68 | |
| 69 // Adds an error. | |
| 70 // Must be called before |InjectErrors()| for a particular download file. | |
|
Randy Smith (Not in Mondays)
2012/03/06 23:05:19
This is a little misleading; you can have multiple
ahendrickson
2012/03/08 22:00:08
Done.
Randy Smith (Not in Mondays)
2012/03/12 01:44:50
Not seeing it?
ahendrickson
2012/03/12 11:51:02
I did change the comment. If it's still not clear
Randy Smith (Not in Mondays)
2012/03/12 17:43:50
Yeah, sorry, I think the interleaving in the diff
| |
| 71 // Only one error per file will be used. | |
|
Randy Smith (Not in Mondays)
2012/03/06 23:05:19
We have one comment thread indicating that it's an
ahendrickson
2012/03/08 22:00:08
The implementation currently DCHECKs if the same U
Randy Smith (Not in Mondays)
2012/03/12 01:44:50
Cool; thanks.
| |
| 72 virtual bool AddError(const FileErrorInfo& error_info) = 0; | |
| 73 | |
| 74 // Clears all errors. | |
| 75 // Only affects files created after the next call to InjectErrors(). | |
| 76 virtual void ClearErrors() = 0; | |
| 77 | |
| 78 // Injects the errors such that new download files will be affected. | |
| 79 // The download system must already be initialized before calling this. | |
| 80 // Multiple calls are allowed, but only useful if the errors have changed. | |
| 81 // Replaces the injected error list. | |
| 82 virtual bool InjectErrors() = 0; | |
| 83 | |
| 84 // Get information about the DownloadFiles created. | |
| 85 virtual size_t CurrentFileCount() const = 0; | |
| 86 virtual size_t TotalFileCount() const = 0; | |
| 87 virtual bool HadFile(const GURL& url) const = 0; | |
| 88 virtual const content::DownloadId GetId(const GURL& url) const = 0; | |
| 89 virtual void ClearFoundFiles() = 0; | |
| 90 | |
| 91 static std::string DebugString(FileOperationCode code); | |
| 92 | |
| 93 protected: | |
| 94 virtual ~TestFileErrorInjector(); | |
| 95 | |
| 96 private: | |
| 97 friend class base::RefCountedThreadSafe<TestFileErrorInjector>; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(TestFileErrorInjector); | |
| 100 }; | |
| 101 | |
| 102 } // namespace content | |
| 103 | |
| 104 #endif // CONTENT_TEST_TEST_FILE_ERROR_INJECTOR_H_ | |
| OLD | NEW |