#include "chrome/browser/extensions/api/image_writer_private/test_utils.h"
#include <string.h>
#include <utility>
#include "base/containers/heap_array.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/path_service.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/api/image_writer_private/error_constants.h"
#include "chrome/common/chrome_paths.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/ash/components/dbus/concierge/concierge_client.h"
#include "chromeos/ash/components/dbus/dbus_thread_manager.h"
#include "chromeos/ash/components/dbus/image_burner/fake_image_burner_client.h"
#include "chromeos/ash/components/dbus/image_burner/image_burner_client.h"
#include "chromeos/ash/components/disks/disk.h"
#endif
namespace extensions {
namespace image_writer {
#if BUILDFLAG(IS_CHROMEOS_ASH)
class ImageWriterFakeImageBurnerClient : public ash::FakeImageBurnerClient {
public:
ImageWriterFakeImageBurnerClient() = default;
~ImageWriterFakeImageBurnerClient() override = default;
void SetEventHandlers(
BurnFinishedHandler burn_finished_handler,
const BurnProgressUpdateHandler& burn_progress_update_handler) override {
burn_finished_handler_ = std::move(burn_finished_handler);
burn_progress_update_handler_ = burn_progress_update_handler;
}
void BurnImage(const std::string& from_path,
const std::string& to_path,
ErrorCallback error_callback) override {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(burn_progress_update_handler_, to_path, 0, 100));
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(burn_progress_update_handler_, to_path, 50, 100));
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(burn_progress_update_handler_, to_path, 100, 100));
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(burn_finished_handler_), to_path, true, ""));
}
private:
BurnFinishedHandler burn_finished_handler_;
BurnProgressUpdateHandler burn_progress_update_handler_;
};
#endif
MockOperationManager::MockOperationManager(content::BrowserContext* context)
: … { … }
MockOperationManager::~MockOperationManager() = default;
#if BUILDFLAG(IS_CHROMEOS_ASH)
FakeDiskMountManager::FakeDiskMountManager() {}
FakeDiskMountManager::~FakeDiskMountManager() = default;
void FakeDiskMountManager::UnmountDeviceRecursively(
const std::string& device_path,
UnmountDeviceRecursivelyCallbackType callback) {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), ash::MountError::kSuccess));
}
#endif
SimulateProgressInfo::SimulateProgressInfo(
const std::vector<int>& progress_list,
bool will_succeed)
: … { … }
SimulateProgressInfo::~SimulateProgressInfo() = default;
SimulateProgressInfo::SimulateProgressInfo(const SimulateProgressInfo&) =
default;
FakeImageWriterClient::FakeImageWriterClient()
: … { … }
FakeImageWriterClient::~FakeImageWriterClient() = default;
void FakeImageWriterClient::SimulateProgressAndCompletion(
const SimulateProgressInfo& info) { … }
void FakeImageWriterClient::Write(ProgressCallback progress_callback,
SuccessCallback success_callback,
ErrorCallback error_callback,
const base::FilePath& source,
const base::FilePath& target) { … }
void FakeImageWriterClient::Verify(ProgressCallback progress_callback,
SuccessCallback success_callback,
ErrorCallback error_callback,
const base::FilePath& source,
const base::FilePath& target) { … }
void FakeImageWriterClient::Cancel(CancelCallback cancel_callback) { … }
void FakeImageWriterClient::Shutdown() { … }
void FakeImageWriterClient::SimulateProgressOnWrite(
const std::vector<int>& progress_list,
bool will_succeed) { … }
void FakeImageWriterClient::SimulateProgressOnVerifyWrite(
const std::vector<int>& progress_list,
bool will_succeed) { … }
void FakeImageWriterClient::Progress(int64_t progress) { … }
void FakeImageWriterClient::Success() { … }
void FakeImageWriterClient::Error(const std::string& message) { … }
void FakeImageWriterClient::Cancel() { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
scoped_refptr<ImageWriterUtilityClient> CreateFakeImageWriterUtilityClient(
ImageWriterTestUtils* utils) { … }
#endif
ImageWriterTestUtils::ImageWriterTestUtils()
#if !BUILDFLAG(IS_CHROMEOS_ASH)
: … { … }
ImageWriterTestUtils::~ImageWriterTestUtils() = default;
#if !BUILDFLAG(IS_CHROMEOS_ASH)
void ImageWriterTestUtils::OnUtilityClientCreated(
FakeImageWriterClient* client) { … }
#endif
#if !BUILDFLAG(IS_CHROMEOS_ASH)
void ImageWriterTestUtils::RunOnUtilityClientCreation(
base::OnceCallback<void(FakeImageWriterClient*)> closure) { … }
#endif
void ImageWriterTestUtils::SetUp() { … }
void ImageWriterTestUtils::TearDown() { … }
const base::FilePath& ImageWriterTestUtils::GetTempDir() { … }
const base::FilePath& ImageWriterTestUtils::GetImagePath() { … }
const base::FilePath& ImageWriterTestUtils::GetDevicePath() { … }
bool ImageWriterTestUtils::ImageWrittenToDevice() { … }
bool ImageWriterTestUtils::FillFile(const base::FilePath& file,
uint8_t pattern,
size_t length) { … }
ImageWriterUnitTestBase::ImageWriterUnitTestBase()
: … { … }
ImageWriterUnitTestBase::~ImageWriterUnitTestBase() = default;
void ImageWriterUnitTestBase::SetUp() { … }
void ImageWriterUnitTestBase::TearDown() { … }
bool GetTestDataDirectory(base::FilePath* path) { … }
}
}