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

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

Issue 2063003003: Implement "scope" Web Manifest parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'webapk_manifest_scope00' into webapk_manifest_scope0 Created 4 years, 6 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
index 5c4faa62440563f736f9bd89bd4fd973aa004924..fb96854fc0fbc9cb75e425d26b8d164035d4edf1 100644
--- a/content/renderer/manifest/manifest_parser_unittest.cc
+++ b/content/renderer/manifest/manifest_parser_unittest.cc
@@ -96,6 +96,7 @@ TEST_F(ManifestParserTest, EmptyStringNull) {
ASSERT_TRUE(manifest.name.is_null());
ASSERT_TRUE(manifest.short_name.is_null());
ASSERT_TRUE(manifest.start_url.is_empty());
+ ASSERT_TRUE(manifest.scope.is_empty());
ASSERT_EQ(manifest.display, blink::WebDisplayModeUndefined);
ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
ASSERT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
@@ -114,6 +115,7 @@ TEST_F(ManifestParserTest, ValidNoContentParses) {
ASSERT_TRUE(manifest.name.is_null());
ASSERT_TRUE(manifest.short_name.is_null());
ASSERT_TRUE(manifest.start_url.is_empty());
+ ASSERT_TRUE(manifest.scope.is_empty());
ASSERT_EQ(manifest.display, blink::WebDisplayModeUndefined);
ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
ASSERT_EQ(manifest.theme_color, Manifest::kInvalidOrMissingColor);
@@ -287,6 +289,151 @@ TEST_F(ManifestParserTest, StartURLParseRules) {
}
}
+TEST_F(ManifestParserTest, ScopeParseRules) {
+ // Smoke test.
+ {
+ Manifest manifest = ParseManifest(
+ "{ \"scope\": \"land\", \"start_url\": \"land/landing.html\" }");
+ ASSERT_EQ(manifest.scope.spec(),
+ default_document_url.Resolve("land").spec());
+ ASSERT_FALSE(manifest.IsEmpty());
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Whitespaces.
+ {
+ Manifest manifest = ParseManifest(
+ "{ \"scope\": \" land \", \"start_url\": \"land/landing.html\" }");
+ ASSERT_EQ(manifest.scope.spec(),
+ default_document_url.Resolve("land").spec());
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Don't parse if property isn't a string.
+ {
+ Manifest manifest = ParseManifest("{ \"scope\": {} }");
+ ASSERT_TRUE(manifest.scope.is_empty());
+ EXPECT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'scope' ignored, type string expected.", errors()[0]);
+ }
+
+ // Don't parse if property isn't a string.
+ {
+ Manifest manifest = ParseManifest("{ \"scope\": 42 }");
+ ASSERT_TRUE(manifest.scope.is_empty());
+ EXPECT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'scope' ignored, type string expected.", errors()[0]);
+ }
+
+ // Absolute scope, start URL is in scope.
+ {
+ Manifest manifest = ParseManifestWithURLs(
+ "{ \"scope\": \"http://foo.com/land\", "
+ "\"start_url\": \"http://foo.com/land/landing.html\" }",
+ GURL("http://foo.com/manifest.json"),
+ GURL("http://foo.com/index.html"));
+ ASSERT_EQ(manifest.scope.spec(), "http://foo.com/land");
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Absolute scope, start URL is not in scope.
+ {
+ Manifest manifest =
+ ParseManifestWithURLs("{ \"scope\": \"http://foo.com/land\", "
+ "\"start_url\": \"http://foo.com/index.html\" }",
+ GURL("http://foo.com/manifest.json"),
+ GURL("http://foo.com/index.html"));
+ ASSERT_TRUE(manifest.scope.is_empty());
+ EXPECT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'scope' ignored. Start url should be within scope "
+ "of scope URL.",
+ errors()[0]);
+ }
+
+ // Absolute scope, start URL has different origin than scope URL.
+ {
+ Manifest manifest =
+ ParseManifestWithURLs("{ \"scope\": \"http://foo.com/land\", "
+ "\"start_url\": \"http://bar.com/land/landing.html\" }",
+ GURL("http://foo.com/manifest.json"),
+ GURL("http://foo.com/index.html"));
+ ASSERT_TRUE(manifest.scope.is_empty());
+ ASSERT_EQ(2u, GetErrorCount());
+ EXPECT_EQ(
+ "property 'start_url' ignored, should be same origin as document.",
+ errors()[0]);
+ EXPECT_EQ("property 'scope' ignored. Start url should be within scope "
+ "of scope URL.",
+ errors()[1]);
+ }
+
+ // scope and start URL have diferent origin than document URL.
+ {
+ Manifest manifest =
+ ParseManifestWithURLs("{ \"scope\": \"http://foo.com/land\", "
+ "\"start_url\": \"http://foo.com/land/landing.html\" }",
+ GURL("http://foo.com/manifest.json"),
+ GURL("http://bar.com/index.html"));
+ ASSERT_TRUE(manifest.scope.is_empty());
+ ASSERT_EQ(2u, GetErrorCount());
+ EXPECT_EQ(
+ "property 'start_url' ignored, should be same origin as document.",
+ errors()[0]);
+ EXPECT_EQ("property 'scope' ignored, should be same origin as document.",
+ errors()[1]);
+ }
+
+ // No start URL. Document URL is in scope.
+ {
+ Manifest manifest = ParseManifestWithURLs("{ \"scope\": \"http://foo.com/land\" }",
+ GURL("http://foo.com/manifest.json"),
+ GURL("http://foo.com/land/index.html"));
+ ASSERT_EQ(manifest.scope.spec(), "http://foo.com/land");
+ ASSERT_EQ(0u, GetErrorCount());
+ }
+
+ // No start URL. Document is out of scope.
+ {
+ Manifest manifest = ParseManifestWithURLs("{ \"scope\": \"http://foo.com/land\" }",
+ GURL("http://foo.com/manifest.json"),
+ GURL("http://foo.com/index.html"));
+ ASSERT_EQ(1u, GetErrorCount());
+ EXPECT_EQ("property 'scope' ignored. Start url should be within scope "
+ "of scope URL.",
+ errors()[0]);
+ }
+
+ // Resolving has to happen based on the manifest_url.
+ {
+ Manifest manifest = ParseManifestWithURLs(
+ "{ \"scope\": \"treasure\" }",
+ GURL("http://foo.com/map/manifest.json"),
+ GURL("http://foo.com/map/treasure/island/index.html"));
+ ASSERT_EQ(manifest.scope.spec(), "http://foo.com/map/treasure");
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Scope is parent directory.
+ {
+ Manifest manifest =
+ ParseManifestWithURLs("{ \"scope\": \"..\" }",
+ GURL("http://foo.com/map/manifest.json"),
+ GURL("http://foo.com/index.html"));
+ ASSERT_EQ(manifest.scope.spec(), "http://foo.com/");
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+
+ // Scope tries to go up past domain.
+ {
+ Manifest manifest =
+ ParseManifestWithURLs("{ \"scope\": \"../..\" }",
+ GURL("http://foo.com/map/manifest.json"),
+ GURL("http://foo.com/index.html"));
+ ASSERT_EQ(manifest.scope.spec(), "http://foo.com/");
+ EXPECT_EQ(0u, GetErrorCount());
+ }
+}
+
TEST_F(ManifestParserTest, DisplayParserRules) {
// Smoke test.
{
« 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