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

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

Issue 1235883007: manifest: add theme_color value to the manifest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reflect change in Blink patch Created 5 years, 5 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 EXPECT_EQ(1u, GetErrorCount()); 70 EXPECT_EQ(1u, GetErrorCount());
71 EXPECT_EQ("Manifest parsing error: Line: 1, column: 1, Unexpected token.", 71 EXPECT_EQ("Manifest parsing error: Line: 1, column: 1, Unexpected token.",
72 errors()[0]); 72 errors()[0]);
73 73
74 // A parsing error is equivalent to an empty manifest. 74 // A parsing error is equivalent to an empty manifest.
75 ASSERT_TRUE(manifest.IsEmpty()); 75 ASSERT_TRUE(manifest.IsEmpty());
76 ASSERT_TRUE(manifest.name.is_null()); 76 ASSERT_TRUE(manifest.name.is_null());
77 ASSERT_TRUE(manifest.short_name.is_null()); 77 ASSERT_TRUE(manifest.short_name.is_null());
78 ASSERT_TRUE(manifest.start_url.is_empty()); 78 ASSERT_TRUE(manifest.start_url.is_empty());
79 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); 79 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED);
80 ASSERT_EQ(manifest.theme_color, Manifest::kInvalidThemeColor);
80 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); 81 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
81 ASSERT_TRUE(manifest.gcm_sender_id.is_null()); 82 ASSERT_TRUE(manifest.gcm_sender_id.is_null());
82 } 83 }
83 84
84 TEST_F(ManifestParserTest, ValidNoContentParses) { 85 TEST_F(ManifestParserTest, ValidNoContentParses) {
85 Manifest manifest = ParseManifest("{}"); 86 Manifest manifest = ParseManifest("{}");
86 87
87 // Empty Manifest is not a parsing error. 88 // Empty Manifest is not a parsing error.
88 EXPECT_EQ(0u, GetErrorCount()); 89 EXPECT_EQ(0u, GetErrorCount());
89 90
90 // Check that all the fields are null in that case. 91 // Check that all the fields are null in that case.
91 ASSERT_TRUE(manifest.IsEmpty()); 92 ASSERT_TRUE(manifest.IsEmpty());
92 ASSERT_TRUE(manifest.name.is_null()); 93 ASSERT_TRUE(manifest.name.is_null());
93 ASSERT_TRUE(manifest.short_name.is_null()); 94 ASSERT_TRUE(manifest.short_name.is_null());
94 ASSERT_TRUE(manifest.start_url.is_empty()); 95 ASSERT_TRUE(manifest.start_url.is_empty());
95 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED); 96 ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED);
97 ASSERT_EQ(manifest.theme_color, Manifest::kInvalidThemeColor);
96 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); 98 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
97 ASSERT_TRUE(manifest.gcm_sender_id.is_null()); 99 ASSERT_TRUE(manifest.gcm_sender_id.is_null());
98 } 100 }
99 101
100 TEST_F(ManifestParserTest, MultipleErrorsReporting) { 102 TEST_F(ManifestParserTest, MultipleErrorsReporting) {
101 Manifest manifest = ParseManifest("{ \"name\": 42, \"short_name\": 4," 103 Manifest manifest = ParseManifest("{ \"name\": 42, \"short_name\": 4,"
102 "\"orientation\": {}, \"display\": \"foo\", \"start_url\": null," 104 "\"theme_color\": 42, \"orientation\": {}, \"display\": \"foo\","
103 "\"icons\": {} }"); 105 "\"start_url\": null, \"icons\": {} }");
104 106
105 EXPECT_EQ(6u, GetErrorCount()); 107 EXPECT_EQ(7u, GetErrorCount());
106 108
107 EXPECT_EQ("Manifest parsing error: property 'name' ignored," 109 EXPECT_EQ("Manifest parsing error: property 'name' ignored,"
108 " type string expected.", 110 " type string expected.",
109 errors()[0]); 111 errors()[0]);
110 EXPECT_EQ("Manifest parsing error: property 'short_name' ignored," 112 EXPECT_EQ("Manifest parsing error: property 'short_name' ignored,"
111 " type string expected.", 113 " type string expected.",
112 errors()[1]); 114 errors()[1]);
113 EXPECT_EQ("Manifest parsing error: property 'start_url' ignored," 115 EXPECT_EQ("Manifest parsing error: property 'start_url' ignored,"
114 " type string expected.", 116 " type string expected.",
115 errors()[2]); 117 errors()[2]);
116 EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.", 118 EXPECT_EQ("Manifest parsing error: unknown 'display' value ignored.",
117 errors()[3]); 119 errors()[3]);
120 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored,"
121 " type string expected.",
122 errors()[4]);
118 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," 123 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored,"
119 " type string expected.", 124 " type string expected.",
120 errors()[4]); 125 errors()[5]);
121 EXPECT_EQ("Manifest parsing error: property 'icons' ignored, " 126 EXPECT_EQ("Manifest parsing error: property 'icons' ignored, "
122 "type array expected.", 127 "type array expected.",
123 errors()[5]); 128 errors()[6]);
124 } 129 }
125 130
126 TEST_F(ManifestParserTest, NameParseRules) { 131 TEST_F(ManifestParserTest, NameParseRules) {
127 // Smoke test. 132 // Smoke test.
128 { 133 {
129 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }"); 134 Manifest manifest = ParseManifest("{ \"name\": \"foo\" }");
130 ASSERT_TRUE(base::EqualsASCII(manifest.name.string(), "foo")); 135 ASSERT_TRUE(base::EqualsASCII(manifest.name.string(), "foo"));
131 ASSERT_FALSE(manifest.IsEmpty()); 136 ASSERT_FALSE(manifest.IsEmpty());
132 EXPECT_EQ(0u, GetErrorCount()); 137 EXPECT_EQ(0u, GetErrorCount());
133 } 138 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 348 }
344 349
345 // Case insensitive. 350 // Case insensitive.
346 { 351 {
347 Manifest manifest = ParseManifest("{ \"display\": \"BROWSER\" }"); 352 Manifest manifest = ParseManifest("{ \"display\": \"BROWSER\" }");
348 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER); 353 EXPECT_EQ(manifest.display, Manifest::DISPLAY_MODE_BROWSER);
349 EXPECT_EQ(0u, GetErrorCount()); 354 EXPECT_EQ(0u, GetErrorCount());
350 } 355 }
351 } 356 }
352 357
358 TEST_F(ManifestParserTest, ThemeColorParserRules) {
359 // Smoke test.
360 {
361 Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }");
mlamouri (slow - plz ping) 2015/07/16 12:35:41 Remove that test, it's not a smoke test.
Lalit Maganti 2015/07/16 14:49:02 Done.
362 EXPECT_EQ(manifest.theme_color, 0xFF0000FF);
363 EXPECT_FALSE(manifest.IsEmpty());
364 EXPECT_EQ(0u, GetErrorCount());
365 }
366
367 // Smoke test.
368 {
369 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }");
370 EXPECT_EQ(manifest.theme_color, 0xFFFF0000);
371 EXPECT_FALSE(manifest.IsEmpty());
372 EXPECT_EQ(0u, GetErrorCount());
373 }
374
375 // Trim whitespaces.
376 {
377 Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }");
mlamouri (slow - plz ping) 2015/07/16 12:35:41 You don't actually have whitespaces here.
Lalit Maganti 2015/07/16 14:49:02 Removed this test - doesn't really apply.
378 EXPECT_EQ(manifest.theme_color, 0xFF0000FF);
379 EXPECT_EQ(0u, GetErrorCount());
380 }
381
382 // Don't parse if name isn't a string.
mlamouri (slow - plz ping) 2015/07/16 12:35:41 nit: s/name/theme_color/
Lalit Maganti 2015/07/16 14:49:02 Done.
383 {
384 Manifest manifest = ParseManifest("{ \"theme_color\": {} }");
385 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidThemeColor);
386 EXPECT_EQ(1u, GetErrorCount());
387 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored,"
388 " type string expected.",
389 errors()[0]);
390 }
391
392 // Don't parse if name isn't a string.
mlamouri (slow - plz ping) 2015/07/16 12:35:41 ditto.
Lalit Maganti 2015/07/16 14:49:02 Done.
393 {
394 Manifest manifest = ParseManifest("{ \"theme_color\": 42 }");
395 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidThemeColor);
396 EXPECT_EQ(1u, GetErrorCount());
397 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored,"
398 " type string expected.",
399 errors()[0]);
400 }
401
402 // Parse fails if string is not in a known format.
403 {
404 Manifest manifest = ParseManifest("{ \"theme_color\": \"foo(bar)\" }");
405 EXPECT_EQ(manifest.theme_color, -1);
406 EXPECT_EQ(1u, GetErrorCount());
407 EXPECT_EQ("Manifest parsing error: unable to parse 'theme_color' as color.",
408 errors()[0]);
409 }
410
411 // Accept CSS color keyword format.
412 {
413 Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }");
mlamouri (slow - plz ping) 2015/07/16 12:35:41 Could you also test a less common value like 'char
Lalit Maganti 2015/07/16 14:49:02 Done.
414 EXPECT_EQ(manifest.theme_color, 0xFF0000FF);
415 EXPECT_EQ(0u, GetErrorCount());
416 }
417
418 // Accept CSS RGB format.
419 {
420 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FFF\" }");
mlamouri (slow - plz ping) 2015/07/16 12:35:41 Try #ABC too. #FFF could be a side effect.
Lalit Maganti 2015/07/16 14:49:02 Done.
421 EXPECT_EQ(manifest.theme_color, 0xFFFFFFFF);
422 EXPECT_EQ(0u, GetErrorCount());
423 }
424
425 // Accept CSS RRGGBB format.
426 {
427 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }");
428 EXPECT_EQ(manifest.theme_color, 0xFFFF0000);
429 EXPECT_EQ(0u, GetErrorCount());
430 }
mlamouri (slow - plz ping) 2015/07/16 12:35:41 Could you add a test checking that we don't parse
Lalit Maganti 2015/07/16 14:49:02 Done.
431 }
432
353 TEST_F(ManifestParserTest, OrientationParserRules) { 433 TEST_F(ManifestParserTest, OrientationParserRules) {
354 // Smoke test. 434 // Smoke test.
355 { 435 {
356 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); 436 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }");
357 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); 437 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural);
358 EXPECT_FALSE(manifest.IsEmpty()); 438 EXPECT_FALSE(manifest.IsEmpty());
359 EXPECT_EQ(0u, GetErrorCount()); 439 EXPECT_EQ(0u, GetErrorCount());
360 } 440 }
361 441
362 // Trim whitespaces. 442 // Trim whitespaces.
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); 1087 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }");
1008 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); 1088 EXPECT_TRUE(manifest.gcm_sender_id.is_null());
1009 EXPECT_EQ(1u, GetErrorCount()); 1089 EXPECT_EQ(1u, GetErrorCount());
1010 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," 1090 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored,"
1011 " type string expected.", 1091 " type string expected.",
1012 errors()[0]); 1092 errors()[0]);
1013 } 1093 }
1014 } 1094 }
1015 1095
1016 } // namespace content 1096 } // namespace content
OLDNEW
« content/renderer/manifest/manifest_parser.cc ('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