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

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

Issue 2637003002: Add share_target field to Manifest. (Closed)
Patch Set: Changed share_target type to base::Optional, and fixed tests, according to feedback. Created 3 years, 11 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
« no previous file with comments | « content/renderer/manifest/manifest_parser.cc ('k') | content/renderer/manifest/manifest_uma_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 8b21c69d5d3e225f69d251ff3cd8e447bfada1a8..aa2e5d9cabfc86be4fa5752ec4dc47e6f29740b8 100644
--- a/content/renderer/manifest/manifest_parser_unittest.cc
+++ b/content/renderer/manifest/manifest_parser_unittest.cc
@@ -9,6 +9,7 @@
#include <memory>
#include "base/macros.h"
+#include "base/optional.h"
#include "base/strings/string_util.h"
#include "content/public/common/manifest.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -982,6 +983,86 @@ TEST_F(ManifestParserTest, IconPurposeParseRules) {
}
}
+TEST_F(ManifestParserTest, ShareTargetParseRules) {
+ // Contains share_target field but no keys.
+ {
+ Manifest manifest = ParseManifest("{ \"share_target\": {} }");
+ EXPECT_FALSE(manifest.share_target.has_value());
+ EXPECT_TRUE(manifest.IsEmpty());
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Key in share_target that isn't valid.
+ {
+ Manifest manifest = ParseManifest(
+ "{ \"share_target\": {\"incorrect_key\": \"some_value\" } }");
+ ASSERT_FALSE(manifest.share_target.has_value());
+ EXPECT_TRUE(manifest.IsEmpty());
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+}
+
+TEST_F(ManifestParserTest, ShareTargetUrlTemplateParseRules) {
+ // Contains share_target and url_template, but url_template is empty.
+ {
+ Manifest manifest =
+ ParseManifest("{ \"share_target\": { \"url_template\": \"\" } }");
+ ASSERT_TRUE(manifest.share_target.has_value());
+ EXPECT_TRUE(base::EqualsASCII(
+ manifest.share_target.value().url_template.string(), ""));
+ EXPECT_FALSE(manifest.IsEmpty());
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Don't parse if property isn't a string.
+ {
+ Manifest manifest =
+ ParseManifest("{ \"share_target\": { \"url_template\": {} } }");
+ EXPECT_FALSE(manifest.share_target.has_value());
+ EXPECT_TRUE(manifest.IsEmpty());
+ EXPECT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'url_template' ignored, type string expected.",
+ errors()[0]);
+ }
+
+ // Don't parse if property isn't a string.
+ {
+ Manifest manifest =
+ ParseManifest("{ \"share_target\": { \"url_template\": 42 } }");
+ EXPECT_FALSE(manifest.share_target.has_value());
+ EXPECT_TRUE(manifest.IsEmpty());
+ EXPECT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'url_template' ignored, type string expected.",
+ errors()[0]);
+ }
+
+ // Smoke test: Contains share_target and url_template, and url_template is
+ // valid template.
+ {
+ Manifest manifest = ParseManifest(
+ "{ \"share_target\": {\"url_template\": \"share/?title={title}\" } }");
+ ASSERT_TRUE(manifest.share_target.has_value());
+ EXPECT_TRUE(
+ base::EqualsASCII(manifest.share_target.value().url_template.string(),
+ "share/?title={title}"));
+ EXPECT_FALSE(manifest.IsEmpty());
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Smoke test: Contains share_target and url_template, and url_template is
+ // invalid template.
+ {
+ Manifest manifest = ParseManifest(
+ "{ \"share_target\": {\"url_template\": \"share/?title={title\" } }");
+ ASSERT_TRUE(manifest.share_target.has_value());
+ EXPECT_TRUE(
+ base::EqualsASCII(manifest.share_target.value().url_template.string(),
+ "share/?title={title"));
+ EXPECT_FALSE(manifest.IsEmpty());
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+}
+
TEST_F(ManifestParserTest, RelatedApplicationsParseRules) {
// If no application, empty list.
{
« no previous file with comments | « content/renderer/manifest/manifest_parser.cc ('k') | content/renderer/manifest/manifest_uma_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698