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

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

Issue 2425833002: Parse "purpose" member from Web Manifest (Closed)
Patch Set: patch 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..b2688a1dd96bb4597f8bf6dd52244e181764ce69 100644
--- a/content/renderer/manifest/manifest_parser_unittest.cc
+++ b/content/renderer/manifest/manifest_parser_unittest.cc
@@ -878,6 +878,89 @@ 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 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);
+ EXPECT_EQ(1u, GetErrorCount());
pkotwicz 2016/10/18 14:13:56 When the remainder of the test will crash (as oppo
F 2016/10/18 15:34:46 Done.
+ 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);
+ EXPECT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'purpose' ignored, type string expected.",
+ errors()[0]);
+ }
+
+ // Smoke test: value correctly parsed.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \"Any Badge\" } ] }");
pkotwicz 2016/10/18 14:13:56 You should add: ASSERT_EQ(manifest.icons[0].purpos
F 2016/10/18 15:34:46 Done.
+ 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\" } ] }");
pkotwicz 2016/10/18 14:13:56 You should add: ASSERT_EQ(manifest.icons[0].purpos
F 2016/10/18 15:34:46 Done.
+ 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\" } ] }");
pkotwicz 2016/10/18 14:13:56 You should add: ASSERT_EQ(manifest.icons[0].purpos
F 2016/10/18 15:34:46 Done.
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE);
+ EXPECT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("found icon with invalid purpose.",
+ errors()[0]);
+ }
+
+ // 'any' is correctly added when the purpose is empty.
pkotwicz 2016/10/18 14:13:56 How about: 'any' is added when developer-supplied-
F 2016/10/18 15:34:46 Done.
+ {
+ Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
+ "\"purpose\": \"notification\" } ] }");
+ EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
+ EXPECT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("found icon with invalid purpose.",
+ errors()[0]);
+ }
pkotwicz 2016/10/18 14:13:56 Maybe add a test case for: \"purpose\": \"any bad
F 2016/10/18 15:34:46 Done.
+}
+
TEST_F(ManifestParserTest, RelatedApplicationsParseRules) {
// If no application, empty list.
{
« content/renderer/manifest/manifest_parser.cc ('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