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

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

Issue 2425833002: Parse "purpose" member from Web Manifest (Closed)
Patch Set: Fix Created 3 years, 12 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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 { 871 {
872 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," 872 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
873 "\"sizes\": \"x 40xx 1x2x3 x42 42xx42\" } ] }"); 873 "\"sizes\": \"x 40xx 1x2x3 x42 42xx42\" } ] }");
874 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); 874 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u);
875 EXPECT_EQ(1u, GetErrorCount()); 875 EXPECT_EQ(1u, GetErrorCount());
876 EXPECT_EQ("found icon with no valid size.", 876 EXPECT_EQ("found icon with no valid size.",
877 errors()[0]); 877 errors()[0]);
878 } 878 }
879 } 879 }
880 880
881 TEST_F(ManifestParserTest, IconPurposeParseRules) {
882 const std::string kPurposeParseStringError =
883 "property 'purpose' ignored, type string expected.";
884 const std::string kPurposeInvalidValueError =
885 "found icon with invalid purpose. "
886 "Using default value 'any'.";
887
888 // Smoke test.
889 {
890 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
891 "\"purpose\": \"any\" } ] }");
892 EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
893 EXPECT_EQ(0u, GetErrorCount());
894 }
895
896 // Trim leading and trailing whitespaces.
897 {
898 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
899 "\"purpose\": \" any \" } ] }");
900 EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
901 EXPECT_EQ(0u, GetErrorCount());
902 }
903
904 // 'any' is added when property isn't present.
905 {
906 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\" } ] }");
907 EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
908 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
909 EXPECT_EQ(0u, GetErrorCount());
910 }
911
912 // 'any' is added with error message when property isn't a string (is a
913 // number).
914 {
915 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
916 "\"purpose\": 42 } ] }");
917 EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
918 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
919 ASSERT_EQ(1u, GetErrorCount());
920 EXPECT_EQ(kPurposeParseStringError, errors()[0]);
921 }
922
923 // 'any' is added with error message when property isn't a string (is a
924 // dictionary).
925 {
926 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
927 "\"purpose\": {} } ] }");
928 EXPECT_EQ(manifest.icons[0].purpose.size(), 1u);
929 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
930 ASSERT_EQ(1u, GetErrorCount());
931 EXPECT_EQ(kPurposeParseStringError, errors()[0]);
932 }
933
934 // Smoke test: values correctly parsed.
935 {
936 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
937 "\"purpose\": \"Any Badge\" } ] }");
938 ASSERT_EQ(manifest.icons[0].purpose.size(), 2u);
939 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
940 EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE);
941 EXPECT_EQ(0u, GetErrorCount());
942 }
943
944 // Trim whitespaces between values.
945 {
946 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
947 "\"purpose\": \" Any Badge \" } ] }");
948 ASSERT_EQ(manifest.icons[0].purpose.size(), 2u);
949 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
950 EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE);
951 EXPECT_EQ(0u, GetErrorCount());
952 }
953
954 // Twice the same value is parsed twice.
955 {
956 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
957 "\"purpose\": \"badge badge\" } ] }");
958 ASSERT_EQ(manifest.icons[0].purpose.size(), 2u);
959 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE);
960 EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE);
961 EXPECT_EQ(0u, GetErrorCount());
962 }
963
964 // Invalid icon purpose is ignored.
965 {
966 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
967 "\"purpose\": \"badge notification\" } ] }");
968 ASSERT_EQ(manifest.icons[0].purpose.size(), 1u);
969 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE);
970 ASSERT_EQ(1u, GetErrorCount());
971 EXPECT_EQ(kPurposeInvalidValueError, errors()[0]);
972 }
973
974 // 'any' is added when developer-supplied purpose is invalid.
975 {
976 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
977 "\"purpose\": \"notification\" } ] }");
978 ASSERT_EQ(manifest.icons[0].purpose.size(), 1u);
979 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
980 ASSERT_EQ(1u, GetErrorCount());
981 EXPECT_EQ(kPurposeInvalidValueError, errors()[0]);
982 }
983 }
984
881 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { 985 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) {
882 // If no application, empty list. 986 // If no application, empty list.
883 { 987 {
884 Manifest manifest = ParseManifest( 988 Manifest manifest = ParseManifest(
885 "{ \"related_applications\": []}"); 989 "{ \"related_applications\": []}");
886 EXPECT_EQ(manifest.related_applications.size(), 0u); 990 EXPECT_EQ(manifest.related_applications.size(), 0u);
887 EXPECT_TRUE(manifest.IsEmpty()); 991 EXPECT_TRUE(manifest.IsEmpty());
888 EXPECT_EQ(0u, GetErrorCount()); 992 EXPECT_EQ(0u, GetErrorCount());
889 } 993 }
890 994
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 { 1518 {
1415 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); 1519 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }");
1416 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); 1520 EXPECT_TRUE(manifest.gcm_sender_id.is_null());
1417 EXPECT_EQ(1u, GetErrorCount()); 1521 EXPECT_EQ(1u, GetErrorCount());
1418 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", 1522 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.",
1419 errors()[0]); 1523 errors()[0]);
1420 } 1524 }
1421 } 1525 }
1422 1526
1423 } // namespace content 1527 } // 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