| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h" |
| 13 #include "chromeos/dbus/cros_disks_client.h" | 14 #include "chromeos/dbus/cros_disks_client.h" |
| 14 #include "storage/browser/fileapi/external_mount_points.h" | 15 #include "storage/browser/fileapi/external_mount_points.h" |
| 15 #include "storage/browser/fileapi/file_system_url.h" | 16 #include "storage/browser/fileapi/file_system_url.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/url_util.h" | 18 #include "url/url_util.h" |
| 18 | 19 |
| 19 #define FPL(x) FILE_PATH_LITERAL(x) | 20 #define FPL(x) FILE_PATH_LITERAL(x) |
| 20 | 21 |
| 21 using storage::ExternalMountPoints; | 22 using storage::ExternalMountPoints; |
| 22 using storage::FileSystemURL; | 23 using storage::FileSystemURL; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 } | 34 } |
| 34 | 35 |
| 35 TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) { | 36 TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) { |
| 36 // Make sure no system-level mount points are registered before testing | 37 // Make sure no system-level mount points are registered before testing |
| 37 // to avoid flakiness. | 38 // to avoid flakiness. |
| 38 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); | 39 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); |
| 39 | 40 |
| 40 scoped_refptr<storage::ExternalMountPoints> mount_points( | 41 scoped_refptr<storage::ExternalMountPoints> mount_points( |
| 41 storage::ExternalMountPoints::CreateRefCounted()); | 42 storage::ExternalMountPoints::CreateRefCounted()); |
| 42 chromeos::FileSystemBackend backend( | 43 chromeos::FileSystemBackend backend( |
| 43 NULL, // drive_delegate | 44 nullptr, // drive_delegate |
| 44 NULL, // file_system_provider_delegate | 45 nullptr, // file_system_provider_delegate |
| 45 NULL, // mtp_delegate | 46 nullptr, // mtp_delegate |
| 46 mount_points.get(), | 47 nullptr, // arc_content_delegate |
| 47 storage::ExternalMountPoints::GetSystemInstance()); | 48 mount_points.get(), storage::ExternalMountPoints::GetSystemInstance()); |
| 48 backend.AddSystemMountPoints(); | 49 backend.AddSystemMountPoints(); |
| 49 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); | 50 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); |
| 50 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); | 51 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); |
| 51 | 52 |
| 52 // By default there should be 3 mount points (in system mount points): | 53 // By default there should be 3 mount points (in system mount points): |
| 53 EXPECT_EQ(3u, root_dirs.size()); | 54 EXPECT_EQ(3u, root_dirs.size()); |
| 54 | 55 |
| 55 EXPECT_TRUE(root_dirs_set.count( | 56 EXPECT_TRUE(root_dirs_set.count( |
| 56 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); | 57 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); |
| 57 EXPECT_TRUE(root_dirs_set.count( | 58 EXPECT_TRUE(root_dirs_set.count( |
| 58 chromeos::CrosDisksClient::GetArchiveMountPoint())); | 59 chromeos::CrosDisksClient::GetArchiveMountPoint())); |
| 59 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); | 60 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); |
| 60 } | 61 } |
| 61 | 62 |
| 62 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) { | 63 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) { |
| 63 scoped_refptr<storage::ExternalMountPoints> mount_points( | 64 scoped_refptr<storage::ExternalMountPoints> mount_points( |
| 64 storage::ExternalMountPoints::CreateRefCounted()); | 65 storage::ExternalMountPoints::CreateRefCounted()); |
| 65 | 66 |
| 66 scoped_refptr<storage::ExternalMountPoints> system_mount_points( | 67 scoped_refptr<storage::ExternalMountPoints> system_mount_points( |
| 67 storage::ExternalMountPoints::CreateRefCounted()); | 68 storage::ExternalMountPoints::CreateRefCounted()); |
| 68 | 69 |
| 69 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 70 chromeos::FileSystemBackend backend(nullptr, // drive_delegate |
| 70 NULL, // file_system_provider_delegate | 71 nullptr, // file_system_provider_delegate |
| 71 NULL, // mtp_delegate | 72 nullptr, // mtp_delegate |
| 73 nullptr, // arc_content_delegate |
| 72 mount_points.get(), | 74 mount_points.get(), |
| 73 system_mount_points.get()); | 75 system_mount_points.get()); |
| 74 | 76 |
| 75 const size_t initial_root_dirs_size = backend.GetRootDirectories().size(); | 77 const size_t initial_root_dirs_size = backend.GetRootDirectories().size(); |
| 76 | 78 |
| 77 // Register 'local' test mount points. | 79 // Register 'local' test mount points. |
| 78 mount_points->RegisterFileSystem("c", | 80 mount_points->RegisterFileSystem("c", |
| 79 storage::kFileSystemTypeNativeLocal, | 81 storage::kFileSystemTypeNativeLocal, |
| 80 storage::FileSystemMountOption(), | 82 storage::FileSystemMountOption(), |
| 81 base::FilePath(FPL("/a/b/c"))); | 83 base::FilePath(FPL("/a/b/c"))); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 103 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); | 105 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); |
| 104 } | 106 } |
| 105 | 107 |
| 106 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) { | 108 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) { |
| 107 url::AddStandardScheme("chrome-extension", url::SCHEME_WITHOUT_PORT); | 109 url::AddStandardScheme("chrome-extension", url::SCHEME_WITHOUT_PORT); |
| 108 | 110 |
| 109 scoped_refptr<storage::ExternalMountPoints> mount_points( | 111 scoped_refptr<storage::ExternalMountPoints> mount_points( |
| 110 storage::ExternalMountPoints::CreateRefCounted()); | 112 storage::ExternalMountPoints::CreateRefCounted()); |
| 111 scoped_refptr<storage::ExternalMountPoints> system_mount_points( | 113 scoped_refptr<storage::ExternalMountPoints> system_mount_points( |
| 112 storage::ExternalMountPoints::CreateRefCounted()); | 114 storage::ExternalMountPoints::CreateRefCounted()); |
| 113 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 115 chromeos::FileSystemBackend backend(nullptr, // drive_delegate |
| 114 NULL, // file_system_provider_delegate | 116 nullptr, // file_system_provider_delegate |
| 115 NULL, // mtp_delegate | 117 nullptr, // mtp_delegate |
| 118 nullptr, // arc_content_delegate |
| 116 mount_points.get(), | 119 mount_points.get(), |
| 117 system_mount_points.get()); | 120 system_mount_points.get()); |
| 118 | 121 |
| 119 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); | 122 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); |
| 120 | 123 |
| 121 // Initialize mount points. | 124 // Initialize mount points. |
| 122 ASSERT_TRUE(system_mount_points->RegisterFileSystem( | 125 ASSERT_TRUE(system_mount_points->RegisterFileSystem( |
| 123 "system", | 126 "system", |
| 124 storage::kFileSystemTypeNativeLocal, | 127 storage::kFileSystemTypeNativeLocal, |
| 125 storage::FileSystemMountOption(), | 128 storage::FileSystemMountOption(), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 backend.RevokeAccessForExtension(extension); | 174 backend.RevokeAccessForExtension(extension); |
| 172 EXPECT_FALSE(backend.IsAccessAllowed( | 175 EXPECT_FALSE(backend.IsAccessAllowed( |
| 173 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); | 176 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); |
| 174 } | 177 } |
| 175 | 178 |
| 176 TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) { | 179 TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) { |
| 177 scoped_refptr<storage::ExternalMountPoints> mount_points( | 180 scoped_refptr<storage::ExternalMountPoints> mount_points( |
| 178 storage::ExternalMountPoints::CreateRefCounted()); | 181 storage::ExternalMountPoints::CreateRefCounted()); |
| 179 scoped_refptr<storage::ExternalMountPoints> system_mount_points( | 182 scoped_refptr<storage::ExternalMountPoints> system_mount_points( |
| 180 storage::ExternalMountPoints::CreateRefCounted()); | 183 storage::ExternalMountPoints::CreateRefCounted()); |
| 181 chromeos::FileSystemBackend backend(NULL, // drive_delegate | 184 chromeos::FileSystemBackend backend(nullptr, // drive_delegate |
| 182 NULL, // file_system_provider_delegate | 185 nullptr, // file_system_provider_delegate |
| 183 NULL, // mtp_delegate | 186 nullptr, // mtp_delegate |
| 187 nullptr, // arc_content_delegate |
| 184 mount_points.get(), | 188 mount_points.get(), |
| 185 system_mount_points.get()); | 189 system_mount_points.get()); |
| 186 | 190 |
| 187 const storage::FileSystemType type = storage::kFileSystemTypeNativeLocal; | 191 const storage::FileSystemType type = storage::kFileSystemTypeNativeLocal; |
| 188 const storage::FileSystemMountOption option = | 192 const storage::FileSystemMountOption option = |
| 189 storage::FileSystemMountOption(); | 193 storage::FileSystemMountOption(); |
| 190 | 194 |
| 191 // Backend specific mount points. | 195 // Backend specific mount points. |
| 192 ASSERT_TRUE(mount_points->RegisterFileSystem( | 196 ASSERT_TRUE(mount_points->RegisterFileSystem( |
| 193 "b", type, option, base::FilePath(FPL("/a/b")))); | 197 "b", type, option, base::FilePath(FPL("/a/b")))); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 if (!kTestCases[i].success) | 241 if (!kTestCases[i].success) |
| 238 continue; | 242 continue; |
| 239 | 243 |
| 240 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); | 244 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); |
| 241 EXPECT_EQ(expected_virtual_path, virtual_path) | 245 EXPECT_EQ(expected_virtual_path, virtual_path) |
| 242 << "Resolving " << kTestCases[i].local_path; | 246 << "Resolving " << kTestCases[i].local_path; |
| 243 } | 247 } |
| 244 } | 248 } |
| 245 | 249 |
| 246 } // namespace | 250 } // namespace |
| OLD | NEW |