| 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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Smoke test. |
| 883 { |
| 884 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 885 "\"purpose\": \"any\" } ] }"); |
| 886 EXPECT_EQ(manifest.icons[0].purpose.size(), 1u); |
| 887 EXPECT_EQ(0u, GetErrorCount()); |
| 888 } |
| 889 |
| 890 // Trim leading and trailing whitespaces. |
| 891 { |
| 892 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 893 "\"purpose\": \" any \" } ] }"); |
| 894 EXPECT_EQ(manifest.icons[0].purpose.size(), 1u); |
| 895 EXPECT_EQ(0u, GetErrorCount()); |
| 896 } |
| 897 |
| 898 // Ignore purpose if property isn't present. |
| 899 { |
| 900 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\" } ] }"); |
| 901 EXPECT_EQ(manifest.icons[0].purpose.size(), 0u); |
| 902 EXPECT_EQ(0u, GetErrorCount()); |
| 903 } |
| 904 |
| 905 // Ignore purpose if property isn't a string (is a number). |
| 906 { |
| 907 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 908 "\"purpose\": 42 } ] }"); |
| 909 EXPECT_EQ(manifest.icons[0].purpose.size(), 0u); |
| 910 ASSERT_EQ(1u, GetErrorCount()); |
| 911 EXPECT_EQ("property 'purpose' ignored, type string expected.", |
| 912 errors()[0]); |
| 913 } |
| 914 |
| 915 // Ignore purpose if property isn't a string (is a dictionary). |
| 916 { |
| 917 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 918 "\"purpose\": {} } ] }"); |
| 919 EXPECT_EQ(manifest.icons[0].purpose.size(), 0u); |
| 920 ASSERT_EQ(1u, GetErrorCount()); |
| 921 EXPECT_EQ("property 'purpose' ignored, type string expected.", |
| 922 errors()[0]); |
| 923 } |
| 924 |
| 925 // Smoke test: values correctly parsed. |
| 926 { |
| 927 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 928 "\"purpose\": \"Any Badge\" } ] }"); |
| 929 ASSERT_EQ(manifest.icons[0].purpose.size(), 2u); |
| 930 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY); |
| 931 EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE); |
| 932 EXPECT_EQ(0u, GetErrorCount()); |
| 933 } |
| 934 |
| 935 // Trim whitespaces between values. |
| 936 { |
| 937 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 938 "\"purpose\": \" Any Badge \" } ] }"); |
| 939 ASSERT_EQ(manifest.icons[0].purpose.size(), 2u); |
| 940 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY); |
| 941 EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE); |
| 942 EXPECT_EQ(0u, GetErrorCount()); |
| 943 } |
| 944 |
| 945 // Twice the same value is parsed twice. |
| 946 { |
| 947 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 948 "\"purpose\": \"badge badge\" } ] }"); |
| 949 ASSERT_EQ(manifest.icons[0].purpose.size(), 2u); |
| 950 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE); |
| 951 EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE); |
| 952 EXPECT_EQ(0u, GetErrorCount()); |
| 953 } |
| 954 |
| 955 // Invalid icon purpose is ignored. |
| 956 { |
| 957 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 958 "\"purpose\": \"badge notification\" } ] }"); |
| 959 ASSERT_EQ(manifest.icons[0].purpose.size(), 1u); |
| 960 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE); |
| 961 ASSERT_EQ(1u, GetErrorCount()); |
| 962 EXPECT_EQ("found icon with invalid purpose.", |
| 963 errors()[0]); |
| 964 } |
| 965 |
| 966 // 'any' is added when developer-supplied purpose is invalid. |
| 967 { |
| 968 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 969 "\"purpose\": \"notification\" } ] }"); |
| 970 ASSERT_EQ(manifest.icons[0].purpose.size(), 1u); |
| 971 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY); |
| 972 ASSERT_EQ(1u, GetErrorCount()); |
| 973 EXPECT_EQ("found icon with invalid purpose.", |
| 974 errors()[0]); |
| 975 } |
| 976 } |
| 977 |
| 881 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { | 978 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { |
| 882 // If no application, empty list. | 979 // If no application, empty list. |
| 883 { | 980 { |
| 884 Manifest manifest = ParseManifest( | 981 Manifest manifest = ParseManifest( |
| 885 "{ \"related_applications\": []}"); | 982 "{ \"related_applications\": []}"); |
| 886 EXPECT_EQ(manifest.related_applications.size(), 0u); | 983 EXPECT_EQ(manifest.related_applications.size(), 0u); |
| 887 EXPECT_TRUE(manifest.IsEmpty()); | 984 EXPECT_TRUE(manifest.IsEmpty()); |
| 888 EXPECT_EQ(0u, GetErrorCount()); | 985 EXPECT_EQ(0u, GetErrorCount()); |
| 889 } | 986 } |
| 890 | 987 |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 { | 1511 { |
| 1415 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); | 1512 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); |
| 1416 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 1513 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
| 1417 EXPECT_EQ(1u, GetErrorCount()); | 1514 EXPECT_EQ(1u, GetErrorCount()); |
| 1418 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", | 1515 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", |
| 1419 errors()[0]); | 1516 errors()[0]); |
| 1420 } | 1517 } |
| 1421 } | 1518 } |
| 1422 | 1519 |
| 1423 } // namespace content | 1520 } // namespace content |
| OLD | NEW |