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..e6b72436993f8c92c6863007e128124ad97137b3 100644 |
--- a/content/renderer/manifest/manifest_parser_unittest.cc |
+++ b/content/renderer/manifest/manifest_parser_unittest.cc |
@@ -77,6 +77,7 @@ TEST_F(ManifestParserTest, EmptyStringNull) { |
ASSERT_TRUE(manifest.short_name.is_null()); |
ASSERT_TRUE(manifest.start_url.is_empty()); |
ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
+ ASSERT_EQ(manifest.theme_color, Manifest::kInvalidThemeColor); |
ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
ASSERT_TRUE(manifest.gcm_sender_id.is_null()); |
} |
@@ -93,16 +94,17 @@ TEST_F(ManifestParserTest, ValidNoContentParses) { |
ASSERT_TRUE(manifest.short_name.is_null()); |
ASSERT_TRUE(manifest.start_url.is_empty()); |
ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
+ ASSERT_EQ(manifest.theme_color, Manifest::kInvalidThemeColor); |
ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
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\": {} }"); |
+ "\"theme_color\": 42, \"orientation\": {}, \"display\": \"foo\"," |
+ "\"start_url\": null, \"icons\": {} }"); |
- EXPECT_EQ(6u, GetErrorCount()); |
+ EXPECT_EQ(7u, GetErrorCount()); |
EXPECT_EQ("Manifest parsing error: property 'name' ignored," |
" type string expected.", |
@@ -115,12 +117,15 @@ TEST_F(ManifestParserTest, MultipleErrorsReporting) { |
errors()[2]); |
EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.", |
errors()[3]); |
- EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," |
+ EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," |
" type string expected.", |
errors()[4]); |
+ EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," |
+ " type string expected.", |
+ errors()[5]); |
EXPECT_EQ("Manifest parsing error: property 'icons' ignored, " |
"type array expected.", |
- errors()[5]); |
+ errors()[6]); |
} |
TEST_F(ManifestParserTest, NameParseRules) { |
@@ -350,6 +355,81 @@ TEST_F(ManifestParserTest, DisplayParserRules) { |
} |
} |
+TEST_F(ManifestParserTest, ThemeColorParserRules) { |
+ // Smoke test. |
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }"); |
mlamouri (slow - plz ping)
2015/07/16 12:35:41
Remove that test, it's not a smoke test.
Lalit Maganti
2015/07/16 14:49:02
Done.
|
+ EXPECT_EQ(manifest.theme_color, 0xFF0000FF); |
+ EXPECT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // Smoke test. |
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }"); |
+ EXPECT_EQ(manifest.theme_color, 0xFFFF0000); |
+ EXPECT_FALSE(manifest.IsEmpty()); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // Trim whitespaces. |
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }"); |
mlamouri (slow - plz ping)
2015/07/16 12:35:41
You don't actually have whitespaces here.
Lalit Maganti
2015/07/16 14:49:02
Removed this test - doesn't really apply.
|
+ EXPECT_EQ(manifest.theme_color, 0xFF0000FF); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // Don't parse if name isn't a string. |
mlamouri (slow - plz ping)
2015/07/16 12:35:41
nit: s/name/theme_color/
Lalit Maganti
2015/07/16 14:49:02
Done.
|
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": {} }"); |
+ EXPECT_EQ(manifest.theme_color, Manifest::kInvalidThemeColor); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," |
+ " type string expected.", |
+ errors()[0]); |
+ } |
+ |
+ // Don't parse if name isn't a string. |
mlamouri (slow - plz ping)
2015/07/16 12:35:41
ditto.
Lalit Maganti
2015/07/16 14:49:02
Done.
|
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": 42 }"); |
+ EXPECT_EQ(manifest.theme_color, Manifest::kInvalidThemeColor); |
+ 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. |
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": \"foo(bar)\" }"); |
+ EXPECT_EQ(manifest.theme_color, -1); |
+ EXPECT_EQ(1u, GetErrorCount()); |
+ EXPECT_EQ("Manifest parsing error: unable to parse 'theme_color' as color.", |
+ errors()[0]); |
+ } |
+ |
+ // Accept CSS color keyword format. |
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }"); |
mlamouri (slow - plz ping)
2015/07/16 12:35:41
Could you also test a less common value like 'char
Lalit Maganti
2015/07/16 14:49:02
Done.
|
+ EXPECT_EQ(manifest.theme_color, 0xFF0000FF); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // Accept CSS RGB format. |
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": \"#FFF\" }"); |
mlamouri (slow - plz ping)
2015/07/16 12:35:41
Try #ABC too. #FFF could be a side effect.
Lalit Maganti
2015/07/16 14:49:02
Done.
|
+ EXPECT_EQ(manifest.theme_color, 0xFFFFFFFF); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
+ |
+ // Accept CSS RRGGBB format. |
+ { |
+ Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }"); |
+ EXPECT_EQ(manifest.theme_color, 0xFFFF0000); |
+ EXPECT_EQ(0u, GetErrorCount()); |
+ } |
mlamouri (slow - plz ping)
2015/07/16 12:35:41
Could you add a test checking that we don't parse
Lalit Maganti
2015/07/16 14:49:02
Done.
|
+} |
+ |
TEST_F(ManifestParserTest, OrientationParserRules) { |
// Smoke test. |
{ |