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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 EXPECT_EQ("Manifest parsing error: Line: 1, column: 1, Unexpected token.", | 59 EXPECT_EQ("Manifest parsing error: Line: 1, column: 1, Unexpected token.", |
60 errors()[0]); | 60 errors()[0]); |
61 | 61 |
62 // A parsing error is equivalent to an empty manifest. | 62 // A parsing error is equivalent to an empty manifest. |
63 ASSERT_TRUE(manifest.IsEmpty()); | 63 ASSERT_TRUE(manifest.IsEmpty()); |
64 ASSERT_TRUE(manifest.name.is_null()); | 64 ASSERT_TRUE(manifest.name.is_null()); |
65 ASSERT_TRUE(manifest.short_name.is_null()); | 65 ASSERT_TRUE(manifest.short_name.is_null()); |
66 ASSERT_TRUE(manifest.start_url.is_empty()); | 66 ASSERT_TRUE(manifest.start_url.is_empty()); |
67 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); | 67 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
68 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); | 68 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
69 ASSERT_TRUE(manifest.gcm_sender_id.is_null()); | |
70 ASSERT_TRUE(manifest.gcm_user_visible_only); | |
69 } | 71 } |
70 | 72 |
71 TEST_F(ManifestParserTest, ValidNoContentParses) { | 73 TEST_F(ManifestParserTest, ValidNoContentParses) { |
72 Manifest manifest = ParseManifest("{}"); | 74 Manifest manifest = ParseManifest("{}"); |
73 | 75 |
74 // Empty Manifest is not a parsing error. | 76 // Empty Manifest is not a parsing error. |
75 EXPECT_EQ(0u, GetErrorCount()); | 77 EXPECT_EQ(0u, GetErrorCount()); |
76 | 78 |
77 // Check that all the fields are null in that case. | 79 // Check that all the fields are null in that case. |
78 ASSERT_TRUE(manifest.IsEmpty()); | 80 ASSERT_TRUE(manifest.IsEmpty()); |
79 ASSERT_TRUE(manifest.name.is_null()); | 81 ASSERT_TRUE(manifest.name.is_null()); |
80 ASSERT_TRUE(manifest.short_name.is_null()); | 82 ASSERT_TRUE(manifest.short_name.is_null()); |
81 ASSERT_TRUE(manifest.start_url.is_empty()); | 83 ASSERT_TRUE(manifest.start_url.is_empty()); |
82 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); | 84 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
83 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); | 85 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); |
86 ASSERT_TRUE(manifest.gcm_sender_id.is_null()); | |
87 ASSERT_TRUE(manifest.gcm_user_visible_only); | |
84 } | 88 } |
85 | 89 |
86 TEST_F(ManifestParserTest, MultipleErrorsReporting) { | 90 TEST_F(ManifestParserTest, MultipleErrorsReporting) { |
87 Manifest manifest = ParseManifest("{ \"name\": 42, \"short_name\": 4," | 91 Manifest manifest = ParseManifest("{ \"name\": 42, \"short_name\": 4," |
88 "\"orientation\": {}, \"display\": \"foo\", \"start_url\": null," | 92 "\"orientation\": {}, \"display\": \"foo\", \"start_url\": null," |
89 "\"icons\": {} }"); | 93 "\"icons\": {}, \"gcm_user_visible_only\": 42 }"); |
90 | 94 |
91 EXPECT_EQ(6u, GetErrorCount()); | 95 EXPECT_EQ(7u, GetErrorCount()); |
92 | 96 |
93 EXPECT_EQ("Manifest parsing error: property 'name' ignored," | 97 EXPECT_EQ("Manifest parsing error: property 'name' ignored," |
94 " type string expected.", | 98 " type string expected.", |
95 errors()[0]); | 99 errors()[0]); |
96 EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," | 100 EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," |
97 " type string expected.", | 101 " type string expected.", |
98 errors()[1]); | 102 errors()[1]); |
99 EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," | 103 EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," |
100 " type string expected.", | 104 " type string expected.", |
101 errors()[2]); | 105 errors()[2]); |
102 EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.", | 106 EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.", |
103 errors()[3]); | 107 errors()[3]); |
104 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," | 108 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," |
105 " type string expected.", | 109 " type string expected.", |
106 errors()[4]); | 110 errors()[4]); |
107 EXPECT_EQ("Manifest parsing error: property 'icons' ignored, " | 111 EXPECT_EQ("Manifest parsing error: property 'icons' ignored, " |
108 "type array expected.", | 112 "type array expected.", |
109 errors()[5]); | 113 errors()[5]); |
114 EXPECT_EQ("Manifest parsing error: property 'gcm_user_visible_only' ignored, " | |
115 "type boolean expected.", | |
116 errors()[6]); | |
110 } | 117 } |
111 | 118 |
112 TEST_F(ManifestParserTest, NameParseRules) { | 119 TEST_F(ManifestParserTest, NameParseRules) { |
113 // Smoke test. | 120 // Smoke test. |
114 { | 121 { |
115 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); | 122 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); |
116 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); | 123 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); |
117 ASSERT_FALSE(manifest.IsEmpty()); | 124 ASSERT_FALSE(manifest.IsEmpty()); |
118 EXPECT_EQ(0u, GetErrorCount()); | 125 EXPECT_EQ(0u, GetErrorCount()); |
119 } | 126 } |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 EXPECT_EQ(0u, GetErrorCount()); | 793 EXPECT_EQ(0u, GetErrorCount()); |
787 } | 794 } |
788 | 795 |
789 // Trim whitespaces. | 796 // Trim whitespaces. |
790 { | 797 { |
791 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \" foo \" }"); | 798 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \" foo \" }"); |
792 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); | 799 EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo")); |
793 EXPECT_EQ(0u, GetErrorCount()); | 800 EXPECT_EQ(0u, GetErrorCount()); |
794 } | 801 } |
795 | 802 |
796 // Don't parse if property isn't a string. | 803 // Don't parse if the property isn't a string. |
797 { | 804 { |
798 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": {} }"); | 805 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": {} }"); |
799 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 806 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
800 EXPECT_EQ(1u, GetErrorCount()); | 807 EXPECT_EQ(1u, GetErrorCount()); |
801 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," | 808 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," |
802 " type string expected.", | 809 " type string expected.", |
803 errors()[0]); | 810 errors()[0]); |
804 } | 811 } |
805 { | 812 { |
806 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); | 813 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); |
807 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 814 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
808 EXPECT_EQ(1u, GetErrorCount()); | 815 EXPECT_EQ(1u, GetErrorCount()); |
809 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," | 816 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," |
810 " type string expected.", | 817 " type string expected.", |
811 errors()[0]); | 818 errors()[0]); |
812 } | 819 } |
813 } | 820 } |
814 | 821 |
822 TEST_F(ManifestParserTest, GCMUserVisibleOnlyParseRules) { | |
823 // Smoke test. | |
824 { | |
825 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": true }"); | |
826 EXPECT_TRUE(manifest.gcm_user_visible_only); | |
827 EXPECT_EQ(0u, GetErrorCount()); | |
828 } | |
829 | |
830 // Don't parse if the property isn't a boolean. | |
831 { | |
832 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": {} }"); | |
833 EXPECT_FALSE(manifest.gcm_user_visible_only); | |
834 EXPECT_EQ(1u, GetErrorCount()); | |
835 EXPECT_EQ( | |
836 "Manifest parsing error: property 'gcm_user_visible_only' ignored," | |
837 " type boolean expected.", | |
838 errors()[0]); | |
839 } | |
840 { | |
841 Manifest manifest = ParseManifest( | |
842 "{ \"gcm_user_visible_only\": \"true\" }"); | |
843 EXPECT_FALSE(manifest.gcm_user_visible_only); | |
844 EXPECT_EQ(1u, GetErrorCount()); | |
845 EXPECT_EQ( | |
846 "Manifest parsing error: property 'gcm_user_visible_only' ignored," | |
847 " type boolean expected.", | |
848 errors()[0]); | |
849 } | |
mlamouri (slow - plz ping)
2014/12/01 21:05:09
Could you check that false is correctly parsed wit
Peter Beverloo
2014/12/03 15:01:59
Done.
| |
850 } | |
851 | |
815 } // namespace content | 852 } // namespace content |
OLD | NEW |