Commit 636b9b42 authored by Luum Habtemariam's avatar Luum Habtemariam Committed by Commit Bot

Remove Epson generic PPD handling

We previously implemented this generic ppd as a fallback for Epson
printers that failed ppd matching. This led to some unforeseen issues
detailed in the bug below; as such this special handling is no
longer needed and this change removes it.

Bug: chromium:1049850
Test: tba
Change-Id: I45c9dce72205f8ed9255d983cac8b1a739fa388a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087959
Commit-Queue: Luum Habtemariam <luum@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#752210}
parent d13faa6c
......@@ -42,12 +42,6 @@ namespace chromeos {
namespace {
// Given a usb device, guesses the make and model for a driver lookup.
//
// TODO(https://crbug.com/895037): Possibly go deeper and query the IEEE1284
// fields for make and model if we determine those are more likely to contain
// what we want. Strings currently come from udev.
// TODO(https://crbug.com/895037): When above is added, parse out document
// formats and add to DetectedPrinter
std::string GuessEffectiveMakeAndModel(
const device::mojom::UsbDeviceInfo& device) {
return base::UTF16ToUTF8(GetManufacturerName(device)) + " " +
......
......@@ -11,6 +11,11 @@
namespace chromeos {
bool CanUseEpsonGenericPPD(const PrinterSearchData& sd) {
// Only matches USB printers.
if (sd.discovery_type != PrinterSearchData::PrinterDiscoveryType::kUsb) {
return false;
}
// Needed to check if its an Epson printer.
if (sd.make_and_model.empty()) {
return false;
......@@ -26,34 +31,15 @@ bool CanUseEpsonGenericPPD(const PrinterSearchData& sd) {
return false;
}
switch (sd.discovery_type) {
case PrinterSearchData::PrinterDiscoveryType::kManual:
// For manually discovered printers, supported_document_formats is
// retrieved via an ippGetAttributes query to the printer.
return base::Contains(sd.supported_document_formats,
"application/octet-stream");
case PrinterSearchData::PrinterDiscoveryType::kUsb: {
// For USB printers, the command set is retrieved from the 'CMD' field of
// the printer's IEEE 1284 Device ID.
for (base::StringPiece format : sd.printer_id.command_set()) {
if (format.starts_with("ESCPR")) {
return true;
}
}
return false;
// The command set is retrieved from the 'CMD' field of the printer's IEEE
// 1284 Device ID.
for (base::StringPiece format : sd.printer_id.command_set()) {
if (format.starts_with("ESCPR")) {
return true;
}
case PrinterSearchData::PrinterDiscoveryType::kZeroconf:
// For printers found through mDNS/DNS-SD discovery,
// supported_document_formats is retrieved via the Printer Description TXT
// Record(from the key 'pdl').
return base::Contains(sd.supported_document_formats,
"application/vnd.epson.escpr");
default:
return false;
}
return false;
}
} // namespace chromeos
......@@ -12,7 +12,7 @@ namespace chromeos {
struct PrinterSearchData;
// Implements PPD matching rules obtained from Epson. Returns true when this
// printer can be saftely setup using the generic Epson PPD.
// printer can be safely setup using the generic Epson PPD.
bool CHROMEOS_EXPORT CanUseEpsonGenericPPD(const PrinterSearchData& sd);
} // namespace chromeos
......
......@@ -13,49 +13,22 @@
namespace chromeos {
namespace {
const char kOctetStream[] = "application/octet-stream";
const char kEscPr[] = "ESCPR1";
const char kEpsonEscpr[] = "application/vnd.epson.escpr";
using PrinterDiscoveryType = PrinterSearchData::PrinterDiscoveryType;
PrinterSearchData GetTestPrinterSearchData(
PrinterDiscoveryType type = PrinterDiscoveryType::kManual) {
// Returns PrinterSearchData that will match the Epson Generic PPD.
PrinterSearchData GetTestPrinterSearchData() {
PrinterSearchData sd;
sd.discovery_type = PrinterDiscoveryType::kUsb;
sd.make_and_model.push_back("epson");
switch (type) {
case PrinterDiscoveryType::kManual:
sd.discovery_type = PrinterDiscoveryType::kManual;
sd.supported_document_formats.push_back(kOctetStream);
break;
case PrinterDiscoveryType::kUsb:
sd.discovery_type = PrinterDiscoveryType::kUsb;
sd.printer_id.set_command_set({kEscPr});
break;
case PrinterDiscoveryType::kZeroconf:
sd.discovery_type = PrinterDiscoveryType::kZeroconf;
sd.supported_document_formats.push_back(kEpsonEscpr);
break;
default:
sd.discovery_type = type;
break;
}
sd.printer_id.set_command_set({kEscPr});
return sd;
}
// Ensuring simple good cases generated above pass.
TEST(EpsonDriverMatchingTest, SimpleSanityTest) {
EXPECT_TRUE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kManual)));
EXPECT_TRUE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kUsb)));
EXPECT_TRUE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kZeroconf)));
EXPECT_TRUE(CanUseEpsonGenericPPD(GetTestPrinterSearchData()));
}
// Always fails printers missing make and model information.
......@@ -65,10 +38,12 @@ TEST(EpsonDriverMatchingTest, EmptyMakeAndModels) {
// Always fails printers with invalid discovery types.
TEST(EpsonDriverMatchingTest, InvalidPrinterDiscoveryType) {
EXPECT_FALSE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kUnknown)));
EXPECT_FALSE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kDiscoveryTypeMax)));
PrinterSearchData sd(GetTestPrinterSearchData());
sd.discovery_type = PrinterDiscoveryType::kUnknown;
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.discovery_type = PrinterDiscoveryType::kDiscoveryTypeMax;
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
}
// Confirms an Epson printer if any make and models have 'epson'.
......@@ -86,27 +61,9 @@ TEST(EpsonDriverMatchingTest, ChecksAllMakeAndModels) {
EXPECT_TRUE(CanUseEpsonGenericPPD(sd));
}
// Simple PrinterDiscoveryType::kManual checks.
TEST(EpsonDriverMatchingTest, ManualDiscovery) {
PrinterSearchData sd(GetTestPrinterSearchData(PrinterDiscoveryType::kManual));
sd.supported_document_formats.clear();
sd.supported_document_formats.push_back("application/");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(std::string(kOctetStream) + "afds");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.printer_id.set_command_set({kOctetStream});
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(kOctetStream);
EXPECT_TRUE(CanUseEpsonGenericPPD(sd));
}
// Simple PrinterDiscoveryType::kUsb checks.
TEST(EpsonDriverMatchingTest, UsbDiscovery) {
PrinterSearchData sd(GetTestPrinterSearchData(PrinterDiscoveryType::kUsb));
PrinterSearchData sd(GetTestPrinterSearchData());
std::vector<std::string> command_set;
command_set.push_back("ESC");
......@@ -125,23 +82,5 @@ TEST(EpsonDriverMatchingTest, UsbDiscovery) {
EXPECT_TRUE(CanUseEpsonGenericPPD(sd));
}
TEST(EpsonDriverMatchingTest, ZerconfDiscovery) {
PrinterSearchData sd(
GetTestPrinterSearchData(PrinterDiscoveryType::kZeroconf));
sd.supported_document_formats.clear();
sd.supported_document_formats.push_back("application/");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(std::string(kEpsonEscpr) + ":asfd");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.printer_id.set_command_set({kEpsonEscpr});
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(kEpsonEscpr);
EXPECT_TRUE(CanUseEpsonGenericPPD(sd));
}
} // namespace
} // namespace chromeos
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