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..ed485ae7af71edb1d1d6459bb7857c6b8fb21cc1 |
| --- /dev/null |
| +++ b/content/test/test_file_error_injector.h |
| @@ -0,0 +1,63 @@ |
| +// 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 "base/memory/ref_counted.h" |
| +#include "net/base/net_errors.h" |
| + |
| +namespace content { |
| + |
| +// Test helper for injecting errors into |DownloadFile| operations. |
| +// All errors must be injected before download starts. |
| +class TestFileErrorInjector |
| + : 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.
|
| + 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 { |
| + 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
|
| + FileOperationCode code; // Operation to affect. |
| + 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.
|
| + net::Error net_error; // Error to inject. |
| + }; |
| + |
| + TestFileErrorInjector() {} |
| + |
| + // Creates an instance. |
| + 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.
|
| + |
| + // 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.
|
| + virtual bool AddError(const FileErrorInfo& error_info) = 0; |
| + |
| + // 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.
|
| + virtual bool InjectErrors() = 0; |
| + |
| + // Get information about the DownloadFiles created. |
| + virtual size_t CurrentFileCount() const = 0; |
| + 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.
|
| + virtual bool HasFile(int file_index) const = 0; |
| + |
| + // 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.
|
| + 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_ |