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 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 { | 975 { |
976 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," | 976 Manifest manifest = ParseManifest("{ \"icons\": [ {\"src\": \"\"," |
977 "\"purpose\": \"notification\" } ] }"); | 977 "\"purpose\": \"notification\" } ] }"); |
978 ASSERT_EQ(manifest.icons[0].purpose.size(), 1u); | 978 ASSERT_EQ(manifest.icons[0].purpose.size(), 1u); |
979 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY); | 979 EXPECT_EQ(manifest.icons[0].purpose[0], Manifest::Icon::IconPurpose::ANY); |
980 ASSERT_EQ(1u, GetErrorCount()); | 980 ASSERT_EQ(1u, GetErrorCount()); |
981 EXPECT_EQ(kPurposeInvalidValueError, errors()[0]); | 981 EXPECT_EQ(kPurposeInvalidValueError, errors()[0]); |
982 } | 982 } |
983 } | 983 } |
984 | 984 |
985 TEST_F(ManifestParserTest, ShareTargetParseRules) { | |
986 // Contains share_target field but no keys. | |
987 { | |
988 Manifest manifest = ParseManifest("{ \"share_target\": {} }"); | |
989 EXPECT_TRUE(manifest.share_target.is_null()); | |
990 EXPECT_TRUE(manifest.IsEmpty()); | |
991 EXPECT_EQ(0u, GetErrorCount()); | |
992 } | |
993 | |
994 // Contains share_target and url_template, but url_template is empty. | |
995 { | |
996 Manifest manifest = | |
997 ParseManifest("{ \"share_target\": { \"url_template\": \"\" } }"); | |
998 EXPECT_TRUE( | |
999 base::EqualsASCII(manifest.share_target.url_template.string(), "")); | |
1000 EXPECT_FALSE(manifest.IsEmpty()); | |
1001 EXPECT_EQ(0u, GetErrorCount()); | |
1002 } | |
1003 | |
1004 // Don't parse if property isn't a string. | |
1005 { | |
1006 Manifest manifest = | |
1007 ParseManifest("{ \"share_target\": { \"url_template\": {} } }"); | |
1008 EXPECT_TRUE(manifest.share_target.is_null()); | |
1009 ASSERT_TRUE(manifest.IsEmpty()); | |
mlamouri (slow - plz ping)
2017/01/23 00:22:26
Why ASSERT?
constantina
2017/01/23 02:51:36
It shouldn't be ASSERT; changed to EXPECT.
| |
1010 EXPECT_EQ(1u, GetErrorCount()); | |
1011 EXPECT_EQ("property 'url_template' ignored, type string expected.", | |
1012 errors()[0]); | |
1013 } | |
1014 | |
1015 // Don't parse if property isn't a string. | |
1016 { | |
1017 Manifest manifest = | |
1018 ParseManifest("{ \"share_target\": { \"url_template\": 42 } }"); | |
1019 EXPECT_TRUE(manifest.share_target.is_null()); | |
1020 ASSERT_TRUE(manifest.IsEmpty()); | |
mlamouri (slow - plz ping)
2017/01/23 00:22:26
ditto
constantina
2017/01/23 02:51:36
Done.
| |
1021 EXPECT_EQ(1u, GetErrorCount()); | |
1022 EXPECT_EQ("property 'url_template' ignored, type string expected.", | |
1023 errors()[0]); | |
1024 } | |
1025 | |
1026 // Smoke test: Contains share_target and url_template, and url_template is | |
1027 // valid template. | |
1028 { | |
1029 Manifest manifest = ParseManifest( | |
1030 "{ \"share_target\": {\"url_template\": \"share/?title={title}\" } }"); | |
1031 EXPECT_TRUE(base::EqualsASCII(manifest.share_target.url_template.string(), | |
1032 "share/?title={title}")); | |
1033 EXPECT_FALSE(manifest.IsEmpty()); | |
1034 EXPECT_EQ(0u, GetErrorCount()); | |
1035 } | |
1036 | |
1037 // Smoke test: Contains share_target and url_template, and url_template is | |
1038 // invalid template. | |
1039 { | |
1040 Manifest manifest = ParseManifest( | |
1041 "{ \"share_target\": {\"url_template\": \"share/?title={title\" } }"); | |
1042 EXPECT_TRUE(base::EqualsASCII(manifest.share_target.url_template.string(), | |
1043 "share/?title={title")); | |
1044 EXPECT_FALSE(manifest.IsEmpty()); | |
1045 EXPECT_EQ(0u, GetErrorCount()); | |
1046 } | |
1047 } | |
mlamouri (slow - plz ping)
2017/01/23 00:22:26
Shouldn't you test `url_template` parsing?
constantina
2017/01/23 02:51:36
Done. Separated out the existing test cases that w
| |
1048 | |
985 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { | 1049 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { |
986 // If no application, empty list. | 1050 // If no application, empty list. |
987 { | 1051 { |
988 Manifest manifest = ParseManifest( | 1052 Manifest manifest = ParseManifest( |
989 "{ \"related_applications\": []}"); | 1053 "{ \"related_applications\": []}"); |
990 EXPECT_EQ(manifest.related_applications.size(), 0u); | 1054 EXPECT_EQ(manifest.related_applications.size(), 0u); |
991 EXPECT_TRUE(manifest.IsEmpty()); | 1055 EXPECT_TRUE(manifest.IsEmpty()); |
992 EXPECT_EQ(0u, GetErrorCount()); | 1056 EXPECT_EQ(0u, GetErrorCount()); |
993 } | 1057 } |
994 | 1058 |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1518 { | 1582 { |
1519 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); | 1583 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); |
1520 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 1584 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
1521 EXPECT_EQ(1u, GetErrorCount()); | 1585 EXPECT_EQ(1u, GetErrorCount()); |
1522 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", | 1586 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", |
1523 errors()[0]); | 1587 errors()[0]); |
1524 } | 1588 } |
1525 } | 1589 } |
1526 | 1590 |
1527 } // namespace content | 1591 } // namespace content |
OLD | NEW |