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..2f553c381593af7cf19b8b91a1b50d9823d5fe92 100644 |
--- a/content/renderer/manifest/manifest_parser_unittest.cc |
+++ b/content/renderer/manifest/manifest_parser_unittest.cc |
@@ -797,6 +797,181 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
} |
} |
+TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { |
+ // If no application, empty list. |
+ { |
+ Manifest manifest = ParseManifest( |
+ "{ \"related_applications\": []}"); |
+ EXPECT_EQ(manifest.related_applications.size(), 0u); |
+ EXPECT_TRUE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // If empty application, empty list. |
+ { |
+ Manifest manifest = ParseManifest( |
+ "{ \"related_applications\": [{}]}"); |
+ EXPECT_EQ(manifest.related_applications.size(), 0u); |
+ EXPECT_TRUE(manifest.IsEmpty()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " |
+ "related application ignored.", |
+ errors()[0]); |
+ } |
+ |
+ // If invalid platform, application is ignored. |
mlamouri (slow - plz ping)
2015/04/10 09:49:45
Keep that test but make it invalid per type like h
benwells
2015/04/15 06:45:22
Done.
|
+ { |
+ Manifest manifest = ParseManifest( |
+ "{ \"related_applications\": [{\"platform\": \"foo\"}]}"); |
+ EXPECT_EQ(manifest.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( |
+ "{ \"related_applications\": [{\"id\": \"foo\"}]}"); |
+ EXPECT_EQ(manifest.related_applications.size(), 0u); |
+ EXPECT_TRUE(manifest.IsEmpty()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " |
+ "related application ignored.", |
+ errors()[0]); |
+ } |
+ |
+ // If missing id and url, application is ignored. |
+ { |
+ Manifest manifest = ParseManifest( |
+ "{ \"related_applications\": [{\"platform\": \"play\"}]}"); |
+ EXPECT_EQ(manifest.related_applications.size(), 0u); |
+ EXPECT_TRUE(manifest.IsEmpty()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: one of 'url' or 'id' is required, " |
+ "related application ignored.", |
+ errors()[0]); |
+ } |
+ |
+ // Android application, with url. |
mlamouri (slow - plz ping)
2015/04/10 09:49:45
I don't think we should test that on the content l
benwells
2015/04/15 06:45:22
Sure, I've reworded the comment and used itunes fo
|
+ { |
+ Manifest manifest = ParseManifest( |
+ "{ \"related_applications\": [" |
+ "{\"platform\": \"play\", \"url\": \"http://www.foo.com\"}]}"); |
+ EXPECT_EQ(manifest.related_applications.size(), 1u); |
+ EXPECT_EQ(manifest.related_applications[0].platform, |
+ Manifest::RELATED_APPLICATION_PLATFORM_PLAY); |
+ EXPECT_EQ(manifest.related_applications[0].url.spec(), |
+ "http://www.foo.com/"); |
+ EXPECT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // Android application, with id. |
mlamouri (slow - plz ping)
2015/04/10 09:49:45
Could you add a test where there is no id nor url?
benwells
2015/04/15 06:45:22
It is two tests up already, "If missing id and url
|
+ { |
+ Manifest manifest = ParseManifest( |
+ "{ \"related_applications\": [" |
+ "{\"platform\": \"play\", \"id\": \"foo\"}]}"); |
+ EXPECT_EQ(manifest.related_applications.size(), 1u); |
+ EXPECT_EQ(manifest.related_applications[0].platform, |
+ Manifest::RELATED_APPLICATION_PLATFORM_PLAY); |
+ EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].id.string(), |
+ "foo")); |
+ EXPECT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // All valid applications are in list. |
+ { |
+ Manifest manifest = ParseManifest( |
+ "{ \"related_applications\": [" |
+ "{\"platform\": \"play\", \"id\": \"foo\"}," |
+ "{\"platform\": \"play\", \"id\": \"bar\"}]}"); |
+ EXPECT_EQ(manifest.related_applications.size(), 2u); |
+ EXPECT_EQ(manifest.related_applications[0].platform, |
+ Manifest::RELATED_APPLICATION_PLATFORM_PLAY); |
+ EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].id.string(), |
+ "foo")); |
+ EXPECT_EQ(manifest.related_applications[1].platform, |
+ Manifest::RELATED_APPLICATION_PLATFORM_PLAY); |
+ EXPECT_TRUE(EqualsASCII(manifest.related_applications[1].id.string(), |
+ "bar")); |
+ 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( |
+ "{ \"related_applications\": [" |
+ "{\"platform\": \"foo\", \"id\": \"bar\"}," |
+ "{\"platform\": \"play\", \"id\": \"foo\"},{}]}"); |
+ EXPECT_EQ(manifest.related_applications.size(), 1u); |
+ EXPECT_EQ(manifest.related_applications[0].platform, |
+ Manifest::RELATED_APPLICATION_PLATFORM_PLAY); |
+ EXPECT_TRUE(EqualsASCII(manifest.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, " |
+ "related application ignored.", |
+ errors()[1]); |
+ } |
+} |
+ |
+TEST_F(ManifestParserTest, ParsePreferRelatedApplicationsParseRules) { |
+ // Smoke test. |
+ { |
+ Manifest manifest = |
+ ParseManifest("{ \"prefer_related_applications\": true }"); |
+ EXPECT_TRUE(manifest.prefer_related_applications); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // Don't parse if the property isn't a boolean. |
+ { |
+ Manifest manifest = |
+ ParseManifest("{ \"prefer_related_applications\": {} }"); |
+ EXPECT_FALSE(manifest.prefer_related_applications); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ( |
+ "Manifest parsing error: property 'prefer_related_applications' " |
+ "ignored, type boolean expected.", |
+ errors()[0]); |
+ } |
+ { |
+ Manifest manifest = ParseManifest( |
+ "{ \"prefer_related_applications\": \"true\" }"); |
+ EXPECT_FALSE(manifest.prefer_related_applications); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ( |
+ "Manifest parsing error: property 'prefer_related_applications' " |
+ "ignored, type boolean expected.", |
+ errors()[0]); |
+ } |
+ { |
+ Manifest manifest = ParseManifest("{ \"prefer_related_applications\": 1 }"); |
+ EXPECT_FALSE(manifest.prefer_related_applications); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ( |
+ "Manifest parsing error: property 'prefer_related_applications' " |
+ "ignored, type boolean expected.", |
+ errors()[0]); |
+ } |
+ |
+ // "False" should set the boolean false without throwing errors. |
+ { |
+ Manifest manifest = |
+ ParseManifest("{ \"prefer_related_applications\": false }"); |
+ EXPECT_FALSE(manifest.prefer_related_applications); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+} |
+ |
TEST_F(ManifestParserTest, GCMSenderIDParseRules) { |
// Smoke test. |
{ |