| 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 "chromeos/dbus/cros_disks_client.h" | 10 #include "chromeos/dbus/cros_disks_client.h" |
| 11 #include "content/public/test/mock_special_storage_policy.h" | |
| 12 #include "storage/browser/fileapi/external_mount_points.h" | 11 #include "storage/browser/fileapi/external_mount_points.h" |
| 13 #include "storage/browser/fileapi/file_system_url.h" | 12 #include "storage/browser/fileapi/file_system_url.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "url/url_util.h" | 14 #include "url/url_util.h" |
| 16 | 15 |
| 17 #define FPL(x) FILE_PATH_LITERAL(x) | 16 #define FPL(x) FILE_PATH_LITERAL(x) |
| 18 | 17 |
| 19 using storage::ExternalMountPoints; | 18 using storage::ExternalMountPoints; |
| 20 using storage::FileSystemURL; | 19 using storage::FileSystemURL; |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 FileSystemURL CreateFileSystemURL(const std::string& extension, | 23 FileSystemURL CreateFileSystemURL(const std::string& extension, |
| 25 const char* path, | 24 const char* path, |
| 26 ExternalMountPoints* mount_points) { | 25 ExternalMountPoints* mount_points) { |
| 27 return mount_points->CreateCrackedFileSystemURL( | 26 return mount_points->CreateCrackedFileSystemURL( |
| 28 GURL("chrome-extension://" + extension + "/"), | 27 GURL("chrome-extension://" + extension + "/"), |
| 29 storage::kFileSystemTypeExternal, | 28 storage::kFileSystemTypeExternal, |
| 30 base::FilePath::FromUTF8Unsafe(path)); | 29 base::FilePath::FromUTF8Unsafe(path)); |
| 31 } | 30 } |
| 32 | 31 |
| 33 TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) { | 32 TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) { |
| 34 // Make sure no system-level mount points are registered before testing | 33 // Make sure no system-level mount points are registered before testing |
| 35 // to avoid flakiness. | 34 // to avoid flakiness. |
| 36 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); | 35 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); |
| 37 | 36 |
| 38 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = | |
| 39 new content::MockSpecialStoragePolicy(); | |
| 40 scoped_refptr<storage::ExternalMountPoints> mount_points( | 37 scoped_refptr<storage::ExternalMountPoints> mount_points( |
| 41 storage::ExternalMountPoints::CreateRefCounted()); | 38 storage::ExternalMountPoints::CreateRefCounted()); |
| 42 chromeos::FileSystemBackend backend( | 39 chromeos::FileSystemBackend backend( |
| 43 NULL, // drive_delegate | 40 NULL, // drive_delegate |
| 44 NULL, // file_system_provider_delegate | 41 NULL, // file_system_provider_delegate |
| 45 NULL, // mtp_delegate | 42 NULL, // mtp_delegate |
| 46 storage_policy, | |
| 47 mount_points.get(), | 43 mount_points.get(), |
| 48 storage::ExternalMountPoints::GetSystemInstance()); | 44 storage::ExternalMountPoints::GetSystemInstance()); |
| 49 backend.AddSystemMountPoints(); | 45 backend.AddSystemMountPoints(); |
| 50 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); | 46 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); |
| 51 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); | 47 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); |
| 52 | 48 |
| 53 // By default there should be 3 mount points (in system mount points): | 49 // By default there should be 3 mount points (in system mount points): |
| 54 EXPECT_EQ(3u, root_dirs.size()); | 50 EXPECT_EQ(3u, root_dirs.size()); |
| 55 | 51 |
| 56 EXPECT_TRUE(root_dirs_set.count( | 52 EXPECT_TRUE(root_dirs_set.count( |
| 57 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); | 53 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); |
| 58 EXPECT_TRUE(root_dirs_set.count( | 54 EXPECT_TRUE(root_dirs_set.count( |
| 59 chromeos::CrosDisksClient::GetArchiveMountPoint())); | 55 chromeos::CrosDisksClient::GetArchiveMountPoint())); |
| 60 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); | 56 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); |
| 61 } | 57 } |
| 62 | 58 |
| 63 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) { | 59 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) { |
| 64 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = | |
| 65 new content::MockSpecialStoragePolicy(); | |
| 66 scoped_refptr<storage::ExternalMountPoints> mount_points( | 60 scoped_refptr<storage::ExternalMountPoints> mount_points( |
| 67 storage::ExternalMountPoints::CreateRefCounted()); | 61 storage::ExternalMountPoints::CreateRefCounted()); |
| 68 | 62 |
| 69 scoped_refptr<storage::ExternalMountPoints> system_mount_points( | 63 scoped_refptr<storage::ExternalMountPoints> system_mount_points( |
| 70 storage::ExternalMountPoints::CreateRefCounted()); | 64 storage::ExternalMountPoints::CreateRefCounted()); |
| 71 | 65 |
| 72 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 66 chromeos::FileSystemBackend backend(NULL, // drive_delegate |
| 73 NULL, // file_system_provider_delegate | 67 NULL, // file_system_provider_delegate |
| 74 NULL, // mtp_delegate | 68 NULL, // mtp_delegate |
| 75 storage_policy, | |
| 76 mount_points.get(), | 69 mount_points.get(), |
| 77 system_mount_points.get()); | 70 system_mount_points.get()); |
| 78 | 71 |
| 79 const size_t initial_root_dirs_size = backend.GetRootDirectories().size(); | 72 const size_t initial_root_dirs_size = backend.GetRootDirectories().size(); |
| 80 | 73 |
| 81 // Register 'local' test mount points. | 74 // Register 'local' test mount points. |
| 82 mount_points->RegisterFileSystem("c", | 75 mount_points->RegisterFileSystem("c", |
| 83 storage::kFileSystemTypeNativeLocal, | 76 storage::kFileSystemTypeNativeLocal, |
| 84 storage::FileSystemMountOption(), | 77 storage::FileSystemMountOption(), |
| 85 base::FilePath(FPL("/a/b/c"))); | 78 base::FilePath(FPL("/a/b/c"))); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 103 EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size()); | 96 EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size()); |
| 104 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c")))); | 97 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c")))); |
| 105 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d")))); | 98 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d")))); |
| 106 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d")))); | 99 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d")))); |
| 107 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); | 100 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); |
| 108 } | 101 } |
| 109 | 102 |
| 110 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) { | 103 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) { |
| 111 url::AddStandardScheme("chrome-extension"); | 104 url::AddStandardScheme("chrome-extension"); |
| 112 | 105 |
| 113 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = | |
| 114 new content::MockSpecialStoragePolicy(); | |
| 115 scoped_refptr<storage::ExternalMountPoints> mount_points( | 106 scoped_refptr<storage::ExternalMountPoints> mount_points( |
| 116 storage::ExternalMountPoints::CreateRefCounted()); | 107 storage::ExternalMountPoints::CreateRefCounted()); |
| 117 scoped_refptr<storage::ExternalMountPoints> system_mount_points( | 108 scoped_refptr<storage::ExternalMountPoints> system_mount_points( |
| 118 storage::ExternalMountPoints::CreateRefCounted()); | 109 storage::ExternalMountPoints::CreateRefCounted()); |
| 119 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 110 chromeos::FileSystemBackend backend(NULL, // drive_delegate |
| 120 NULL, // file_system_provider_delegate | 111 NULL, // file_system_provider_delegate |
| 121 NULL, // mtp_delegate | 112 NULL, // mtp_delegate |
| 122 storage_policy, | |
| 123 mount_points.get(), | 113 mount_points.get(), |
| 124 system_mount_points.get()); | 114 system_mount_points.get()); |
| 125 | 115 |
| 126 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); | 116 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); |
| 127 | 117 |
| 128 storage_policy->AddFileHandler(extension); | |
| 129 | |
| 130 // Initialize mount points. | 118 // Initialize mount points. |
| 131 ASSERT_TRUE(system_mount_points->RegisterFileSystem( | 119 ASSERT_TRUE(system_mount_points->RegisterFileSystem( |
| 132 "system", | 120 "system", |
| 133 storage::kFileSystemTypeNativeLocal, | 121 storage::kFileSystemTypeNativeLocal, |
| 134 storage::FileSystemMountOption(), | 122 storage::FileSystemMountOption(), |
| 135 base::FilePath(FPL("/g/system")))); | 123 base::FilePath(FPL("/g/system")))); |
| 136 ASSERT_TRUE(mount_points->RegisterFileSystem( | 124 ASSERT_TRUE(mount_points->RegisterFileSystem( |
| 137 "removable", | 125 "removable", |
| 138 storage::kFileSystemTypeNativeLocal, | 126 storage::kFileSystemTypeNativeLocal, |
| 139 storage::FileSystemMountOption(), | 127 storage::FileSystemMountOption(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 base::FilePath(FPL("/foo/test")))); | 164 base::FilePath(FPL("/foo/test")))); |
| 177 EXPECT_FALSE(backend.IsAccessAllowed( | 165 EXPECT_FALSE(backend.IsAccessAllowed( |
| 178 CreateFileSystemURL(extension, "test_/foo", mount_points.get()))); | 166 CreateFileSystemURL(extension, "test_/foo", mount_points.get()))); |
| 179 | 167 |
| 180 backend.RevokeAccessForExtension(extension); | 168 backend.RevokeAccessForExtension(extension); |
| 181 EXPECT_FALSE(backend.IsAccessAllowed( | 169 EXPECT_FALSE(backend.IsAccessAllowed( |
| 182 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); | 170 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); |
| 183 } | 171 } |
| 184 | 172 |
| 185 TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) { | 173 TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) { |
| 186 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = | |
| 187 new content::MockSpecialStoragePolicy(); | |
| 188 scoped_refptr<storage::ExternalMountPoints> mount_points( | 174 scoped_refptr<storage::ExternalMountPoints> mount_points( |
| 189 storage::ExternalMountPoints::CreateRefCounted()); | 175 storage::ExternalMountPoints::CreateRefCounted()); |
| 190 scoped_refptr<storage::ExternalMountPoints> system_mount_points( | 176 scoped_refptr<storage::ExternalMountPoints> system_mount_points( |
| 191 storage::ExternalMountPoints::CreateRefCounted()); | 177 storage::ExternalMountPoints::CreateRefCounted()); |
| 192 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 178 chromeos::FileSystemBackend backend(NULL, // drive_delegate |
| 193 NULL, // file_system_provider_delegate | 179 NULL, // file_system_provider_delegate |
| 194 NULL, // mtp_delegate | 180 NULL, // mtp_delegate |
| 195 storage_policy, | |
| 196 mount_points.get(), | 181 mount_points.get(), |
| 197 system_mount_points.get()); | 182 system_mount_points.get()); |
| 198 | 183 |
| 199 const storage::FileSystemType type = storage::kFileSystemTypeNativeLocal; | 184 const storage::FileSystemType type = storage::kFileSystemTypeNativeLocal; |
| 200 const storage::FileSystemMountOption option = | 185 const storage::FileSystemMountOption option = |
| 201 storage::FileSystemMountOption(); | 186 storage::FileSystemMountOption(); |
| 202 | 187 |
| 203 // Backend specific mount points. | 188 // Backend specific mount points. |
| 204 ASSERT_TRUE(mount_points->RegisterFileSystem( | 189 ASSERT_TRUE(mount_points->RegisterFileSystem( |
| 205 "b", type, option, base::FilePath(FPL("/a/b")))); | 190 "b", type, option, base::FilePath(FPL("/a/b")))); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 if (!kTestCases[i].success) | 234 if (!kTestCases[i].success) |
| 250 continue; | 235 continue; |
| 251 | 236 |
| 252 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); | 237 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); |
| 253 EXPECT_EQ(expected_virtual_path, virtual_path) | 238 EXPECT_EQ(expected_virtual_path, virtual_path) |
| 254 << "Resolving " << kTestCases[i].local_path; | 239 << "Resolving " << kTestCases[i].local_path; |
| 255 } | 240 } |
| 256 } | 241 } |
| 257 | 242 |
| 258 } // namespace | 243 } // namespace |
| OLD | NEW |