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

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

Issue 1901363003: Remove support for the web manifest icon density member. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename test Created 4 years, 8 months 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
« no previous file with comments | « content/renderer/manifest/manifest_parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 Manifest manifest = 624 Manifest manifest =
625 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": 42 } ] }"); 625 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"type\": 42 } ] }");
626 EXPECT_TRUE(manifest.icons[0].type.is_null()); 626 EXPECT_TRUE(manifest.icons[0].type.is_null());
627 EXPECT_EQ(1u, GetErrorCount()); 627 EXPECT_EQ(1u, GetErrorCount());
628 EXPECT_EQ("Manifest parsing error: property 'type' ignored," 628 EXPECT_EQ("Manifest parsing error: property 'type' ignored,"
629 " type string expected.", 629 " type string expected.",
630 errors()[0]); 630 errors()[0]);
631 } 631 }
632 } 632 }
633 633
634 TEST_F(ManifestParserTest, IconDensityParseRules) {
635 // Smoke test.
636 {
637 Manifest manifest =
638 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 42 } ] }");
639 EXPECT_EQ(manifest.icons[0].density, 42);
640 EXPECT_EQ(0u, GetErrorCount());
641 }
642
643 // Decimal value.
644 {
645 Manifest manifest =
646 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 2.5 } ] }");
647 EXPECT_EQ(manifest.icons[0].density, 2.5);
648 EXPECT_EQ(0u, GetErrorCount());
649 }
650
651 // Parse fail if it isn't a float.
652 {
653 Manifest manifest =
654 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": {} } ] }");
655 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
656 EXPECT_EQ(1u, GetErrorCount());
657 EXPECT_EQ("Manifest parsing error: icon 'density' ignored, "
658 "must be float greater than 0.",
659 errors()[0]);
660 }
661
662 // Parse fail if it isn't a float.
663 {
664 Manifest manifest =
665 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\":\"2\" } ] }");
666 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
667 EXPECT_EQ(1u, GetErrorCount());
668 EXPECT_EQ("Manifest parsing error: icon 'density' ignored, "
669 "must be float greater than 0.",
670 errors()[0]);
671 }
672
673 // Edge case: 1.0.
674 {
675 Manifest manifest =
676 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 1.00 } ] }");
677 EXPECT_EQ(manifest.icons[0].density, 1);
678 EXPECT_EQ(0u, GetErrorCount());
679 }
680
681 // Edge case: values between 0.0 and 1.0 are allowed.
682 {
683 Manifest manifest =
684 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.42 } ] }");
685 EXPECT_EQ(manifest.icons[0].density, 0.42);
686 EXPECT_EQ(0u, GetErrorCount());
687 }
688
689 // 0 is an invalid value.
690 {
691 Manifest manifest =
692 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": 0.0 } ] }");
693 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
694 EXPECT_EQ(1u, GetErrorCount());
695 EXPECT_EQ("Manifest parsing error: icon 'density' ignored, "
696 "must be float greater than 0.",
697 errors()[0]);
698 }
699
700 // Negative values are invalid.
701 {
702 Manifest manifest =
703 ParseManifest("{ \"icons\": [ {\"src\": \"\", \"density\": -2.5 } ] }");
704 EXPECT_EQ(manifest.icons[0].density, Manifest::Icon::kDefaultDensity);
705 EXPECT_EQ(1u, GetErrorCount());
706 EXPECT_EQ("Manifest parsing error: icon 'density' ignored, "
707 "must be float greater than 0.",
708 errors()[0]);
709 }
710 }
711
712 TEST_F(ManifestParserTest, IconSizesParseRules) { 634 TEST_F(ManifestParserTest, IconSizesParseRules) {
713 // Smoke test. 635 // Smoke test.
714 { 636 {
715 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," 637 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
716 "\"sizes\": \"42x42\" } ] }"); 638 "\"sizes\": \"42x42\" } ] }");
717 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u); 639 EXPECT_EQ(manifest.icons[0].sizes.size(), 1u);
718 EXPECT_EQ(0u, GetErrorCount()); 640 EXPECT_EQ(0u, GetErrorCount());
719 } 641 }
720 642
721 // Trim whitespaces. 643 // Trim whitespaces.
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); 1297 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }");
1376 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); 1298 EXPECT_TRUE(manifest.gcm_sender_id.is_null());
1377 EXPECT_EQ(1u, GetErrorCount()); 1299 EXPECT_EQ(1u, GetErrorCount());
1378 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," 1300 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored,"
1379 " type string expected.", 1301 " type string expected.",
1380 errors()[0]); 1302 errors()[0]);
1381 } 1303 }
1382 } 1304 }
1383 1305
1384 } // namespace content 1306 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/manifest/manifest_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698