Chromium Code Reviews| 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 790 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
| 791 "\"sizes\": \"x 40xx 1x2x3 x42 42xx42\" } ] }"); | 791 "\"sizes\": \"x 40xx 1x2x3 x42 42xx42\" } ] }"); |
| 792 gfx::Size any = gfx::Size(0, 0); | 792 gfx::Size any = gfx::Size(0, 0); |
| 793 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); | 793 EXPECT_EQ(manifest.icons[0].sizes.size(), 0u); |
| 794 EXPECT_EQ(1u, GetErrorCount()); | 794 EXPECT_EQ(1u, GetErrorCount()); |
| 795 EXPECT_EQ("Manifest parsing error: found icon with no valid size.", | 795 EXPECT_EQ("Manifest parsing error: found icon with no valid size.", |
| 796 errors()[0]); | 796 errors()[0]); |
| 797 } | 797 } |
| 798 } | 798 } |
| 799 | 799 |
| 800 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { | |
| 801 // If no application, empty list. | |
| 802 { | |
| 803 Manifest manifest = ParseManifest( | |
| 804 "{ \"related_applications\": []}"); | |
| 805 EXPECT_EQ(manifest.related_applications.size(), 0u); | |
| 806 EXPECT_TRUE(manifest.IsEmpty()); | |
| 807 EXPECT_EQ(0u, GetErrorCount()); | |
| 808 } | |
| 809 | |
| 810 // If empty application, empty list. | |
| 811 { | |
| 812 Manifest manifest = ParseManifest( | |
| 813 "{ \"related_applications\": [{}]}"); | |
| 814 EXPECT_EQ(manifest.related_applications.size(), 0u); | |
| 815 EXPECT_TRUE(manifest.IsEmpty()); | |
| 816 EXPECT_EQ(1u, GetErrorCount()); | |
| 817 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " | |
| 818 "related application ignored.", | |
| 819 errors()[0]); | |
| 820 } | |
| 821 | |
| 822 // If invalid platform, application is ignored. | |
| 823 { | |
| 824 Manifest manifest = ParseManifest( | |
| 825 "{ \"related_applications\": [{\"platform\": 123}]}"); | |
| 826 EXPECT_EQ(manifest.related_applications.size(), 0u); | |
| 827 EXPECT_TRUE(manifest.IsEmpty()); | |
| 828 EXPECT_EQ(2u, GetErrorCount()); | |
| 829 EXPECT_EQ( | |
| 830 "Manifest parsing error: property 'platform' ignored, type string " | |
| 831 "expected.", | |
| 832 errors()[0]); | |
| 833 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " | |
| 834 "related application ignored.", | |
| 835 errors()[1]); | |
| 836 } | |
| 837 | |
| 838 // If missing platform, application is ignored. | |
| 839 { | |
| 840 Manifest manifest = ParseManifest( | |
| 841 "{ \"related_applications\": [{\"id\": \"foo\"}]}"); | |
| 842 EXPECT_EQ(manifest.related_applications.size(), 0u); | |
| 843 EXPECT_TRUE(manifest.IsEmpty()); | |
| 844 EXPECT_EQ(1u, GetErrorCount()); | |
| 845 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " | |
| 846 "related application ignored.", | |
| 847 errors()[0]); | |
| 848 } | |
| 849 | |
| 850 // If missing id and url, application is ignored. | |
| 851 { | |
| 852 Manifest manifest = ParseManifest( | |
| 853 "{ \"related_applications\": [{\"platform\": \"play\"}]}"); | |
| 854 EXPECT_EQ(manifest.related_applications.size(), 0u); | |
| 855 EXPECT_TRUE(manifest.IsEmpty()); | |
| 856 EXPECT_EQ(1u, GetErrorCount()); | |
| 857 EXPECT_EQ("Manifest parsing error: one of 'url' or 'id' is required, " | |
| 858 "related application ignored.", | |
| 859 errors()[0]); | |
| 860 } | |
| 861 | |
| 862 // Valid application, with url. | |
| 863 { | |
| 864 Manifest manifest = ParseManifest( | |
| 865 "{ \"related_applications\": [" | |
| 866 "{\"platform\": \"play\", \"url\": \"http://www.foo.com\"}]}"); | |
| 867 EXPECT_EQ(manifest.related_applications.size(), 1u); | |
| 868 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].platform.string(), | |
| 869 "play")); | |
| 870 EXPECT_EQ(manifest.related_applications[0].url.spec(), | |
| 871 "http://www.foo.com/"); | |
| 872 EXPECT_FALSE(manifest.IsEmpty()); | |
| 873 EXPECT_EQ(0u, GetErrorCount()); | |
| 874 } | |
| 875 | |
| 876 // Valid application, with id. | |
| 877 { | |
| 878 Manifest manifest = ParseManifest( | |
| 879 "{ \"related_applications\": [" | |
| 880 "{\"platform\": \"itunes\", \"id\": \"foo\"}]}"); | |
| 881 EXPECT_EQ(manifest.related_applications.size(), 1u); | |
| 882 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].platform.string(), | |
| 883 "itunes")); | |
| 884 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].id.string(), | |
| 885 "foo")); | |
| 886 EXPECT_FALSE(manifest.IsEmpty()); | |
| 887 EXPECT_EQ(0u, GetErrorCount()); | |
| 888 } | |
| 889 | |
| 890 // All valid applications are in list. | |
| 891 { | |
| 892 Manifest manifest = ParseManifest( | |
| 893 "{ \"related_applications\": [" | |
| 894 "{\"platform\": \"play\", \"id\": \"foo\"}," | |
| 895 "{\"platform\": \"itunes\", \"id\": \"bar\"}]}"); | |
| 896 EXPECT_EQ(manifest.related_applications.size(), 2u); | |
| 897 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].platform.string(), | |
| 898 "play")); | |
| 899 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].id.string(), | |
| 900 "foo")); | |
| 901 EXPECT_TRUE(EqualsASCII(manifest.related_applications[1].platform.string(), | |
| 902 "itunes")); | |
| 903 EXPECT_TRUE(EqualsASCII(manifest.related_applications[1].id.string(), | |
| 904 "bar")); | |
| 905 EXPECT_FALSE(manifest.IsEmpty()); | |
| 906 EXPECT_EQ(0u, GetErrorCount()); | |
| 907 } | |
| 908 | |
| 909 // Two invalid applications and one valid. Only the valid application should | |
| 910 // be in the list. | |
| 911 { | |
| 912 Manifest manifest = ParseManifest( | |
| 913 "{ \"related_applications\": [" | |
| 914 "{\"platform\": \"itunes\"}," | |
| 915 "{\"platform\": \"play\", \"id\": \"foo\"},{}]}"); | |
|
mlamouri (slow - plz ping)
2015/04/15 08:46:31
Could you put the empty application in a new line?
benwells
2015/04/16 01:30:46
Done.
| |
| 916 EXPECT_EQ(manifest.related_applications.size(), 1u); | |
| 917 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].platform.string(), | |
| 918 "play")); | |
| 919 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].id.string(), | |
| 920 "foo")); | |
| 921 EXPECT_FALSE(manifest.IsEmpty()); | |
| 922 EXPECT_EQ(2u, GetErrorCount()); | |
| 923 EXPECT_EQ("Manifest parsing error: one of 'url' or 'id' is required, " | |
| 924 "related application ignored.", | |
| 925 errors()[0]); | |
| 926 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " | |
| 927 "related application ignored.", | |
| 928 errors()[1]); | |
| 929 } | |
| 930 } | |
| 931 | |
| 932 TEST_F(ManifestParserTest, ParsePreferRelatedApplicationsParseRules) { | |
| 933 // Smoke test. | |
| 934 { | |
| 935 Manifest manifest = | |
| 936 ParseManifest("{ \"prefer_related_applications\": true }"); | |
| 937 EXPECT_TRUE(manifest.prefer_related_applications); | |
| 938 EXPECT_EQ(0u, GetErrorCount()); | |
| 939 } | |
| 940 | |
| 941 // Don't parse if the property isn't a boolean. | |
| 942 { | |
| 943 Manifest manifest = | |
| 944 ParseManifest("{ \"prefer_related_applications\": {} }"); | |
| 945 EXPECT_FALSE(manifest.prefer_related_applications); | |
| 946 EXPECT_EQ(1u, GetErrorCount()); | |
| 947 EXPECT_EQ( | |
| 948 "Manifest parsing error: property 'prefer_related_applications' " | |
| 949 "ignored, type boolean expected.", | |
| 950 errors()[0]); | |
| 951 } | |
| 952 { | |
| 953 Manifest manifest = ParseManifest( | |
| 954 "{ \"prefer_related_applications\": \"true\" }"); | |
| 955 EXPECT_FALSE(manifest.prefer_related_applications); | |
| 956 EXPECT_EQ(1u, GetErrorCount()); | |
| 957 EXPECT_EQ( | |
| 958 "Manifest parsing error: property 'prefer_related_applications' " | |
| 959 "ignored, type boolean expected.", | |
| 960 errors()[0]); | |
| 961 } | |
| 962 { | |
| 963 Manifest manifest = ParseManifest("{ \"prefer_related_applications\": 1 }"); | |
| 964 EXPECT_FALSE(manifest.prefer_related_applications); | |
| 965 EXPECT_EQ(1u, GetErrorCount()); | |
| 966 EXPECT_EQ( | |
| 967 "Manifest parsing error: property 'prefer_related_applications' " | |
| 968 "ignored, type boolean expected.", | |
| 969 errors()[0]); | |
| 970 } | |
| 971 | |
| 972 // "False" should set the boolean false without throwing errors. | |
| 973 { | |
| 974 Manifest manifest = | |
| 975 ParseManifest("{ \"prefer_related_applications\": false }"); | |
| 976 EXPECT_FALSE(manifest.prefer_related_applications); | |
| 977 EXPECT_EQ(0u, GetErrorCount()); | |
| 978 } | |
| 979 } | |
| 980 | |
| 800 TEST_F(ManifestParserTest, GCMSenderIDParseRules) { | 981 TEST_F(ManifestParserTest, GCMSenderIDParseRules) { |
| 801 // Smoke test. | 982 // Smoke test. |
| 802 { | 983 { |
| 803 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); | 984 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); |
| 804 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); | 985 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); |
| 805 EXPECT_EQ(0u, GetErrorCount()); | 986 EXPECT_EQ(0u, GetErrorCount()); |
| 806 } | 987 } |
| 807 | 988 |
| 808 // Trim whitespaces. | 989 // Trim whitespaces. |
| 809 { | 990 { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 | 1052 |
| 872 // "False" should set the boolean false without throwing errors. | 1053 // "False" should set the boolean false without throwing errors. |
| 873 { | 1054 { |
| 874 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }"); | 1055 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }"); |
| 875 EXPECT_FALSE(manifest.gcm_user_visible_only); | 1056 EXPECT_FALSE(manifest.gcm_user_visible_only); |
| 876 EXPECT_EQ(0u, GetErrorCount()); | 1057 EXPECT_EQ(0u, GetErrorCount()); |
| 877 } | 1058 } |
| 878 } | 1059 } |
| 879 | 1060 |
| 880 } // namespace content | 1061 } // namespace content |
| OLD | NEW |