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

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: Fix some small mistakes 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.orientation, blink::WebScreenOrientationLockDefault); 80 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
81 ASSERT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor);
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);
96 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault); 97 ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
98 ASSERT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor);
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 "\"orientation\": {}, \"display\": \"foo\","
103 "\"icons\": {} }"); 105 "\"start_url\": null, \"icons\": {}, \"theme_color\": 42 }");
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]);
118 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored," 120 EXPECT_EQ("Manifest parsing error: property 'orientation' ignored,"
119 " type string expected.", 121 " type string expected.",
120 errors()[4]); 122 errors()[4]);
121 EXPECT_EQ("Manifest parsing error: property 'icons' ignored, " 123 EXPECT_EQ("Manifest parsing error: property 'icons' ignored, "
122 "type array expected.", 124 "type array expected.",
123 errors()[5]); 125 errors()[5]);
126 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored,"
127 " type string expected.",
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) {
mlamouri (slow - plz ping) 2015/07/16 14:53:31 I wanted you to remove the first smoke test, not b
Lalit Maganti 2015/07/16 15:12:28 Done.
359 // Don't parse if theme_color isn't a string.
mlamouri (slow - plz ping) 2015/07/16 14:53:31 You removed the whitespace test too. Could you add
Lalit Maganti 2015/07/16 15:12:28 Done.
360 {
361 Manifest manifest = ParseManifest("{ \"theme_color\": {} }");
362 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor);
363 EXPECT_EQ(1u, GetErrorCount());
364 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored,"
365 " type string expected.",
366 errors()[0]);
367 }
368
369 // Don't parse if theme_color isn't a string.
370 {
371 Manifest manifest = ParseManifest("{ \"theme_color\": 42 }");
372 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor);
373 EXPECT_EQ(1u, GetErrorCount());
374 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored,"
375 " type string expected.",
376 errors()[0]);
377 }
378
379 // Parse fails if string is not in a known format.
mlamouri (slow - plz ping) 2015/07/16 14:53:31 Could you add more test for this case? Things clos
Lalit Maganti 2015/07/16 15:12:28 Done.
380 {
381 Manifest manifest = ParseManifest("{ \"theme_color\": \"foo(bar)\" }");
382 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor);
383 EXPECT_EQ(1u, GetErrorCount());
384 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored,"
385 " invalid color specified.",
386 errors()[0]);
387 }
388
389 // Parse fails if multiple values for theme_color are given.
390 {
391 Manifest manifest = ParseManifest("{ \"theme_color\": \"#ABC#DEF\" }");
mlamouri (slow - plz ping) 2015/07/16 14:53:31 This sounds more like a wrong format. You could ke
Lalit Maganti 2015/07/16 15:12:28 Done.
392 EXPECT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingThemeColor);
393 EXPECT_EQ(1u, GetErrorCount());
394 EXPECT_EQ("Manifest parsing error: property 'theme_color' ignored,"
395 " invalid color specified.",
396 errors()[0]);
397 }
398
399 // Accept CSS color keyword format.
400 {
401 Manifest manifest = ParseManifest("{ \"theme_color\": \"blue\" }");
402 EXPECT_EQ(manifest.theme_color, 0xFF0000FF);
403 EXPECT_EQ(0u, GetErrorCount());
404 }
405
406 // Accept CSS color keyword format.
407 {
408 Manifest manifest = ParseManifest("{ \"theme_color\": \"chartreuse\" }");
409 EXPECT_EQ(manifest.theme_color, 0xFF7FFF00);
410 EXPECT_EQ(0u, GetErrorCount());
411 }
412
413 // Accept CSS RGB format.
414 {
415 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FFF\" }");
416 EXPECT_EQ(manifest.theme_color, 0xFFFFFFFF);
417 EXPECT_EQ(0u, GetErrorCount());
418 }
419
420 // Accept CSS RGB format.
421 {
422 Manifest manifest = ParseManifest("{ \"theme_color\": \"#ABC\" }");
423 EXPECT_EQ(manifest.theme_color, 0xFFAABBCC);
424 EXPECT_EQ(0u, GetErrorCount());
425 }
426
427 // Accept CSS RRGGBB format.
428 {
429 Manifest manifest = ParseManifest("{ \"theme_color\": \"#FF0000\" }");
430 EXPECT_EQ(manifest.theme_color, 0xFFFF0000);
431 EXPECT_EQ(0u, GetErrorCount());
432 }
433 }
434
353 TEST_F(ManifestParserTest, OrientationParserRules) { 435 TEST_F(ManifestParserTest, OrientationParserRules) {
354 // Smoke test. 436 // Smoke test.
355 { 437 {
356 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }"); 438 Manifest manifest = ParseManifest("{ \"orientation\": \"natural\" }");
357 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural); 439 EXPECT_EQ(manifest.orientation, blink::WebScreenOrientationLockNatural);
358 EXPECT_FALSE(manifest.IsEmpty()); 440 EXPECT_FALSE(manifest.IsEmpty());
359 EXPECT_EQ(0u, GetErrorCount()); 441 EXPECT_EQ(0u, GetErrorCount());
360 } 442 }
361 443
362 // Trim whitespaces. 444 // Trim whitespaces.
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); 1089 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }");
1008 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); 1090 EXPECT_TRUE(manifest.gcm_sender_id.is_null());
1009 EXPECT_EQ(1u, GetErrorCount()); 1091 EXPECT_EQ(1u, GetErrorCount());
1010 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored," 1092 EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored,"
1011 " type string expected.", 1093 " type string expected.",
1012 errors()[0]); 1094 errors()[0]);
1013 } 1095 }
1014 } 1096 }
1015 1097
1016 } // namespace content 1098 } // 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