OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" | 5 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "chromeos/dbus/cros_disks_client.h" | 11 #include "chromeos/dbus/cros_disks_client.h" |
| 12 #include "content/public/test/mock_special_storage_policy.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "url/url_util.h" | 14 #include "url/url_util.h" |
14 #include "webkit/browser/fileapi/external_mount_points.h" | 15 #include "webkit/browser/fileapi/external_mount_points.h" |
15 #include "webkit/browser/fileapi/file_system_url.h" | 16 #include "webkit/browser/fileapi/file_system_url.h" |
16 #include "webkit/browser/quota/mock_special_storage_policy.h" | |
17 | 17 |
18 #define FPL(x) FILE_PATH_LITERAL(x) | 18 #define FPL(x) FILE_PATH_LITERAL(x) |
19 | 19 |
20 using fileapi::ExternalMountPoints; | 20 using fileapi::ExternalMountPoints; |
21 using fileapi::FileSystemURL; | 21 using fileapi::FileSystemURL; |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 FileSystemURL CreateFileSystemURL(const std::string& extension, | 25 FileSystemURL CreateFileSystemURL(const std::string& extension, |
26 const char* path, | 26 const char* path, |
27 ExternalMountPoints* mount_points) { | 27 ExternalMountPoints* mount_points) { |
28 return mount_points->CreateCrackedFileSystemURL( | 28 return mount_points->CreateCrackedFileSystemURL( |
29 GURL("chrome-extension://" + extension + "/"), | 29 GURL("chrome-extension://" + extension + "/"), |
30 fileapi::kFileSystemTypeExternal, | 30 fileapi::kFileSystemTypeExternal, |
31 base::FilePath::FromUTF8Unsafe(path)); | 31 base::FilePath::FromUTF8Unsafe(path)); |
32 } | 32 } |
33 | 33 |
34 TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) { | 34 TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) { |
35 // Make sure no system-level mount points are registered before testing | 35 // Make sure no system-level mount points are registered before testing |
36 // to avoid flakiness. | 36 // to avoid flakiness. |
37 fileapi::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); | 37 fileapi::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); |
38 | 38 |
39 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 39 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
40 new quota::MockSpecialStoragePolicy(); | 40 new content::MockSpecialStoragePolicy(); |
41 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 41 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
42 fileapi::ExternalMountPoints::CreateRefCounted()); | 42 fileapi::ExternalMountPoints::CreateRefCounted()); |
43 chromeos::FileSystemBackend backend( | 43 chromeos::FileSystemBackend backend( |
44 NULL, // drive_delegate | 44 NULL, // drive_delegate |
45 NULL, // file_system_provider_delegate | 45 NULL, // file_system_provider_delegate |
46 NULL, // mtp_delegate | 46 NULL, // mtp_delegate |
47 storage_policy, | 47 storage_policy, |
48 mount_points.get(), | 48 mount_points.get(), |
49 fileapi::ExternalMountPoints::GetSystemInstance()); | 49 fileapi::ExternalMountPoints::GetSystemInstance()); |
50 backend.AddSystemMountPoints(); | 50 backend.AddSystemMountPoints(); |
51 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); | 51 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); |
52 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); | 52 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); |
53 | 53 |
54 // By default there should be 3 mount points (in system mount points): | 54 // By default there should be 3 mount points (in system mount points): |
55 EXPECT_EQ(3u, root_dirs.size()); | 55 EXPECT_EQ(3u, root_dirs.size()); |
56 | 56 |
57 EXPECT_TRUE(root_dirs_set.count( | 57 EXPECT_TRUE(root_dirs_set.count( |
58 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); | 58 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); |
59 EXPECT_TRUE(root_dirs_set.count( | 59 EXPECT_TRUE(root_dirs_set.count( |
60 chromeos::CrosDisksClient::GetArchiveMountPoint())); | 60 chromeos::CrosDisksClient::GetArchiveMountPoint())); |
61 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); | 61 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); |
62 } | 62 } |
63 | 63 |
64 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) { | 64 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) { |
65 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 65 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
66 new quota::MockSpecialStoragePolicy(); | 66 new content::MockSpecialStoragePolicy(); |
67 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 67 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
68 fileapi::ExternalMountPoints::CreateRefCounted()); | 68 fileapi::ExternalMountPoints::CreateRefCounted()); |
69 | 69 |
70 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 70 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( |
71 fileapi::ExternalMountPoints::CreateRefCounted()); | 71 fileapi::ExternalMountPoints::CreateRefCounted()); |
72 | 72 |
73 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 73 chromeos::FileSystemBackend backend(NULL, // drive_delegate |
74 NULL, // file_system_provider_delegate | 74 NULL, // file_system_provider_delegate |
75 NULL, // mtp_delegate | 75 NULL, // mtp_delegate |
76 storage_policy, | 76 storage_policy, |
(...skipping 27 matching lines...) Expand all Loading... |
104 EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size()); | 104 EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size()); |
105 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c")))); | 105 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c")))); |
106 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d")))); | 106 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d")))); |
107 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d")))); | 107 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d")))); |
108 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); | 108 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); |
109 } | 109 } |
110 | 110 |
111 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) { | 111 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) { |
112 url_util::AddStandardScheme("chrome-extension"); | 112 url_util::AddStandardScheme("chrome-extension"); |
113 | 113 |
114 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = | 114 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = |
115 new quota::MockSpecialStoragePolicy(); | 115 new content::MockSpecialStoragePolicy(); |
116 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 116 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
117 fileapi::ExternalMountPoints::CreateRefCounted()); | 117 fileapi::ExternalMountPoints::CreateRefCounted()); |
118 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 118 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( |
119 fileapi::ExternalMountPoints::CreateRefCounted()); | 119 fileapi::ExternalMountPoints::CreateRefCounted()); |
120 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 120 chromeos::FileSystemBackend backend(NULL, // drive_delegate |
121 NULL, // file_system_provider_delegate | 121 NULL, // file_system_provider_delegate |
122 NULL, // mtp_delegate | 122 NULL, // mtp_delegate |
123 storage_policy, | 123 storage_policy, |
124 mount_points.get(), | 124 mount_points.get(), |
125 system_mount_points.get()); | 125 system_mount_points.get()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 base::FilePath(FPL("/foo/test")))); | 198 base::FilePath(FPL("/foo/test")))); |
199 EXPECT_FALSE(backend.IsAccessAllowed( | 199 EXPECT_FALSE(backend.IsAccessAllowed( |
200 CreateFileSystemURL(extension, "test_/foo", mount_points.get()))); | 200 CreateFileSystemURL(extension, "test_/foo", mount_points.get()))); |
201 | 201 |
202 backend.RevokeAccessForExtension(extension); | 202 backend.RevokeAccessForExtension(extension); |
203 EXPECT_FALSE(backend.IsAccessAllowed( | 203 EXPECT_FALSE(backend.IsAccessAllowed( |
204 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); | 204 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); |
205 } | 205 } |
206 | 206 |
207 TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) { | 207 TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) { |
208 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = | 208 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = |
209 new quota::MockSpecialStoragePolicy(); | 209 new content::MockSpecialStoragePolicy(); |
210 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 210 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
211 fileapi::ExternalMountPoints::CreateRefCounted()); | 211 fileapi::ExternalMountPoints::CreateRefCounted()); |
212 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 212 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( |
213 fileapi::ExternalMountPoints::CreateRefCounted()); | 213 fileapi::ExternalMountPoints::CreateRefCounted()); |
214 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 214 chromeos::FileSystemBackend backend(NULL, // drive_delegate |
215 NULL, // file_system_provider_delegate | 215 NULL, // file_system_provider_delegate |
216 NULL, // mtp_delegate | 216 NULL, // mtp_delegate |
217 storage_policy, | 217 storage_policy, |
218 mount_points.get(), | 218 mount_points.get(), |
219 system_mount_points.get()); | 219 system_mount_points.get()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (!kTestCases[i].success) | 271 if (!kTestCases[i].success) |
272 continue; | 272 continue; |
273 | 273 |
274 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); | 274 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); |
275 EXPECT_EQ(expected_virtual_path, virtual_path) | 275 EXPECT_EQ(expected_virtual_path, virtual_path) |
276 << "Resolving " << kTestCases[i].local_path; | 276 << "Resolving " << kTestCases[i].local_path; |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 } // namespace | 280 } // namespace |
OLD | NEW |