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 1e3770b4e74db62068f443688334c1d5824eaea0..4419ac5de2c243a9c5004c4a0f17b79373b88689 100644 |
--- a/content/renderer/manifest/manifest_parser_unittest.cc |
+++ b/content/renderer/manifest/manifest_parser_unittest.cc |
@@ -15,16 +15,34 @@ class ManifestParserTest : public testing::Test { |
ManifestParserTest() {} |
~ManifestParserTest() override {} |
- Manifest ParseManifest(const base::StringPiece& json, |
- const GURL& document_url = default_document_url, |
- const GURL& manifest_url = default_manifest_url) { |
- return ManifestParser::Parse(json, document_url, manifest_url); |
+ Manifest ParseManifestWithURLs(const base::StringPiece& data, |
+ const GURL& document_url, |
+ const GURL& manifest_url) { |
+ ManifestParser parser(data, document_url, manifest_url); |
+ parser.Parse(); |
+ errors_ = parser.errors(); |
+ return parser.manifest(); |
+ } |
+ |
+ Manifest ParseManifest(const base::StringPiece& data) { |
+ return ParseManifestWithURLs( |
+ data, default_document_url, default_manifest_url); |
+ } |
+ |
+ const std::vector<std::string>& errors() const { |
+ return errors_; |
+ } |
+ |
+ unsigned int GetErrorCount() const { |
+ return errors_.size(); |
} |
static const GURL default_document_url; |
static const GURL default_manifest_url; |
private: |
+ std::vector<std::string> errors_; |
+ |
DISALLOW_COPY_AND_ASSIGN(ManifestParserTest); |
}; |
@@ -36,6 +54,11 @@ const GURL ManifestParserTest::default_manifest_url( |
TEST_F(ManifestParserTest, EmptyStringNull) { |
Manifest manifest = ParseManifest(""); |
+ // This Manifest is not a valid JSON object, it's a parsing error. |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: Line: 1, column: 1, Unexpected token.", |
+ errors()[0]); |
+ |
// A parsing error is equivalent to an empty manifest. |
ASSERT_TRUE(manifest.IsEmpty()); |
ASSERT_TRUE(manifest.name.is_null()); |
@@ -48,6 +71,9 @@ TEST_F(ManifestParserTest, EmptyStringNull) { |
TEST_F(ManifestParserTest, ValidNoContentParses) { |
Manifest manifest = ParseManifest("{}"); |
+ // Empty Manifest is not a parsing error. |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ |
// Check that all the fields are null in that case. |
ASSERT_TRUE(manifest.IsEmpty()); |
ASSERT_TRUE(manifest.name.is_null()); |
@@ -57,30 +83,66 @@ TEST_F(ManifestParserTest, ValidNoContentParses) { |
ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
} |
+TEST_F(ManifestParserTest, MultipleErrorsReporting) { |
+ Manifest manifest = ParseManifest("{ \"name\": 42, \"short_name\": 4," |
+ "\"orientation\": {}, \"display\": \"foo\", \"start_url\": null," |
+ "\"icons\": {} }"); |
+ |
+ EXPECT_EQ(6u, GetErrorCount()); |
+ |
+ EXPECT_EQ("Manifest parsing error: property 'name' ignored," |
+ " type string expected.", |
+ errors()[0]); |
+ EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," |
+ " type string expected.", |
+ errors()[1]); |
+ EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," |
+ " type string expected.", |
+ errors()[2]); |
+ EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.", |
+ errors()[3]); |
+ EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," |
+ " type string expected.", |
+ errors()[4]); |
+ EXPECT_EQ("Manifest parsing error: property 'icons' ignored, " |
+ "type array expected.", |
+ errors()[5]); |
+} |
+ |
TEST_F(ManifestParserTest, NameParseRules) { |
// Smoke test. |
{ |
Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); |
ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); |
ASSERT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Trim whitespaces. |
{ |
Manifest manifest = ParseManifest("{ \"name\": \" foo \" }"); |
ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Don't parse if name isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"name\": {} }"); |
ASSERT_TRUE(manifest.name.is_null()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'name' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Don't parse if name isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"name\": 42 }"); |
ASSERT_TRUE(manifest.name.is_null()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'name' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
} |
@@ -90,24 +152,34 @@ TEST_F(ManifestParserTest, ShortNameParseRules) { |
Manifest manifest = ParseManifest("{ \"short_name\": \"foo\" }"); |
ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); |
ASSERT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Trim whitespaces. |
{ |
Manifest manifest = ParseManifest("{ \"short_name\": \" foo \" }"); |
ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Don't parse if name isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"short_name\": {} }"); |
ASSERT_TRUE(manifest.short_name.is_null()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Don't parse if name isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"short_name\": 42 }"); |
ASSERT_TRUE(manifest.short_name.is_null()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
} |
@@ -118,6 +190,7 @@ TEST_F(ManifestParserTest, StartURLParseRules) { |
ASSERT_EQ(manifest.start_url.spec(), |
default_document_url.Resolve("land.html").spec()); |
ASSERT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Whitespaces. |
@@ -125,45 +198,60 @@ TEST_F(ManifestParserTest, StartURLParseRules) { |
Manifest manifest = ParseManifest("{ \"start_url\": \" land.html \" }"); |
ASSERT_EQ(manifest.start_url.spec(), |
default_document_url.Resolve("land.html").spec()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Don't parse if property isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"start_url\": {} }"); |
ASSERT_TRUE(manifest.start_url.is_empty()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Don't parse if property isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"start_url\": 42 }"); |
ASSERT_TRUE(manifest.start_url.is_empty()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Absolute start_url, same origin with document. |
{ |
Manifest manifest = |
- ParseManifest("{ \"start_url\": \"http://foo.com/land.html\" }", |
- GURL("http://foo.com/manifest.json"), |
- GURL("http://foo.com/index.html")); |
+ ParseManifestWithURLs("{ \"start_url\": \"http://foo.com/land.html\" }", |
+ GURL("http://foo.com/manifest.json"), |
+ GURL("http://foo.com/index.html")); |
ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/land.html"); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Absolute start_url, cross origin with document. |
{ |
Manifest manifest = |
- ParseManifest("{ \"start_url\": \"http://bar.com/land.html\" }", |
- GURL("http://foo.com/manifest.json"), |
- GURL("http://foo.com/index.html")); |
+ ParseManifestWithURLs("{ \"start_url\": \"http://bar.com/land.html\" }", |
+ GURL("http://foo.com/manifest.json"), |
+ GURL("http://foo.com/index.html")); |
ASSERT_TRUE(manifest.start_url.is_empty()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'start_url' ignored, should " |
+ "be same origin as document.", |
+ errors()[0]); |
} |
// Resolving has to happen based on the manifest_url. |
{ |
Manifest manifest = |
- ParseManifest("{ \"start_url\": \"land.html\" }", |
- GURL("http://foo.com/landing/manifest.json"), |
- GURL("http://foo.com/index.html")); |
+ ParseManifestWithURLs("{ \"start_url\": \"land.html\" }", |
+ GURL("http://foo.com/landing/manifest.json"), |
+ GURL("http://foo.com/index.html")); |
ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/landing/land.html"); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
} |
@@ -173,60 +261,78 @@ TEST_F(ManifestParserTest, DisplayParserRules) { |
Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
EXPECT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Trim whitespaces. |
{ |
Manifest manifest = ParseManifest("{ \"display\": \" browser \" }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Don't parse if name isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"display\": {} }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'display' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Don't parse if name isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"display\": 42 }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'display' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Parse fails if string isn't known. |
{ |
Manifest manifest = ParseManifest("{ \"display\": \"browser_something\" }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.", |
+ errors()[0]); |
} |
// Accept 'fullscreen'. |
{ |
Manifest manifest = ParseManifest("{ \"display\": \"fullscreen\" }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_FULLSCREEN); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'fullscreen'. |
{ |
Manifest manifest = ParseManifest("{ \"display\": \"standalone\" }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_STANDALONE); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'minimal-ui'. |
{ |
Manifest manifest = ParseManifest("{ \"display\": \"minimal-ui\" }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_MINIMAL_UI); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'browser'. |
{ |
Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Case insensitive. |
{ |
Manifest manifest = ParseManifest("{ \"display\": \"BROWSER\" }"); |
EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
} |
@@ -236,48 +342,64 @@ TEST_F(ManifestParserTest, OrientationParserRules) { |
Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); |
EXPECT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Trim whitespaces. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Don't parse if name isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": {} }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Don't parse if name isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": 42 }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Parse fails if string isn't known. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": \"naturalish\" }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: unknown 'orientation' value ignored.", |
+ errors()[0]); |
} |
// Accept 'any'. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": \"any\" }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockAny); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'natural'. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'landscape'. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": \"landscape\" }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'landscape-primary'. |
@@ -286,6 +408,7 @@ TEST_F(ManifestParserTest, OrientationParserRules) { |
ParseManifest("{ \"orientation\": \"landscape-primary\" }"); |
EXPECT_EQ(manifest.orientation, |
blink::WebScreenOrientationLockLandscapePrimary); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'landscape-secondary'. |
@@ -294,12 +417,14 @@ TEST_F(ManifestParserTest, OrientationParserRules) { |
ParseManifest("{ \"orientation\": \"landscape-secondary\" }"); |
EXPECT_EQ(manifest.orientation, |
blink::WebScreenOrientationLockLandscapeSecondary); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'portrait'. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": \"portrait\" }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockPortrait); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'portrait-primary'. |
@@ -308,6 +433,7 @@ TEST_F(ManifestParserTest, OrientationParserRules) { |
ParseManifest("{ \"orientation\": \"portrait-primary\" }"); |
EXPECT_EQ(manifest.orientation, |
blink::WebScreenOrientationLockPortraitPrimary); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Accept 'portrait-secondary'. |
@@ -316,12 +442,14 @@ TEST_F(ManifestParserTest, OrientationParserRules) { |
ParseManifest("{ \"orientation\": \"portrait-secondary\" }"); |
EXPECT_EQ(manifest.orientation, |
blink::WebScreenOrientationLockPortraitSecondary); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Case insensitive. |
{ |
Manifest manifest = ParseManifest("{ \"orientation\": \"LANDSCAPE\" }"); |
EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
} |
@@ -331,6 +459,7 @@ TEST_F(ManifestParserTest, IconsParseRules) { |
Manifest manifest = ParseManifest("{ \"icons\": [] }"); |
EXPECT_EQ(manifest.icons.size(), 0u); |
EXPECT_TRUE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Smoke test: if empty icon, empty list. |
@@ -338,6 +467,7 @@ TEST_F(ManifestParserTest, IconsParseRules) { |
Manifest manifest = ParseManifest("{ \"icons\": [ {} ] }"); |
EXPECT_EQ(manifest.icons.size(), 0u); |
EXPECT_TRUE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Smoke test: icon with invalid src, empty list. |
@@ -345,6 +475,7 @@ TEST_F(ManifestParserTest, IconsParseRules) { |
Manifest manifest = ParseManifest("{ \"icons\": [ { \"icons\": [] } ] }"); |
EXPECT_EQ(manifest.icons.size(), 0u); |
EXPECT_TRUE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Smoke test: if icon with empty src, it will be present in the list. |
@@ -353,6 +484,7 @@ TEST_F(ManifestParserTest, IconsParseRules) { |
EXPECT_EQ(manifest.icons.size(), 1u); |
EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/index.html"); |
EXPECT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Smoke test: if one icons with valid src, it will be present in the list. |
@@ -362,6 +494,7 @@ TEST_F(ManifestParserTest, IconsParseRules) { |
EXPECT_EQ(manifest.icons.size(), 1u); |
EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/foo.jpg"); |
EXPECT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
} |
@@ -372,6 +505,7 @@ TEST_F(ManifestParserTest, IconSrcParseRules) { |
ParseManifest("{ \"icons\": [ {\"src\": \"foo.png\" } ] }"); |
EXPECT_EQ(manifest.icons[0].src.spec(), |
default_document_url.Resolve("foo.png").spec()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Whitespaces. |
@@ -380,27 +514,38 @@ TEST_F(ManifestParserTest, IconSrcParseRules) { |
ParseManifest("{ \"icons\": [ {\"src\": \" foo.png \" } ] }"); |
EXPECT_EQ(manifest.icons[0].src.spec(), |
default_document_url.Resolve("foo.png").spec()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Don't parse if property isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": {} } ] }"); |
EXPECT_TRUE(manifest.icons.empty()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'src' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Don't parse if property isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": 42 } ] }"); |
EXPECT_TRUE(manifest.icons.empty()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'src' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Resolving has to happen based on the document_url. |
{ |
- Manifest manifest = |
- ParseManifest("{ \"icons\": [ {\"src\": \"icons/foo.png\" } ] }", |
- GURL("http://foo.com/landing/index.html")); |
+ Manifest manifest = ParseManifestWithURLs( |
+ "{ \"icons\": [ {\"src\": \"icons/foo.png\" } ] }", |
+ GURL("http://foo.com/landing/index.html"), |
+ default_manifest_url); |
EXPECT_EQ(manifest.icons[0].src.spec(), |
"http://foo.com/landing/icons/foo.png"); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
} |
@@ -410,6 +555,7 @@ TEST_F(ManifestParserTest, IconTypeParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": \"foo\" } ] }"); |
EXPECT_TRUE(EqualsASCII(manifest.icons[0].type.string(), "foo")); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Trim whitespaces. |
@@ -417,6 +563,7 @@ TEST_F(ManifestParserTest, IconTypeParseRules) { |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
" \"type\": \" foo \" } ] }"); |
EXPECT_TRUE(EqualsASCII(manifest.icons[0].type.string(), "foo")); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Don't parse if property isn't a string. |
@@ -424,6 +571,10 @@ TEST_F(ManifestParserTest, IconTypeParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": {} } ] }"); |
EXPECT_TRUE(manifest.icons[0].type.is_null()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'type' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Don't parse if property isn't a string. |
@@ -431,6 +582,10 @@ TEST_F(ManifestParserTest, IconTypeParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": 42 } ] }"); |
EXPECT_TRUE(manifest.icons[0].type.is_null()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'type' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
} |
@@ -440,6 +595,7 @@ TEST_F(ManifestParserTest, IconDensityParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 42 } ] }"); |
EXPECT_EQ(manifest.icons[0].density, 42); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Decimal value. |
@@ -447,6 +603,7 @@ TEST_F(ManifestParserTest, IconDensityParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 2.5 } ] }"); |
EXPECT_EQ(manifest.icons[0].density, 2.5); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Parse fail if it isn't a float. |
@@ -454,6 +611,10 @@ TEST_F(ManifestParserTest, IconDensityParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": {} } ] }"); |
EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: icon 'density' ignored, " |
+ "must be float greater than 0.", |
+ errors()[0]); |
} |
// Parse fail if it isn't a float. |
@@ -461,6 +622,10 @@ TEST_F(ManifestParserTest, IconDensityParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\":\"2\" } ] }"); |
EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: icon 'density' ignored, " |
+ "must be float greater than 0.", |
+ errors()[0]); |
} |
// Edge case: 1.0. |
@@ -468,6 +633,7 @@ TEST_F(ManifestParserTest, IconDensityParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 1.00 } ] }"); |
EXPECT_EQ(manifest.icons[0].density, 1); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Edge case: values between 0.0 and 1.0 are allowed. |
@@ -475,6 +641,7 @@ TEST_F(ManifestParserTest, IconDensityParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.42 } ] }"); |
EXPECT_EQ(manifest.icons[0].density, 0.42); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// 0 is an invalid value. |
@@ -482,6 +649,10 @@ TEST_F(ManifestParserTest, IconDensityParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.0 } ] }"); |
EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: icon 'density' ignored, " |
+ "must be float greater than 0.", |
+ errors()[0]); |
} |
// Negative values are invalid. |
@@ -489,6 +660,10 @@ TEST_F(ManifestParserTest, IconDensityParseRules) { |
Manifest manifest = |
ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }"); |
EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: icon 'density' ignored, " |
+ "must be float greater than 0.", |
+ errors()[0]); |
} |
} |
@@ -498,6 +673,7 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
"\"sizes\": \"42x42\" } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Trim whitespaces. |
@@ -505,20 +681,29 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
"\"sizes\": \" 42x42 \" } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
- // Don't parse if name isn't a string. |
+ // Ignore sizes if property isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
"\"sizes\": {} } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'sizes' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
- // Don't parse if name isn't a string. |
+ // Ignore sizes if property isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
"\"sizes\": 42 } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'sizes' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
// Smoke test: value correctly parsed. |
@@ -527,6 +712,7 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
"\"sizes\": \"42x42 48x48\" } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48)); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// <WIDTH>'x'<HEIGHT> and <WIDTH>'X'<HEIGHT> are equivalent. |
@@ -535,6 +721,7 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
"\"sizes\": \"42X42 48X48\" } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48)); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Twice the same value is parsed twice. |
@@ -543,6 +730,7 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
"\"sizes\": \"42X42 42x42\" } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(42, 42)); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Width or height can't start with 0. |
@@ -550,6 +738,9 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
"\"sizes\": \"004X007 042x00\" } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: found icon with no valid size.", |
+ errors()[0]); |
} |
// Width and height MUST contain digits. |
@@ -557,6 +748,9 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
"\"sizes\": \"e4X1.0 55ax1e10\" } ] }"); |
EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: found icon with no valid size.", |
+ errors()[0]); |
} |
// 'any' is correctly parsed and transformed to gfx::Size(0,0). |
@@ -569,6 +763,7 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
EXPECT_EQ(manifest.icons[0].sizes[1], any); |
EXPECT_EQ(manifest.icons[0].sizes[2], any); |
EXPECT_EQ(manifest.icons[0].sizes[3], any); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Some invalid width/height combinations. |
@@ -577,6 +772,9 @@ TEST_F(ManifestParserTest, IconSizesParseRules) { |
"\"sizes\": \"x 40xx 1x2x3 x42 42xx42\" } ] }"); |
gfx::Size any = gfx::Size(0, 0); |
EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: found icon with no valid size.", |
+ errors()[0]); |
} |
} |
@@ -585,22 +783,32 @@ TEST_F(ManifestParserTest, GCMSenderIDParseRules) { |
{ |
Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); |
EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Trim whitespaces. |
{ |
Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \" foo \" }"); |
EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); |
+ EXPECT_EQ(0u, GetErrorCount()); |
} |
// Don't parse if property isn't a string. |
{ |
Manifest manifest = ParseManifest("{ \"gcm_sender_id\": {} }"); |
EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
{ |
Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); |
EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," |
+ " type string expected.", |
+ errors()[0]); |
} |
} |