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

Unified Diff: content/renderer/manifest/manifest_parser_unittest.cc

Issue 550173002: Implement ManifestParser in content/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_fetcher
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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/manifest/manifest_parser_unittest.cc
diff --git a/content/renderer/manifest/manifest_parser_unittest.cc b/content/renderer/manifest/manifest_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eb75919be1267f70801a888f55e547e9e18e1e8b
--- /dev/null
+++ b/content/renderer/manifest/manifest_parser_unittest.cc
@@ -0,0 +1,84 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/manifest/manifest_parser.h"
+
+#include "base/strings/string_util.h"
+#include "content/public/common/manifest.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+TEST(ManifestParserTest, EmptyStringNull) {
+ Manifest manifest = ManifestParser::Parse("");
+
+ // A parsing error is equivalent to an empty manifest.
+ ASSERT_TRUE(manifest.IsEmpty());
+ ASSERT_TRUE(manifest.name.is_null());
+ ASSERT_TRUE(manifest.short_name.is_null());
+}
+
+TEST(ManifestParserTest, ValidNoContentParses) {
+ Manifest manifest = ManifestParser::Parse("{}");
+
+ // Check that all the fields are null in that case.
+ ASSERT_TRUE(manifest.IsEmpty());
+ ASSERT_TRUE(manifest.name.is_null());
+ ASSERT_TRUE(manifest.short_name.is_null());
+}
+
+TEST(ManifestParserTest, NameParseRules) {
+ // Smoke test.
+ {
+ Manifest manifest = ManifestParser::Parse("{ \"name\": \"foo\" }");
+ ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo"));
+ }
+
+ // Trim whitespaces.
+ {
+ Manifest manifest = ManifestParser::Parse("{ \"name\": \" foo \" }");
+ ASSERT_TRUE(EqualsASCII(manifest.name.string(), "foo"));
+ }
+
+ // Don't parse if name isn't a string.
+ {
+ Manifest manifest = ManifestParser::Parse("{ \"name\": {} }");
+ ASSERT_TRUE(manifest.name.is_null());
+ }
+
+ // Don't parse if name isn't a string.
+ {
+ Manifest manifest = ManifestParser::Parse("{ \"name\": 42 }");
+ ASSERT_TRUE(manifest.name.is_null());
+ }
+}
+
+TEST(ManifestParserTest, ShortNameParseRules) {
+ // Smoke test.
+ {
+ Manifest manifest = ManifestParser::Parse("{ \"short_name\": \"foo\" }");
+ ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo"));
+ }
+
+ // Trim whitespaces.
+ {
+ Manifest manifest =
+ ManifestParser::Parse("{ \"short_name\": \" foo \" }");
+ ASSERT_TRUE(EqualsASCII(manifest.short_name.string(), "foo"));
+ }
+
+ // Don't parse if name isn't a string.
+ {
+ Manifest manifest = ManifestParser::Parse("{ \"short_name\": {} }");
+ ASSERT_TRUE(manifest.short_name.is_null());
+ }
+
+ // Don't parse if name isn't a string.
+ {
+ Manifest manifest = ManifestParser::Parse("{ \"short_name\": 42 }");
+ ASSERT_TRUE(manifest.short_name.is_null());
+ }
+}
+
+} // namespace content
« content/renderer/manifest/manifest_parser.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