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

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

Issue 576073004: Add support for 'orientation' in Manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_display
Patch Set: Created 6 years, 3 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 "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 24 matching lines...) Expand all
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 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED);
45 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
45 } 46 }
46 47
47 TEST_F(ManifestParserTest, ValidNoContentParses) { 48 TEST_F(ManifestParserTest, ValidNoContentParses) {
48 Manifest manifest = ParseManifest("{}"); 49 Manifest manifest = ParseManifest("{}");
49 50
50 // Check that all the fields are null in that case. 51 // Check that all the fields are null in that case.
51 ASSERT_TRUE(manifest.IsEmpty()); 52 ASSERT_TRUE(manifest.IsEmpty());
52 ASSERT_TRUE(manifest.name.is_null()); 53 ASSERT_TRUE(manifest.name.is_null());
53 ASSERT_TRUE(manifest.short_name.is_null()); 54 ASSERT_TRUE(manifest.short_name.is_null());
54 ASSERT_TRUE(manifest.start_url.is_empty()); 55 ASSERT_TRUE(manifest.start_url.is_empty());
55 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); 56 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED);
57 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
56 } 58 }
57 59
58 TEST_F(ManifestParserTest, NameParseRules) { 60 TEST_F(ManifestParserTest, NameParseRules) {
59 // Smoke test. 61 // Smoke test.
60 { 62 {
61 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); 63 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }");
62 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo")); 64 ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo"));
63 ASSERT_FALSE(manifest.IsEmpty()); 65 ASSERT_FALSE(manifest.IsEmpty());
64 } 66 }
65 67
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); 223 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER);
222 } 224 }
223 225
224 // Case insensitive. 226 // Case insensitive.
225 { 227 {
226 Manifest manifest = ParseManifest("{ \"display\": \"BROWSER\" }"); 228 Manifest manifest = ParseManifest("{ \"display\": \"BROWSER\" }");
227 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); 229 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER);
228 } 230 }
229 } 231 }
230 232
233 TEST_F(ManifestParserTest, OrientationParserRules) {
234 // Smoke test.
235 {
236 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }");
237 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural);
238 EXPECT_FALSE(manifest.IsEmpty());
239 }
240
241 // Trim whitespaces.
242 {
243 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }");
244 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural);
245 }
246
247 // Don't parse if name isn't a string.
248 {
249 Manifest manifest = ParseManifest("{ \"orientation\": {} }");
250 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
251 }
252
253 // Don't parse if name isn't a string.
254 {
255 Manifest manifest = ParseManifest("{ \"orientation\": 42 }");
256 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
257 }
258
259 // Parse fails if string isn't known.
260 {
261 Manifest manifest = ParseManifest("{ \"orientation\": \"naturalish\" }");
262 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
263 }
264
265 // Accept 'any'.
266 {
267 Manifest manifest = ParseManifest("{ \"orientation\": \"any\" }");
268 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockAny);
269 }
270
271 // Accept 'natural'.
272 {
273 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }");
274 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural);
275 }
276
277 // Accept 'landscape'.
278 {
279 Manifest manifest = ParseManifest("{ \"orientation\": \"landscape\" }");
280 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape);
281 }
282
283 // Accept 'landscape-primary'.
284 {
285 Manifest manifest =
286 ParseManifest("{ \"orientation\": \"landscape-primary\" }");
287 EXPECT_EQ(manifest.orientation,
288 blink::WebScreenOrientationLockLandscapePrimary);
289 }
290
291 // Accept 'landscape-secondary'.
292 {
293 Manifest manifest =
294 ParseManifest("{ \"orientation\": \"landscape-secondary\" }");
295 EXPECT_EQ(manifest.orientation,
296 blink::WebScreenOrientationLockLandscapeSecondary);
297 }
298
299 // Accept 'portrait'.
300 {
301 Manifest manifest = ParseManifest("{ \"orientation\": \"portrait\" }");
302 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockPortrait);
303 }
304
305 // Accept 'portrait-primary'.
306 {
307 Manifest manifest =
308 ParseManifest("{ \"orientation\": \"portrait-primary\" }");
309 EXPECT_EQ(manifest.orientation,
310 blink::WebScreenOrientationLockPortraitPrimary);
311 }
312
313 // Accept 'portrait-secondary'.
314 {
315 Manifest manifest =
316 ParseManifest("{ \"orientation\": \"portrait-secondary\" }");
317 EXPECT_EQ(manifest.orientation,
318 blink::WebScreenOrientationLockPortraitSecondary);
319 }
320
321 // Case insensitive.
322 {
323 Manifest manifest = ParseManifest("{ \"orientation\": \"LANDSCAPE\" }");
324 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockLandscape);
325 }
326 }
327
231 } // namespace content 328 } // namespace content
OLDNEW
« content/common/manifest_manager_messages.h ('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