Chromium Code Reviews| 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 39384f8be7598d7b36e2f375f1d4d458af4ac02a..0940d4827065705593428d6032f90a2bebc42307 100644 |
| --- a/content/renderer/manifest/manifest_parser_unittest.cc |
| +++ b/content/renderer/manifest/manifest_parser_unittest.cc |
| @@ -78,6 +78,7 @@ TEST_F(ManifestParserTest, EmptyStringNull) { |
| ASSERT_TRUE(manifest.start_url.is_empty()); |
| ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
| ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
| + ASSERT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); |
| ASSERT_TRUE(manifest.gcm_sender_id.is_null()); |
| } |
| @@ -94,15 +95,16 @@ TEST_F(ManifestParserTest, ValidNoContentParses) { |
| ASSERT_TRUE(manifest.start_url.is_empty()); |
| ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
| ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
| + ASSERT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); |
| ASSERT_TRUE(manifest.gcm_sender_id.is_null()); |
| } |
| TEST_F(ManifestParserTest, MultipleErrorsReporting) { |
| Manifest manifest = ParseManifest("{ \"name\": 42, \"short_name\": 4," |
| - "\"orientation\": {}, \"display\": \"foo\", \"start_url\": null," |
| - "\"icons\": {} }"); |
| + "\"orientation\": {}, \"display\": \"foo\"," |
| + "\"start_url\": null, \"icons\": {}, \"theme_color\": 42 }"); |
| - EXPECT_EQ(6u, GetErrorCount()); |
| + EXPECT_EQ(7u, GetErrorCount()); |
| EXPECT_EQ("Manifest parsing error: property 'name' ignored," |
| " type string expected.", |
| @@ -121,6 +123,9 @@ TEST_F(ManifestParserTest, MultipleErrorsReporting) { |
| EXPECT_EQ("Manifest parsing error: property 'icons' ignored, " |
| "type array expected.", |
| errors()[5]); |
| + EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," |
| + " type string expected.", |
| + errors()[6]); |
| } |
| TEST_F(ManifestParserTest, NameParseRules) { |
| @@ -350,6 +355,83 @@ TEST_F(ManifestParserTest, DisplayParserRules) { |
| } |
| } |
| +TEST_F(ManifestParserTest, ThemeColorParserRules) { |
|
mlamouri (slow - plz ping)
2015/07/16 14:53:31
I wanted you to remove the first smoke test, not b
Lalit Maganti
2015/07/16 15:12:28
Done.
|
| + // Don't parse if theme_color isn't a string. |
|
mlamouri (slow - plz ping)
2015/07/16 14:53:31
You removed the whitespace test too. Could you add
Lalit Maganti
2015/07/16 15:12:28
Done.
|
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": {} }"); |
| + EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); |
| + EXPECT_EQ(1u, GetErrorCount()); |
| + EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," |
| + " type string expected.", |
| + errors()[0]); |
| + } |
| + |
| + // Don't parse if theme_color isn't a string. |
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": 42 }"); |
| + EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); |
| + EXPECT_EQ(1u, GetErrorCount()); |
| + EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," |
| + " type string expected.", |
| + errors()[0]); |
| + } |
| + |
| + // Parse fails if string is not in a known format. |
|
mlamouri (slow - plz ping)
2015/07/16 14:53:31
Could you add more test for this case? Things clos
Lalit Maganti
2015/07/16 15:12:28
Done.
|
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": \"foo(bar)\" }"); |
| + EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); |
| + EXPECT_EQ(1u, GetErrorCount()); |
| + EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," |
| + " invalid color specified.", |
| + errors()[0]); |
| + } |
| + |
| + // Parse fails if multiple values for theme_color are given. |
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": \"#ABC#DEF\" }"); |
|
mlamouri (slow - plz ping)
2015/07/16 14:53:31
This sounds more like a wrong format. You could ke
Lalit Maganti
2015/07/16 15:12:28
Done.
|
| + EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); |
| + EXPECT_EQ(1u, GetErrorCount()); |
| + EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," |
| + " invalid color specified.", |
| + errors()[0]); |
| + } |
| + |
| + // Accept CSS color keyword format. |
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }"); |
| + EXPECT_EQ(manifest.theme_color, 0xFF0000FF); |
| + EXPECT_EQ(0u, GetErrorCount()); |
| + } |
| + |
| + // Accept CSS color keyword format. |
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": \"chartreuse\" }"); |
| + EXPECT_EQ(manifest.theme_color, 0xFF7FFF00); |
| + EXPECT_EQ(0u, GetErrorCount()); |
| + } |
| + |
| + // Accept CSS RGB format. |
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": \"#FFF\" }"); |
| + EXPECT_EQ(manifest.theme_color, 0xFFFFFFFF); |
| + EXPECT_EQ(0u, GetErrorCount()); |
| + } |
| + |
| + // Accept CSS RGB format. |
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": \"#ABC\" }"); |
| + EXPECT_EQ(manifest.theme_color, 0xFFAABBCC); |
| + EXPECT_EQ(0u, GetErrorCount()); |
| + } |
| + |
| + // Accept CSS RRGGBB format. |
| + { |
| + Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }"); |
| + EXPECT_EQ(manifest.theme_color, 0xFFFF0000); |
| + EXPECT_EQ(0u, GetErrorCount()); |
| + } |
| +} |
| + |
| TEST_F(ManifestParserTest, OrientationParserRules) { |
| // Smoke test. |
| { |