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

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

Issue 2425833002: Parse "purpose" member from Web Manifest (Closed)
Patch Set: Addressing comments Created 4 years, 2 months 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
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..acd554b02145449a19aa7cdf045fb0d2e5cd4d78 100644
--- a/content/renderer/manifest/manifest_parser_unittest.cc
+++ b/content/renderer/manifest/manifest_parser_unittest.cc
@@ -878,6 +878,103 @@ TEST_F(ManifestParserTest, IconSizesParseRules) {
}
}
+TEST_F(ManifestParserTest, IconPurposeParseRules) {
+ // 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());
+ }
+
+ // Ignore purpose if property isn't present.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\" } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose.size(), 0u);
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Ignore purpose if property isn't a string (is a number).
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": 42 } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose.size(), 0u);
+ ASSERT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'purpose' ignored, type string expected.",
+ errors()[0]);
+ }
+
+ // Ignore purpose if property isn't a string (is a dictionary).
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": {} } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose.size(), 0u);
+ ASSERT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'purpose' ignored, type string expected.",
+ 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("found icon with invalid purpose.",
+ 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("found icon with invalid purpose.",
+ errors()[0]);
+ }
+}
+
TEST_F(ManifestParserTest, RelatedApplicationsParseRules) {
// If no application, empty list.
{
« content/public/common/manifest.h ('K') | « content/renderer/manifest/manifest_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698