Chromium Code Reviews| Index: content/test/test_file_error_injector.h |
| diff --git a/content/test/test_file_error_injector.h b/content/test/test_file_error_injector.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d40e7cb8cd32560a4dab633049d1ac8b6022bfea |
| --- /dev/null |
| +++ b/content/test/test_file_error_injector.h |
| @@ -0,0 +1,83 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_TEST_TEST_FILE_ERROR_INJECTOR_H_ |
| +#define CONTENT_TEST_TEST_FILE_ERROR_INJECTOR_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "content/public/browser/download_id.h" |
| +#include "net/base/net_errors.h" |
| + |
| +class GURL; |
| + |
| +namespace content { |
| + |
| +// Test helper for injecting errors into download file operations. |
| +// All errors for a download must be injected before it starts. |
| +// This class needs to be |RefCountedThreadSafe| because the implementation |
| +// is referenced by other classes that live past the time when the user is |
| +// nominally done with it. These classes are internal to content/. |
| +// |
| +// NOTE: No more than one download with the same URL can be in progress at |
| +// the same time. You can have multiple simultaneous downloads as long as the |
| +// 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.
|
| +class TestFileErrorInjector |
| + : public base::RefCountedThreadSafe<TestFileErrorInjector> { |
| + public: |
| + enum FileOperationCode { |
| + FILE_OPERATION_INITIALIZE, |
| + FILE_OPERATION_WRITE, |
| + FILE_OPERATION_RENAME |
| + }; |
| + |
| + // Structure that encapsulates the information needed to inject a file error. |
| + struct FileErrorInfo { |
| + std::string url; // Full URL of the download. Identifies the download. |
| + FileOperationCode code; // Operation to affect. |
| + int operation_instance; // 0-based count of operation calls. |
| + net::Error net_error; // Error to inject. |
| + }; |
| + |
| + TestFileErrorInjector() {} |
| + |
| + // Creates an instance. |
| + static scoped_refptr<TestFileErrorInjector> Get(); |
| + |
| + // Adds an error. |
| + // Must be called before |InjectErrors()| for a particular download file. |
| + // 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.
|
| + virtual bool AddError(const FileErrorInfo& error_info) = 0; |
| + |
| + // Clears all errors. |
| + // 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.
|
| + 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.
|
| + |
| + // Injects the errors. |
| + // The download system must already be initialized before calling this. |
| + 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
|
| + |
| + // Get information about the DownloadFiles created. |
| + virtual size_t CurrentFileCount() const = 0; |
| + virtual size_t TotalFileCount() const = 0; |
| + virtual bool HadFile(const GURL& url) const = 0; |
| + virtual const content::DownloadId GetId(const GURL& url) const = 0; |
| + virtual void ClearFoundFiles() = 0; |
| + |
| + static std::string DebugString(FileOperationCode code); |
| + |
| + protected: |
| + virtual ~TestFileErrorInjector() {} |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<TestFileErrorInjector>; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestFileErrorInjector); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_TEST_TEST_FILE_ERROR_INJECTOR_H_ |