#include "base/values.h"
#include "build/build_config.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "printing/mojom/print.mojom.h"
#include "printing/mojom/printing_context.mojom.h"
#include "printing/page_range.h"
#include "printing/page_setup.h"
#include "printing/print_settings.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
namespace printing {
namespace {
const PageMargins kPageMarginNonzero(1,
2,
3,
4,
5,
6);
constexpr int kPageSetupTextHeight = …;
constexpr gfx::Size kPageSetupPhysicalSize = …;
constexpr gfx::Rect kPageSetupPrintableArea = …;
const PageMargins kPageSetupRequestedMargins(
10,
20,
5,
15,
10 + kPageSetupTextHeight,
20 + kPageSetupTextHeight);
const PageSetup kPageSetupAsymmetricalMargins(kPageSetupPhysicalSize,
kPageSetupPrintableArea,
kPageSetupRequestedMargins,
false,
kPageSetupTextHeight);
const PageSetup kPageSetupForcedMargins(kPageSetupPhysicalSize,
kPageSetupPrintableArea,
kPageSetupRequestedMargins,
true,
kPageSetupTextHeight);
constexpr gfx::Size kRequestedMediaSize = …;
const char kRequestedMediaVendorId[] = …;
PrintSettings::RequestedMedia GenerateSampleRequestedMedia() { … }
#if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
base::Value::Dict GenerateSampleSystemPrintDialogData(
#if BUILDFLAG(IS_MAC)
bool include_optional_data
#endif
) { … }
#endif
const PageRanges kPrintSettingsPageRanges{ … };
constexpr char16_t kPrintSettingsTitle[] = …;
constexpr char16_t kPrintSettingsUrl[] = …;
constexpr int kPrintSettingsCopies = …;
constexpr char16_t kPrintSettingsDeviceName[] = …;
const PrintSettings::RequestedMedia kPrintSettingsRequestedMedia{ … };
const PageMargins kPrintSettingsCustomMarginsInPoints(10,
15,
20,
25,
30,
35);
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
PrintSettings::AdvancedSettings GenerateSampleAdvancedSettings() { … }
const PrintSettings::AdvancedSettings kPrintSettingsAdvancedSettings = …;
#endif
#if BUILDFLAG(IS_CHROMEOS)
constexpr char kPrintSettingsUsername[] = "username";
constexpr char kPrintSettingsPinValue[] = "pin-value";
#endif
constexpr bool kPrintSettingsSetSelection1 = …;
constexpr bool kPrintSettingsSetSelection2 = …;
constexpr mojom::MarginType kPrintSettingsMarginType1 = …;
constexpr mojom::MarginType kPrintSettingsMarginType2 = …;
constexpr bool kPrintSettingsDisplayHeaderFooter1 = …;
constexpr bool kPrintSettingsDisplayHeaderFooter2 = …;
constexpr bool kPrintSettingsShouldPrintBackgrounds1 = …;
constexpr bool kPrintSettingsShouldPrintBackgrounds2 = …;
constexpr bool kPrintSettingsCollate1 = …;
constexpr bool kPrintSettingsCollate2 = …;
constexpr mojom::ColorModel kPrintSettingsColorModel1 = …;
constexpr mojom::ColorModel kPrintSettingsColorModel2 = …;
constexpr mojom::DuplexMode kPrintSettingsDuplexMode1 = …;
constexpr mojom::DuplexMode kPrintSettingsDuplexMode2 = …;
constexpr gfx::Size kPrintSettingsDpi1(600, 600);
constexpr gfx::Size kPrintSettingsDpi2(1200, 600);
const char kPrintSettingsMediaTypeEmpty[] = …;
const char kPrintSettingsMediaTypePlain[] = …;
constexpr bool kPrintSettingsBorderless1 = …;
constexpr bool kPrintSettingsBorderless2 = …;
constexpr double kPrintSettingsScaleFactor1 = …;
constexpr double kPrintSettingsScaleFactor2 = …;
constexpr bool kPrintSettingsRasterizePdf1 = …;
constexpr bool kPrintSettingsRasterizePdf2 = …;
constexpr bool kPrintSettingsLandscape1 = …;
constexpr bool kPrintSettingsLandscape2 = …;
#if BUILDFLAG(IS_WIN)
constexpr mojom::PrinterLanguageType kPrintSettingsPrinterLanguageType1 =
mojom::PrinterLanguageType::kTextOnly;
constexpr mojom::PrinterLanguageType kPrintSettingsPrinterLanguageType2 =
mojom::PrinterLanguageType::kXps;
#endif
constexpr bool kPrintSettingsModifiable1 = …;
constexpr bool kPrintSettingsModifiable2 = …;
constexpr int kPrintSettingsPagesPerSheet1 = …;
constexpr int kPrintSettingsPagesPerSheet2 = …;
#if BUILDFLAG(IS_CHROMEOS)
constexpr bool kPrintSettingsSendUserInfo1 = true;
constexpr bool kPrintSettingsSendUserInfo2 = false;
#endif
struct GenerationParams { … };
PrintSettings GenerateSamplePrintSettingsCommon() { … }
PrintSettings GenerateSamplePrintSettingsDefaultMargins() { … }
PrintSettings GenerateSamplePrintSettingsCustomMarginsWithParams(
GenerationParams params) { … }
PrintSettings GenerateSamplePrintSettingsCustomMargins() { … }
bool RequestedMediasEqual(const PrintSettings::RequestedMedia& lhs,
const PrintSettings::RequestedMedia& rhs) { … }
bool PageMarginsEqual(const PageMargins& lhs, const PageMargins& rhs) { … }
}
TEST(PrintingContextMojomTraitsTest, TestSerializeAndDeserializePageMargins) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePageMarginsNoMargins) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePageMarginsNegativeValues) { … }
TEST(PrintingContextMojomTraitsTest, TestSerializeAndDeserializePageSetup) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePageSetupForcedMargins) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePageRangeMultiPage) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePageRangeSinglePage) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePageRangeReverseRange) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializeRequestedMedia) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializeRequestedMediaEmpty) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsDefaultMargins) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsCustomMargins) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsEmptyPageRanges) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsEmptyPrintableArea) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsEmptyAdvancedSettings) { … }
#endif
#if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogData) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogDataInvalid) { … }
TEST(PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogDataExtraKey) { … }
#if BUILDFLAG(IS_MAC)
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogDataDestTypeOutOfRange) {
PrintSettings input = GenerateSamplePrintSettingsDefaultMargins();
base::Value::Dict data =
GenerateSampleSystemPrintDialogData(false);
data.Set(kMacSystemPrintDialogDataDestinationType, 0x10000);
input.set_system_print_dialog_data(std::move(data));
PrintSettings output;
EXPECT_FALSE(
mojo::test::SerializeAndDeserialize<mojom::PrintSettings>(input, output));
}
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogDataDestTypeInvalidDataType) {
PrintSettings input = GenerateSamplePrintSettingsDefaultMargins();
base::Value::Dict data =
GenerateSampleSystemPrintDialogData(false);
data.Set(kMacSystemPrintDialogDataDestinationType, "supposed to be an int");
input.set_system_print_dialog_data(std::move(data));
PrintSettings output;
EXPECT_FALSE(
mojo::test::SerializeAndDeserialize<mojom::PrintSettings>(input, output));
}
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogPageFormatInvalidDataType) {
PrintSettings input = GenerateSamplePrintSettingsDefaultMargins();
base::Value::Dict data =
GenerateSampleSystemPrintDialogData(false);
data.Set(kMacSystemPrintDialogDataPageFormat, "supposed to be a BlobStorage");
input.set_system_print_dialog_data(std::move(data));
PrintSettings output;
EXPECT_FALSE(
mojo::test::SerializeAndDeserialize<mojom::PrintSettings>(input, output));
}
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogPrintSettingsInvalidDataType) {
PrintSettings input = GenerateSamplePrintSettingsDefaultMargins();
base::Value::Dict data =
GenerateSampleSystemPrintDialogData(false);
data.Set(kMacSystemPrintDialogDataPrintSettings,
"supposed to be a BlobStorage");
input.set_system_print_dialog_data(std::move(data));
PrintSettings output;
EXPECT_FALSE(
mojo::test::SerializeAndDeserialize<mojom::PrintSettings>(input, output));
}
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogDestinationFormatInvalidDataType) {
PrintSettings input = GenerateSamplePrintSettingsDefaultMargins();
base::Value::Dict data =
GenerateSampleSystemPrintDialogData(false);
data.Set(kMacSystemPrintDialogDataPageFormat, 0xBAD);
input.set_system_print_dialog_data(std::move(data));
PrintSettings output;
EXPECT_FALSE(
mojo::test::SerializeAndDeserialize<mojom::PrintSettings>(input, output));
}
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogDestinationLocationInvalidDataType) {
PrintSettings input = GenerateSamplePrintSettingsDefaultMargins();
base::Value::Dict data =
GenerateSampleSystemPrintDialogData(false);
data.Set(kMacSystemPrintDialogDataDestinationLocation, 0xBAD);
input.set_system_print_dialog_data(std::move(data));
PrintSettings output;
EXPECT_FALSE(
mojo::test::SerializeAndDeserialize<mojom::PrintSettings>(input, output));
}
#endif
#if BUILDFLAG(IS_LINUX)
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogPrinterInvalidDataType) { … }
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogPrintSettingsDataType) { … }
TEST(
PrintingContextMojomTraitsTest,
TestSerializeAndDeserializePrintSettingsSystemPrintDialogPageSetupDataType) { … }
#endif
#endif
}