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

Unified Diff: webkit/chromeos/fileapi/file_access_permissions_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
« no previous file with comments | « webkit/chromeos/fileapi/file_access_permissions.cc ('k') | webkit/database/database_tracker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/chromeos/fileapi/file_access_permissions_unittest.cc
===================================================================
--- webkit/chromeos/fileapi/file_access_permissions_unittest.cc (revision 0)
+++ webkit/chromeos/fileapi/file_access_permissions_unittest.cc (revision 0)
@@ -0,0 +1,67 @@
+// Copyright (c) 2011 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 "webkit/chromeos/fileapi/file_access_permissions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+
+class FileAccessPermissionsTest : public testing::Test {
+};
+
+TEST_F(FileAccessPermissionsTest, FileAccessChecks) {
+#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
+ std::string extension1("ddammdhioacbehjngdmkjcjbnfginlla");
+ std::string extension2("jkhdjkhkhsdkfhsdkhrterwmtermeter");
+
+ chromeos::FileAccessPermissions permissions;
+ // By default extension have no access to any local file.
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_dir));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, bad_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_dir));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, bad_file));
+
+ // After granting file access to the handler extension for a given file, it
+ // can only access that file an nothing else.
+ permissions.GrantAccessPermission(extension1, good_file);
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_dir));
+ EXPECT_TRUE(permissions.HasAccessPermission(extension1, good_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, bad_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_dir));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, bad_file));
+
+
+ // After granting file access to the handler extension for a given directory,
+ // it can access that directory and all files within it.
+ permissions.GrantAccessPermission(extension2, good_dir);
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_dir));
+ EXPECT_TRUE(permissions.HasAccessPermission(extension1, good_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, bad_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_dir));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, bad_file));
+
+ // After revoking rights for extensions, they should not be able to access
+ // any file system element anymore.
+ permissions.RevokePermissions(extension1);
+ permissions.RevokePermissions(extension2);
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_dir));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension1, bad_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_dir));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_file));
+ EXPECT_FALSE(permissions.HasAccessPermission(extension2, bad_file));
+}
Property changes on: webkit/chromeos/fileapi/file_access_permissions_unittest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « webkit/chromeos/fileapi/file_access_permissions.cc ('k') | webkit/database/database_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698