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

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

Issue 2425833002: Parse "purpose" member from Web Manifest (Closed)
Patch Set: patch Created 4 years, 2 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
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 // 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 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 EXPECT_EQ(1u, GetErrorCount());
pkotwicz 2016/10/18 14:13:56 When the remainder of the test will crash (as oppo
F 2016/10/18 15:34:46 Done.
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 EXPECT_EQ(1u, GetErrorCount());
921 EXPECT_EQ("property 'purpose' ignored, type string expected.",
922 errors()[0]);
923 }
924
925 // Smoke test: value correctly parsed.
926 {
927 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
928 "\"purpose\": \"Any Badge\" } ] }");
pkotwicz 2016/10/18 14:13:56 You should add: ASSERT_EQ(manifest.icons[0].purpos
F 2016/10/18 15:34:46 Done.
929 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
930 EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE);
931 EXPECT_EQ(0u, GetErrorCount());
932 }
933
934 // Twice the same value is parsed twice.
935 {
936 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
937 "\"purpose\": \"badge badge\" } ] }");
pkotwicz 2016/10/18 14:13:56 You should add: ASSERT_EQ(manifest.icons[0].purpos
F 2016/10/18 15:34:46 Done.
938 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE);
939 EXPECT_EQ(manifest.icons[0].purpose[1], Manifest::Icon::IconPurpose::BADGE);
940 EXPECT_EQ(0u, GetErrorCount());
941 }
942
943 // Invalid icon purpose is ignored.
944 {
945 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
946 "\"purpose\": \"badge notification\" } ] }");
pkotwicz 2016/10/18 14:13:56 You should add: ASSERT_EQ(manifest.icons[0].purpos
F 2016/10/18 15:34:46 Done.
947 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::BADGE);
948 EXPECT_EQ(1u, GetErrorCount());
949 EXPECT_EQ("found icon with invalid purpose.",
950 errors()[0]);
951 }
952
953 // 'any' is correctly added when the purpose is empty.
pkotwicz 2016/10/18 14:13:56 How about: 'any' is added when developer-supplied-
F 2016/10/18 15:34:46 Done.
954 {
955 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\","
956 "\"purpose\": \"notification\" } ] }");
957 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY);
958 EXPECT_EQ(1u, GetErrorCount());
959 EXPECT_EQ("found icon with invalid purpose.",
960 errors()[0]);
961 }
pkotwicz 2016/10/18 14:13:56 Maybe add a test case for: \"purpose\": \"any bad
F 2016/10/18 15:34:46 Done.
962 }
963
881 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { 964 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) {
882 // If no application, empty list. 965 // If no application, empty list.
883 { 966 {
884 Manifest manifest = ParseManifest( 967 Manifest manifest = ParseManifest(
885 "{ \"related_applications\": []}"); 968 "{ \"related_applications\": []}");
886 EXPECT_EQ(manifest.related_applications.size(), 0u); 969 EXPECT_EQ(manifest.related_applications.size(), 0u);
887 EXPECT_TRUE(manifest.IsEmpty()); 970 EXPECT_TRUE(manifest.IsEmpty());
888 EXPECT_EQ(0u, GetErrorCount()); 971 EXPECT_EQ(0u, GetErrorCount());
889 } 972 }
890 973
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 { 1497 {
1415 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); 1498 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }");
1416 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); 1499 EXPECT_TRUE(manifest.gcm_sender_id.is_null());
1417 EXPECT_EQ(1u, GetErrorCount()); 1500 EXPECT_EQ(1u, GetErrorCount());
1418 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", 1501 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.",
1419 errors()[0]); 1502 errors()[0]);
1420 } 1503 }
1421 } 1504 }
1422 1505
1423 } // namespace content 1506 } // namespace content
OLDNEW
« content/renderer/manifest/manifest_parser.cc ('K') | « content/renderer/manifest/manifest_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698