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 class ManifestParserTest : public testing::Test { | 13 class ManifestParserTest : public testing::Test { |
14 protected: | 14 protected: |
15 ManifestParserTest() {} | 15 ManifestParserTest() {} |
16 ~ManifestParserTest() override {} | 16 ~ManifestParserTest() override {} |
17 | 17 |
18 Manifest ParseManifest(const base::StringPiece& json, | 18 Manifest ParseManifest(const base::StringPiece& json, |
Peter Beverloo
2014/11/27 13:24:31
micro nit: you call this |data| elsewhere.
mlamouri (slow - plz ping)
2014/11/27 13:49:09
Done.
| |
19 const GURL& document_url = default_document_url, | 19 const GURL& document_url = default_document_url, |
20 const GURL& manifest_url = default_manifest_url) { | 20 const GURL& manifest_url = default_manifest_url) { |
21 return ManifestParser::Parse(json, document_url, manifest_url); | 21 ManifestParser parser(json, document_url, manifest_url); |
22 parser.Parse(); | |
23 errors_ = parser.errors(); | |
24 return parser.manifest(); | |
25 } | |
Peter Beverloo
2014/11/27 13:24:31
Whilst annoying (as indicated by your stumbling ac
mlamouri (slow - plz ping)
2014/11/27 13:49:09
Done.
| |
26 | |
27 const std::vector<std::string>& GetParseErrors() const { | |
Peter Beverloo
2014/11/27 13:24:31
nit: this should be named errors().
mlamouri (slow - plz ping)
2014/11/27 13:49:09
Done.
| |
28 return errors_; | |
22 } | 29 } |
23 | 30 |
24 static const GURL default_document_url; | 31 static const GURL default_document_url; |
25 static const GURL default_manifest_url; | 32 static const GURL default_manifest_url; |
26 | 33 |
27 private: | 34 private: |
35 std::vector<std::string> errors_; | |
36 | |
28 DISALLOW_COPY_AND_ASSIGN(ManifestParserTest); | 37 DISALLOW_COPY_AND_ASSIGN(ManifestParserTest); |
29 }; | 38 }; |
30 | 39 |
31 const GURL ManifestParserTest::default_document_url( | 40 const GURL ManifestParserTest::default_document_url( |
32 "http://foo.com/index.html"); | 41 "http://foo.com/index.html"); |
33 const GURL ManifestParserTest::default_manifest_url( | 42 const GURL ManifestParserTest::default_manifest_url( |
34 "http://foo.com/manifest.json"); | 43 "http://foo.com/manifest.json"); |
35 | 44 |
36 TEST_F(ManifestParserTest, EmptyStringNull) { | 45 TEST_F(ManifestParserTest, EmptyStringNull) { |
37 Manifest manifest = ParseManifest(""); | 46 Manifest manifest = ParseManifest(""); |
38 | 47 |
48 // This Manifest is not a valid JSON object, it's a parsing error. | |
49 EXPECT_EQ(1u, GetParseErrors().size()); | |
50 EXPECT_EQ("Manifest parsing error: Line: 1, column: 1, Unexpected token.", | |
51 GetParseErrors()[0]); | |
52 | |
39 // A parsing error is equivalent to an empty manifest. | 53 // A parsing error is equivalent to an empty manifest. |
40 ASSERT_TRUE(manifest.IsEmpty()); | 54 ASSERT_TRUE(manifest.IsEmpty()); |
41 ASSERT_TRUE(manifest.name.is_null()); | 55 ASSERT_TRUE(manifest.name.is_null()); |
42 ASSERT_TRUE(manifest.short_name.is_null()); | 56 ASSERT_TRUE(manifest.short_name.is_null()); |
43 ASSERT_TRUE(manifest.start_url.is_empty()); | 57 ASSERT_TRUE(manifest.start_url.is_empty()); |
44 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); | 58 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
45 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); | 59 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
46 } | 60 } |
47 | 61 |
48 TEST_F(ManifestParserTest, ValidNoContentParses) { | 62 TEST_F(ManifestParserTest, ValidNoContentParses) { |
49 Manifest manifest = ParseManifest("{}"); | 63 Manifest manifest = ParseManifest("{}"); |
50 | 64 |
65 // Empty Manifest is not a parsing error. | |
66 EXPECT_EQ(0u, GetParseErrors().size()); | |
67 | |
51 // Check that all the fields are null in that case. | 68 // Check that all the fields are null in that case. |
52 ASSERT_TRUE(manifest.IsEmpty()); | 69 ASSERT_TRUE(manifest.IsEmpty()); |
53 ASSERT_TRUE(manifest.name.is_null()); | 70 ASSERT_TRUE(manifest.name.is_null()); |
54 ASSERT_TRUE(manifest.short_name.is_null()); | 71 ASSERT_TRUE(manifest.short_name.is_null()); |
55 ASSERT_TRUE(manifest.start_url.is_empty()); | 72 ASSERT_TRUE(manifest.start_url.is_empty()); |
56 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); | 73 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
57 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); | 74 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
58 } | 75 } |
59 | 76 |
77 TEST_F(ManifestParserTest, MultipleErrorsReporting) { | |
78 Manifest manifest = ParseManifest("{ \"name\": 42, \"short_name\": 4," | |
79 "\"orientation\": {}, \"display\": \"foo\", \"start_url\": null," | |
80 "\"icons\": {} }"); | |
81 | |
82 EXPECT_EQ(6u, GetParseErrors().size()); | |
83 | |
84 EXPECT_EQ("Manifest parsing error: property 'name' ignored," | |
85 " type string expected.", | |
86 GetParseErrors()[0]); | |
87 EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," | |
88 " type string expected.", | |
89 GetParseErrors()[1]); | |
90 EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," | |
91 " type string expected.", | |
92 GetParseErrors()[2]); | |
93 EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.", | |
94 GetParseErrors()[3]); | |
95 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," | |
96 " type string expected.", | |
97 GetParseErrors()[4]); | |
98 EXPECT_EQ("Manifest parsing error: property 'icons' ignored, " | |
99 "type array expected.", | |
100 GetParseErrors()[5]); | |
101 } | |
102 | |
60 TEST_F(ManifestParserTest, NameParseRules) { | 103 TEST_F(ManifestParserTest, NameParseRules) { |
61 // Smoke test. | 104 // Smoke test. |
62 { | 105 { |
63 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); | 106 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); |
64 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); | 107 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); |
65 ASSERT_FALSE(manifest.IsEmpty()); | 108 ASSERT_FALSE(manifest.IsEmpty()); |
109 EXPECT_EQ(0u, GetParseErrors().size()); | |
66 } | 110 } |
67 | 111 |
68 // Trim whitespaces. | 112 // Trim whitespaces. |
69 { | 113 { |
70 Manifest manifest = ParseManifest("{ \"name\": \" foo \" }"); | 114 Manifest manifest = ParseManifest("{ \"name\": \" foo \" }"); |
71 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); | 115 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); |
116 EXPECT_EQ(0u, GetParseErrors().size()); | |
72 } | 117 } |
73 | 118 |
74 // Don't parse if name isn't a string. | 119 // Don't parse if name isn't a string. |
75 { | 120 { |
76 Manifest manifest = ParseManifest("{ \"name\": {} }"); | 121 Manifest manifest = ParseManifest("{ \"name\": {} }"); |
77 ASSERT_TRUE(manifest.name.is_null()); | 122 ASSERT_TRUE(manifest.name.is_null()); |
123 EXPECT_EQ(1u, GetParseErrors().size()); | |
124 EXPECT_EQ("Manifest parsing error: property 'name' ignored," | |
125 " type string expected.", | |
126 GetParseErrors()[0]); | |
78 } | 127 } |
79 | 128 |
80 // Don't parse if name isn't a string. | 129 // Don't parse if name isn't a string. |
81 { | 130 { |
82 Manifest manifest = ParseManifest("{ \"name\": 42 }"); | 131 Manifest manifest = ParseManifest("{ \"name\": 42 }"); |
83 ASSERT_TRUE(manifest.name.is_null()); | 132 ASSERT_TRUE(manifest.name.is_null()); |
133 EXPECT_EQ(1u, GetParseErrors().size()); | |
134 EXPECT_EQ("Manifest parsing error: property 'name' ignored," | |
135 " type string expected.", | |
136 GetParseErrors()[0]); | |
84 } | 137 } |
85 } | 138 } |
86 | 139 |
87 TEST_F(ManifestParserTest, ShortNameParseRules) { | 140 TEST_F(ManifestParserTest, ShortNameParseRules) { |
88 // Smoke test. | 141 // Smoke test. |
89 { | 142 { |
90 Manifest manifest = ParseManifest("{ \"short_name\": \"foo\" }"); | 143 Manifest manifest = ParseManifest("{ \"short_name\": \"foo\" }"); |
91 ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); | 144 ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); |
92 ASSERT_FALSE(manifest.IsEmpty()); | 145 ASSERT_FALSE(manifest.IsEmpty()); |
146 EXPECT_EQ(0u, GetParseErrors().size()); | |
93 } | 147 } |
94 | 148 |
95 // Trim whitespaces. | 149 // Trim whitespaces. |
96 { | 150 { |
97 Manifest manifest = ParseManifest("{ \"short_name\": \" foo \" }"); | 151 Manifest manifest = ParseManifest("{ \"short_name\": \" foo \" }"); |
98 ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); | 152 ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); |
153 EXPECT_EQ(0u, GetParseErrors().size()); | |
99 } | 154 } |
100 | 155 |
101 // Don't parse if name isn't a string. | 156 // Don't parse if name isn't a string. |
102 { | 157 { |
103 Manifest manifest = ParseManifest("{ \"short_name\": {} }"); | 158 Manifest manifest = ParseManifest("{ \"short_name\": {} }"); |
104 ASSERT_TRUE(manifest.short_name.is_null()); | 159 ASSERT_TRUE(manifest.short_name.is_null()); |
160 EXPECT_EQ(1u, GetParseErrors().size()); | |
161 EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," | |
162 " type string expected.", | |
163 GetParseErrors()[0]); | |
105 } | 164 } |
106 | 165 |
107 // Don't parse if name isn't a string. | 166 // Don't parse if name isn't a string. |
108 { | 167 { |
109 Manifest manifest = ParseManifest("{ \"short_name\": 42 }"); | 168 Manifest manifest = ParseManifest("{ \"short_name\": 42 }"); |
110 ASSERT_TRUE(manifest.short_name.is_null()); | 169 ASSERT_TRUE(manifest.short_name.is_null()); |
170 EXPECT_EQ(1u, GetParseErrors().size()); | |
171 EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," | |
172 " type string expected.", | |
173 GetParseErrors()[0]); | |
111 } | 174 } |
112 } | 175 } |
113 | 176 |
114 TEST_F(ManifestParserTest, StartURLParseRules) { | 177 TEST_F(ManifestParserTest, StartURLParseRules) { |
115 // Smoke test. | 178 // Smoke test. |
116 { | 179 { |
117 Manifest manifest = ParseManifest("{ \"start_url\": \"land.html\" }"); | 180 Manifest manifest = ParseManifest("{ \"start_url\": \"land.html\" }"); |
118 ASSERT_EQ(manifest.start_url.spec(), | 181 ASSERT_EQ(manifest.start_url.spec(), |
119 default_document_url.Resolve("land.html").spec()); | 182 default_document_url.Resolve("land.html").spec()); |
120 ASSERT_FALSE(manifest.IsEmpty()); | 183 ASSERT_FALSE(manifest.IsEmpty()); |
184 EXPECT_EQ(0u, GetParseErrors().size()); | |
121 } | 185 } |
122 | 186 |
123 // Whitespaces. | 187 // Whitespaces. |
124 { | 188 { |
125 Manifest manifest = ParseManifest("{ \"start_url\": \" land.html \" }"); | 189 Manifest manifest = ParseManifest("{ \"start_url\": \" land.html \" }"); |
126 ASSERT_EQ(manifest.start_url.spec(), | 190 ASSERT_EQ(manifest.start_url.spec(), |
127 default_document_url.Resolve("land.html").spec()); | 191 default_document_url.Resolve("land.html").spec()); |
192 EXPECT_EQ(0u, GetParseErrors().size()); | |
128 } | 193 } |
129 | 194 |
130 // Don't parse if property isn't a string. | 195 // Don't parse if property isn't a string. |
131 { | 196 { |
132 Manifest manifest = ParseManifest("{ \"start_url\": {} }"); | 197 Manifest manifest = ParseManifest("{ \"start_url\": {} }"); |
133 ASSERT_TRUE(manifest.start_url.is_empty()); | 198 ASSERT_TRUE(manifest.start_url.is_empty()); |
199 EXPECT_EQ(1u, GetParseErrors().size()); | |
200 EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," | |
201 " type string expected.", | |
202 GetParseErrors()[0]); | |
134 } | 203 } |
135 | 204 |
136 // Don't parse if property isn't a string. | 205 // Don't parse if property isn't a string. |
137 { | 206 { |
138 Manifest manifest = ParseManifest("{ \"start_url\": 42 }"); | 207 Manifest manifest = ParseManifest("{ \"start_url\": 42 }"); |
139 ASSERT_TRUE(manifest.start_url.is_empty()); | 208 ASSERT_TRUE(manifest.start_url.is_empty()); |
209 EXPECT_EQ(1u, GetParseErrors().size()); | |
210 EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," | |
211 " type string expected.", | |
212 GetParseErrors()[0]); | |
140 } | 213 } |
141 | 214 |
142 // Absolute start_url, same origin with document. | 215 // Absolute start_url, same origin with document. |
143 { | 216 { |
144 Manifest manifest = | 217 Manifest manifest = |
145 ParseManifest("{ \"start_url\": \"http://foo.com/land.html\" }", | 218 ParseManifest("{ \"start_url\": \"http://foo.com/land.html\" }", |
146 GURL("http://foo.com/manifest.json"), | 219 GURL("http://foo.com/manifest.json"), |
147 GURL("http://foo.com/index.html")); | 220 GURL("http://foo.com/index.html")); |
148 ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/land.html"); | 221 ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/land.html"); |
222 EXPECT_EQ(0u, GetParseErrors().size()); | |
149 } | 223 } |
150 | 224 |
151 // Absolute start_url, cross origin with document. | 225 // Absolute start_url, cross origin with document. |
152 { | 226 { |
153 Manifest manifest = | 227 Manifest manifest = |
154 ParseManifest("{ \"start_url\": \"http://bar.com/land.html\" }", | 228 ParseManifest("{ \"start_url\": \"http://bar.com/land.html\" }", |
155 GURL("http://foo.com/manifest.json"), | 229 GURL("http://foo.com/manifest.json"), |
156 GURL("http://foo.com/index.html")); | 230 GURL("http://foo.com/index.html")); |
157 ASSERT_TRUE(manifest.start_url.is_empty()); | 231 ASSERT_TRUE(manifest.start_url.is_empty()); |
232 EXPECT_EQ(1u, GetParseErrors().size()); | |
233 EXPECT_EQ("Manifest parsing error: property 'start_url' ignored, should " | |
234 "be same origin as Document.", | |
235 GetParseErrors()[0]); | |
158 } | 236 } |
159 | 237 |
160 // Resolving has to happen based on the manifest_url. | 238 // Resolving has to happen based on the manifest_url. |
161 { | 239 { |
162 Manifest manifest = | 240 Manifest manifest = |
163 ParseManifest("{ \"start_url\": \"land.html\" }", | 241 ParseManifest("{ \"start_url\": \"land.html\" }", |
164 GURL("http://foo.com/landing/manifest.json"), | 242 GURL("http://foo.com/landing/manifest.json"), |
165 GURL("http://foo.com/index.html")); | 243 GURL("http://foo.com/index.html")); |
166 ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/landing/land.html"); | 244 ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/landing/land.html"); |
245 EXPECT_EQ(0u, GetParseErrors().size()); | |
167 } | 246 } |
168 } | 247 } |
169 | 248 |
170 TEST_F(ManifestParserTest, DisplayParserRules) { | 249 TEST_F(ManifestParserTest, DisplayParserRules) { |
171 // Smoke test. | 250 // Smoke test. |
172 { | 251 { |
173 Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); | 252 Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); |
174 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); | 253 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
175 EXPECT_FALSE(manifest.IsEmpty()); | 254 EXPECT_FALSE(manifest.IsEmpty()); |
255 EXPECT_EQ(0u, GetParseErrors().size()); | |
176 } | 256 } |
177 | 257 |
178 // Trim whitespaces. | 258 // Trim whitespaces. |
179 { | 259 { |
180 Manifest manifest = ParseManifest("{ \"display\": \" browser \" }"); | 260 Manifest manifest = ParseManifest("{ \"display\": \" browser \" }"); |
181 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); | 261 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
262 EXPECT_EQ(0u, GetParseErrors().size()); | |
182 } | 263 } |
183 | 264 |
184 // Don't parse if name isn't a string. | 265 // Don't parse if name isn't a string. |
185 { | 266 { |
186 Manifest manifest = ParseManifest("{ \"display\": {} }"); | 267 Manifest manifest = ParseManifest("{ \"display\": {} }"); |
187 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); | 268 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
269 EXPECT_EQ(1u, GetParseErrors().size()); | |
270 EXPECT_EQ("Manifest parsing error: property 'display' ignored," | |
271 " type string expected.", | |
272 GetParseErrors()[0]); | |
188 } | 273 } |
189 | 274 |
190 // Don't parse if name isn't a string. | 275 // Don't parse if name isn't a string. |
191 { | 276 { |
192 Manifest manifest = ParseManifest("{ \"display\": 42 }"); | 277 Manifest manifest = ParseManifest("{ \"display\": 42 }"); |
193 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); | 278 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
279 EXPECT_EQ(1u, GetParseErrors().size()); | |
280 EXPECT_EQ("Manifest parsing error: property 'display' ignored," | |
281 " type string expected.", | |
282 GetParseErrors()[0]); | |
194 } | 283 } |
195 | 284 |
196 // Parse fails if string isn't known. | 285 // Parse fails if string isn't known. |
197 { | 286 { |
198 Manifest manifest = ParseManifest("{ \"display\": \"browser_something\" }"); | 287 Manifest manifest = ParseManifest("{ \"display\": \"browser_something\" }"); |
199 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); | 288 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
289 EXPECT_EQ(1u, GetParseErrors().size()); | |
290 EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.", | |
291 GetParseErrors()[0]); | |
200 } | 292 } |
201 | 293 |
202 // Accept 'fullscreen'. | 294 // Accept 'fullscreen'. |
203 { | 295 { |
204 Manifest manifest = ParseManifest("{ \"display\": \"fullscreen\" }"); | 296 Manifest manifest = ParseManifest("{ \"display\": \"fullscreen\" }"); |
205 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_FULLSCREEN); | 297 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_FULLSCREEN); |
298 EXPECT_EQ(0u, GetParseErrors().size()); | |
206 } | 299 } |
207 | 300 |
208 // Accept 'fullscreen'. | 301 // Accept 'fullscreen'. |
209 { | 302 { |
210 Manifest manifest = ParseManifest("{ \"display\": \"standalone\" }"); | 303 Manifest manifest = ParseManifest("{ \"display\": \"standalone\" }"); |
211 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_STANDALONE); | 304 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_STANDALONE); |
305 EXPECT_EQ(0u, GetParseErrors().size()); | |
212 } | 306 } |
213 | 307 |
214 // Accept 'minimal-ui'. | 308 // Accept 'minimal-ui'. |
215 { | 309 { |
216 Manifest manifest = ParseManifest("{ \"display\": \"minimal-ui\" }"); | 310 Manifest manifest = ParseManifest("{ \"display\": \"minimal-ui\" }"); |
217 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_MINIMAL_UI); | 311 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_MINIMAL_UI); |
312 EXPECT_EQ(0u, GetParseErrors().size()); | |
218 } | 313 } |
219 | 314 |
220 // Accept 'browser'. | 315 // Accept 'browser'. |
221 { | 316 { |
222 Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); | 317 Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); |
223 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); | 318 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
319 EXPECT_EQ(0u, GetParseErrors().size()); | |
224 } | 320 } |
225 | 321 |
226 // Case insensitive. | 322 // Case insensitive. |
227 { | 323 { |
228 Manifest manifest = ParseManifest("{ \"display\": \"BROWSER\" }"); | 324 Manifest manifest = ParseManifest("{ \"display\": \"BROWSER\" }"); |
229 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); | 325 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
326 EXPECT_EQ(0u, GetParseErrors().size()); | |
230 } | 327 } |
231 } | 328 } |
232 | 329 |
233 TEST_F(ManifestParserTest, OrientationParserRules) { | 330 TEST_F(ManifestParserTest, OrientationParserRules) { |
234 // Smoke test. | 331 // Smoke test. |
235 { | 332 { |
236 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); | 333 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); |
237 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); | 334 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); |
238 EXPECT_FALSE(manifest.IsEmpty()); | 335 EXPECT_FALSE(manifest.IsEmpty()); |
336 EXPECT_EQ(0u, GetParseErrors().size()); | |
239 } | 337 } |
240 | 338 |
241 // Trim whitespaces. | 339 // Trim whitespaces. |
242 { | 340 { |
243 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); | 341 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); |
244 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); | 342 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); |
343 EXPECT_EQ(0u, GetParseErrors().size()); | |
245 } | 344 } |
246 | 345 |
247 // Don't parse if name isn't a string. | 346 // Don't parse if name isn't a string. |
248 { | 347 { |
249 Manifest manifest = ParseManifest("{ \"orientation\": {} }"); | 348 Manifest manifest = ParseManifest("{ \"orientation\": {} }"); |
250 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); | 349 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
350 EXPECT_EQ(1u, GetParseErrors().size()); | |
351 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," | |
352 " type string expected.", | |
353 GetParseErrors()[0]); | |
251 } | 354 } |
252 | 355 |
253 // Don't parse if name isn't a string. | 356 // Don't parse if name isn't a string. |
254 { | 357 { |
255 Manifest manifest = ParseManifest("{ \"orientation\": 42 }"); | 358 Manifest manifest = ParseManifest("{ \"orientation\": 42 }"); |
256 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); | 359 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
360 EXPECT_EQ(1u, GetParseErrors().size()); | |
361 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," | |
362 " type string expected.", | |
363 GetParseErrors()[0]); | |
257 } | 364 } |
258 | 365 |
259 // Parse fails if string isn't known. | 366 // Parse fails if string isn't known. |
260 { | 367 { |
261 Manifest manifest = ParseManifest("{ \"orientation\": \"naturalish\" }"); | 368 Manifest manifest = ParseManifest("{ \"orientation\": \"naturalish\" }"); |
262 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); | 369 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
370 EXPECT_EQ(1u, GetParseErrors().size()); | |
371 EXPECT_EQ("Manifest parsing error: unknown 'orientation' value ignored.", | |
372 GetParseErrors()[0]); | |
263 } | 373 } |
264 | 374 |
265 // Accept 'any'. | 375 // Accept 'any'. |
266 { | 376 { |
267 Manifest manifest = ParseManifest("{ \"orientation\": \"any\" }"); | 377 Manifest manifest = ParseManifest("{ \"orientation\": \"any\" }"); |
268 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockAny); | 378 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockAny); |
379 EXPECT_EQ(0u, GetParseErrors().size()); | |
269 } | 380 } |
270 | 381 |
271 // Accept 'natural'. | 382 // Accept 'natural'. |
272 { | 383 { |
273 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); | 384 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); |
274 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); | 385 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); |
386 EXPECT_EQ(0u, GetParseErrors().size()); | |
275 } | 387 } |
276 | 388 |
277 // Accept 'landscape'. | 389 // Accept 'landscape'. |
278 { | 390 { |
279 Manifest manifest = ParseManifest("{ \"orientation\": \"landscape\" }"); | 391 Manifest manifest = ParseManifest("{ \"orientation\": \"landscape\" }"); |
280 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape); | 392 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape); |
393 EXPECT_EQ(0u, GetParseErrors().size()); | |
281 } | 394 } |
282 | 395 |
283 // Accept 'landscape-primary'. | 396 // Accept 'landscape-primary'. |
284 { | 397 { |
285 Manifest manifest = | 398 Manifest manifest = |
286 ParseManifest("{ \"orientation\": \"landscape-primary\" }"); | 399 ParseManifest("{ \"orientation\": \"landscape-primary\" }"); |
287 EXPECT_EQ(manifest.orientation, | 400 EXPECT_EQ(manifest.orientation, |
288 blink::WebScreenOrientationLockLandscapePrimary); | 401 blink::WebScreenOrientationLockLandscapePrimary); |
402 EXPECT_EQ(0u, GetParseErrors().size()); | |
289 } | 403 } |
290 | 404 |
291 // Accept 'landscape-secondary'. | 405 // Accept 'landscape-secondary'. |
292 { | 406 { |
293 Manifest manifest = | 407 Manifest manifest = |
294 ParseManifest("{ \"orientation\": \"landscape-secondary\" }"); | 408 ParseManifest("{ \"orientation\": \"landscape-secondary\" }"); |
295 EXPECT_EQ(manifest.orientation, | 409 EXPECT_EQ(manifest.orientation, |
296 blink::WebScreenOrientationLockLandscapeSecondary); | 410 blink::WebScreenOrientationLockLandscapeSecondary); |
411 EXPECT_EQ(0u, GetParseErrors().size()); | |
297 } | 412 } |
298 | 413 |
299 // Accept 'portrait'. | 414 // Accept 'portrait'. |
300 { | 415 { |
301 Manifest manifest = ParseManifest("{ \"orientation\": \"portrait\" }"); | 416 Manifest manifest = ParseManifest("{ \"orientation\": \"portrait\" }"); |
302 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockPortrait); | 417 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockPortrait); |
418 EXPECT_EQ(0u, GetParseErrors().size()); | |
303 } | 419 } |
304 | 420 |
305 // Accept 'portrait-primary'. | 421 // Accept 'portrait-primary'. |
306 { | 422 { |
307 Manifest manifest = | 423 Manifest manifest = |
308 ParseManifest("{ \"orientation\": \"portrait-primary\" }"); | 424 ParseManifest("{ \"orientation\": \"portrait-primary\" }"); |
309 EXPECT_EQ(manifest.orientation, | 425 EXPECT_EQ(manifest.orientation, |
310 blink::WebScreenOrientationLockPortraitPrimary); | 426 blink::WebScreenOrientationLockPortraitPrimary); |
427 EXPECT_EQ(0u, GetParseErrors().size()); | |
311 } | 428 } |
312 | 429 |
313 // Accept 'portrait-secondary'. | 430 // Accept 'portrait-secondary'. |
314 { | 431 { |
315 Manifest manifest = | 432 Manifest manifest = |
316 ParseManifest("{ \"orientation\": \"portrait-secondary\" }"); | 433 ParseManifest("{ \"orientation\": \"portrait-secondary\" }"); |
317 EXPECT_EQ(manifest.orientation, | 434 EXPECT_EQ(manifest.orientation, |
318 blink::WebScreenOrientationLockPortraitSecondary); | 435 blink::WebScreenOrientationLockPortraitSecondary); |
436 EXPECT_EQ(0u, GetParseErrors().size()); | |
319 } | 437 } |
320 | 438 |
321 // Case insensitive. | 439 // Case insensitive. |
322 { | 440 { |
323 Manifest manifest = ParseManifest("{ \"orientation\": \"LANDSCAPE\" }"); | 441 Manifest manifest = ParseManifest("{ \"orientation\": \"LANDSCAPE\" }"); |
324 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape); | 442 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape); |
443 EXPECT_EQ(0u, GetParseErrors().size()); | |
325 } | 444 } |
326 } | 445 } |
327 | 446 |
328 TEST_F(ManifestParserTest, IconsParseRules) { | 447 TEST_F(ManifestParserTest, IconsParseRules) { |
329 // Smoke test: if no icon, empty list. | 448 // Smoke test: if no icon, empty list. |
330 { | 449 { |
331 Manifest manifest = ParseManifest("{ \"icons\": [] }"); | 450 Manifest manifest = ParseManifest("{ \"icons\": [] }"); |
332 EXPECT_EQ(manifest.icons.size(), 0u); | 451 EXPECT_EQ(manifest.icons.size(), 0u); |
333 EXPECT_TRUE(manifest.IsEmpty()); | 452 EXPECT_TRUE(manifest.IsEmpty()); |
453 EXPECT_EQ(0u, GetParseErrors().size()); | |
334 } | 454 } |
335 | 455 |
336 // Smoke test: if empty icon, empty list. | 456 // Smoke test: if empty icon, empty list. |
337 { | 457 { |
338 Manifest manifest = ParseManifest("{ \"icons\": [ {} ] }"); | 458 Manifest manifest = ParseManifest("{ \"icons\": [ {} ] }"); |
339 EXPECT_EQ(manifest.icons.size(), 0u); | 459 EXPECT_EQ(manifest.icons.size(), 0u); |
340 EXPECT_TRUE(manifest.IsEmpty()); | 460 EXPECT_TRUE(manifest.IsEmpty()); |
461 EXPECT_EQ(0u, GetParseErrors().size()); | |
341 } | 462 } |
342 | 463 |
343 // Smoke test: icon with invalid src, empty list. | 464 // Smoke test: icon with invalid src, empty list. |
344 { | 465 { |
345 Manifest manifest = ParseManifest("{ \"icons\": [ { \"icons\": [] } ] }"); | 466 Manifest manifest = ParseManifest("{ \"icons\": [ { \"icons\": [] } ] }"); |
346 EXPECT_EQ(manifest.icons.size(), 0u); | 467 EXPECT_EQ(manifest.icons.size(), 0u); |
347 EXPECT_TRUE(manifest.IsEmpty()); | 468 EXPECT_TRUE(manifest.IsEmpty()); |
469 EXPECT_EQ(0u, GetParseErrors().size()); | |
348 } | 470 } |
349 | 471 |
350 // Smoke test: if icon with empty src, it will be present in the list. | 472 // Smoke test: if icon with empty src, it will be present in the list. |
351 { | 473 { |
352 Manifest manifest = ParseManifest("{ \"icons\": [ { \"src\": \"\" } ] }"); | 474 Manifest manifest = ParseManifest("{ \"icons\": [ { \"src\": \"\" } ] }"); |
353 EXPECT_EQ(manifest.icons.size(), 1u); | 475 EXPECT_EQ(manifest.icons.size(), 1u); |
354 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/index.html"); | 476 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/index.html"); |
355 EXPECT_FALSE(manifest.IsEmpty()); | 477 EXPECT_FALSE(manifest.IsEmpty()); |
478 EXPECT_EQ(0u, GetParseErrors().size()); | |
356 } | 479 } |
357 | 480 |
358 // Smoke test: if one icons with valid src, it will be present in the list. | 481 // Smoke test: if one icons with valid src, it will be present in the list. |
359 { | 482 { |
360 Manifest manifest = | 483 Manifest manifest = |
361 ParseManifest("{ \"icons\": [{ \"src\": \"foo.jpg\" }] }"); | 484 ParseManifest("{ \"icons\": [{ \"src\": \"foo.jpg\" }] }"); |
362 EXPECT_EQ(manifest.icons.size(), 1u); | 485 EXPECT_EQ(manifest.icons.size(), 1u); |
363 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/foo.jpg"); | 486 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/foo.jpg"); |
364 EXPECT_FALSE(manifest.IsEmpty()); | 487 EXPECT_FALSE(manifest.IsEmpty()); |
488 EXPECT_EQ(0u, GetParseErrors().size()); | |
Peter Beverloo
2014/11/27 13:24:32
nit: since you have the "GetParseErrors().size()"
mlamouri (slow - plz ping)
2014/11/27 13:49:09
Done.
| |
365 } | 489 } |
366 } | 490 } |
367 | 491 |
368 TEST_F(ManifestParserTest, IconSrcParseRules) { | 492 TEST_F(ManifestParserTest, IconSrcParseRules) { |
369 // Smoke test. | 493 // Smoke test. |
370 { | 494 { |
371 Manifest manifest = | 495 Manifest manifest = |
372 ParseManifest("{ \"icons\": [ {\"src\": \"foo.png\" } ] }"); | 496 ParseManifest("{ \"icons\": [ {\"src\": \"foo.png\" } ] }"); |
373 EXPECT_EQ(manifest.icons[0].src.spec(), | 497 EXPECT_EQ(manifest.icons[0].src.spec(), |
374 default_document_url.Resolve("foo.png").spec()); | 498 default_document_url.Resolve("foo.png").spec()); |
499 EXPECT_EQ(0u, GetParseErrors().size()); | |
375 } | 500 } |
376 | 501 |
377 // Whitespaces. | 502 // Whitespaces. |
378 { | 503 { |
379 Manifest manifest = | 504 Manifest manifest = |
380 ParseManifest("{ \"icons\": [ {\"src\": \" foo.png \" } ] }"); | 505 ParseManifest("{ \"icons\": [ {\"src\": \" foo.png \" } ] }"); |
381 EXPECT_EQ(manifest.icons[0].src.spec(), | 506 EXPECT_EQ(manifest.icons[0].src.spec(), |
382 default_document_url.Resolve("foo.png").spec()); | 507 default_document_url.Resolve("foo.png").spec()); |
508 EXPECT_EQ(0u, GetParseErrors().size()); | |
383 } | 509 } |
384 | 510 |
385 // Don't parse if property isn't a string. | 511 // Don't parse if property isn't a string. |
386 { | 512 { |
387 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": {} } ] }"); | 513 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": {} } ] }"); |
388 EXPECT_TRUE(manifest.icons.empty()); | 514 EXPECT_TRUE(manifest.icons.empty()); |
515 EXPECT_EQ(1u, GetParseErrors().size()); | |
516 EXPECT_EQ("Manifest parsing error: property 'src' ignored," | |
517 " type string expected.", | |
518 GetParseErrors()[0]); | |
389 } | 519 } |
390 | 520 |
391 // Don't parse if property isn't a string. | 521 // Don't parse if property isn't a string. |
392 { | 522 { |
393 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": 42 } ] }"); | 523 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": 42 } ] }"); |
394 EXPECT_TRUE(manifest.icons.empty()); | 524 EXPECT_TRUE(manifest.icons.empty()); |
525 EXPECT_EQ(1u, GetParseErrors().size()); | |
526 EXPECT_EQ("Manifest parsing error: property 'src' ignored," | |
527 " type string expected.", | |
528 GetParseErrors()[0]); | |
395 } | 529 } |
396 | 530 |
397 // Resolving has to happen based on the document_url. | 531 // Resolving has to happen based on the document_url. |
398 { | 532 { |
399 Manifest manifest = | 533 Manifest manifest = |
400 ParseManifest("{ \"icons\": [ {\"src\": \"icons/foo.png\" } ] }", | 534 ParseManifest("{ \"icons\": [ {\"src\": \"icons/foo.png\" } ] }", |
401 GURL("http://foo.com/landing/index.html")); | 535 GURL("http://foo.com/landing/index.html")); |
402 EXPECT_EQ(manifest.icons[0].src.spec(), | 536 EXPECT_EQ(manifest.icons[0].src.spec(), |
403 "http://foo.com/landing/icons/foo.png"); | 537 "http://foo.com/landing/icons/foo.png"); |
538 EXPECT_EQ(0u, GetParseErrors().size()); | |
404 } | 539 } |
405 } | 540 } |
406 | 541 |
407 TEST_F(ManifestParserTest, IconTypeParseRules) { | 542 TEST_F(ManifestParserTest, IconTypeParseRules) { |
408 // Smoke test. | 543 // Smoke test. |
409 { | 544 { |
410 Manifest manifest = | 545 Manifest manifest = |
411 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": \"foo\" } ] }"); | 546 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": \"foo\" } ] }"); |
412 EXPECT_TRUE(EqualsASCII(manifest.icons[0].type.string(), "foo")); | 547 EXPECT_TRUE(EqualsASCII(manifest.icons[0].type.string(), "foo")); |
548 EXPECT_EQ(0u, GetParseErrors().size()); | |
413 } | 549 } |
414 | 550 |
415 // Trim whitespaces. | 551 // Trim whitespaces. |
416 { | 552 { |
417 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 553 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
418 " \"type\": \" foo \" } ] }"); | 554 " \"type\": \" foo \" } ] }"); |
419 EXPECT_TRUE(EqualsASCII(manifest.icons[0].type.string(), "foo")); | 555 EXPECT_TRUE(EqualsASCII(manifest.icons[0].type.string(), "foo")); |
556 EXPECT_EQ(0u, GetParseErrors().size()); | |
420 } | 557 } |
421 | 558 |
422 // Don't parse if property isn't a string. | 559 // Don't parse if property isn't a string. |
423 { | 560 { |
424 Manifest manifest = | 561 Manifest manifest = |
425 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": {} } ] }"); | 562 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": {} } ] }"); |
426 EXPECT_TRUE(manifest.icons[0].type.is_null()); | 563 EXPECT_TRUE(manifest.icons[0].type.is_null()); |
564 EXPECT_EQ(1u, GetParseErrors().size()); | |
565 EXPECT_EQ("Manifest parsing error: property 'type' ignored," | |
566 " type string expected.", | |
567 GetParseErrors()[0]); | |
427 } | 568 } |
428 | 569 |
429 // Don't parse if property isn't a string. | 570 // Don't parse if property isn't a string. |
430 { | 571 { |
431 Manifest manifest = | 572 Manifest manifest = |
432 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": 42 } ] }"); | 573 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": 42 } ] }"); |
433 EXPECT_TRUE(manifest.icons[0].type.is_null()); | 574 EXPECT_TRUE(manifest.icons[0].type.is_null()); |
575 EXPECT_EQ(1u, GetParseErrors().size()); | |
576 EXPECT_EQ("Manifest parsing error: property 'type' ignored," | |
577 " type string expected.", | |
578 GetParseErrors()[0]); | |
434 } | 579 } |
435 } | 580 } |
436 | 581 |
437 TEST_F(ManifestParserTest, IconDensityParseRules) { | 582 TEST_F(ManifestParserTest, IconDensityParseRules) { |
438 // Smoke test. | 583 // Smoke test. |
439 { | 584 { |
440 Manifest manifest = | 585 Manifest manifest = |
441 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 42 } ] }"); | 586 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 42 } ] }"); |
442 EXPECT_EQ(manifest.icons[0].density, 42); | 587 EXPECT_EQ(manifest.icons[0].density, 42); |
588 EXPECT_EQ(0u, GetParseErrors().size()); | |
443 } | 589 } |
444 | 590 |
445 // Decimal value. | 591 // Decimal value. |
446 { | 592 { |
447 Manifest manifest = | 593 Manifest manifest = |
448 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 2.5 } ] }"); | 594 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 2.5 } ] }"); |
449 EXPECT_EQ(manifest.icons[0].density, 2.5); | 595 EXPECT_EQ(manifest.icons[0].density, 2.5); |
596 EXPECT_EQ(0u, GetParseErrors().size()); | |
450 } | 597 } |
451 | 598 |
452 // Parse fail if it isn't a float. | 599 // Parse fail if it isn't a float. |
453 { | 600 { |
454 Manifest manifest = | 601 Manifest manifest = |
455 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": {} } ] }"); | 602 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": {} } ] }"); |
456 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); | 603 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
604 EXPECT_EQ(1u, GetParseErrors().size()); | |
605 EXPECT_EQ("Manifest parsing error: icon 'density' ignored, " | |
606 "must be float greater than 0.", | |
607 GetParseErrors()[0]); | |
457 } | 608 } |
458 | 609 |
459 // Parse fail if it isn't a float. | 610 // Parse fail if it isn't a float. |
460 { | 611 { |
461 Manifest manifest = | 612 Manifest manifest = |
462 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\":\"2\" } ] }"); | 613 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\":\"2\" } ] }"); |
463 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); | 614 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
615 EXPECT_EQ(1u, GetParseErrors().size()); | |
616 EXPECT_EQ("Manifest parsing error: icon 'density' ignored, " | |
617 "must be float greater than 0.", | |
618 GetParseErrors()[0]); | |
464 } | 619 } |
465 | 620 |
466 // Edge case: 1.0. | 621 // Edge case: 1.0. |
467 { | 622 { |
468 Manifest manifest = | 623 Manifest manifest = |
469 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 1.00 } ] }"); | 624 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 1.00 } ] }"); |
470 EXPECT_EQ(manifest.icons[0].density, 1); | 625 EXPECT_EQ(manifest.icons[0].density, 1); |
626 EXPECT_EQ(0u, GetParseErrors().size()); | |
471 } | 627 } |
472 | 628 |
473 // Edge case: values between 0.0 and 1.0 are allowed. | 629 // Edge case: values between 0.0 and 1.0 are allowed. |
474 { | 630 { |
475 Manifest manifest = | 631 Manifest manifest = |
476 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.42 } ] }"); | 632 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.42 } ] }"); |
477 EXPECT_EQ(manifest.icons[0].density, 0.42); | 633 EXPECT_EQ(manifest.icons[0].density, 0.42); |
634 EXPECT_EQ(0u, GetParseErrors().size()); | |
478 } | 635 } |
479 | 636 |
480 // 0 is an invalid value. | 637 // 0 is an invalid value. |
481 { | 638 { |
482 Manifest manifest = | 639 Manifest manifest = |
483 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.0 } ] }"); | 640 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.0 } ] }"); |
484 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); | 641 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
642 EXPECT_EQ(1u, GetParseErrors().size()); | |
643 EXPECT_EQ("Manifest parsing error: icon 'density' ignored, " | |
644 "must be float greater than 0.", | |
645 GetParseErrors()[0]); | |
485 } | 646 } |
486 | 647 |
487 // Negative values are invalid. | 648 // Negative values are invalid. |
488 { | 649 { |
489 Manifest manifest = | 650 Manifest manifest = |
490 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }"); | 651 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }"); |
491 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); | 652 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
653 EXPECT_EQ(1u, GetParseErrors().size()); | |
654 EXPECT_EQ("Manifest parsing error: icon 'density' ignored, " | |
655 "must be float greater than 0.", | |
656 GetParseErrors()[0]); | |
492 } | 657 } |
493 } | 658 } |
494 | 659 |
495 TEST_F(ManifestParserTest, IconSizesParseRules) { | 660 TEST_F(ManifestParserTest, IconSizesParseRules) { |
496 // Smoke test. | 661 // Smoke test. |
497 { | 662 { |
498 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 663 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
499 "\"sizes\": \"42x42\" } ] }"); | 664 "\"sizes\": \"42x42\" } ] }"); |
500 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); | 665 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); |
666 EXPECT_EQ(0u, GetParseErrors().size()); | |
501 } | 667 } |
502 | 668 |
503 // Trim whitespaces. | 669 // Trim whitespaces. |
504 { | 670 { |
505 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 671 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
506 "\"sizes\": \" 42x42 \" } ] }"); | 672 "\"sizes\": \" 42x42 \" } ] }"); |
507 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); | 673 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); |
674 EXPECT_EQ(0u, GetParseErrors().size()); | |
508 } | 675 } |
509 | 676 |
510 // Don't parse if name isn't a string. | 677 // Ignore sizes if property isn't a string. |
511 { | 678 { |
512 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 679 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
513 "\"sizes\": {} } ] }"); | 680 "\"sizes\": {} } ] }"); |
514 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); | 681 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
682 EXPECT_EQ(1u, GetParseErrors().size()); | |
683 EXPECT_EQ("Manifest parsing error: property 'sizes' ignored," | |
684 " type string expected.", | |
685 GetParseErrors()[0]); | |
515 } | 686 } |
516 | 687 |
517 // Don't parse if name isn't a string. | 688 // Ignore sizes if property isn't a string. |
518 { | 689 { |
519 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 690 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
520 "\"sizes\": 42 } ] }"); | 691 "\"sizes\": 42 } ] }"); |
521 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); | 692 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
693 EXPECT_EQ(1u, GetParseErrors().size()); | |
694 EXPECT_EQ("Manifest parsing error: property 'sizes' ignored," | |
695 " type string expected.", | |
696 GetParseErrors()[0]); | |
522 } | 697 } |
523 | 698 |
524 // Smoke test: value correctly parsed. | 699 // Smoke test: value correctly parsed. |
525 { | 700 { |
526 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 701 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
527 "\"sizes\": \"42x42 48x48\" } ] }"); | 702 "\"sizes\": \"42x42 48x48\" } ] }"); |
528 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); | 703 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
529 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48)); | 704 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48)); |
705 EXPECT_EQ(0u, GetParseErrors().size()); | |
530 } | 706 } |
531 | 707 |
532 // <WIDTH>'x'<HEIGHT> and <WIDTH>'X'<HEIGHT> are equivalent. | 708 // <WIDTH>'x'<HEIGHT> and <WIDTH>'X'<HEIGHT> are equivalent. |
533 { | 709 { |
534 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 710 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
535 "\"sizes\": \"42X42 48X48\" } ] }"); | 711 "\"sizes\": \"42X42 48X48\" } ] }"); |
536 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); | 712 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
537 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48)); | 713 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48)); |
714 EXPECT_EQ(0u, GetParseErrors().size()); | |
538 } | 715 } |
539 | 716 |
540 // Twice the same value is parsed twice. | 717 // Twice the same value is parsed twice. |
541 { | 718 { |
542 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 719 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
543 "\"sizes\": \"42X42 42x42\" } ] }"); | 720 "\"sizes\": \"42X42 42x42\" } ] }"); |
544 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); | 721 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
545 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(42, 42)); | 722 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(42, 42)); |
723 EXPECT_EQ(0u, GetParseErrors().size()); | |
546 } | 724 } |
547 | 725 |
548 // Width or height can't start with 0. | 726 // Width or height can't start with 0. |
549 { | 727 { |
550 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 728 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
551 "\"sizes\": \"004X007 042x00\" } ] }"); | 729 "\"sizes\": \"004X007 042x00\" } ] }"); |
552 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); | 730 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
731 EXPECT_EQ(1u, GetParseErrors().size()); | |
732 EXPECT_EQ("Manifest parsing error: found icon with no valid size.", | |
733 GetParseErrors()[0]); | |
553 } | 734 } |
554 | 735 |
555 // Width and height MUST contain digits. | 736 // Width and height MUST contain digits. |
556 { | 737 { |
557 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 738 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
558 "\"sizes\": \"e4X1.0 55ax1e10\" } ] }"); | 739 "\"sizes\": \"e4X1.0 55ax1e10\" } ] }"); |
559 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); | 740 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
741 EXPECT_EQ(1u, GetParseErrors().size()); | |
742 EXPECT_EQ("Manifest parsing error: found icon with no valid size.", | |
743 GetParseErrors()[0]); | |
560 } | 744 } |
561 | 745 |
562 // 'any' is correctly parsed and transformed to gfx::Size(0,0). | 746 // 'any' is correctly parsed and transformed to gfx::Size(0,0). |
563 { | 747 { |
564 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 748 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
565 "\"sizes\": \"any AnY ANY aNy\" } ] }"); | 749 "\"sizes\": \"any AnY ANY aNy\" } ] }"); |
566 gfx::Size any = gfx::Size(0, 0); | 750 gfx::Size any = gfx::Size(0, 0); |
567 EXPECT_EQ(manifest.icons[0].sizes.size(), 4u); | 751 EXPECT_EQ(manifest.icons[0].sizes.size(), 4u); |
568 EXPECT_EQ(manifest.icons[0].sizes[0], any); | 752 EXPECT_EQ(manifest.icons[0].sizes[0], any); |
569 EXPECT_EQ(manifest.icons[0].sizes[1], any); | 753 EXPECT_EQ(manifest.icons[0].sizes[1], any); |
570 EXPECT_EQ(manifest.icons[0].sizes[2], any); | 754 EXPECT_EQ(manifest.icons[0].sizes[2], any); |
571 EXPECT_EQ(manifest.icons[0].sizes[3], any); | 755 EXPECT_EQ(manifest.icons[0].sizes[3], any); |
756 EXPECT_EQ(0u, GetParseErrors().size()); | |
572 } | 757 } |
573 | 758 |
574 // Some invalid width/height combinations. | 759 // Some invalid width/height combinations. |
575 { | 760 { |
576 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 761 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
577 "\"sizes\": \"x 40xx 1x2x3 x42 42xx42\" } ] }"); | 762 "\"sizes\": \"x 40xx 1x2x3 x42 42xx42\" } ] }"); |
578 gfx::Size any = gfx::Size(0, 0); | 763 gfx::Size any = gfx::Size(0, 0); |
579 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); | 764 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
765 EXPECT_EQ(1u, GetParseErrors().size()); | |
766 EXPECT_EQ("Manifest parsing error: found icon with no valid size.", | |
767 GetParseErrors()[0]); | |
580 } | 768 } |
581 } | 769 } |
582 | 770 |
583 TEST_F(ManifestParserTest, GCMSenderIDParseRules) { | 771 TEST_F(ManifestParserTest, GCMSenderIDParseRules) { |
584 // Smoke test. | 772 // Smoke test. |
585 { | 773 { |
586 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); | 774 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); |
587 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); | 775 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); |
776 EXPECT_EQ(0u, GetParseErrors().size()); | |
588 } | 777 } |
589 | 778 |
590 // Trim whitespaces. | 779 // Trim whitespaces. |
591 { | 780 { |
592 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \" foo \" }"); | 781 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \" foo \" }"); |
593 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); | 782 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); |
783 EXPECT_EQ(0u, GetParseErrors().size()); | |
594 } | 784 } |
595 | 785 |
596 // Don't parse if property isn't a string. | 786 // Don't parse if property isn't a string. |
597 { | 787 { |
598 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": {} }"); | 788 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": {} }"); |
599 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 789 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
790 EXPECT_EQ(1u, GetParseErrors().size()); | |
791 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," | |
792 " type string expected.", | |
793 GetParseErrors()[0]); | |
600 } | 794 } |
601 { | 795 { |
602 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); | 796 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); |
603 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 797 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
798 EXPECT_EQ(1u, GetParseErrors().size()); | |
799 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," | |
800 " type string expected.", | |
801 GetParseErrors()[0]); | |
604 } | 802 } |
605 } | 803 } |
606 | 804 |
607 } // namespace content | 805 } // namespace content |
OLD | NEW |