#ifndef PRINTING_TEST_PRINTING_CONTEXT_H_
#define PRINTING_TEST_PRINTING_CONTEXT_H_
#include <memory>
#include <optional>
#include <string>
#include "base/containers/flat_map.h"
#include "base/functional/callback_forward.h"
#include "build/build_config.h"
#include "printing/mojom/print.mojom.h"
#include "printing/print_settings.h"
#include "printing/printing_context.h"
namespace printing {
class TestPrintingContextDelegate : public PrintingContext::Delegate {
public:
TestPrintingContextDelegate();
TestPrintingContextDelegate(const TestPrintingContextDelegate&) = delete;
TestPrintingContextDelegate& operator=(const TestPrintingContextDelegate&) =
delete;
~TestPrintingContextDelegate() override;
gfx::NativeView GetParentView() override;
std::string GetAppLocale() override;
};
class TestPrintingContext : public PrintingContext {
public:
using OnNewDocumentCallback = base::RepeatingCallback<void(
#if BUILDFLAG(IS_MAC)
bool destination_is_preview,
#endif
const PrintSettings&)>;
TestPrintingContext(Delegate* delegate,
OutOfProcessBehavior out_of_process_behavior);
TestPrintingContext(const TestPrintingContext&) = delete;
TestPrintingContext& operator=(const TestPrintingContext&) = delete;
~TestPrintingContext() override;
void SetDeviceSettings(const std::string& device_name,
std::unique_ptr<PrintSettings> settings);
void SetNewDocumentJobId(int job_id);
void SetUserSettings(const PrintSettings& settings);
void SetNewDocumentBlockedByPermissions() {
new_document_blocked_by_permissions_ = true;
}
#if BUILDFLAG(IS_WIN)
void SetOnRenderPageBlockedByPermissions() {
render_page_blocked_by_permissions_ = true;
}
void SetOnRenderPageFailsForPage(uint32_t page_number) {
render_page_fail_for_page_number_ = page_number;
}
#endif
void SetOnRenderDocumentBlockedByPermissions() {
render_document_blocked_by_permissions_ = true;
}
void SetDocumentDoneBlockedByPermissions() {
document_done_blocked_by_permissions_ = true;
}
void SetNewDocumentFails() { new_document_fails_ = true; }
void SetUpdatePrinterSettingsFails() {
update_printer_settings_fails_ = true;
}
void SetUseDefaultSettingsFails() { use_default_settings_fails_ = true; }
void SetAskUserForSettingsFails() { ask_user_for_settings_fails_ = true; }
void SetNewDocumentCancels() { new_document_cancels_ = true; }
void SetAskUserForSettingsCanceled() { ask_user_for_settings_cancel_ = true; }
void SetOnNewDocumentCallback(OnNewDocumentCallback callback) {
on_new_document_callback_ = std::move(callback);
}
void AskUserForSettings(int max_pages,
bool has_selection,
bool is_scripted,
PrintSettingsCallback callback) override;
mojom::ResultCode UseDefaultSettings() override;
gfx::Size GetPdfPaperSizeDeviceUnits() override;
mojom::ResultCode UpdatePrinterSettings(
const PrinterSettings& printer_settings) override;
mojom::ResultCode NewDocument(const std::u16string& document_name) override;
#if BUILDFLAG(IS_WIN)
mojom::ResultCode RenderPage(const PrintedPage& page,
const PageSetup& page_setup) override;
#endif
mojom::ResultCode PrintDocument(const MetafilePlayer& metafile,
const PrintSettings& settings,
uint32_t num_pages) override;
mojom::ResultCode DocumentDone() override;
void Cancel() override;
void ReleaseContext() override;
NativeDrawingContext context() const override;
#if BUILDFLAG(IS_WIN)
mojom::ResultCode InitWithSettingsForTest(
std::unique_ptr<PrintSettings> settings) override;
#endif
private:
mojom::ResultCode AskUserForSettingsImpl(int max_pages,
bool has_selection,
bool is_scripted);
base::flat_map<std::string, std::unique_ptr<PrintSettings>> device_settings_;
std::optional<PrintSettings> user_settings_;
PrintSettings applied_settings_;
#if BUILDFLAG(IS_MAC)
bool destination_is_preview_ = false;
#endif
bool update_printer_settings_fails_ = false;
bool use_default_settings_fails_ = false;
bool ask_user_for_settings_cancel_ = false;
bool ask_user_for_settings_fails_ = false;
bool new_document_cancels_ = false;
bool new_document_fails_ = false;
bool new_document_blocked_by_permissions_ = false;
#if BUILDFLAG(IS_WIN)
bool render_page_blocked_by_permissions_ = false;
std::optional<uint32_t> render_page_fail_for_page_number_;
#endif
bool render_document_blocked_by_permissions_ = false;
bool document_done_blocked_by_permissions_ = false;
OnNewDocumentCallback on_new_document_callback_;
std::optional<int> new_document_job_id_;
};
}
#endif