| 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 362177eb0511119d4c3efd1fc8ea92dcce9f4254..3d5a8466ef92e262064fd2d56eea03ff9461b3c4 100644
|
| --- a/content/renderer/manifest/manifest_parser_unittest.cc
|
| +++ b/content/renderer/manifest/manifest_parser_unittest.cc
|
| @@ -877,4 +877,115 @@ TEST_F(ManifestParserTest, GCMUserVisibleOnlyParseRules) {
|
| }
|
| }
|
|
|
| +TEST_F(ManifestParserTest, ChromeRelatedApplicationsParseRules) {
|
| + // If no application, empty list.
|
| + {
|
| + Manifest manifest = ParseManifest(
|
| + "{ \"chrome_related_applications\": []}");
|
| + EXPECT_EQ(manifest.chrome_related_applications.size(), 0u);
|
| + EXPECT_TRUE(manifest.IsEmpty());
|
| + EXPECT_EQ(0u, GetErrorCount());
|
| + }
|
| +
|
| + // If empty application, empty list.
|
| + {
|
| + Manifest manifest = ParseManifest(
|
| + "{ \"chrome_related_applications\": [{}]}");
|
| + EXPECT_EQ(manifest.chrome_related_applications.size(), 0u);
|
| + EXPECT_TRUE(manifest.IsEmpty());
|
| + EXPECT_EQ(1u, GetErrorCount());
|
| + EXPECT_EQ("Manifest parsing error: 'platform' is a required field, "
|
| + "chrome related application ignored.",
|
| + errors()[0]);
|
| + }
|
| +
|
| + // If invalid package, application is ignored.
|
| + {
|
| + Manifest manifest = ParseManifest(
|
| + "{ \"chrome_related_applications\": [{\"platform\": \"foo\"}]}");
|
| + EXPECT_EQ(manifest.chrome_related_applications.size(), 0u);
|
| + EXPECT_TRUE(manifest.IsEmpty());
|
| + EXPECT_EQ(1u, GetErrorCount());
|
| + EXPECT_EQ("Manifest parsing error: unknown 'platform' value ignored.",
|
| + errors()[0]);
|
| + }
|
| +
|
| + // If missing platform, application is ignored.
|
| + {
|
| + Manifest manifest = ParseManifest(
|
| + "{ \"chrome_related_applications\": [{\"id\": \"foo\"}]}");
|
| + EXPECT_EQ(manifest.chrome_related_applications.size(), 0u);
|
| + EXPECT_TRUE(manifest.IsEmpty());
|
| + EXPECT_EQ(1u, GetErrorCount());
|
| + EXPECT_EQ("Manifest parsing error: 'platform' is a required field, "
|
| + "chrome related application ignored.",
|
| + errors()[0]);
|
| + }
|
| +
|
| + // Web application, without id.
|
| + {
|
| + Manifest manifest = ParseManifest(
|
| + "{ \"chrome_related_applications\": [{\"platform\": \"web\"}]}");
|
| + EXPECT_EQ(manifest.chrome_related_applications.size(), 1u);
|
| + EXPECT_EQ(manifest.chrome_related_applications[0].platform,
|
| + Manifest::CHROME_RELATED_APPLICATION_PLATFORM_WEB);
|
| + EXPECT_TRUE(manifest.chrome_related_applications[0].id.is_null());
|
| + EXPECT_FALSE(manifest.IsEmpty());
|
| + EXPECT_EQ(0u, GetErrorCount());
|
| + }
|
| +
|
| + // Android application, with id.
|
| + {
|
| + Manifest manifest = ParseManifest(
|
| + "{ \"chrome_related_applications\": ["
|
| + "{\"platform\": \"android\", \"id\": \"foo\"}]}");
|
| + EXPECT_EQ(manifest.chrome_related_applications.size(), 1u);
|
| + EXPECT_EQ(manifest.chrome_related_applications[0].platform,
|
| + Manifest::CHROME_RELATED_APPLICATION_PLATFORM_ANDROID);
|
| + EXPECT_TRUE(EqualsASCII(manifest.chrome_related_applications[0].id.string(),
|
| + "foo"));
|
| + EXPECT_FALSE(manifest.IsEmpty());
|
| + EXPECT_EQ(0u, GetErrorCount());
|
| + }
|
| +
|
| + // All valid applications are in list.
|
| + {
|
| + Manifest manifest = ParseManifest(
|
| + "{ \"chrome_related_applications\": ["
|
| + "{\"platform\": \"android\", \"id\": \"foo\"},"
|
| + "{\"platform\": \"web\"}]}");
|
| + EXPECT_EQ(manifest.chrome_related_applications.size(), 2u);
|
| + EXPECT_EQ(manifest.chrome_related_applications[0].platform,
|
| + Manifest::CHROME_RELATED_APPLICATION_PLATFORM_ANDROID);
|
| + EXPECT_TRUE(EqualsASCII(manifest.chrome_related_applications[0].id.string(),
|
| + "foo"));
|
| + EXPECT_EQ(manifest.chrome_related_applications[1].platform,
|
| + Manifest::CHROME_RELATED_APPLICATION_PLATFORM_WEB);
|
| + EXPECT_TRUE(manifest.chrome_related_applications[1].id.is_null());
|
| + EXPECT_FALSE(manifest.IsEmpty());
|
| + EXPECT_EQ(0u, GetErrorCount());
|
| + }
|
| +
|
| + // Two invalid applications and one valid. Only the valid application should
|
| + // be in the list.
|
| + {
|
| + Manifest manifest = ParseManifest(
|
| + "{ \"chrome_related_applications\": ["
|
| + "{\"platform\": \"foo\", \"id\": \"bar\"},"
|
| + "{\"platform\": \"android\", \"id\": \"foo\"},{}]}");
|
| + EXPECT_EQ(manifest.chrome_related_applications.size(), 1u);
|
| + EXPECT_EQ(manifest.chrome_related_applications[0].platform,
|
| + Manifest::CHROME_RELATED_APPLICATION_PLATFORM_ANDROID);
|
| + EXPECT_TRUE(EqualsASCII(manifest.chrome_related_applications[0].id.string(),
|
| + "foo"));
|
| + EXPECT_FALSE(manifest.IsEmpty());
|
| + EXPECT_EQ(2u, GetErrorCount());
|
| + EXPECT_EQ("Manifest parsing error: unknown 'platform' value ignored.",
|
| + errors()[0]);
|
| + EXPECT_EQ("Manifest parsing error: 'platform' is a required field, "
|
| + "chrome related application ignored.",
|
| + errors()[1]);
|
| + }
|
| +}
|
| +
|
| } // namespace content
|
|
|