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

Unified Diff: chrome/browser/extensions/extension_special_storage_policy_unittest.cc

Issue 6810037: File API changes needed for safely passing user selected file entities from the file browser comp... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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: chrome/browser/extensions/extension_special_storage_policy_unittest.cc
===================================================================
--- chrome/browser/extensions/extension_special_storage_policy_unittest.cc (revision 80841)
+++ chrome/browser/extensions/extension_special_storage_policy_unittest.cc (working copy)
@@ -58,6 +58,59 @@
EXPECT_TRUE(unlimited_app.get()) << error;
return unlimited_app;
}
+
+ scoped_refptr<Extension> CreateComponentApp() {
ericu 2011/04/09 01:45:13 I'm not really sure what you're testing here. Can
zel 2011/04/13 00:44:26 I've added some comments that describe what is goi
ericu 2011/04/13 20:12:46 I like the comments, and the tests are clear--it's
+#if defined(OS_WIN)
+ FilePath path(FILE_PATH_LITERAL("c:\\component"));
+#elif defined(OS_POSIX)
+ FilePath path(FILE_PATH_LITERAL("/component"));
+#endif
+ DictionaryValue manifest;
+ manifest.SetString(keys::kName, "Component");
+ manifest.SetString(keys::kVersion, "1");
+ manifest.SetString(keys::kPublicKey,
+ "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDOuXEIuoK1kAkBe0SKiJn/N9oNn3oU" \
+ "xGa4dwj40MnJqPn+w0aR2vuyocm0R4Drp67aYwtLjOVPF4CICRq6ICP6eU07gGwQxGdZ" \
+ "7HJASXV8hm0tab5I70oJmRLfFJyVAMCeWlFaOGq05v2i6EbifZM0qO5xALKNGQt+yjXi" \
+ "5INM5wIBIw==");
+ ListValue* list = new ListValue();
+ list->Append(Value::CreateStringValue("unlimitedStorage"));
+ list->Append(Value::CreateStringValue("fileSystem"));
+ list->Append(Value::CreateStringValue("fileBrowserPrivate"));
+ manifest.Set(keys::kPermissions, list);
+ std::string error;
+ scoped_refptr<Extension> component_app = Extension::Create(
+ path, Extension::COMPONENT, manifest, Extension::STRICT_ERROR_CHECKS,
+ &error);
+ EXPECT_TRUE(component_app.get()) << error;
+ return component_app;
+ }
+
+ scoped_refptr<Extension> CreateHandlerApp() {
+#if defined(OS_WIN)
+ FilePath path(FILE_PATH_LITERAL("c:\\handler"));
+#elif defined(OS_POSIX)
+ FilePath path(FILE_PATH_LITERAL("/handler"));
+#endif
+ DictionaryValue manifest;
+ manifest.SetString(keys::kName, "Handler");
+ manifest.SetString(keys::kVersion, "1");
+ manifest.SetString(keys::kPublicKey,
+ "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQChptAQ0n4R56N03nWQ1ogR7DVRBjGo" \
+ "80Vw6G9KLjzZv44D8rq5Q5IkeQrtKgWyZfXevlsCe3LaLo18rcz8iZx6lK2xhLdUR+OR" \
+ "jsjuBfdEL5a5cWeRTSxf75AcqndQsmpwMBdrMTCZ8jQNusUI+XlrihLNNJuI5TM4vNIN" \
+ "I5bYFQIBIw==");
+ ListValue* list = new ListValue();
+ list->Append(Value::CreateStringValue("unlimitedStorage"));
+ list->Append(Value::CreateStringValue("fileSystem"));
+ manifest.Set(keys::kPermissions, list);
+ std::string error;
+ scoped_refptr<Extension> hanlder_app = Extension::Create(
+ path, Extension::INVALID, manifest, Extension::STRICT_ERROR_CHECKS,
+ &error);
+ EXPECT_TRUE(hanlder_app.get()) << error;
+ return hanlder_app;
+ }
};
TEST_F(ExtensionSpecialStoragePolicyTest, EmptyPolicy) {
@@ -157,3 +210,55 @@
EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/")));
EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/")));
}
+
+TEST_F(ExtensionSpecialStoragePolicyTest, LocalFileAccess) {
+ scoped_refptr<Extension> component_app(CreateComponentApp());
+ scoped_refptr<Extension> handler_app(CreateHandlerApp());
+ scoped_refptr<ExtensionSpecialStoragePolicy> policy(
+ new ExtensionSpecialStoragePolicy);
+ policy->GrantRightsForExtension(component_app);
+ policy->GrantRightsForExtension(handler_app);
+
+ const GURL& component_url = component_app->url();
+ const GURL& hanlder_url = handler_app->url();
ericu 2011/04/09 01:45:13 s/hanlder/handler/ throughout.
+#if defined(OS_WIN)
+ FilePath good_dir(FILE_PATH_LITERAL("c:\\root\\dir"));
+ FilePath bad_dir(FILE_PATH_LITERAL("c:\\root"));
+ FilePath good_file(FILE_PATH_LITERAL("c:\\root\\dir\\good_file.txt"));
+ FilePath bad_file(FILE_PATH_LITERAL("c:\\root\\dir\\bad_file.txt"));
+#elif defined(OS_POSIX)
+ FilePath good_dir(FILE_PATH_LITERAL("/root/dir"));
+ FilePath bad_dir(FILE_PATH_LITERAL("/root"));
+ FilePath good_file(FILE_PATH_LITERAL("/root/dir/good_file.txt"));
+ FilePath bad_file(FILE_PATH_LITERAL("/root/dir/bad_file.txt"));
+#endif
+
+ EXPECT_TRUE(policy->IsLocalFileSystemAccessAllowed(component_url, good_dir));
+ EXPECT_TRUE(policy->IsLocalFileSystemAccessAllowed(component_url, good_file));
+ EXPECT_TRUE(policy->IsLocalFileSystemAccessAllowed(component_url, bad_file));
+
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, good_dir));
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, good_file));
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, bad_file));
+
+ policy->GrantLocalFileSystemAccess(hanlder_url, good_file);
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, good_dir));
+ EXPECT_TRUE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, good_file));
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, bad_file));
+
+ policy->GrantLocalFileSystemAccess(hanlder_url, good_dir);
+ EXPECT_TRUE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, good_dir));
+ EXPECT_TRUE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, good_file));
+ EXPECT_TRUE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, bad_file));
+
+ policy->RevokeRightsForExtension(handler_app);
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, good_dir));
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, good_file));
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(hanlder_url, bad_file));
+
+ policy->RevokeRightsForExtension(component_app);
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(component_url, good_dir));
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(component_url,
+ good_file));
+ EXPECT_FALSE(policy->IsLocalFileSystemAccessAllowed(component_url, bad_file));
+}

Powered by Google App Engine
This is Rietveld 408576698