Commit 5b6c485c authored by Kalvin Lee's avatar Kalvin Lee Committed by Commit Bot

cups_ipp_util: hide special papers

This change modifies the CUPS IPP backend to suppress papers whose
vendor IDs are not meant for users' eyes - i.e. the "custom_min" and
"custom_max" sizes that CUPS incidentally exposes.

Bug: 1026938
Change-Id: I047844030e7f7a161bda32755754494567e7734c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1935173Reviewed-by: default avatarSean Kau <skau@chromium.org>
Commit-Queue: Kalvin Lee <kdlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720578}
parent a2ee7f23
...@@ -40,6 +40,12 @@ constexpr double kMMPerInch = 25.4; ...@@ -40,6 +40,12 @@ constexpr double kMMPerInch = 25.4;
constexpr double kMicronsPerInch = kMMPerInch * kMicronsPerMM; constexpr double kMicronsPerInch = kMMPerInch * kMicronsPerMM;
constexpr double kCmPerInch = kMMPerInch * 0.1; constexpr double kCmPerInch = kMMPerInch * 0.1;
// Defines two prefixes of a special breed of media sizes not meant for
// users' eyes. CUPS incidentally returns these IPP values to us, but
// we have no use for them.
constexpr base::StringPiece kMediaCustomMinPrefix = "custom_min";
constexpr base::StringPiece kMediaCustomMaxPrefix = "custom_max";
enum Unit { enum Unit {
INCHES, INCHES,
MILLIMETERS, MILLIMETERS,
...@@ -138,8 +144,11 @@ PrinterSemanticCapsAndDefaults::Paper ParsePaper(base::StringPiece value) { ...@@ -138,8 +144,11 @@ PrinterSemanticCapsAndDefaults::Paper ParsePaper(base::StringPiece value) {
std::vector<base::StringPiece> pieces = base::SplitStringPiece( std::vector<base::StringPiece> pieces = base::SplitStringPiece(
value, "_", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); value, "_", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
// we expect at least a display string and a dimension string // We expect at least a display string and a dimension string.
if (pieces.size() < 2) // Additionally, we drop the "custom_min*" and "custom_max*" special
// "sizes" (not for users' eyes).
if (pieces.size() < 2 || value.starts_with(kMediaCustomMinPrefix) ||
value.starts_with(kMediaCustomMaxPrefix))
return PrinterSemanticCapsAndDefaults::Paper(); return PrinterSemanticCapsAndDefaults::Paper();
base::StringPiece dimensions = pieces.back(); base::StringPiece dimensions = pieces.back();
......
...@@ -207,8 +207,8 @@ TEST_F(PrintBackendCupsIppUtilTest, LegalPaperDefault) { ...@@ -207,8 +207,8 @@ TEST_F(PrintBackendCupsIppUtilTest, LegalPaperDefault) {
EXPECT_EQ(355600, caps.default_paper.size_um.height()); EXPECT_EQ(355600, caps.default_paper.size_um.height());
} }
// Tests that CapsAndDefaultsFromPrinter does not propagate papers with // Tests that CapsAndDefaultsFromPrinter() does not propagate papers
// badly formatted vendor IDs - such papers will not transform into // with badly formatted vendor IDs - such papers will not transform into
// meaningful ParsedPaper instances and are sometimes inimical to // meaningful ParsedPaper instances and are sometimes inimical to
// ARC++. // ARC++.
TEST_F(PrintBackendCupsIppUtilTest, OmitPapersWithoutVendorIds) { TEST_F(PrintBackendCupsIppUtilTest, OmitPapersWithoutVendorIds) {
...@@ -236,6 +236,44 @@ TEST_F(PrintBackendCupsIppUtilTest, OmitPapersWithoutVendorIds) { ...@@ -236,6 +236,44 @@ TEST_F(PrintBackendCupsIppUtilTest, OmitPapersWithoutVendorIds) {
"iso b5"))); "iso b5")));
} }
// Tests that CapsAndDefaultsFromPrinter() does not propagate the
// special IPP values that CUPS happens to expose to the Chromium print
// backend.
TEST_F(PrintBackendCupsIppUtilTest, OmitPapersWithSpecialVendorIds) {
// Maintainer's note: there's no reason why a printer would deliver
// two discrete sizes for custom_min* and custom_max*; in practice,
// we always see the fully qualified custom_m(in|ax)_<DIMENSIONS>
// delivered to the Chromium print backend.
printer_->SetSupportedOptions(
"media",
MakeStringCollection(
ipp_, {"na_number-11_4.5x10.375in", "custom_max", "custom_min_0x0in",
"na_govt-letter_8x10in", "custom_min",
"custom_max_1000x1000in", "iso_b0_1000x1414mm"}));
PrinterSemanticCapsAndDefaults caps;
CapsAndDefaultsFromPrinter(*printer_, &caps);
// The printer reports that it supports seven media sizes, four of
// which are not meant for users' eyes (``custom_min*'' and
// ``custom_max*''). The preceding call to
// CapsAndDefaultsFromPrinter() will have dropped these sizes,
// refusing to propagate them out of the backend.
ASSERT_EQ(3U, caps.papers.size());
// While not directly pertinent to this test, we expect a certain
// format for the other supported papers.
EXPECT_THAT(
caps.papers,
testing::UnorderedElementsAre(
testing::Field(&PrinterSemanticCapsAndDefaults::Paper::display_name,
"na number-11"),
testing::Field(&PrinterSemanticCapsAndDefaults::Paper::display_name,
"na govt-letter"),
testing::Field(&PrinterSemanticCapsAndDefaults::Paper::display_name,
"iso b0")));
}
TEST_F(PrintBackendCupsIppUtilTest, PinSupported) { TEST_F(PrintBackendCupsIppUtilTest, PinSupported) {
printer_->SetSupportedOptions("job-password", MakeInteger(ipp_, 4)); printer_->SetSupportedOptions("job-password", MakeInteger(ipp_, 4));
printer_->SetSupportedOptions("job-password-encryption", printer_->SetSupportedOptions("job-password-encryption",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment