Chromium Code Reviews| 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/cros_mount_point_provider.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 "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "url/url_util.h" | 13 #include "url/url_util.h" |
| 14 #include "webkit/browser/fileapi/external_mount_points.h" | 14 #include "webkit/browser/fileapi/external_mount_points.h" |
| 15 #include "webkit/browser/fileapi/file_permission_policy.h" | 15 #include "webkit/browser/fileapi/file_permission_policy.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 FileSystemURL CreateFileSystemURL(const std::string& extension, | 27 FileSystemURL CreateFileSystemURL(const std::string& extension, |
| 28 const char* path, | 28 const char* path, |
| 29 ExternalMountPoints* mount_points) { | 29 ExternalMountPoints* mount_points) { |
| 30 return mount_points->CreateCrackedFileSystemURL( | 30 return mount_points->CreateCrackedFileSystemURL( |
| 31 GURL("chrome-extension://" + extension + "/"), | 31 GURL("chrome-extension://" + extension + "/"), |
| 32 fileapi::kFileSystemTypeExternal, | 32 fileapi::kFileSystemTypeExternal, |
| 33 base::FilePath::FromUTF8Unsafe(path)); | 33 base::FilePath::FromUTF8Unsafe(path)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 TEST(CrosMountPointProviderTest, DefaultMountPoints) { | 36 TEST(CrosMountPointProviderTest, DefaultMountPoints) { |
|
hidehiko
2013/07/04 07:14:40
Probably, we want to rename CrosMountProviderTest
satorux1
2013/07/04 08:11:32
Done.
| |
| 37 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 37 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
| 38 new quota::MockSpecialStoragePolicy(); | 38 new quota::MockSpecialStoragePolicy(); |
| 39 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 39 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
| 40 fileapi::ExternalMountPoints::CreateRefCounted()); | 40 fileapi::ExternalMountPoints::CreateRefCounted()); |
| 41 chromeos::CrosMountPointProvider provider( | 41 chromeos::FileSystemBackend provider( |
|
hidehiko
2013/07/04 07:14:40
s/provider/backend/
satorux1
2013/07/04 08:11:32
Done.
| |
| 42 storage_policy, | 42 storage_policy, |
| 43 mount_points.get(), | 43 mount_points.get(), |
| 44 fileapi::ExternalMountPoints::GetSystemInstance()); | 44 fileapi::ExternalMountPoints::GetSystemInstance()); |
| 45 provider.AddSystemMountPoints(); | 45 provider.AddSystemMountPoints(); |
| 46 std::vector<base::FilePath> root_dirs = provider.GetRootDirectories(); | 46 std::vector<base::FilePath> root_dirs = provider.GetRootDirectories(); |
| 47 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()); |
| 48 | 48 |
| 49 // By default there should be 4 mount points (in system mount points): | 49 // By default there should be 4 mount points (in system mount points): |
| 50 EXPECT_EQ(4u, root_dirs.size()); | 50 EXPECT_EQ(4u, root_dirs.size()); |
| 51 base::FilePath home_path; | 51 base::FilePath home_path; |
| 52 ASSERT_TRUE(PathService::Get(base::DIR_HOME, &home_path)); | 52 ASSERT_TRUE(PathService::Get(base::DIR_HOME, &home_path)); |
| 53 | 53 |
| 54 EXPECT_TRUE(root_dirs_set.count(home_path.AppendASCII("Downloads"))); | 54 EXPECT_TRUE(root_dirs_set.count(home_path.AppendASCII("Downloads"))); |
| 55 EXPECT_TRUE(root_dirs_set.count( | 55 EXPECT_TRUE(root_dirs_set.count( |
| 56 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); | 56 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); |
| 57 EXPECT_TRUE(root_dirs_set.count( | 57 EXPECT_TRUE(root_dirs_set.count( |
| 58 chromeos::CrosDisksClient::GetArchiveMountPoint())); | 58 chromeos::CrosDisksClient::GetArchiveMountPoint())); |
| 59 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); | 59 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST(CrosMountPointProviderTest, GetRootDirectories) { | 62 TEST(CrosMountPointProviderTest, GetRootDirectories) { |
| 63 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 63 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
| 64 new quota::MockSpecialStoragePolicy(); | 64 new quota::MockSpecialStoragePolicy(); |
| 65 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 65 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
| 66 fileapi::ExternalMountPoints::CreateRefCounted()); | 66 fileapi::ExternalMountPoints::CreateRefCounted()); |
| 67 | 67 |
| 68 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 68 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( |
| 69 fileapi::ExternalMountPoints::CreateRefCounted()); | 69 fileapi::ExternalMountPoints::CreateRefCounted()); |
| 70 | 70 |
| 71 chromeos::CrosMountPointProvider provider( | 71 chromeos::FileSystemBackend provider( |
|
hidehiko
2013/07/04 07:14:40
ditto.
satorux1
2013/07/04 08:11:32
Done.
| |
| 72 storage_policy, | 72 storage_policy, |
| 73 mount_points.get(), | 73 mount_points.get(), |
| 74 system_mount_points.get()); | 74 system_mount_points.get()); |
| 75 | 75 |
| 76 const size_t initial_root_dirs_size = provider.GetRootDirectories().size(); | 76 const size_t initial_root_dirs_size = provider.GetRootDirectories().size(); |
| 77 | 77 |
| 78 // Register 'local' test mount points. | 78 // Register 'local' test mount points. |
| 79 mount_points->RegisterFileSystem("c", | 79 mount_points->RegisterFileSystem("c", |
| 80 fileapi::kFileSystemTypeNativeLocal, | 80 fileapi::kFileSystemTypeNativeLocal, |
| 81 base::FilePath(FPL("/a/b/c"))); | 81 base::FilePath(FPL("/a/b/c"))); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 102 | 102 |
| 103 TEST(CrosMountPointProviderTest, AccessPermissions) { | 103 TEST(CrosMountPointProviderTest, AccessPermissions) { |
| 104 url_util::AddStandardScheme("chrome-extension"); | 104 url_util::AddStandardScheme("chrome-extension"); |
| 105 | 105 |
| 106 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = | 106 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = |
| 107 new quota::MockSpecialStoragePolicy(); | 107 new quota::MockSpecialStoragePolicy(); |
| 108 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 108 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
| 109 fileapi::ExternalMountPoints::CreateRefCounted()); | 109 fileapi::ExternalMountPoints::CreateRefCounted()); |
| 110 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 110 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( |
| 111 fileapi::ExternalMountPoints::CreateRefCounted()); | 111 fileapi::ExternalMountPoints::CreateRefCounted()); |
| 112 chromeos::CrosMountPointProvider provider( | 112 chromeos::FileSystemBackend provider( |
|
hidehiko
2013/07/04 07:14:40
ditto.
satorux1
2013/07/04 08:11:32
Done.
| |
| 113 storage_policy, | 113 storage_policy, |
| 114 mount_points.get(), | 114 mount_points.get(), |
| 115 system_mount_points.get()); | 115 system_mount_points.get()); |
| 116 | 116 |
| 117 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); | 117 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); |
| 118 | 118 |
| 119 storage_policy->AddFileHandler(extension); | 119 storage_policy->AddFileHandler(extension); |
| 120 | 120 |
| 121 // Initialize mount points. | 121 // Initialize mount points. |
| 122 ASSERT_TRUE(system_mount_points->RegisterFileSystem( | 122 ASSERT_TRUE(system_mount_points->RegisterFileSystem( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); | 190 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); |
| 191 | 191 |
| 192 fileapi::FileSystemURL internal_url = FileSystemURL::CreateForTest( | 192 fileapi::FileSystemURL internal_url = FileSystemURL::CreateForTest( |
| 193 GURL("chrome://foo"), | 193 GURL("chrome://foo"), |
| 194 fileapi::kFileSystemTypeExternal, | 194 fileapi::kFileSystemTypeExternal, |
| 195 base::FilePath(FPL("removable/"))); | 195 base::FilePath(FPL("removable/"))); |
| 196 // Internal WebUI should have full access. | 196 // Internal WebUI should have full access. |
| 197 EXPECT_TRUE(provider.IsAccessAllowed(internal_url)); | 197 EXPECT_TRUE(provider.IsAccessAllowed(internal_url)); |
| 198 } | 198 } |
| 199 | 199 |
| 200 TEST(CrosMountPointProvider, GetVirtualPathConflictWithSystemPoints) { | 200 TEST(FileSystemBackend, GetVirtualPathConflictWithSystemPoints) { |
| 201 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = | 201 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = |
| 202 new quota::MockSpecialStoragePolicy(); | 202 new quota::MockSpecialStoragePolicy(); |
| 203 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 203 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
| 204 fileapi::ExternalMountPoints::CreateRefCounted()); | 204 fileapi::ExternalMountPoints::CreateRefCounted()); |
| 205 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 205 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( |
| 206 fileapi::ExternalMountPoints::CreateRefCounted()); | 206 fileapi::ExternalMountPoints::CreateRefCounted()); |
| 207 chromeos::CrosMountPointProvider provider(storage_policy, | 207 chromeos::FileSystemBackend provider(storage_policy, |
|
hidehiko
2013/07/04 07:14:40
ditto.
satorux1
2013/07/04 08:11:32
Done.
| |
| 208 mount_points.get(), | 208 mount_points.get(), |
| 209 system_mount_points.get()); | 209 system_mount_points.get()); |
| 210 | 210 |
| 211 const fileapi::FileSystemType type = fileapi::kFileSystemTypeNativeLocal; | 211 const fileapi::FileSystemType type = fileapi::kFileSystemTypeNativeLocal; |
| 212 | 212 |
| 213 // Provider specific mount points. | 213 // Provider specific mount points. |
| 214 ASSERT_TRUE( | 214 ASSERT_TRUE( |
| 215 mount_points->RegisterFileSystem("b", type, base::FilePath(FPL("/a/b")))); | 215 mount_points->RegisterFileSystem("b", type, base::FilePath(FPL("/a/b")))); |
| 216 ASSERT_TRUE( | 216 ASSERT_TRUE( |
| 217 mount_points->RegisterFileSystem("y", type, base::FilePath(FPL("/z/y")))); | 217 mount_points->RegisterFileSystem("y", type, base::FilePath(FPL("/z/y")))); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 if (!kTestCases[i].success) | 259 if (!kTestCases[i].success) |
| 260 continue; | 260 continue; |
| 261 | 261 |
| 262 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); | 262 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); |
| 263 EXPECT_EQ(expected_virtual_path, virtual_path) | 263 EXPECT_EQ(expected_virtual_path, virtual_path) |
| 264 << "Resolving " << kTestCases[i].local_path; | 264 << "Resolving " << kTestCases[i].local_path; |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 } // namespace | 268 } // namespace |
| OLD | NEW |