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 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 } | 870 } |
871 | 871 |
872 // "False" should set the boolean false without throwing errors. | 872 // "False" should set the boolean false without throwing errors. |
873 { | 873 { |
874 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }"); | 874 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }"); |
875 EXPECT_FALSE(manifest.gcm_user_visible_only); | 875 EXPECT_FALSE(manifest.gcm_user_visible_only); |
876 EXPECT_EQ(0u, GetErrorCount()); | 876 EXPECT_EQ(0u, GetErrorCount()); |
877 } | 877 } |
878 } | 878 } |
879 | 879 |
| 880 TEST_F(ManifestParserTest, ChromeRelatedApplicationsParseRules) { |
| 881 // If no application, empty list. |
| 882 { |
| 883 Manifest manifest = ParseManifest( |
| 884 "{ \"chrome_related_applications\": []}"); |
| 885 EXPECT_EQ(manifest.chrome_related_applications.size(), 0u); |
| 886 EXPECT_TRUE(manifest.IsEmpty()); |
| 887 EXPECT_EQ(0u, GetErrorCount()); |
| 888 } |
| 889 |
| 890 // If empty application, empty list. |
| 891 { |
| 892 Manifest manifest = ParseManifest( |
| 893 "{ \"chrome_related_applications\": [{}]}"); |
| 894 EXPECT_EQ(manifest.chrome_related_applications.size(), 0u); |
| 895 EXPECT_TRUE(manifest.IsEmpty()); |
| 896 EXPECT_EQ(1u, GetErrorCount()); |
| 897 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " |
| 898 "chrome related application ignored.", |
| 899 errors()[0]); |
| 900 } |
| 901 |
| 902 // If invalid package, application is ignored. |
| 903 { |
| 904 Manifest manifest = ParseManifest( |
| 905 "{ \"chrome_related_applications\": [{\"platform\": \"foo\"}]}"); |
| 906 EXPECT_EQ(manifest.chrome_related_applications.size(), 0u); |
| 907 EXPECT_TRUE(manifest.IsEmpty()); |
| 908 EXPECT_EQ(1u, GetErrorCount()); |
| 909 EXPECT_EQ("Manifest parsing error: unknown 'platform' value ignored.", |
| 910 errors()[0]); |
| 911 } |
| 912 |
| 913 // If missing platform, application is ignored. |
| 914 { |
| 915 Manifest manifest = ParseManifest( |
| 916 "{ \"chrome_related_applications\": [{\"id\": \"foo\"}]}"); |
| 917 EXPECT_EQ(manifest.chrome_related_applications.size(), 0u); |
| 918 EXPECT_TRUE(manifest.IsEmpty()); |
| 919 EXPECT_EQ(1u, GetErrorCount()); |
| 920 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " |
| 921 "chrome related application ignored.", |
| 922 errors()[0]); |
| 923 } |
| 924 |
| 925 // Web application, without id. |
| 926 { |
| 927 Manifest manifest = ParseManifest( |
| 928 "{ \"chrome_related_applications\": [{\"platform\": \"web\"}]}"); |
| 929 EXPECT_EQ(manifest.chrome_related_applications.size(), 1u); |
| 930 EXPECT_EQ(manifest.chrome_related_applications[0].platform, |
| 931 Manifest::CHROME_RELATED_APPLICATION_PLATFORM_WEB); |
| 932 EXPECT_TRUE(manifest.chrome_related_applications[0].id.is_null()); |
| 933 EXPECT_FALSE(manifest.IsEmpty()); |
| 934 EXPECT_EQ(0u, GetErrorCount()); |
| 935 } |
| 936 |
| 937 // Android application, with id. |
| 938 { |
| 939 Manifest manifest = ParseManifest( |
| 940 "{ \"chrome_related_applications\": [" |
| 941 "{\"platform\": \"android\", \"id\": \"foo\"}]}"); |
| 942 EXPECT_EQ(manifest.chrome_related_applications.size(), 1u); |
| 943 EXPECT_EQ(manifest.chrome_related_applications[0].platform, |
| 944 Manifest::CHROME_RELATED_APPLICATION_PLATFORM_ANDROID); |
| 945 EXPECT_TRUE(EqualsASCII(manifest.chrome_related_applications[0].id.string(), |
| 946 "foo")); |
| 947 EXPECT_FALSE(manifest.IsEmpty()); |
| 948 EXPECT_EQ(0u, GetErrorCount()); |
| 949 } |
| 950 |
| 951 // All valid applications are in list. |
| 952 { |
| 953 Manifest manifest = ParseManifest( |
| 954 "{ \"chrome_related_applications\": [" |
| 955 "{\"platform\": \"android\", \"id\": \"foo\"}," |
| 956 "{\"platform\": \"web\"}]}"); |
| 957 EXPECT_EQ(manifest.chrome_related_applications.size(), 2u); |
| 958 EXPECT_EQ(manifest.chrome_related_applications[0].platform, |
| 959 Manifest::CHROME_RELATED_APPLICATION_PLATFORM_ANDROID); |
| 960 EXPECT_TRUE(EqualsASCII(manifest.chrome_related_applications[0].id.string(), |
| 961 "foo")); |
| 962 EXPECT_EQ(manifest.chrome_related_applications[1].platform, |
| 963 Manifest::CHROME_RELATED_APPLICATION_PLATFORM_WEB); |
| 964 EXPECT_TRUE(manifest.chrome_related_applications[1].id.is_null()); |
| 965 EXPECT_FALSE(manifest.IsEmpty()); |
| 966 EXPECT_EQ(0u, GetErrorCount()); |
| 967 } |
| 968 |
| 969 // Two invalid applications and one valid. Only the valid application should |
| 970 // be in the list. |
| 971 { |
| 972 Manifest manifest = ParseManifest( |
| 973 "{ \"chrome_related_applications\": [" |
| 974 "{\"platform\": \"foo\", \"id\": \"bar\"}," |
| 975 "{\"platform\": \"android\", \"id\": \"foo\"},{}]}"); |
| 976 EXPECT_EQ(manifest.chrome_related_applications.size(), 1u); |
| 977 EXPECT_EQ(manifest.chrome_related_applications[0].platform, |
| 978 Manifest::CHROME_RELATED_APPLICATION_PLATFORM_ANDROID); |
| 979 EXPECT_TRUE(EqualsASCII(manifest.chrome_related_applications[0].id.string(), |
| 980 "foo")); |
| 981 EXPECT_FALSE(manifest.IsEmpty()); |
| 982 EXPECT_EQ(2u, GetErrorCount()); |
| 983 EXPECT_EQ("Manifest parsing error: unknown 'platform' value ignored.", |
| 984 errors()[0]); |
| 985 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " |
| 986 "chrome related application ignored.", |
| 987 errors()[1]); |
| 988 } |
| 989 } |
| 990 |
880 } // namespace content | 991 } // namespace content |
OLD | NEW |