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 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 } | 485 } |
486 | 486 |
487 // Negative values are invalid. | 487 // Negative values are invalid. |
488 { | 488 { |
489 Manifest manifest = | 489 Manifest manifest = |
490 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }"); | 490 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }"); |
491 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); | 491 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity); |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
| 495 TEST_F(ManifestParserTest, IconSizesParseRules) { |
| 496 // Smoke test. |
| 497 { |
| 498 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 499 "\"sizes\": \"42x42\" } ] }"); |
| 500 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); |
| 501 } |
| 502 |
| 503 // Trim whitespaces. |
| 504 { |
| 505 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 506 "\"sizes\": \" 42x42 \" } ] }"); |
| 507 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); |
| 508 } |
| 509 |
| 510 // Don't parse if name isn't a string. |
| 511 { |
| 512 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 513 "\"sizes\": {} } ] }"); |
| 514 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
| 515 } |
| 516 |
| 517 // Don't parse if name isn't a string. |
| 518 { |
| 519 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 520 "\"sizes\": 42 } ] }"); |
| 521 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
| 522 } |
| 523 |
| 524 // Smoke test: value correctly parsed. |
| 525 { |
| 526 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 527 "\"sizes\": \"42x42 48x48\" } ] }"); |
| 528 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
| 529 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48)); |
| 530 } |
| 531 |
| 532 // <WIDTH>'x'<HEIGHT> and <WIDTH>'X'<HEIGHT> are equivalent. |
| 533 { |
| 534 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 535 "\"sizes\": \"42X42 48X48\" } ] }"); |
| 536 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
| 537 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(48, 48)); |
| 538 } |
| 539 |
| 540 // Twice the same value is parsed twice. |
| 541 { |
| 542 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 543 "\"sizes\": \"42X42 42x42\" } ] }"); |
| 544 EXPECT_EQ(manifest.icons[0].sizes[0], gfx::Size(42, 42)); |
| 545 EXPECT_EQ(manifest.icons[0].sizes[1], gfx::Size(42, 42)); |
| 546 } |
| 547 |
| 548 // Width or height can't start with 0. |
| 549 { |
| 550 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 551 "\"sizes\": \"004X007 042x00\" } ] }"); |
| 552 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
| 553 } |
| 554 |
| 555 // Width and height MUST contain digits. |
| 556 { |
| 557 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 558 "\"sizes\": \"e4X1.0 55ax1e10\" } ] }"); |
| 559 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
| 560 } |
| 561 |
| 562 // 'any' is correctly parsed and transformed to gfx::Size(0,0). |
| 563 { |
| 564 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 565 "\"sizes\": \"any AnY ANY aNy\" } ] }"); |
| 566 gfx::Size any = gfx::Size(0, 0); |
| 567 EXPECT_EQ(manifest.icons[0].sizes.size(), 4u); |
| 568 EXPECT_EQ(manifest.icons[0].sizes[0], any); |
| 569 EXPECT_EQ(manifest.icons[0].sizes[1], any); |
| 570 EXPECT_EQ(manifest.icons[0].sizes[2], any); |
| 571 EXPECT_EQ(manifest.icons[0].sizes[3], any); |
| 572 } |
| 573 } |
| 574 |
495 } // namespace content | 575 } // namespace content |
OLD | NEW |