Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: content/renderer/manifest/manifest_parser_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698