| 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 4311531436d78de57d0c0b231a1da9f67df11f81..974c69ae7e0174c18427a0625c22f584036b5ad1 100644
|
| --- a/content/renderer/manifest/manifest_parser_unittest.cc
|
| +++ b/content/renderer/manifest/manifest_parser_unittest.cc
|
| @@ -15,14 +15,6 @@
|
|
|
| namespace content {
|
|
|
| -namespace {
|
| -
|
| -uint32_t ExtractColor(int64_t color) {
|
| - return reinterpret_cast<uint32_t&>(color);
|
| -}
|
| -
|
| -} // anonymous namespace
|
| -
|
| class ManifestParserTest : public testing::Test {
|
| protected:
|
| ManifestParserTest() {}
|
| @@ -98,8 +90,8 @@ TEST_F(ManifestParserTest, EmptyStringNull) {
|
| ASSERT_TRUE(manifest.start_url.is_empty());
|
| ASSERT_EQ(manifest.display, blink::WebDisplayModeUndefined);
|
| ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
|
| - ASSERT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| - ASSERT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + ASSERT_FALSE(manifest.theme_color.has_value());
|
| + ASSERT_FALSE(manifest.background_color.has_value());
|
| ASSERT_TRUE(manifest.gcm_sender_id.is_null());
|
| ASSERT_TRUE(manifest.scope.is_empty());
|
| }
|
| @@ -117,8 +109,8 @@ TEST_F(ManifestParserTest, ValidNoContentParses) {
|
| ASSERT_TRUE(manifest.start_url.is_empty());
|
| ASSERT_EQ(manifest.display, blink::WebDisplayModeUndefined);
|
| ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
|
| - ASSERT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| - ASSERT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + ASSERT_FALSE(manifest.theme_color.has_value());
|
| + ASSERT_FALSE(manifest.background_color.has_value());
|
| ASSERT_TRUE(manifest.gcm_sender_id.is_null());
|
| ASSERT_TRUE(manifest.scope.is_empty());
|
| }
|
| @@ -1063,7 +1055,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Smoke test.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFFFF0000u);
|
| + EXPECT_EQ(0xFFFF0000, manifest.theme_color);
|
| EXPECT_FALSE(manifest.IsEmpty());
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
| @@ -1071,14 +1063,14 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Trim whitespaces.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \" blue \" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFF0000FFu);
|
| + EXPECT_EQ(0xFF0000FFu, manifest.theme_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Don't parse if theme_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": {} }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1087,7 +1079,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Don't parse if theme_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": false }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1096,7 +1088,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Don't parse if theme_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": null }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1105,7 +1097,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Don't parse if theme_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": [] }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1114,7 +1106,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Don't parse if theme_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": 42 }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1123,7 +1115,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Parse fails if string is not in a known format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"foo(bar)\" }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored,"
|
| " 'foo(bar)' is not a valid color.",
|
| @@ -1133,7 +1125,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Parse fails if string is not in a known format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"bleu\" }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, 'bleu' is not a valid color.",
|
| errors()[0]);
|
| @@ -1142,7 +1134,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Parse fails if string is not in a known format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"FF00FF\" }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, 'FF00FF'"
|
| " is not a valid color.",
|
| @@ -1152,7 +1144,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Parse fails if multiple values for theme_color are given.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"#ABC #DEF\" }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, "
|
| "'#ABC #DEF' is not a valid color.",
|
| @@ -1163,7 +1155,7 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| {
|
| Manifest manifest = ParseManifest(
|
| "{ \"theme_color\": \"#AABBCC #DDEEFF\" }");
|
| - EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.theme_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'theme_color' ignored, "
|
| "'#AABBCC #DDEEFF' is not a valid color.",
|
| @@ -1173,35 +1165,35 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| // Accept CSS color keyword format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFF0000FFu);
|
| + EXPECT_EQ(0xFF0000FFu, manifest.theme_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Accept CSS color keyword format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"chartreuse\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFF7FFF00u);
|
| + EXPECT_EQ(0xFF7FFF00u, manifest.theme_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Accept CSS RGB format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"#FFF\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFFFFFFFFu);
|
| + EXPECT_EQ(0xFFFFFFFFu, manifest.theme_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Accept CSS RGB format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"#ABC\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFFAABBCCu);
|
| + EXPECT_EQ(0xFFAABBCCu, manifest.theme_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Accept CSS RRGGBB format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFFFF0000u);
|
| + EXPECT_EQ(0xFFFF0000u, manifest.theme_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| @@ -1209,14 +1201,14 @@ TEST_F(ManifestParserTest, ThemeColorParserRules) {
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"rgba(255,0,0,"
|
| "0.4)\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0x66FF0000u);
|
| + EXPECT_EQ(0x66FF0000u, manifest.theme_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Accept transparent colors.
|
| {
|
| Manifest manifest = ParseManifest("{ \"theme_color\": \"rgba(0,0,0,0)\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.theme_color), 0x00000000u);
|
| + EXPECT_EQ(0x00000000u, manifest.theme_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
| }
|
| @@ -1225,7 +1217,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Smoke test.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"#FF0000\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0xFFFF0000u);
|
| + EXPECT_EQ(0xFFFF0000u, manifest.background_color);
|
| EXPECT_FALSE(manifest.IsEmpty());
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
| @@ -1234,14 +1226,14 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| {
|
| Manifest manifest = ParseManifest(
|
| "{ \"background_color\": \" blue \" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0xFF0000FFu);
|
| + EXPECT_EQ(0xFF0000FFu, manifest.background_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Don't parse if background_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": {} }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1250,7 +1242,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Don't parse if background_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": false }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1259,7 +1251,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Don't parse if background_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": null }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1268,7 +1260,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Don't parse if background_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": [] }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1277,7 +1269,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Don't parse if background_color isn't a string.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": 42 }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored, type string expected.",
|
| errors()[0]);
|
| @@ -1286,7 +1278,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Parse fails if string is not in a known format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"foo(bar)\" }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored,"
|
| " 'foo(bar)' is not a valid color.",
|
| @@ -1296,7 +1288,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Parse fails if string is not in a known format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"bleu\" }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored,"
|
| " 'bleu' is not a valid color.",
|
| @@ -1306,7 +1298,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Parse fails if string is not in a known format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"FF00FF\" }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored,"
|
| " 'FF00FF' is not a valid color.",
|
| @@ -1317,7 +1309,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| {
|
| Manifest manifest = ParseManifest(
|
| "{ \"background_color\": \"#ABC #DEF\" }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored, "
|
| "'#ABC #DEF' is not a valid color.",
|
| @@ -1328,7 +1320,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| {
|
| Manifest manifest = ParseManifest(
|
| "{ \"background_color\": \"#AABBCC #DDEEFF\" }");
|
| - EXPECT_EQ(manifest.background_color, Manifest::kInvalidOrMissingColor);
|
| + EXPECT_FALSE(manifest.background_color.has_value());
|
| EXPECT_EQ(1u, GetErrorCount());
|
| EXPECT_EQ("property 'background_color' ignored, "
|
| "'#AABBCC #DDEEFF' is not a valid color.",
|
| @@ -1338,7 +1330,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| // Accept CSS color keyword format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"blue\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0xFF0000FFu);
|
| + EXPECT_EQ(0xFF0000FFu, manifest.background_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| @@ -1346,28 +1338,28 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| {
|
| Manifest manifest = ParseManifest(
|
| "{ \"background_color\": \"chartreuse\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0xFF7FFF00u);
|
| + EXPECT_EQ(0xFF7FFF00u, manifest.background_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Accept CSS RGB format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"#FFF\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0xFFFFFFFFu);
|
| + EXPECT_EQ(0xFFFFFFFFu, manifest.background_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Accept CSS RGB format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"#ABC\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0xFFAABBCCu);
|
| + EXPECT_EQ(0xFFAABBCCu, manifest.background_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| // Accept CSS RRGGBB format.
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"#FF0000\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0xFFFF0000u);
|
| + EXPECT_EQ(0xFFFF0000, manifest.background_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| @@ -1375,7 +1367,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"rgba(255,0,0,"
|
| "0.4)\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0x66FF0000u);
|
| + EXPECT_EQ(0x66FF0000u, manifest.background_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
|
|
| @@ -1383,7 +1375,7 @@ TEST_F(ManifestParserTest, BackgroundColorParserRules) {
|
| {
|
| Manifest manifest = ParseManifest("{ \"background_color\": \"rgba(0,0,0,"
|
| "0)\" }");
|
| - EXPECT_EQ(ExtractColor(manifest.background_color), 0x00000000u);
|
| + EXPECT_EQ(0x00000000u, manifest.background_color);
|
| EXPECT_EQ(0u, GetErrorCount());
|
| }
|
| }
|
|
|