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. | |
mlamouri (slow - plz ping)
2015/04/10 09:49:45
Keep that test but make it invalid per type like h
benwells
2015/04/15 06:45:22
Done.
| |
823 { | |
824 Manifest manifest = ParseManifest( | |
825 "{ \"related_applications\": [{\"platform\": \"foo\"}]}"); | |
826 EXPECT_EQ(manifest.related_applications.size(), 0u); | |
827 EXPECT_TRUE(manifest.IsEmpty()); | |
828 EXPECT_EQ(1u, GetErrorCount()); | |
829 EXPECT_EQ("Manifest parsing error: unknown 'platform' value ignored.", | |
830 errors()[0]); | |
831 } | |
832 | |
833 // If missing platform, application is ignored. | |
834 { | |
835 Manifest manifest = ParseManifest( | |
836 "{ \"related_applications\": [{\"id\": \"foo\"}]}"); | |
837 EXPECT_EQ(manifest.related_applications.size(), 0u); | |
838 EXPECT_TRUE(manifest.IsEmpty()); | |
839 EXPECT_EQ(1u, GetErrorCount()); | |
840 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " | |
841 "related application ignored.", | |
842 errors()[0]); | |
843 } | |
844 | |
845 // If missing id and url, application is ignored. | |
846 { | |
847 Manifest manifest = ParseManifest( | |
848 "{ \"related_applications\": [{\"platform\": \"play\"}]}"); | |
849 EXPECT_EQ(manifest.related_applications.size(), 0u); | |
850 EXPECT_TRUE(manifest.IsEmpty()); | |
851 EXPECT_EQ(1u, GetErrorCount()); | |
852 EXPECT_EQ("Manifest parsing error: one of 'url' or 'id' is required, " | |
853 "related application ignored.", | |
854 errors()[0]); | |
855 } | |
856 | |
857 // Android application, with url. | |
mlamouri (slow - plz ping)
2015/04/10 09:49:45
I don't think we should test that on the content l
benwells
2015/04/15 06:45:22
Sure, I've reworded the comment and used itunes fo
| |
858 { | |
859 Manifest manifest = ParseManifest( | |
860 "{ \"related_applications\": [" | |
861 "{\"platform\": \"play\", \"url\": \"http://www.foo.com\"}]}"); | |
862 EXPECT_EQ(manifest.related_applications.size(), 1u); | |
863 EXPECT_EQ(manifest.related_applications[0].platform, | |
864 Manifest::RELATED_APPLICATION_PLATFORM_PLAY); | |
865 EXPECT_EQ(manifest.related_applications[0].url.spec(), | |
866 "http://www.foo.com/"); | |
867 EXPECT_FALSE(manifest.IsEmpty()); | |
868 EXPECT_EQ(0u, GetErrorCount()); | |
869 } | |
870 | |
871 // Android application, with id. | |
mlamouri (slow - plz ping)
2015/04/10 09:49:45
Could you add a test where there is no id nor url?
benwells
2015/04/15 06:45:22
It is two tests up already, "If missing id and url
| |
872 { | |
873 Manifest manifest = ParseManifest( | |
874 "{ \"related_applications\": [" | |
875 "{\"platform\": \"play\", \"id\": \"foo\"}]}"); | |
876 EXPECT_EQ(manifest.related_applications.size(), 1u); | |
877 EXPECT_EQ(manifest.related_applications[0].platform, | |
878 Manifest::RELATED_APPLICATION_PLATFORM_PLAY); | |
879 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].id.string(), | |
880 "foo")); | |
881 EXPECT_FALSE(manifest.IsEmpty()); | |
882 EXPECT_EQ(0u, GetErrorCount()); | |
883 } | |
884 | |
885 // All valid applications are in list. | |
886 { | |
887 Manifest manifest = ParseManifest( | |
888 "{ \"related_applications\": [" | |
889 "{\"platform\": \"play\", \"id\": \"foo\"}," | |
890 "{\"platform\": \"play\", \"id\": \"bar\"}]}"); | |
891 EXPECT_EQ(manifest.related_applications.size(), 2u); | |
892 EXPECT_EQ(manifest.related_applications[0].platform, | |
893 Manifest::RELATED_APPLICATION_PLATFORM_PLAY); | |
894 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].id.string(), | |
895 "foo")); | |
896 EXPECT_EQ(manifest.related_applications[1].platform, | |
897 Manifest::RELATED_APPLICATION_PLATFORM_PLAY); | |
898 EXPECT_TRUE(EqualsASCII(manifest.related_applications[1].id.string(), | |
899 "bar")); | |
900 EXPECT_FALSE(manifest.IsEmpty()); | |
901 EXPECT_EQ(0u, GetErrorCount()); | |
902 } | |
903 | |
904 // Two invalid applications and one valid. Only the valid application should | |
905 // be in the list. | |
906 { | |
907 Manifest manifest = ParseManifest( | |
908 "{ \"related_applications\": [" | |
909 "{\"platform\": \"foo\", \"id\": \"bar\"}," | |
910 "{\"platform\": \"play\", \"id\": \"foo\"},{}]}"); | |
911 EXPECT_EQ(manifest.related_applications.size(), 1u); | |
912 EXPECT_EQ(manifest.related_applications[0].platform, | |
913 Manifest::RELATED_APPLICATION_PLATFORM_PLAY); | |
914 EXPECT_TRUE(EqualsASCII(manifest.related_applications[0].id.string(), | |
915 "foo")); | |
916 EXPECT_FALSE(manifest.IsEmpty()); | |
917 EXPECT_EQ(2u, GetErrorCount()); | |
918 EXPECT_EQ("Manifest parsing error: unknown 'platform' value ignored.", | |
919 errors()[0]); | |
920 EXPECT_EQ("Manifest parsing error: 'platform' is a required field, " | |
921 "related application ignored.", | |
922 errors()[1]); | |
923 } | |
924 } | |
925 | |
926 TEST_F(ManifestParserTest, ParsePreferRelatedApplicationsParseRules) { | |
927 // Smoke test. | |
928 { | |
929 Manifest manifest = | |
930 ParseManifest("{ \"prefer_related_applications\": true }"); | |
931 EXPECT_TRUE(manifest.prefer_related_applications); | |
932 EXPECT_EQ(0u, GetErrorCount()); | |
933 } | |
934 | |
935 // Don't parse if the property isn't a boolean. | |
936 { | |
937 Manifest manifest = | |
938 ParseManifest("{ \"prefer_related_applications\": {} }"); | |
939 EXPECT_FALSE(manifest.prefer_related_applications); | |
940 EXPECT_EQ(1u, GetErrorCount()); | |
941 EXPECT_EQ( | |
942 "Manifest parsing error: property 'prefer_related_applications' " | |
943 "ignored, type boolean expected.", | |
944 errors()[0]); | |
945 } | |
946 { | |
947 Manifest manifest = ParseManifest( | |
948 "{ \"prefer_related_applications\": \"true\" }"); | |
949 EXPECT_FALSE(manifest.prefer_related_applications); | |
950 EXPECT_EQ(1u, GetErrorCount()); | |
951 EXPECT_EQ( | |
952 "Manifest parsing error: property 'prefer_related_applications' " | |
953 "ignored, type boolean expected.", | |
954 errors()[0]); | |
955 } | |
956 { | |
957 Manifest manifest = ParseManifest("{ \"prefer_related_applications\": 1 }"); | |
958 EXPECT_FALSE(manifest.prefer_related_applications); | |
959 EXPECT_EQ(1u, GetErrorCount()); | |
960 EXPECT_EQ( | |
961 "Manifest parsing error: property 'prefer_related_applications' " | |
962 "ignored, type boolean expected.", | |
963 errors()[0]); | |
964 } | |
965 | |
966 // "False" should set the boolean false without throwing errors. | |
967 { | |
968 Manifest manifest = | |
969 ParseManifest("{ \"prefer_related_applications\": false }"); | |
970 EXPECT_FALSE(manifest.prefer_related_applications); | |
971 EXPECT_EQ(0u, GetErrorCount()); | |
972 } | |
973 } | |
974 | |
800 TEST_F(ManifestParserTest, GCMSenderIDParseRules) { | 975 TEST_F(ManifestParserTest, GCMSenderIDParseRules) { |
801 // Smoke test. | 976 // Smoke test. |
802 { | 977 { |
803 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); | 978 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }"); |
804 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); | 979 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); |
805 EXPECT_EQ(0u, GetErrorCount()); | 980 EXPECT_EQ(0u, GetErrorCount()); |
806 } | 981 } |
807 | 982 |
808 // Trim whitespaces. | 983 // Trim whitespaces. |
809 { | 984 { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 | 1046 |
872 // "False" should set the boolean false without throwing errors. | 1047 // "False" should set the boolean false without throwing errors. |
873 { | 1048 { |
874 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }"); | 1049 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }"); |
875 EXPECT_FALSE(manifest.gcm_user_visible_only); | 1050 EXPECT_FALSE(manifest.gcm_user_visible_only); |
876 EXPECT_EQ(0u, GetErrorCount()); | 1051 EXPECT_EQ(0u, GetErrorCount()); |
877 } | 1052 } |
878 } | 1053 } |
879 | 1054 |
880 } // namespace content | 1055 } // namespace content |
OLD | NEW |