Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / fileapi / file_access_permissions_unittest.cc
blobf0f466c2c896dccffda3eded85d5bd007aa698df
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace chromeos {
11 TEST(FileAccessPermissionsTest, FileAccessChecks) {
12 base::FilePath good_dir(FILE_PATH_LITERAL("/root/dir"));
13 base::FilePath bad_dir(FILE_PATH_LITERAL("/root"));
14 base::FilePath good_file(FILE_PATH_LITERAL("/root/dir/good_file.txt"));
15 base::FilePath bad_file(FILE_PATH_LITERAL("/root/dir/bad_file.txt"));
17 std::string extension1("ddammdhioacbehjngdmkjcjbnfginlla");
18 std::string extension2("jkhdjkhkhsdkfhsdkhrterwmtermeter");
20 FileAccessPermissions permissions;
21 // By default extension have no access to any local file.
22 EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_dir));
23 EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_file));
24 EXPECT_FALSE(permissions.HasAccessPermission(extension1, bad_file));
25 EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_dir));
26 EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_file));
27 EXPECT_FALSE(permissions.HasAccessPermission(extension2, bad_file));
29 // After granting file access to the handler extension for a given file, it
30 // can only access that file an nothing else.
31 permissions.GrantAccessPermission(extension1, good_file);
32 EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_dir));
33 EXPECT_TRUE(permissions.HasAccessPermission(extension1, good_file));
34 EXPECT_FALSE(permissions.HasAccessPermission(extension1, bad_file));
35 EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_dir));
36 EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_file));
37 EXPECT_FALSE(permissions.HasAccessPermission(extension2, bad_file));
40 // After granting file access to the handler extension for a given directory,
41 // it can access that directory and all files within it.
42 permissions.GrantAccessPermission(extension2, good_dir);
43 EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_dir));
44 EXPECT_TRUE(permissions.HasAccessPermission(extension1, good_file));
45 EXPECT_FALSE(permissions.HasAccessPermission(extension1, bad_file));
46 EXPECT_TRUE(permissions.HasAccessPermission(extension2, good_dir));
47 EXPECT_TRUE(permissions.HasAccessPermission(extension2, good_file));
48 EXPECT_TRUE(permissions.HasAccessPermission(extension2, bad_file));
50 // After revoking rights for extensions, they should not be able to access
51 // any file system element anymore.
52 permissions.RevokePermissions(extension1);
53 permissions.RevokePermissions(extension2);
54 EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_dir));
55 EXPECT_FALSE(permissions.HasAccessPermission(extension1, good_file));
56 EXPECT_FALSE(permissions.HasAccessPermission(extension1, bad_file));
57 EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_dir));
58 EXPECT_FALSE(permissions.HasAccessPermission(extension2, good_file));
59 EXPECT_FALSE(permissions.HasAccessPermission(extension2, bad_file));
62 } // namespace chromeos