Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 { | 280 { |
| 281 Manifest manifest = | 281 Manifest manifest = |
| 282 ParseManifestWithURLs("{ \"start_url\": \"land.html\" }", | 282 ParseManifestWithURLs("{ \"start_url\": \"land.html\" }", |
| 283 GURL("http://foo.com/landing/manifest.json"), | 283 GURL("http://foo.com/landing/manifest.json"), |
| 284 GURL("http://foo.com/index.html")); | 284 GURL("http://foo.com/index.html")); |
| 285 ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/landing/land.html"); | 285 ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/landing/land.html"); |
| 286 EXPECT_EQ(0u, GetErrorCount()); | 286 EXPECT_EQ(0u, GetErrorCount()); |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 TEST_F(ManifestParserTest, ScopeParseRules) { | |
|
hartmanng
2016/06/14 18:29:43
these tests look good, but I suggest adding in som
pkotwicz
2016/06/15 01:29:31
Added a test for '..' scope
| |
| 291 // Smoke test. | |
| 292 { | |
| 293 Manifest manifest = ParseManifest( | |
| 294 "{ \"scope\": \"land\", \"start_url\": \"land/landing.html\" }"); | |
| 295 ASSERT_EQ(manifest.scope.spec(), | |
| 296 default_document_url.Resolve("land").spec()); | |
| 297 ASSERT_FALSE(manifest.IsEmpty()); | |
| 298 EXPECT_EQ(0u, GetErrorCount()); | |
| 299 } | |
| 300 | |
| 301 // Whitespaces. | |
| 302 { | |
| 303 Manifest manifest = ParseManifest( | |
| 304 "{ \"scope\": \" land \", \"start_url\": \"land/landing.html\" }"); | |
| 305 ASSERT_EQ(manifest.scope.spec(), | |
| 306 default_document_url.Resolve("land").spec()); | |
| 307 EXPECT_EQ(0u, GetErrorCount()); | |
| 308 } | |
| 309 | |
| 310 // Don't parse if property isn't a string. | |
| 311 { | |
| 312 Manifest manifest = ParseManifest("{ \"scope\": {} }"); | |
| 313 ASSERT_TRUE(manifest.scope.is_empty()); | |
| 314 EXPECT_EQ(1u, GetErrorCount()); | |
| 315 EXPECT_EQ("property 'scope' ignored, type string expected.", errors()[0]); | |
| 316 } | |
| 317 | |
| 318 // Don't parse if property isn't a string. | |
| 319 { | |
| 320 Manifest manifest = ParseManifest("{ \"scope\": 42 }"); | |
| 321 ASSERT_TRUE(manifest.scope.is_empty()); | |
| 322 EXPECT_EQ(1u, GetErrorCount()); | |
| 323 EXPECT_EQ("property 'scope' ignored, type string expected.", errors()[0]); | |
| 324 } | |
| 325 | |
| 326 // Absolute scope, start URL is in scope. | |
| 327 { | |
| 328 Manifest manifest = ParseManifestWithURLs( | |
| 329 "{ \"scope\": \"http://foo.com/land\", " | |
| 330 "\"start_url\": \"http://foo.com/land/landing.html\" }", | |
| 331 GURL("http://foo.com/manifest.json"), | |
| 332 GURL("http://foo.com/index.html")); | |
| 333 ASSERT_EQ(manifest.scope.spec(), "http://foo.com/land"); | |
| 334 EXPECT_EQ(0u, GetErrorCount()); | |
| 335 } | |
| 336 | |
| 337 // Absolute scope, start URL is not in scope. | |
| 338 { | |
| 339 Manifest manifest = | |
| 340 ParseManifestWithURLs("{ \"scope\": \"http://foo.com/land\", " | |
| 341 "\"start_url\": \"http://foo.com/index.html\" }", | |
| 342 GURL("http://foo.com/manifest.json"), | |
|
Xi Han
2016/06/14 19:07:01
The last parameter is the manifest_url, not the se
pkotwicz
2016/06/15 01:29:31
Thank you for pointing it out. I have fixed this i
| |
| 343 GURL("http://foo.com/index.html")); | |
| 344 ASSERT_TRUE(manifest.scope.is_empty()); | |
| 345 EXPECT_EQ(1u, GetErrorCount()); | |
| 346 EXPECT_EQ("property 'scope' ignored. 'start_url' should be within scope " | |
| 347 "of scope URL.", | |
| 348 errors()[0]); | |
| 349 } | |
| 350 | |
| 351 // Absolute scope, start URL has different origin than scope URL. | |
| 352 { | |
| 353 Manifest manifest = | |
| 354 ParseManifestWithURLs("{ \"scope\": \"http://foo.com/land\", " | |
| 355 "\"start_url\": \"http://bar.com/land/landing.html \" }", | |
| 356 GURL("http://foo.com/manifest.json"), | |
|
Xi Han
2016/06/14 19:07:01
Same above.
| |
| 357 GURL("http://foo.com/index.html")); | |
| 358 ASSERT_TRUE(manifest.scope.is_empty()); | |
| 359 ASSERT_EQ(2u, GetErrorCount()); | |
| 360 EXPECT_EQ( | |
| 361 "property 'start_url' ignored, should be same origin as document.", | |
| 362 errors()[0]); | |
| 363 EXPECT_EQ("property 'scope' ignored. 'start_url' should be within scope " | |
| 364 "of scope URL.", | |
| 365 errors()[1]); | |
| 366 } | |
| 367 | |
| 368 // scope and start URL have diferent origin than document URL. | |
| 369 { | |
| 370 Manifest manifest = | |
| 371 ParseManifestWithURLs("{ \"scope\": \"http://foo.com/land\", " | |
| 372 "\"start_url\": \"http://foo.com/land/landing.html \" }", | |
| 373 GURL("http://foo.com/manifest.json"), | |
|
Xi Han
2016/06/14 19:07:01
Same above.
| |
| 374 GURL("http://bar.com/index.html")); | |
| 375 ASSERT_TRUE(manifest.scope.is_empty()); | |
| 376 ASSERT_EQ(2u, GetErrorCount()); | |
| 377 EXPECT_EQ( | |
| 378 "property 'start_url' ignored, should be same origin as document.", | |
| 379 errors()[0]); | |
| 380 EXPECT_EQ("property 'scope' ignored, should be same origin as document.", | |
| 381 errors()[1]); | |
| 382 } | |
| 383 | |
| 384 // No start URL. | |
| 385 { | |
| 386 Manifest manifest = ParseManifest("{ \"scope\": \"land\" }"); | |
| 387 ASSERT_EQ(1u, GetErrorCount()); | |
| 388 EXPECT_EQ("property 'scope' ignored. 'start_url' should be within scope " | |
| 389 "of scope URL.", | |
| 390 errors()[0]); | |
| 391 } | |
| 392 | |
| 393 // Resolving has to happen based on the manifest_url. | |
| 394 { | |
| 395 Manifest manifest = | |
| 396 ParseManifestWithURLs("{ \"scope\": \"land\", " | |
| 397 "\"start_url\": \"landing.html\" }", | |
| 398 GURL("http://foo.com/secret/manifest.json"), | |
|
Xi Han
2016/06/14 19:07:01
Same as above.
| |
| 399 GURL("http://foo.com/index.html")); | |
| 400 ASSERT_EQ(manifest.scope.spec(), "http://foo.com/secret/land"); | |
| 401 EXPECT_EQ(0u, GetErrorCount()); | |
| 402 } | |
| 403 } | |
| 404 | |
| 290 TEST_F(ManifestParserTest, DisplayParserRules) { | 405 TEST_F(ManifestParserTest, DisplayParserRules) { |
| 291 // Smoke test. | 406 // Smoke test. |
| 292 { | 407 { |
| 293 Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); | 408 Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); |
| 294 EXPECT_EQ(manifest.display, blink::WebDisplayModeBrowser); | 409 EXPECT_EQ(manifest.display, blink::WebDisplayModeBrowser); |
| 295 EXPECT_FALSE(manifest.IsEmpty()); | 410 EXPECT_FALSE(manifest.IsEmpty()); |
| 296 EXPECT_EQ(0u, GetErrorCount()); | 411 EXPECT_EQ(0u, GetErrorCount()); |
| 297 } | 412 } |
| 298 | 413 |
| 299 // Trim whitespaces. | 414 // Trim whitespaces. |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1260 { | 1375 { |
| 1261 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); | 1376 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); |
| 1262 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 1377 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
| 1263 EXPECT_EQ(1u, GetErrorCount()); | 1378 EXPECT_EQ(1u, GetErrorCount()); |
| 1264 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", | 1379 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", |
| 1265 errors()[0]); | 1380 errors()[0]); |
| 1266 } | 1381 } |
| 1267 } | 1382 } |
| 1268 | 1383 |
| 1269 } // namespace content | 1384 } // namespace content |
| OLD | NEW |