Add PrinterBasicInfo to print backend mojom
Adding support for PrintBackend queries to happen out of the browser process requires related data structures to be made available via a Mojo interface. These are moved into their own mojom file separate from the common definition in printing/mojom since they are specific to a new process being introduced and do not need to be encumbered by the dependencies which exist for print.mojom. Add PrinterBasicInfo to the definitions. This will support forthcoming queries such as EnumeratePrinters and FetchCapabilities. Bug: 809738 Change-Id: I7a87e747a9b58f8e0f8460ecf85fb27466a0a8f5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438580 Reviewed-by: Chris Palmer <palmer@chromium.org> Reviewed-by: Rebekah Potter <rbpotter@chromium.org> Reviewed-by: Daniel Hosseinian <dhoss@chromium.org> Commit-Queue: Alan Screen <awscreen@chromium.org> Cr-Commit-Position: refs/heads/master@{#832546}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
4b4a433b5c
commit
cca43d145a
@ -15,6 +15,10 @@ mojom("mojom") {
|
||||
cpp_typemaps = [
|
||||
{
|
||||
types = [
|
||||
{
|
||||
mojom = "printing.mojom.PrinterBasicInfo"
|
||||
cpp = "::printing::PrinterBasicInfo"
|
||||
},
|
||||
{
|
||||
mojom = "printing.mojom.Paper"
|
||||
cpp = "::printing::PrinterSemanticCapsAndDefaults::Paper"
|
||||
|
@ -7,6 +7,16 @@ module printing.mojom;
|
||||
import "printing/mojom/print.mojom";
|
||||
import "ui/gfx/geometry/mojom/geometry.mojom";
|
||||
|
||||
// Basic information for a specific printer.
|
||||
struct PrinterBasicInfo {
|
||||
string printer_name;
|
||||
string display_name;
|
||||
string printer_description;
|
||||
int32 printer_status;
|
||||
bool is_default;
|
||||
map<string, string> options;
|
||||
};
|
||||
|
||||
// Paper used by printer semantic capabilities and defaults.
|
||||
struct Paper {
|
||||
string display_name;
|
||||
|
@ -72,6 +72,39 @@ class DuplicateChecker {
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
bool StructTraits<printing::mojom::PrinterBasicInfoDataView,
|
||||
printing::PrinterBasicInfo>::
|
||||
Read(printing::mojom::PrinterBasicInfoDataView data,
|
||||
printing::PrinterBasicInfo* out) {
|
||||
if (!data.ReadPrinterName(&out->printer_name) ||
|
||||
!data.ReadDisplayName(&out->display_name) ||
|
||||
!data.ReadPrinterDescription(&out->printer_description)) {
|
||||
return false;
|
||||
}
|
||||
out->printer_status = data.printer_status();
|
||||
out->is_default = data.is_default();
|
||||
if (!data.ReadOptions(&out->options))
|
||||
return false;
|
||||
|
||||
// There should be a non-empty value for `printer_name` since it needs to
|
||||
// uniquely identify the printer with the operating system among multiple
|
||||
// possible destinations.
|
||||
if (out->printer_name.empty()) {
|
||||
DLOG(ERROR) << "The printer name must not be empty.";
|
||||
return false;
|
||||
}
|
||||
// There should be a non-empty value for `display_name` since it needs to
|
||||
// uniquely identify the printer in user dialogs among multiple possible
|
||||
// destinations.
|
||||
if (out->display_name.empty()) {
|
||||
DLOG(ERROR) << "The printer's display name must not be empty.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// static
|
||||
bool StructTraits<printing::mojom::PaperDataView,
|
||||
printing::PrinterSemanticCapsAndDefaults::Paper>::
|
||||
|
@ -15,6 +15,34 @@
|
||||
|
||||
namespace mojo {
|
||||
|
||||
template <>
|
||||
struct StructTraits<printing::mojom::PrinterBasicInfoDataView,
|
||||
printing::PrinterBasicInfo> {
|
||||
static const std::string& printer_name(const printing::PrinterBasicInfo& i) {
|
||||
return i.printer_name;
|
||||
}
|
||||
static const std::string& display_name(const printing::PrinterBasicInfo& i) {
|
||||
return i.display_name;
|
||||
}
|
||||
static const std::string& printer_description(
|
||||
const printing::PrinterBasicInfo& i) {
|
||||
return i.printer_description;
|
||||
}
|
||||
static int printer_status(const printing::PrinterBasicInfo& i) {
|
||||
return i.printer_status;
|
||||
}
|
||||
static bool is_default(const printing::PrinterBasicInfo& i) {
|
||||
return i.is_default;
|
||||
}
|
||||
static const printing::PrinterBasicInfoOptions& options(
|
||||
const printing::PrinterBasicInfo& i) {
|
||||
return i.options;
|
||||
}
|
||||
|
||||
static bool Read(printing::mojom::PrinterBasicInfoDataView data,
|
||||
printing::PrinterBasicInfo* out);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct StructTraits<printing::mojom::PaperDataView,
|
||||
printing::PrinterSemanticCapsAndDefaults::Paper> {
|
||||
|
@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "mojo/public/cpp/test_support/test_utils.h"
|
||||
@ -113,6 +115,70 @@ GenerateSamplePrinterSemanticCapsAndDefaults() {
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(PrintBackendMojomTraitsTest, TestSerializeAndDeserializePrinterBasicInfo) {
|
||||
static const printing::PrinterBasicInfo kPrinterBasicInfo1(
|
||||
/*printer_name=*/"test printer name 1",
|
||||
/*display_name=*/"test display name 1",
|
||||
/*printer_description=*/"This is printer #1 for unit testing.",
|
||||
/*printer_status=*/0,
|
||||
/*is_default=*/true,
|
||||
/*options=*/
|
||||
std::map<std::string, std::string>{{"opt1", "123"}, {"opt2", "456"}});
|
||||
static const printing::PrinterBasicInfo kPrinterBasicInfo2(
|
||||
/*printer_name=*/"test printer name 2",
|
||||
/*display_name=*/"test display name 2",
|
||||
/*printer_description=*/"This is printer #2 for unit testing.",
|
||||
/*printer_status=*/1,
|
||||
/*is_default=*/false,
|
||||
/*options=*/std::map<std::string, std::string>{});
|
||||
static const printing::PrinterBasicInfo kPrinterBasicInfo3(
|
||||
/*printer_name=*/"test printer name 2",
|
||||
/*display_name=*/"test display name 2",
|
||||
/*printer_description=*/"",
|
||||
/*printer_status=*/9,
|
||||
/*is_default=*/false,
|
||||
/*options=*/std::map<std::string, std::string>{});
|
||||
static const PrinterList kPrinterList{kPrinterBasicInfo1, kPrinterBasicInfo2,
|
||||
kPrinterBasicInfo3};
|
||||
|
||||
for (auto info : kPrinterList) {
|
||||
printing::PrinterBasicInfo input = info;
|
||||
printing::PrinterBasicInfo output;
|
||||
EXPECT_TRUE(
|
||||
mojo::test::SerializeAndDeserialize<printing::mojom::PrinterBasicInfo>(
|
||||
input, output));
|
||||
EXPECT_EQ(info, output);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PrintBackendMojomTraitsTest,
|
||||
TestSerializeAndDeserializePrinterBasicInfoEmptyNames) {
|
||||
static const printing::PrinterBasicInfo kPrinterBasicInfoEmptyPrinterName(
|
||||
/*printer_name=*/"",
|
||||
/*display_name=*/"test display name",
|
||||
/*printer_description=*/"",
|
||||
/*printer_status=*/0,
|
||||
/*is_default=*/true,
|
||||
/*options=*/std::map<std::string, std::string>{});
|
||||
static const printing::PrinterBasicInfo kPrinterBasicInfoEmptyDisplayName(
|
||||
/*printer_name=*/"test printer name",
|
||||
/*display_name=*/"",
|
||||
/*printer_description=*/"",
|
||||
/*printer_status=*/0,
|
||||
/*is_default=*/true,
|
||||
/*options=*/std::map<std::string, std::string>{});
|
||||
static const PrinterList kPrinterList{kPrinterBasicInfoEmptyPrinterName,
|
||||
kPrinterBasicInfoEmptyDisplayName};
|
||||
|
||||
for (auto info : kPrinterList) {
|
||||
printing::PrinterBasicInfo input = info;
|
||||
printing::PrinterBasicInfo output;
|
||||
EXPECT_FALSE(
|
||||
mojo::test::SerializeAndDeserialize<printing::mojom::PrinterBasicInfo>(
|
||||
input, output));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PrintBackendMojomTraitsTest, TestSerializeAndDeserializePaper) {
|
||||
for (const auto& paper : kPapers) {
|
||||
printing::PrinterSemanticCapsAndDefaults::Paper input = paper;
|
||||
|
Reference in New Issue
Block a user