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

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

Issue 2637003002: Add share_target field to Manifest. (Closed)
Patch Set: Doc update and clean up Created 3 years, 11 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 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
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());
1021 EXPECT_EQ(1u, GetErrorCount());
1022 EXPECT_EQ("property 'url_template' ignored, type string expected.",
1023 errors()[0]);
1024 }
1025
1026 // Contains share_target and url_template, and url_template is valid template.
Matt Giuca 2017/01/18 07:51:32 What if it's an invalid template? Is it expected t
constantina 2017/01/18 23:28:10 Test added. We will let it parse correctly, at lea
1027 {
1028 Manifest manifest = ParseManifest(
1029 "{ \"share_target\": {\"url_template\": \"share/?title={title}\" } }");
1030 EXPECT_TRUE(base::EqualsASCII(manifest.share_target.url_template.string(),
1031 "share/?title={title}"));
1032 EXPECT_FALSE(manifest.IsEmpty());
1033 EXPECT_EQ(0u, GetErrorCount());
1034 }
1035 }
1036
985 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) { 1037 TEST_F(ManifestParserTest, RelatedApplicationsParseRules) {
986 // If no application, empty list. 1038 // If no application, empty list.
987 { 1039 {
988 Manifest manifest = ParseManifest( 1040 Manifest manifest = ParseManifest(
989 "{ \"related_applications\": []}"); 1041 "{ \"related_applications\": []}");
990 EXPECT_EQ(manifest.related_applications.size(), 0u); 1042 EXPECT_EQ(manifest.related_applications.size(), 0u);
991 EXPECT_TRUE(manifest.IsEmpty()); 1043 EXPECT_TRUE(manifest.IsEmpty());
992 EXPECT_EQ(0u, GetErrorCount()); 1044 EXPECT_EQ(0u, GetErrorCount());
993 } 1045 }
994 1046
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 { 1570 {
1519 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); 1571 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }");
1520 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); 1572 EXPECT_TRUE(manifest.gcm_sender_id.is_null());
1521 EXPECT_EQ(1u, GetErrorCount()); 1573 EXPECT_EQ(1u, GetErrorCount());
1522 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", 1574 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.",
1523 errors()[0]); 1575 errors()[0]);
1524 } 1576 }
1525 } 1577 }
1526 1578
1527 } // namespace content 1579 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698