Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: chrome/browser/chromeos/fileapi/file_system_backend_unittest.cc

Issue 18344013: fileapi: Rename FileSystemMountProvider to FileSystemBackend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(ChromeOSFileSystemBackendTest, DefaultMountPoints) {
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 backend(
42 NULL, // drive_delegate 42 NULL, // drive_delegate
43 storage_policy, 43 storage_policy,
44 mount_points.get(), 44 mount_points.get(),
45 fileapi::ExternalMountPoints::GetSystemInstance()); 45 fileapi::ExternalMountPoints::GetSystemInstance());
46 provider.AddSystemMountPoints(); 46 backend.AddSystemMountPoints();
47 std::vector<base::FilePath> root_dirs = provider.GetRootDirectories(); 47 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories();
48 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); 48 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end());
49 49
50 // By default there should be 4 mount points (in system mount points): 50 // By default there should be 4 mount points (in system mount points):
51 EXPECT_EQ(4u, root_dirs.size()); 51 EXPECT_EQ(4u, root_dirs.size());
52 base::FilePath home_path; 52 base::FilePath home_path;
53 ASSERT_TRUE(PathService::Get(base::DIR_HOME, &home_path)); 53 ASSERT_TRUE(PathService::Get(base::DIR_HOME, &home_path));
54 54
55 EXPECT_TRUE(root_dirs_set.count(home_path.AppendASCII("Downloads"))); 55 EXPECT_TRUE(root_dirs_set.count(home_path.AppendASCII("Downloads")));
56 EXPECT_TRUE(root_dirs_set.count( 56 EXPECT_TRUE(root_dirs_set.count(
57 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); 57 chromeos::CrosDisksClient::GetRemovableDiskMountPoint()));
58 EXPECT_TRUE(root_dirs_set.count( 58 EXPECT_TRUE(root_dirs_set.count(
59 chromeos::CrosDisksClient::GetArchiveMountPoint())); 59 chromeos::CrosDisksClient::GetArchiveMountPoint()));
60 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"))));
61 } 61 }
62 62
63 TEST(CrosMountPointProviderTest, GetRootDirectories) { 63 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) {
64 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 64 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
65 new quota::MockSpecialStoragePolicy(); 65 new quota::MockSpecialStoragePolicy();
66 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 66 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
67 fileapi::ExternalMountPoints::CreateRefCounted()); 67 fileapi::ExternalMountPoints::CreateRefCounted());
68 68
69 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 69 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points(
70 fileapi::ExternalMountPoints::CreateRefCounted()); 70 fileapi::ExternalMountPoints::CreateRefCounted());
71 71
72 chromeos::CrosMountPointProvider provider( 72 chromeos::FileSystemBackend backend(
73 NULL, // drive_delegate 73 NULL, // drive_delegate
74 storage_policy, 74 storage_policy,
75 mount_points.get(), 75 mount_points.get(),
76 system_mount_points.get()); 76 system_mount_points.get());
77 77
78 const size_t initial_root_dirs_size = provider.GetRootDirectories().size(); 78 const size_t initial_root_dirs_size = backend.GetRootDirectories().size();
79 79
80 // Register 'local' test mount points. 80 // Register 'local' test mount points.
81 mount_points->RegisterFileSystem("c", 81 mount_points->RegisterFileSystem("c",
82 fileapi::kFileSystemTypeNativeLocal, 82 fileapi::kFileSystemTypeNativeLocal,
83 base::FilePath(FPL("/a/b/c"))); 83 base::FilePath(FPL("/a/b/c")));
84 mount_points->RegisterFileSystem("d", 84 mount_points->RegisterFileSystem("d",
85 fileapi::kFileSystemTypeNativeLocal, 85 fileapi::kFileSystemTypeNativeLocal,
86 base::FilePath(FPL("/b/c/d"))); 86 base::FilePath(FPL("/b/c/d")));
87 87
88 // Register system test mount points. 88 // Register system test mount points.
89 system_mount_points->RegisterFileSystem("d", 89 system_mount_points->RegisterFileSystem("d",
90 fileapi::kFileSystemTypeNativeLocal, 90 fileapi::kFileSystemTypeNativeLocal,
91 base::FilePath(FPL("/g/c/d"))); 91 base::FilePath(FPL("/g/c/d")));
92 system_mount_points->RegisterFileSystem("e", 92 system_mount_points->RegisterFileSystem("e",
93 fileapi::kFileSystemTypeNativeLocal, 93 fileapi::kFileSystemTypeNativeLocal,
94 base::FilePath(FPL("/g/d/e"))); 94 base::FilePath(FPL("/g/d/e")));
95 95
96 std::vector<base::FilePath> root_dirs = provider.GetRootDirectories(); 96 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories();
97 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); 97 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end());
98 EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size()); 98 EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size());
99 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c")))); 99 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c"))));
100 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d")))); 100 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d"))));
101 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d")))); 101 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d"))));
102 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); 102 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e"))));
103 } 103 }
104 104
105 TEST(CrosMountPointProviderTest, AccessPermissions) { 105 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) {
106 url_util::AddStandardScheme("chrome-extension"); 106 url_util::AddStandardScheme("chrome-extension");
107 107
108 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = 108 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy =
109 new quota::MockSpecialStoragePolicy(); 109 new quota::MockSpecialStoragePolicy();
110 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 110 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
111 fileapi::ExternalMountPoints::CreateRefCounted()); 111 fileapi::ExternalMountPoints::CreateRefCounted());
112 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 112 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points(
113 fileapi::ExternalMountPoints::CreateRefCounted()); 113 fileapi::ExternalMountPoints::CreateRefCounted());
114 chromeos::CrosMountPointProvider provider( 114 chromeos::FileSystemBackend backend(
115 NULL, // drive_delegate 115 NULL, // drive_delegate
116 storage_policy, 116 storage_policy,
117 mount_points.get(), 117 mount_points.get(),
118 system_mount_points.get()); 118 system_mount_points.get());
119 119
120 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); 120 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla");
121 121
122 storage_policy->AddFileHandler(extension); 122 storage_policy->AddFileHandler(extension);
123 123
124 // Initialize mount points. 124 // Initialize mount points.
125 ASSERT_TRUE(system_mount_points->RegisterFileSystem( 125 ASSERT_TRUE(system_mount_points->RegisterFileSystem(
126 "system", 126 "system",
127 fileapi::kFileSystemTypeNativeLocal, 127 fileapi::kFileSystemTypeNativeLocal,
128 base::FilePath(FPL("/g/system")))); 128 base::FilePath(FPL("/g/system"))));
129 ASSERT_TRUE(mount_points->RegisterFileSystem( 129 ASSERT_TRUE(mount_points->RegisterFileSystem(
130 "removable", 130 "removable",
131 fileapi::kFileSystemTypeNativeLocal, 131 fileapi::kFileSystemTypeNativeLocal,
132 base::FilePath(FPL("/media/removable")))); 132 base::FilePath(FPL("/media/removable"))));
133 ASSERT_TRUE(mount_points->RegisterFileSystem( 133 ASSERT_TRUE(mount_points->RegisterFileSystem(
134 "oem", 134 "oem",
135 fileapi::kFileSystemTypeRestrictedNativeLocal, 135 fileapi::kFileSystemTypeRestrictedNativeLocal,
136 base::FilePath(FPL("/usr/share/oem")))); 136 base::FilePath(FPL("/usr/share/oem"))));
137 137
138 // Provider specific mount point access. 138 // Backend specific mount point access.
139 EXPECT_FALSE(provider.IsAccessAllowed( 139 EXPECT_FALSE(backend.IsAccessAllowed(
140 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 140 CreateFileSystemURL(extension, "removable/foo", mount_points.get())));
141 141
142 provider.GrantFileAccessToExtension(extension, 142 backend.GrantFileAccessToExtension(extension,
143 base::FilePath(FPL("removable/foo"))); 143 base::FilePath(FPL("removable/foo")));
144 EXPECT_TRUE(provider.IsAccessAllowed( 144 EXPECT_TRUE(backend.IsAccessAllowed(
145 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 145 CreateFileSystemURL(extension, "removable/foo", mount_points.get())));
146 EXPECT_FALSE(provider.IsAccessAllowed( 146 EXPECT_FALSE(backend.IsAccessAllowed(
147 CreateFileSystemURL(extension, "removable/foo1", mount_points.get()))); 147 CreateFileSystemURL(extension, "removable/foo1", mount_points.get())));
148 148
149 // System mount point access. 149 // System mount point access.
150 EXPECT_FALSE(provider.IsAccessAllowed( 150 EXPECT_FALSE(backend.IsAccessAllowed(
151 CreateFileSystemURL(extension, "system/foo", system_mount_points.get()))); 151 CreateFileSystemURL(extension, "system/foo", system_mount_points.get())));
152 152
153 provider.GrantFileAccessToExtension(extension, 153 backend.GrantFileAccessToExtension(extension,
154 base::FilePath(FPL("system/foo"))); 154 base::FilePath(FPL("system/foo")));
155 EXPECT_TRUE(provider.IsAccessAllowed( 155 EXPECT_TRUE(backend.IsAccessAllowed(
156 CreateFileSystemURL(extension, "system/foo", system_mount_points.get()))); 156 CreateFileSystemURL(extension, "system/foo", system_mount_points.get())));
157 EXPECT_FALSE(provider.IsAccessAllowed( 157 EXPECT_FALSE(backend.IsAccessAllowed(
158 CreateFileSystemURL(extension, "system/foo1", 158 CreateFileSystemURL(extension, "system/foo1",
159 system_mount_points.get()))); 159 system_mount_points.get())));
160 160
161 // oem is restricted file system. 161 // oem is restricted file system.
162 provider.GrantFileAccessToExtension( 162 backend.GrantFileAccessToExtension(
163 extension, base::FilePath(FPL("oem/foo"))); 163 extension, base::FilePath(FPL("oem/foo")));
164 // The extension should not be able to access the file even if 164 // The extension should not be able to access the file even if
165 // GrantFileAccessToExtension was called. 165 // GrantFileAccessToExtension was called.
166 EXPECT_FALSE(provider.IsAccessAllowed( 166 EXPECT_FALSE(backend.IsAccessAllowed(
167 CreateFileSystemURL(extension, "oem/foo", mount_points.get()))); 167 CreateFileSystemURL(extension, "oem/foo", mount_points.get())));
168 168
169 provider.GrantFullAccessToExtension(extension); 169 backend.GrantFullAccessToExtension(extension);
170 // The extension should be able to access restricted file system after it was 170 // The extension should be able to access restricted file system after it was
171 // granted full access. 171 // granted full access.
172 EXPECT_TRUE(provider.IsAccessAllowed( 172 EXPECT_TRUE(backend.IsAccessAllowed(
173 CreateFileSystemURL(extension, "oem/foo", mount_points.get()))); 173 CreateFileSystemURL(extension, "oem/foo", mount_points.get())));
174 // The extension which was granted full access should be able to access any 174 // The extension which was granted full access should be able to access any
175 // path on current file systems. 175 // path on current file systems.
176 EXPECT_TRUE(provider.IsAccessAllowed( 176 EXPECT_TRUE(backend.IsAccessAllowed(
177 CreateFileSystemURL(extension, "removable/foo1", mount_points.get()))); 177 CreateFileSystemURL(extension, "removable/foo1", mount_points.get())));
178 EXPECT_TRUE(provider.IsAccessAllowed( 178 EXPECT_TRUE(backend.IsAccessAllowed(
179 CreateFileSystemURL(extension, "system/foo1", 179 CreateFileSystemURL(extension, "system/foo1",
180 system_mount_points.get()))); 180 system_mount_points.get())));
181 181
182 // The extension cannot access new mount points. 182 // The extension cannot access new mount points.
183 // TODO(tbarzic): This should probably be changed. 183 // TODO(tbarzic): This should probably be changed.
184 ASSERT_TRUE(mount_points->RegisterFileSystem( 184 ASSERT_TRUE(mount_points->RegisterFileSystem(
185 "test", 185 "test",
186 fileapi::kFileSystemTypeNativeLocal, 186 fileapi::kFileSystemTypeNativeLocal,
187 base::FilePath(FPL("/foo/test")))); 187 base::FilePath(FPL("/foo/test"))));
188 EXPECT_FALSE(provider.IsAccessAllowed( 188 EXPECT_FALSE(backend.IsAccessAllowed(
189 CreateFileSystemURL(extension, "test_/foo", mount_points.get()))); 189 CreateFileSystemURL(extension, "test_/foo", mount_points.get())));
190 190
191 provider.RevokeAccessForExtension(extension); 191 backend.RevokeAccessForExtension(extension);
192 EXPECT_FALSE(provider.IsAccessAllowed( 192 EXPECT_FALSE(backend.IsAccessAllowed(
193 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 193 CreateFileSystemURL(extension, "removable/foo", mount_points.get())));
194 194
195 fileapi::FileSystemURL internal_url = FileSystemURL::CreateForTest( 195 fileapi::FileSystemURL internal_url = FileSystemURL::CreateForTest(
196 GURL("chrome://foo"), 196 GURL("chrome://foo"),
197 fileapi::kFileSystemTypeExternal, 197 fileapi::kFileSystemTypeExternal,
198 base::FilePath(FPL("removable/"))); 198 base::FilePath(FPL("removable/")));
199 // Internal WebUI should have full access. 199 // Internal WebUI should have full access.
200 EXPECT_TRUE(provider.IsAccessAllowed(internal_url)); 200 EXPECT_TRUE(backend.IsAccessAllowed(internal_url));
201 } 201 }
202 202
203 TEST(CrosMountPointProvider, GetVirtualPathConflictWithSystemPoints) { 203 TEST(FileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) {
204 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = 204 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy =
205 new quota::MockSpecialStoragePolicy(); 205 new quota::MockSpecialStoragePolicy();
206 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 206 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
207 fileapi::ExternalMountPoints::CreateRefCounted()); 207 fileapi::ExternalMountPoints::CreateRefCounted());
208 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 208 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points(
209 fileapi::ExternalMountPoints::CreateRefCounted()); 209 fileapi::ExternalMountPoints::CreateRefCounted());
210 chromeos::CrosMountPointProvider provider( 210 chromeos::FileSystemBackend backend(
211 NULL, // drive_delegate 211 NULL, // drive_delegate
212 storage_policy, 212 storage_policy,
213 mount_points.get(), 213 mount_points.get(),
214 system_mount_points.get()); 214 system_mount_points.get());
215 215
216 const fileapi::FileSystemType type = fileapi::kFileSystemTypeNativeLocal; 216 const fileapi::FileSystemType type = fileapi::kFileSystemTypeNativeLocal;
217 217
218 // Provider specific mount points. 218 // Backend specific mount points.
219 ASSERT_TRUE( 219 ASSERT_TRUE(
220 mount_points->RegisterFileSystem("b", type, base::FilePath(FPL("/a/b")))); 220 mount_points->RegisterFileSystem("b", type, base::FilePath(FPL("/a/b"))));
221 ASSERT_TRUE( 221 ASSERT_TRUE(
222 mount_points->RegisterFileSystem("y", type, base::FilePath(FPL("/z/y")))); 222 mount_points->RegisterFileSystem("y", type, base::FilePath(FPL("/z/y"))));
223 ASSERT_TRUE( 223 ASSERT_TRUE(
224 mount_points->RegisterFileSystem("n", type, base::FilePath(FPL("/m/n")))); 224 mount_points->RegisterFileSystem("n", type, base::FilePath(FPL("/m/n"))));
225 225
226 // System mount points 226 // System mount points
227 ASSERT_TRUE(system_mount_points->RegisterFileSystem( 227 ASSERT_TRUE(system_mount_points->RegisterFileSystem(
228 "gb", type, base::FilePath(FPL("/a/b")))); 228 "gb", type, base::FilePath(FPL("/a/b"))));
(...skipping 20 matching lines...) Expand all
249 { FPL("/z/q/r/s"), true, FPL("gz/q/r/s") }, 249 { FPL("/z/q/r/s"), true, FPL("gz/q/r/s") },
250 // No match. 250 // No match.
251 { FPL("/foo/xxx"), false, FPL("") }, 251 { FPL("/foo/xxx"), false, FPL("") },
252 }; 252 };
253 253
254 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 254 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
255 // Initialize virtual path with a value. 255 // Initialize virtual path with a value.
256 base::FilePath virtual_path(FPL("/mount")); 256 base::FilePath virtual_path(FPL("/mount"));
257 base::FilePath local_path(kTestCases[i].local_path); 257 base::FilePath local_path(kTestCases[i].local_path);
258 EXPECT_EQ(kTestCases[i].success, 258 EXPECT_EQ(kTestCases[i].success,
259 provider.GetVirtualPath(local_path, &virtual_path)) 259 backend.GetVirtualPath(local_path, &virtual_path))
260 << "Resolving " << kTestCases[i].local_path; 260 << "Resolving " << kTestCases[i].local_path;
261 261
262 // There are no guarantees for |virtual_path| value if |GetVirtualPath| 262 // There are no guarantees for |virtual_path| value if |GetVirtualPath|
263 // fails. 263 // fails.
264 if (!kTestCases[i].success) 264 if (!kTestCases[i].success)
265 continue; 265 continue;
266 266
267 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); 267 base::FilePath expected_virtual_path(kTestCases[i].virtual_path);
268 EXPECT_EQ(expected_virtual_path, virtual_path) 268 EXPECT_EQ(expected_virtual_path, virtual_path)
269 << "Resolving " << kTestCases[i].local_path; 269 << "Resolving " << kTestCases[i].local_path;
270 } 270 }
271 } 271 }
272 272
273 } // namespace 273 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698