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 23 matching lines...) Expand all Loading... |
34 "http://foo.com/manifest.json"); | 34 "http://foo.com/manifest.json"); |
35 | 35 |
36 TEST_F(ManifestParserTest, EmptyStringNull) { | 36 TEST_F(ManifestParserTest, EmptyStringNull) { |
37 Manifest manifest = ParseManifest(""); | 37 Manifest manifest = ParseManifest(""); |
38 | 38 |
39 // A parsing error is equivalent to an empty manifest. | 39 // A parsing error is equivalent to an empty manifest. |
40 ASSERT_TRUE(manifest.IsEmpty()); | 40 ASSERT_TRUE(manifest.IsEmpty()); |
41 ASSERT_TRUE(manifest.name.is_null()); | 41 ASSERT_TRUE(manifest.name.is_null()); |
42 ASSERT_TRUE(manifest.short_name.is_null()); | 42 ASSERT_TRUE(manifest.short_name.is_null()); |
43 ASSERT_TRUE(manifest.start_url.is_empty()); | 43 ASSERT_TRUE(manifest.start_url.is_empty()); |
| 44 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
44 } | 45 } |
45 | 46 |
46 TEST_F(ManifestParserTest, ValidNoContentParses) { | 47 TEST_F(ManifestParserTest, ValidNoContentParses) { |
47 Manifest manifest = ParseManifest("{}"); | 48 Manifest manifest = ParseManifest("{}"); |
48 | 49 |
49 // Check that all the fields are null in that case. | 50 // Check that all the fields are null in that case. |
50 ASSERT_TRUE(manifest.IsEmpty()); | 51 ASSERT_TRUE(manifest.IsEmpty()); |
51 ASSERT_TRUE(manifest.name.is_null()); | 52 ASSERT_TRUE(manifest.name.is_null()); |
52 ASSERT_TRUE(manifest.short_name.is_null()); | 53 ASSERT_TRUE(manifest.short_name.is_null()); |
53 ASSERT_TRUE(manifest.start_url.is_empty()); | 54 ASSERT_TRUE(manifest.start_url.is_empty()); |
| 55 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
54 } | 56 } |
55 | 57 |
56 TEST_F(ManifestParserTest, NameParseRules) { | 58 TEST_F(ManifestParserTest, NameParseRules) { |
57 // Smoke test. | 59 // Smoke test. |
58 { | 60 { |
59 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); | 61 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); |
60 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); | 62 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); |
| 63 ASSERT_FALSE(manifest.IsEmpty()); |
61 } | 64 } |
62 | 65 |
63 // Trim whitespaces. | 66 // Trim whitespaces. |
64 { | 67 { |
65 Manifest manifest = ParseManifest("{ \"name\": \" foo \" }"); | 68 Manifest manifest = ParseManifest("{ \"name\": \" foo \" }"); |
66 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); | 69 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); |
67 } | 70 } |
68 | 71 |
69 // Don't parse if name isn't a string. | 72 // Don't parse if name isn't a string. |
70 { | 73 { |
71 Manifest manifest = ParseManifest("{ \"name\": {} }"); | 74 Manifest manifest = ParseManifest("{ \"name\": {} }"); |
72 ASSERT_TRUE(manifest.name.is_null()); | 75 ASSERT_TRUE(manifest.name.is_null()); |
73 } | 76 } |
74 | 77 |
75 // Don't parse if name isn't a string. | 78 // Don't parse if name isn't a string. |
76 { | 79 { |
77 Manifest manifest = ParseManifest("{ \"name\": 42 }"); | 80 Manifest manifest = ParseManifest("{ \"name\": 42 }"); |
78 ASSERT_TRUE(manifest.name.is_null()); | 81 ASSERT_TRUE(manifest.name.is_null()); |
79 } | 82 } |
80 } | 83 } |
81 | 84 |
82 TEST_F(ManifestParserTest, ShortNameParseRules) { | 85 TEST_F(ManifestParserTest, ShortNameParseRules) { |
83 // Smoke test. | 86 // Smoke test. |
84 { | 87 { |
85 Manifest manifest = ParseManifest("{ \"short_name\": \"foo\" }"); | 88 Manifest manifest = ParseManifest("{ \"short_name\": \"foo\" }"); |
86 ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); | 89 ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); |
| 90 ASSERT_FALSE(manifest.IsEmpty()); |
87 } | 91 } |
88 | 92 |
89 // Trim whitespaces. | 93 // Trim whitespaces. |
90 { | 94 { |
91 Manifest manifest = ParseManifest("{ \"short_name\": \" foo \" }"); | 95 Manifest manifest = ParseManifest("{ \"short_name\": \" foo \" }"); |
92 ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); | 96 ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo")); |
93 } | 97 } |
94 | 98 |
95 // Don't parse if name isn't a string. | 99 // Don't parse if name isn't a string. |
96 { | 100 { |
97 Manifest manifest = ParseManifest("{ \"short_name\": {} }"); | 101 Manifest manifest = ParseManifest("{ \"short_name\": {} }"); |
98 ASSERT_TRUE(manifest.short_name.is_null()); | 102 ASSERT_TRUE(manifest.short_name.is_null()); |
99 } | 103 } |
100 | 104 |
101 // Don't parse if name isn't a string. | 105 // Don't parse if name isn't a string. |
102 { | 106 { |
103 Manifest manifest = ParseManifest("{ \"short_name\": 42 }"); | 107 Manifest manifest = ParseManifest("{ \"short_name\": 42 }"); |
104 ASSERT_TRUE(manifest.short_name.is_null()); | 108 ASSERT_TRUE(manifest.short_name.is_null()); |
105 } | 109 } |
106 } | 110 } |
107 | 111 |
108 TEST_F(ManifestParserTest, StartURLParseRules) { | 112 TEST_F(ManifestParserTest, StartURLParseRules) { |
109 // Smoke test. | 113 // Smoke test. |
110 { | 114 { |
111 Manifest manifest = ParseManifest("{ \"start_url\": \"land.html\" }"); | 115 Manifest manifest = ParseManifest("{ \"start_url\": \"land.html\" }"); |
112 ASSERT_EQ(manifest.start_url.spec(), | 116 ASSERT_EQ(manifest.start_url.spec(), |
113 default_document_url.Resolve("land.html").spec()); | 117 default_document_url.Resolve("land.html").spec()); |
| 118 ASSERT_FALSE(manifest.IsEmpty()); |
114 } | 119 } |
115 | 120 |
116 // Whitespaces. | 121 // Whitespaces. |
117 { | 122 { |
118 Manifest manifest = ParseManifest("{ \"start_url\": \" land.html \" }"); | 123 Manifest manifest = ParseManifest("{ \"start_url\": \" land.html \" }"); |
119 ASSERT_EQ(manifest.start_url.spec(), | 124 ASSERT_EQ(manifest.start_url.spec(), |
120 default_document_url.Resolve("land.html").spec()); | 125 default_document_url.Resolve("land.html").spec()); |
121 } | 126 } |
122 | 127 |
123 // Don't parse if property isn't a string. | 128 // Don't parse if property isn't a string. |
(...skipping 29 matching lines...) Expand all Loading... |
153 // Resolving has to happen based on the manifest_url. | 158 // Resolving has to happen based on the manifest_url. |
154 { | 159 { |
155 Manifest manifest = | 160 Manifest manifest = |
156 ParseManifest("{ \"start_url\": \"land.html\" }", | 161 ParseManifest("{ \"start_url\": \"land.html\" }", |
157 GURL("http://foo.com/landing/manifest.json"), | 162 GURL("http://foo.com/landing/manifest.json"), |
158 GURL("http://foo.com/index.html")); | 163 GURL("http://foo.com/index.html")); |
159 ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/landing/land.html"); | 164 ASSERT_EQ(manifest.start_url.spec(), "http://foo.com/landing/land.html"); |
160 } | 165 } |
161 } | 166 } |
162 | 167 |
| 168 TEST_F(ManifestParserTest, DisplayParserRules) { |
| 169 // Smoke test. |
| 170 { |
| 171 Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); |
| 172 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
| 173 EXPECT_FALSE(manifest.IsEmpty()); |
| 174 } |
| 175 |
| 176 // Trim whitespaces. |
| 177 { |
| 178 Manifest manifest = ParseManifest("{ \"display\": \" browser \" }"); |
| 179 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
| 180 } |
| 181 |
| 182 // Don't parse if name isn't a string. |
| 183 { |
| 184 Manifest manifest = ParseManifest("{ \"display\": {} }"); |
| 185 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
| 186 } |
| 187 |
| 188 // Don't parse if name isn't a string. |
| 189 { |
| 190 Manifest manifest = ParseManifest("{ \"display\": 42 }"); |
| 191 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
| 192 } |
| 193 |
| 194 // Parse fails if string isn't known. |
| 195 { |
| 196 Manifest manifest = ParseManifest("{ \"display\": \"browser_something\" }"); |
| 197 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); |
| 198 } |
| 199 |
| 200 // Accept 'fullscreen'. |
| 201 { |
| 202 Manifest manifest = ParseManifest("{ \"display\": \"fullscreen\" }"); |
| 203 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_FULLSCREEN); |
| 204 } |
| 205 |
| 206 // Accept 'fullscreen'. |
| 207 { |
| 208 Manifest manifest = ParseManifest("{ \"display\": \"standalone\" }"); |
| 209 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_STANDALONE); |
| 210 } |
| 211 |
| 212 // Accept 'minimal-ui'. |
| 213 { |
| 214 Manifest manifest = ParseManifest("{ \"display\": \"minimal-ui\" }"); |
| 215 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_MINIMAL_UI); |
| 216 } |
| 217 |
| 218 // Accept 'browser'. |
| 219 { |
| 220 Manifest manifest = ParseManifest("{ \"display\": \"browser\" }"); |
| 221 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
| 222 } |
| 223 |
| 224 // Case insensitive. |
| 225 { |
| 226 Manifest manifest = ParseManifest("{ \"display\": \"BROWSER\" }"); |
| 227 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); |
| 228 } |
| 229 } |
| 230 |
163 } // namespace content | 231 } // namespace content |
OLD | NEW |