Commit 4db39e3b authored by Kalvin Lee's avatar Kalvin Lee Committed by Commit Bot

PpdProvider v3: parse PPD licenses

This change modifies ParseForwardIndex() to account for the presence
of licenses in forward index metadata.

Bug: chromium:888189
Test: chromeos_unittests --gtest_filter='PpdMetadataParserTest.*'
Change-Id: I6af51413dc26d7a8cb213a5bee8be35332b4f409
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354908
Commit-Queue: Kalvin Lee <kdlee@chromium.org>
Reviewed-by: default avatarLuum Habtemariam <luum@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804118}
parent f02dbfca
...@@ -139,6 +139,12 @@ base::Optional<ParsedIndexLeaf> ParsedIndexLeafFrom(const base::Value& value) { ...@@ -139,6 +139,12 @@ base::Optional<ParsedIndexLeaf> ParsedIndexLeafFrom(const base::Value& value) {
if (restrictions_value) { if (restrictions_value) {
leaf.restrictions = ParseRestrictionsFromValue(*restrictions_value); leaf.restrictions = ParseRestrictionsFromValue(*restrictions_value);
} }
const std::string* const ppd_license = value.FindStringKey("license");
if (ppd_license && !ppd_license->empty()) {
leaf.license = *ppd_license;
}
return leaf; return leaf;
} }
......
...@@ -55,6 +55,7 @@ struct CHROMEOS_EXPORT ParsedIndexLeaf { ...@@ -55,6 +55,7 @@ struct CHROMEOS_EXPORT ParsedIndexLeaf {
std::string ppd_basename; std::string ppd_basename;
base::Optional<PpdProvider::Restrictions> restrictions; base::Optional<PpdProvider::Restrictions> restrictions;
std::string license;
}; };
// A collection of values parsed from a forward index. // A collection of values parsed from a forward index.
......
...@@ -533,6 +533,44 @@ TEST(PpdMetadataParserTest, CanParseForwardIndexWithMalformedRestrictions) { ...@@ -533,6 +533,44 @@ TEST(PpdMetadataParserTest, CanParseForwardIndexWithMalformedRestrictions) {
Field(&ParsedIndexLeaf::restrictions, Eq(base::nullopt))))))); Field(&ParsedIndexLeaf::restrictions, Eq(base::nullopt)))))));
} }
// Verifies that ParseForwardIndex() can parse forward index metadata
// specifying PPD licenses.
TEST(PpdMetadataParserTest, CanParseForwardIndexWithLicenses) {
// Specifies two PPDs, each with a license associated.
constexpr base::StringPiece kJsonForwardIndex = R"({
"ppdIndex": {
"der fischer": {
"ppdMetadata": [ {
"name": "d-225.ppd.gz",
"license": "two two five license"
} ]
},
"erster verlust": {
"ppdMetadata": [ {
"name": "d-226.ppd.gz",
"license": "two two six license"
} ]
}
}
})";
const auto parsed = ParseForwardIndex(kJsonForwardIndex);
ASSERT_TRUE(parsed.has_value());
EXPECT_THAT(
parsed.value(),
UnorderedElementsAre(
ParsedIndexEntryLike(
"der fischer", UnorderedElementsAre(AllOf(
ParsedIndexLeafWithPpdBasename("d-225.ppd.gz"),
Field(&ParsedIndexLeaf::license,
StrEq("two two five license"))))),
ParsedIndexEntryLike(
"erster verlust",
UnorderedElementsAre(
AllOf(ParsedIndexLeafWithPpdBasename("d-226.ppd.gz"),
Field(&ParsedIndexLeaf::license,
StrEq("two two six license")))))));
}
// Verifies that ParseForwardIndex() returns base::nullopt rather than // Verifies that ParseForwardIndex() returns base::nullopt rather than
// an empty container. // an empty container.
TEST(PpdMetadataParserTest, ParseForwardIndexDoesNotReturnEmptyContainer) { TEST(PpdMetadataParserTest, ParseForwardIndexDoesNotReturnEmptyContainer) {
......
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