#include <map>
#include <string>
#include <utility>
#include <vector>
#include "build/build_config.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "printing/backend/mojom/print_backend.mojom.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_test_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
namespace printing {
TEST(PrintBackendMojomTraitsTest, TestSerializeAndDeserializePrinterBasicInfo) { … }
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterBasicInfoEmptyNames) { … }
TEST(PrintBackendMojomTraitsTest, TestSerializeAndDeserializePaper) { … }
TEST(PrintBackendMojomTraitsTest, TestPaperCtors) { … }
TEST(PrintBackendMojomTraitsTest, TestPaperEmpty) { … }
TEST(PrintBackendMojomTraitsTest, TestPaperInvalidCustomSize) { … }
TEST(PrintBackendMojomTraitsTest, TestPaperEmptyPrintableArea) { … }
TEST(PrintBackendMojomTraitsTest, TestPaperPrintableAreaLargerThanSize) { … }
TEST(PrintBackendMojomTraitsTest, TestPaperPrintableAreaLargerThanCustomSize) { … }
TEST(PrintBackendMojomTraitsTest, TestPaperPrintableAreaOutOfBounds) { … }
TEST(PrintBackendMojomTraitsTest, TestPaperNegativePrintableArea) { … }
#if BUILDFLAG(IS_CHROMEOS)
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializeAdvancedCapability) {
for (const auto& advanced_capability : kAdvancedCapabilities) {
AdvancedCapability input = advanced_capability;
AdvancedCapability output;
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<mojom::AdvancedCapability>(
input, output));
EXPECT_EQ(advanced_capability, output);
}
}
#endif
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaults) { … }
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsCopiesMax) { … }
TEST(
PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsAllowableEmptyArrays) { … }
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsEmptyPapers) { … }
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsEmptyMediaTypes) { … }
TEST(
PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsNoDuplicatesInArrays) { … }
TEST(
PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsAllowedDuplicatesInArrays) { … }
#if BUILDFLAG(IS_WIN)
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePageOutputQualityAttribute) {
PageOutputQualityAttribute input = kPageOutputQualityAttribute1;
PageOutputQualityAttribute output;
EXPECT_TRUE(
mojo::test::SerializeAndDeserialize<mojom::PageOutputQualityAttribute>(
input, output));
EXPECT_EQ(kPageOutputQualityAttribute1.display_name, output.display_name);
EXPECT_EQ(kPageOutputQualityAttribute1.name, output.name);
}
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePageOutputQuality) {
PageOutputQuality input = kPageOutputQuality;
PageOutputQuality output;
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<mojom::PageOutputQuality>(
input, output));
EXPECT_EQ(kPageOutputQuality.qualities, output.qualities);
EXPECT_EQ(kPageOutputQuality.default_quality, output.default_quality);
}
TEST(PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsXpsCapabilities) {
PrinterSemanticCapsAndDefaults input =
GenerateSamplePrinterSemanticCapsAndDefaults(
SampleWithPageOutputQuality());
PrinterSemanticCapsAndDefaults output;
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
mojom::PrinterSemanticCapsAndDefaults>(input, output));
ASSERT_TRUE(output.page_output_quality);
EXPECT_EQ(kPageOutputQuality.qualities,
output.page_output_quality->qualities);
EXPECT_EQ(kPageOutputQuality.default_quality,
output.page_output_quality->default_quality);
}
TEST(
PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsAllowableEmptyArraysXpsCapabilities) {
const PageOutputQualityAttributes kEmptyQualities;
PageOutputQuality quality(kEmptyQualities, std::nullopt);
PrinterSemanticCapsAndDefaults input =
GenerateSamplePrinterSemanticCapsAndDefaults({});
input.page_output_quality = quality;
PrinterSemanticCapsAndDefaults output;
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
mojom::PrinterSemanticCapsAndDefaults>(input, output));
ASSERT_TRUE(output.page_output_quality);
EXPECT_EQ(kEmptyQualities, output.page_output_quality->qualities);
}
TEST(
PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsDefaultQualityInArraysXpsCapabilities) {
PrinterSemanticCapsAndDefaults input =
GenerateSamplePrinterSemanticCapsAndDefaults(
SampleWithPageOutputQuality());
input.page_output_quality->default_quality = kDefaultQuality;
PrinterSemanticCapsAndDefaults output;
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
mojom::PrinterSemanticCapsAndDefaults>(input, output));
ASSERT_TRUE(output.page_output_quality);
EXPECT_EQ(kPageOutputQuality.qualities,
output.page_output_quality->qualities);
EXPECT_EQ(kDefaultQuality, output.page_output_quality->default_quality);
}
TEST(
PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsMissingDefaultQualityInArraysXpsCapabilities) {
PrinterSemanticCapsAndDefaults input =
GenerateSamplePrinterSemanticCapsAndDefaults(
SampleWithPageOutputQuality());
input.page_output_quality->default_quality = "ns000:MissingDefault";
PrinterSemanticCapsAndDefaults output;
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
mojom::PrinterSemanticCapsAndDefaults>(input, output));
}
TEST(
PrintBackendMojomTraitsTest,
TestSerializeAndDeserializePrinterSemanticCapsAndDefaultsNoDuplicatesInArraysXpsCapabilities) {
const PageOutputQualityAttribute kPageOutputQualityAttributePrime(
"Normal",
"ns000:Normal");
PageOutputQuality page_output_quality(
{kPageOutputQualityAttribute1, kPageOutputQualityAttributePrime,
kPageOutputQualityAttribute2},
std::nullopt);
PrinterSemanticCapsAndDefaults input =
GenerateSamplePrinterSemanticCapsAndDefaults({});
input.page_output_quality = page_output_quality;
PrinterSemanticCapsAndDefaults output;
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
mojom::PrinterSemanticCapsAndDefaults>(input, output));
}
#endif
}