Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1105)

Unified Diff: content/renderer/manifest/manifest_parser_unittest.cc

Issue 2425833002: Parse "purpose" member from Web Manifest (Closed)
Patch Set: Fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/manifest/manifest_parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/manifest/manifest_parser_unittest.cc
diff --git a/content/renderer/manifest/manifest_parser_unittest.cc b/content/renderer/manifest/manifest_parser_unittest.cc
index a2d12554fabe47faaac556f47ac0733f2fa65d6e..1026b3e3c14e521432523e8230edb6d2db2b374c 100644
--- a/content/renderer/manifest/manifest_parser_unittest.cc
+++ b/content/renderer/manifest/manifest_parser_unittest.cc
@@ -878,6 +878,110 @@ TEST_F(ManifestParserTest, IconSizesParseRules) {
}
}
+TEST_F(ManifestParserTest, IconPurposeParseRules) {
+ const std::string kPurposeParseStringError =
+ "property 'purpose' ignored, type string expected.";
+ const std::string kPurposeInvalidValueError =
+ "found icon with invalid purpose. "
+ "Using default value 'any'.";
+
+ // Smoke test.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \"any\" } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Trim leading and trailing whitespaces.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \" any \" } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // 'any' is added when property isn't present.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\" } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // 'any' is added with error message when property isn't a string (is a
+ // number).
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": 42 } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
+ ASSERT_EQ(1u, GetErrorCount());
+ EXPECT_EQ(kPurposeParseStringError, errors()[0]);
+ }
+
+ // 'any' is added with error message when property isn't a string (is a
+ // dictionary).
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": {} } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
+ ASSERT_EQ(1u, GetErrorCount());
+ EXPECT_EQ(kPurposeParseStringError, errors()[0]);
+ }
+
+ // Smoke test: values correctly parsed.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \"Any Badge\" } ] }");
+ ASSERT_EQ(manifest.icons[0].purpose.size(), 2u);
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
+ EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE);
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Trim whitespaces between values.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \" Any Badge \" } ] }");
+ ASSERT_EQ(manifest.icons[0].purpose.size(), 2u);
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
+ EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE);
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Twice the same value is parsed twice.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \"badge badge\" } ] }");
+ ASSERT_EQ(manifest.icons[0].purpose.size(), 2u);
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE);
+ EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE);
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Invalid icon purpose is ignored.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \"badge notification\" } ] }");
+ ASSERT_EQ(manifest.icons[0].purpose.size(), 1u);
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE);
+ ASSERT_EQ(1u, GetErrorCount());
+ EXPECT_EQ(kPurposeInvalidValueError, errors()[0]);
+ }
+
+ // 'any' is added when developer-supplied purpose is invalid.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \"notification\" } ] }");
+ ASSERT_EQ(manifest.icons[0].purpose.size(), 1u);
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
+ ASSERT_EQ(1u, GetErrorCount());
+ EXPECT_EQ(kPurposeInvalidValueError, errors()[0]);
+ }
+}
+
TEST_F(ManifestParserTest, RelatedApplicationsParseRules) {
// If no application, empty list.
{
« no previous file with comments | « content/renderer/manifest/manifest_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698