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 "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. |
| 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. |
| 53 virtual bool AddError(const FileErrorInfo& error_info) = 0; |
| 54 |
| 55 // Clears all errors. |
| 56 // Doesn't affect files already created. |
| 57 virtual void ClearErrors() = 0; |
| 58 |
| 59 // Injects the errors. |
| 60 // The download system must already be initialized before calling this. |
| 61 virtual bool InjectErrors() = 0; |
| 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_ |
OLD | NEW |