#ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_
#define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h"
#include "chrome/browser/extensions/api/image_writer_private/operation_manager.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace image_writer {
const char kDummyExtensionId[] = "DummyExtension";
const int kTestFileSize = 32 * 1024;
const int kImagePattern = 0x55555555;
const int kDevicePattern = 0xAAAAAAAA;
class MockOperationManager : public OperationManager {
public:
MockOperationManager();
explicit MockOperationManager(content::BrowserContext* context);
virtual ~MockOperationManager();
MOCK_METHOD3(OnProgress, void(const ExtensionId& extension_id,
image_writer_api::Stage stage,
int progress));
MOCK_METHOD1(OnComplete, void(const std::string& extension_id));
MOCK_METHOD4(OnError, void(const ExtensionId& extension_id,
image_writer_api::Stage stage,
int progress,
const std::string& error_message));
};
class FakeImageWriterClient : public ImageWriterUtilityClient {
public:
FakeImageWriterClient();
virtual void Write(const ProgressCallback& progress_callback,
const SuccessCallback& success_callback,
const ErrorCallback& error_callback,
const base::FilePath& source,
const base::FilePath& target) OVERRIDE;
virtual void Verify(const ProgressCallback& progress_callback,
const SuccessCallback& success_callback,
const ErrorCallback& error_callback,
const base::FilePath& source,
const base::FilePath& target) OVERRIDE;
virtual void Cancel(const CancelCallback& cancel_callback) OVERRIDE;
virtual void Shutdown() OVERRIDE;
void Progress(int64 progress);
void Success();
void Error(const std::string& message);
void Cancel();
static scoped_refptr<FakeImageWriterClient> Create();
private:
virtual ~FakeImageWriterClient();
ProgressCallback progress_callback_;
SuccessCallback success_callback_;
ErrorCallback error_callback_;
CancelCallback cancel_callback_;
};
class ImageWriterUnitTestBase : public testing::Test {
protected:
ImageWriterUnitTestBase();
virtual ~ImageWriterUnitTestBase();
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
bool ImageWrittenToDevice(const base::FilePath& image_path,
const base::FilePath& device_path);
bool FillFile(const base::FilePath& file,
const int pattern,
const int length);
base::ScopedTempDir temp_dir_;
base::FilePath test_image_path_;
base::FilePath test_device_path_;
private:
content::TestBrowserThreadBundle thread_bundle_;
};
}
}
#endif