OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/manifest/manifest_parser.h" | 5 #include "content/renderer/manifest/manifest_parser.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "content/public/common/manifest.h" | 8 #include "content/public/common/manifest.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 namespace { | |
14 | |
15 uint32_t ExtractColor(int64_t color) { | |
16 return reinterpret_cast<uint32_t&>(color); | |
17 } | |
18 | |
19 } // anonymous namespace | |
20 | |
13 class ManifestParserTest : public testing::Test { | 21 class ManifestParserTest : public testing::Test { |
14 protected: | 22 protected: |
15 ManifestParserTest() {} | 23 ManifestParserTest() {} |
16 ~ManifestParserTest() override {} | 24 ~ManifestParserTest() override {} |
17 | 25 |
18 Manifest ParseManifestWithURLs(const base::StringPiece& data, | 26 Manifest ParseManifestWithURLs(const base::StringPiece& data, |
19 const GURL& document_url, | 27 const GURL& document_url, |
20 const GURL& manifest_url) { | 28 const GURL& manifest_url) { |
21 ManifestParser parser(data, document_url, manifest_url); | 29 ManifestParser parser(data, document_url, manifest_url); |
22 parser.Parse(); | 30 parser.Parse(); |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
981 ParseManifest("{ \"prefer_related_applications\": false }"); | 989 ParseManifest("{ \"prefer_related_applications\": false }"); |
982 EXPECT_FALSE(manifest.prefer_related_applications); | 990 EXPECT_FALSE(manifest.prefer_related_applications); |
983 EXPECT_EQ(0u, GetErrorCount()); | 991 EXPECT_EQ(0u, GetErrorCount()); |
984 } | 992 } |
985 } | 993 } |
986 | 994 |
987 TEST_F(ManifestParserTest, ThemeColorParserRules) { | 995 TEST_F(ManifestParserTest, ThemeColorParserRules) { |
988 // Smoke test. | 996 // Smoke test. |
989 { | 997 { |
990 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }"); | 998 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }"); |
991 EXPECT_EQ(manifest.theme_color, 0xFFFF0000); | 999 EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFFFF0000); |
992 EXPECT_FALSE(manifest.IsEmpty()); | 1000 EXPECT_FALSE(manifest.IsEmpty()); |
993 EXPECT_EQ(0u, GetErrorCount()); | 1001 EXPECT_EQ(0u, GetErrorCount()); |
994 } | 1002 } |
995 | 1003 |
996 // Trim whitespaces. | 1004 // Trim whitespaces. |
997 { | 1005 { |
998 Manifest manifest = ParseManifest("{ \"theme_color\": \" blue \" }"); | 1006 Manifest manifest = ParseManifest("{ \"theme_color\": \" blue \" }"); |
999 EXPECT_EQ(manifest.theme_color, 0xFF0000FF); | 1007 EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFF0000FF); |
1000 EXPECT_EQ(0u, GetErrorCount()); | 1008 EXPECT_EQ(0u, GetErrorCount()); |
1001 } | 1009 } |
1002 | 1010 |
1003 // Don't parse if theme_color isn't a string. | 1011 // Don't parse if theme_color isn't a string. |
1004 { | 1012 { |
1005 Manifest manifest = ParseManifest("{ \"theme_color\": {} }"); | 1013 Manifest manifest = ParseManifest("{ \"theme_color\": {} }"); |
1006 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); | 1014 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); |
1007 EXPECT_EQ(1u, GetErrorCount()); | 1015 EXPECT_EQ(1u, GetErrorCount()); |
1008 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," | 1016 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored," |
1009 " type string expected.", | 1017 " type string expected.", |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); | 1105 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor); |
1098 EXPECT_EQ(1u, GetErrorCount()); | 1106 EXPECT_EQ(1u, GetErrorCount()); |
1099 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored, " | 1107 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored, " |
1100 "'#AABBCC #DDEEFF' is not a valid color.", | 1108 "'#AABBCC #DDEEFF' is not a valid color.", |
1101 errors()[0]); | 1109 errors()[0]); |
1102 } | 1110 } |
1103 | 1111 |
1104 // Accept CSS color keyword format. | 1112 // Accept CSS color keyword format. |
1105 { | 1113 { |
1106 Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }"); | 1114 Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }"); |
1107 EXPECT_EQ(manifest.theme_color, 0xFF0000FF); | 1115 EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFF0000FF); |
1108 EXPECT_EQ(0u, GetErrorCount()); | 1116 EXPECT_EQ(0u, GetErrorCount()); |
1109 } | 1117 } |
1110 | 1118 |
1111 // Accept CSS color keyword format. | 1119 // Accept CSS color keyword format. |
1112 { | 1120 { |
1113 Manifest manifest = ParseManifest("{ \"theme_color\": \"chartreuse\" }"); | 1121 Manifest manifest = ParseManifest("{ \"theme_color\": \"chartreuse\" }"); |
1114 EXPECT_EQ(manifest.theme_color, 0xFF7FFF00); | 1122 EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFF7FFF00); |
1115 EXPECT_EQ(0u, GetErrorCount()); | 1123 EXPECT_EQ(0u, GetErrorCount()); |
1116 } | 1124 } |
1117 | 1125 |
1118 // Accept CSS RGB format. | 1126 // Accept CSS RGB format. |
1119 { | 1127 { |
1120 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FFF\" }"); | 1128 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FFF\" }"); |
1121 EXPECT_EQ(manifest.theme_color, 0xFFFFFFFF); | 1129 EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFFFFFFFF); |
1122 EXPECT_EQ(0u, GetErrorCount()); | 1130 EXPECT_EQ(0u, GetErrorCount()); |
1123 } | 1131 } |
1124 | 1132 |
1125 // Accept CSS RGB format. | 1133 // Accept CSS RGB format. |
1126 { | 1134 { |
1127 Manifest manifest = ParseManifest("{ \"theme_color\": \"#ABC\" }"); | 1135 Manifest manifest = ParseManifest("{ \"theme_color\": \"#ABC\" }"); |
1128 EXPECT_EQ(manifest.theme_color, 0xFFAABBCC); | 1136 EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFFAABBCC); |
1129 EXPECT_EQ(0u, GetErrorCount()); | 1137 EXPECT_EQ(0u, GetErrorCount()); |
1130 } | 1138 } |
1131 | 1139 |
1132 // Accept CSS RRGGBB format. | 1140 // Accept CSS RRGGBB format. |
1133 { | 1141 { |
1134 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }"); | 1142 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }"); |
1135 EXPECT_EQ(manifest.theme_color, 0xFFFF0000); | 1143 EXPECT_EQ(ExtractColor(manifest.theme_color), 0xFFFF0000); |
1136 EXPECT_EQ(0u, GetErrorCount()); | 1144 EXPECT_EQ(0u, GetErrorCount()); |
1137 } | 1145 } |
Bernhard Bauer
2015/07/31 10:07:45
Out of curiosity, do we allow transparent colors h
Lalit Maganti
2015/07/31 10:13:17
As far as I know there is no check against it here
Bernhard Bauer
2015/07/31 10:26:55
OK, in that case would it make sense to add tests
mlamouri (slow - plz ping)
2015/08/05 13:35:33
We could add a test with AA=00 in there, right?
| |
1138 } | 1146 } |
1139 | 1147 |
1140 TEST_F(ManifestParserTest, GCMSenderIDParseRules) { | 1148 TEST_F(ManifestParserTest, GCMSenderIDParseRules) { |
1141 // Smoke test. | 1149 // Smoke test. |
1142 { | 1150 { |
1143 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); | 1151 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); |
1144 EXPECT_TRUE(base::EqualsASCII(manifest.gcm_sender_id.string(), "foo")); | 1152 EXPECT_TRUE(base::EqualsASCII(manifest.gcm_sender_id.string(), "foo")); |
1145 EXPECT_EQ(0u, GetErrorCount()); | 1153 EXPECT_EQ(0u, GetErrorCount()); |
1146 } | 1154 } |
1147 | 1155 |
(...skipping 17 matching lines...) Expand all Loading... | |
1165 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); | 1173 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); |
1166 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 1174 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
1167 EXPECT_EQ(1u, GetErrorCount()); | 1175 EXPECT_EQ(1u, GetErrorCount()); |
1168 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," | 1176 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," |
1169 " type string expected.", | 1177 " type string expected.", |
1170 errors()[0]); | 1178 errors()[0]); |
1171 } | 1179 } |
1172 } | 1180 } |
1173 | 1181 |
1174 } // namespace content | 1182 } // namespace content |
OLD | NEW |