| Index: chrome/browser/extensions/api/image_writer_private/test_utils.cc
|
| diff --git a/chrome/browser/extensions/api/image_writer_private/test_utils.cc b/chrome/browser/extensions/api/image_writer_private/test_utils.cc
|
| index 29c5b5cc3e467aabb2f6152bcc89ca7ef7ad2e80..0bbb196cbfa384eb783406f81764a3b2a89c8250 100644
|
| --- a/chrome/browser/extensions/api/image_writer_private/test_utils.cc
|
| +++ b/chrome/browser/extensions/api/image_writer_private/test_utils.cc
|
| @@ -55,14 +55,65 @@ MockOperationManager::MockOperationManager(Profile* profile)
|
| : OperationManager(profile) {}
|
| MockOperationManager::~MockOperationManager() {}
|
|
|
| +FakeImageWriterClient::FakeImageWriterClient() {}
|
| +FakeImageWriterClient::~FakeImageWriterClient() {}
|
| +
|
| +void FakeImageWriterClient::Write(const ProgressCallback& progress_callback,
|
| + const SuccessCallback& success_callback,
|
| + const ErrorCallback& error_callback,
|
| + const base::FilePath& source,
|
| + const base::FilePath& target) {
|
| + progress_callback_ = progress_callback;
|
| + success_callback_ = success_callback;
|
| + error_callback_ = error_callback;
|
| +}
|
| +
|
| +void FakeImageWriterClient::Verify(const ProgressCallback& progress_callback,
|
| + const SuccessCallback& success_callback,
|
| + const ErrorCallback& error_callback,
|
| + const base::FilePath& source,
|
| + const base::FilePath& target) {
|
| + progress_callback_ = progress_callback;
|
| + success_callback_ = success_callback;
|
| + error_callback_ = error_callback;
|
| +}
|
| +
|
| +void FakeImageWriterClient::Cancel(const CancelCallback& cancel_callback) {
|
| + cancel_callback_ = cancel_callback;
|
| +}
|
| +
|
| +void FakeImageWriterClient::Shutdown() {
|
| + // Clear handlers to not hold any reference to the caller.
|
| + success_callback_ = base::Closure();
|
| + progress_callback_ = base::Callback<void(int64)>();
|
| + error_callback_ = base::Callback<void(const std::string&)>();
|
| + cancel_callback_ = base::Closure();
|
| +}
|
| +
|
| +void FakeImageWriterClient::Progress(int64 progress) {
|
| + progress_callback_.Run(progress);
|
| +}
|
| +
|
| +void FakeImageWriterClient::Success() { success_callback_.Run(); }
|
| +
|
| +void FakeImageWriterClient::Error(const std::string& message) {
|
| + error_callback_.Run(message);
|
| +}
|
| +
|
| +void FakeImageWriterClient::Cancel() { cancel_callback_.Run(); }
|
| +
|
| +scoped_refptr<FakeImageWriterClient> FakeImageWriterClient::Create() {
|
| + return scoped_refptr<FakeImageWriterClient>(new FakeImageWriterClient());
|
| +}
|
| +
|
| ImageWriterUnitTestBase::ImageWriterUnitTestBase()
|
| : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
|
| ImageWriterUnitTestBase::~ImageWriterUnitTestBase() {}
|
|
|
| void ImageWriterUnitTestBase::SetUp() {
|
| testing::Test::SetUp();
|
| - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
|
|
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
|
| &test_image_path_));
|
| ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
|
| @@ -89,6 +140,27 @@ void ImageWriterUnitTestBase::TearDown() {
|
| #endif
|
| }
|
|
|
| +bool ImageWriterUnitTestBase::ImageWrittenToDevice(
|
| + const base::FilePath& image_path,
|
| + const base::FilePath& device_path) {
|
| + scoped_ptr<char[]> image_buffer(new char[kTestFileSize]);
|
| + scoped_ptr<char[]> device_buffer(new char[kTestFileSize]);
|
| +
|
| + int image_bytes_read =
|
| + ReadFile(image_path, image_buffer.get(), kTestFileSize);
|
| +
|
| + if (image_bytes_read < 0)
|
| + return false;
|
| +
|
| + int device_bytes_read =
|
| + ReadFile(device_path, device_buffer.get(), kTestFileSize);
|
| +
|
| + if (image_bytes_read != device_bytes_read)
|
| + return false;
|
| +
|
| + return memcmp(image_buffer.get(), device_buffer.get(), image_bytes_read) == 0;
|
| +}
|
| +
|
| bool ImageWriterUnitTestBase::FillFile(const base::FilePath& file,
|
| const int pattern,
|
| const int length) {
|
|
|