Skip to content
Permalink
Browse files

cups_ipp_util: hide unparsable papers

This change modifies the CUPS IPP backend to suppress papers whose
vendor IDs do not parse meaningfully into user-visible display names.

(cherry picked from commit 489da72)

Bug: 1022272
Change-Id: Iaae9dc150612d4128028442267e2af9be0081621
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1924170
Commit-Queue: Kalvin Lee <kdlee@chromium.org>
Reviewed-by: Sean Kau <skau@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#717777}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1934687
Cr-Commit-Position: refs/branch-heads/3945@{#782}
Cr-Branched-From: e4635ff-refs/heads/master@{#706915}
  • Loading branch information
Kalvin Lee Sean Kau
Kalvin Lee authored and Sean Kau committed Nov 25, 2019
1 parent 5720ae0 commit a62a1a76f6b8becaa4f3f1f1db50066ea31d970c
Showing with 38 additions and 2 deletions.
  1. +9 −2 printing/backend/cups_ipp_util.cc
  2. +29 −0 printing/backend/cups_ipp_util_unittest.cc
@@ -288,8 +288,15 @@ PrinterSemanticCapsAndDefaults::Papers SupportedPapers(
printer.GetSupportedOptionValueStrings(kIppMedia);
PrinterSemanticCapsAndDefaults::Papers parsed_papers;
parsed_papers.reserve(papers.size());
for (base::StringPiece paper : papers)
parsed_papers.push_back(ParsePaper(paper));
for (base::StringPiece paper : papers) {
PrinterSemanticCapsAndDefaults::Paper parsed = ParsePaper(paper);
// If a paper fails to parse reasonably, we should avoid propagating
// it - e.g. CUPS is known to give out empty vendor IDs at times:
// https://crbug.com/920295#c23
if (!parsed.display_name.empty()) {
parsed_papers.push_back(parsed);
}
}

return parsed_papers;
}
@@ -207,6 +207,35 @@ TEST_F(PrintBackendCupsIppUtilTest, LegalPaperDefault) {
EXPECT_EQ(355600, caps.default_paper.size_um.height());
}

// Tests that CapsAndDefaultsFromPrinter does not propagate papers with
// badly formatted vendor IDs - such papers will not transform into
// meaningful ParsedPaper instances and are sometimes inimical to
// ARC++.
TEST_F(PrintBackendCupsIppUtilTest, OmitPapersWithoutVendorIds) {
printer_->SetSupportedOptions(
"media", MakeStringCollection(ipp_, {"jis_b5_182x257mm", "invalidsize",
"", "iso_b5_176x250mm"}));

PrinterSemanticCapsAndDefaults caps;
CapsAndDefaultsFromPrinter(*printer_, &caps);

// The printer reports that it supports four media sizes, two of which
// are invalid (``invalidsize'' and the empty vendor ID). The
// preceding call to CapsAndDefaultsFromPrinter() will have dropped
// these invalid sizes.
ASSERT_EQ(2U, 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,
"jis b5"),
testing::Field(&PrinterSemanticCapsAndDefaults::Paper::display_name,
"iso b5")));
}

TEST_F(PrintBackendCupsIppUtilTest, PinSupported) {
printer_->SetSupportedOptions("job-password", MakeInteger(ipp_, 4));
printer_->SetSupportedOptions("job-password-encryption",

0 comments on commit a62a1a7

Please sign in to comment.
You can’t perform that action at this time.