OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 5 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "googleurl/src/url_util.h" | 10 #include "googleurl/src/url_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webkit/fileapi/external_mount_points.h" | 12 #include "webkit/fileapi/external_mount_points.h" |
13 #include "webkit/fileapi/file_system_url.h" | 13 #include "webkit/fileapi/file_system_url.h" |
14 #include "webkit/fileapi/isolated_context.h" | 14 #include "webkit/fileapi/isolated_context.h" |
15 #include "webkit/quota/mock_special_storage_policy.h" | 15 #include "webkit/quota/mock_special_storage_policy.h" |
16 | 16 |
17 #define FPL(x) FILE_PATH_LITERAL(x) | 17 #define FPL(x) FILE_PATH_LITERAL(x) |
18 | 18 |
| 19 using fileapi::ExternalMountPoints; |
| 20 using fileapi::FileSystemURL; |
| 21 |
19 namespace { | 22 namespace { |
20 | 23 |
21 fileapi::FileSystemURL CreateFileSystemURL(const std::string& extension, | 24 FileSystemURL CreateFileSystemURL(const std::string& extension, |
22 const char* path) { | 25 const char* path, |
23 return fileapi::FileSystemURL(GURL("chrome-extension://" + extension + "/"), | 26 ExternalMountPoints* mount_points) { |
24 fileapi::kFileSystemTypeNativeLocal, | 27 return mount_points->CreateCrackedFileSystemURL( |
25 FilePath::FromUTF8Unsafe(path)); | 28 GURL("chrome-extension://" + extension + "/"), |
| 29 fileapi::kFileSystemTypeExternal, |
| 30 FilePath::FromUTF8Unsafe(path)); |
26 } | 31 } |
27 | 32 |
28 TEST(CrosMountPointProviderTest, DefaultMountPoints) { | 33 TEST(CrosMountPointProviderTest, DefaultMountPoints) { |
29 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 34 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
30 new quota::MockSpecialStoragePolicy(); | 35 new quota::MockSpecialStoragePolicy(); |
31 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 36 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
32 fileapi::ExternalMountPoints::CreateRefCounted()); | 37 fileapi::ExternalMountPoints::CreateRefCounted()); |
33 chromeos::CrosMountPointProvider provider( | 38 chromeos::CrosMountPointProvider provider( |
34 storage_policy, | 39 storage_policy, |
35 mount_points.get(), | 40 mount_points.get(), |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // Initialize mount points. | 198 // Initialize mount points. |
194 system_mount_points->RegisterFileSystem("system", | 199 system_mount_points->RegisterFileSystem("system", |
195 fileapi::kFileSystemTypeNativeLocal, | 200 fileapi::kFileSystemTypeNativeLocal, |
196 FilePath(FPL("/g/system"))); | 201 FilePath(FPL("/g/system"))); |
197 ASSERT_TRUE(provider.AddLocalMountPoint(FilePath(FPL("/media/removable")))); | 202 ASSERT_TRUE(provider.AddLocalMountPoint(FilePath(FPL("/media/removable")))); |
198 ASSERT_TRUE(provider.AddRestrictedLocalMountPoint( | 203 ASSERT_TRUE(provider.AddRestrictedLocalMountPoint( |
199 FilePath(FPL("/usr/share/oem")))); | 204 FilePath(FPL("/usr/share/oem")))); |
200 | 205 |
201 // Provider specific mount point access. | 206 // Provider specific mount point access. |
202 EXPECT_FALSE(provider.IsAccessAllowed( | 207 EXPECT_FALSE(provider.IsAccessAllowed( |
203 CreateFileSystemURL(extension, "removable/foo"))); | 208 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); |
204 | 209 |
205 provider.GrantFileAccessToExtension(extension, | 210 provider.GrantFileAccessToExtension(extension, |
206 FilePath(FPL("removable/foo"))); | 211 FilePath(FPL("removable/foo"))); |
207 EXPECT_TRUE(provider.IsAccessAllowed( | 212 EXPECT_TRUE(provider.IsAccessAllowed( |
208 CreateFileSystemURL(extension, "removable/foo"))); | 213 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); |
209 EXPECT_FALSE(provider.IsAccessAllowed( | 214 EXPECT_FALSE(provider.IsAccessAllowed( |
210 CreateFileSystemURL(extension, "removable/foo1"))); | 215 CreateFileSystemURL(extension, "removable/foo1", mount_points.get()))); |
211 | 216 |
212 // System mount point access. | 217 // System mount point access. |
213 EXPECT_FALSE(provider.IsAccessAllowed( | 218 EXPECT_FALSE(provider.IsAccessAllowed( |
214 CreateFileSystemURL(extension, "system/foo"))); | 219 CreateFileSystemURL(extension, "system/foo", system_mount_points.get()))); |
215 | 220 |
216 provider.GrantFileAccessToExtension(extension, FilePath(FPL("system/foo"))); | 221 provider.GrantFileAccessToExtension(extension, FilePath(FPL("system/foo"))); |
217 EXPECT_TRUE(provider.IsAccessAllowed( | 222 EXPECT_TRUE(provider.IsAccessAllowed( |
218 CreateFileSystemURL(extension, "system/foo"))); | 223 CreateFileSystemURL(extension, "system/foo", system_mount_points.get()))); |
219 EXPECT_FALSE(provider.IsAccessAllowed( | 224 EXPECT_FALSE(provider.IsAccessAllowed(CreateFileSystemURL( |
220 CreateFileSystemURL(extension, "system/foo1"))); | 225 extension, "system/foo1", system_mount_points.get()))); |
221 | 226 |
222 // oem is restricted file system. | 227 // oem is restricted file system. |
223 provider.GrantFileAccessToExtension(extension, FilePath(FPL("oem/foo"))); | 228 provider.GrantFileAccessToExtension(extension, FilePath(FPL("oem/foo"))); |
224 // The extension should not be able to access the file even if | 229 // The extension should not be able to access the file even if |
225 // GrantFileAccessToExtension was called. | 230 // GrantFileAccessToExtension was called. |
226 EXPECT_FALSE(provider.IsAccessAllowed( | 231 EXPECT_FALSE(provider.IsAccessAllowed( |
227 CreateFileSystemURL(extension, "oem/foo"))); | 232 CreateFileSystemURL(extension, "oem/foo", mount_points.get()))); |
228 | 233 |
229 provider.GrantFullAccessToExtension(extension); | 234 provider.GrantFullAccessToExtension(extension); |
230 // The extension should be able to access restricted file system after it was | 235 // The extension should be able to access restricted file system after it was |
231 // granted full access. | 236 // granted full access. |
232 EXPECT_TRUE(provider.IsAccessAllowed( | 237 EXPECT_TRUE(provider.IsAccessAllowed( |
233 CreateFileSystemURL(extension, "oem/foo"))); | 238 CreateFileSystemURL(extension, "oem/foo", mount_points.get()))); |
234 // The extension which was granted full access should be able to access any | 239 // The extension which was granted full access should be able to access any |
235 // path on current file systems. | 240 // path on curent file systems. |
236 EXPECT_TRUE(provider.IsAccessAllowed( | 241 EXPECT_TRUE(provider.IsAccessAllowed( |
237 CreateFileSystemURL(extension, "removable/foo1"))); | 242 CreateFileSystemURL(extension, "removable/foo1", mount_points.get()))); |
238 EXPECT_TRUE(provider.IsAccessAllowed( | 243 EXPECT_TRUE(provider.IsAccessAllowed(CreateFileSystemURL( |
239 CreateFileSystemURL(extension, "system/foo1"))); | 244 extension, "system/foo1", system_mount_points.get()))); |
240 | 245 |
241 // The extension still cannot access new mount points. | 246 // The extension cannot access new mount points. |
| 247 // TODO(tbarzic): This should probably be changed. |
242 ASSERT_TRUE(provider.AddLocalMountPoint(FilePath(FPL("/foo/test")))); | 248 ASSERT_TRUE(provider.AddLocalMountPoint(FilePath(FPL("/foo/test")))); |
243 EXPECT_FALSE(provider.IsAccessAllowed( | 249 EXPECT_FALSE(provider.IsAccessAllowed( |
244 CreateFileSystemURL(extension, "test_/foo"))); | 250 CreateFileSystemURL(extension, "test_/foo", mount_points.get()))); |
245 | 251 |
246 provider.RevokeAccessForExtension(extension); | 252 provider.RevokeAccessForExtension(extension); |
247 EXPECT_FALSE(provider.IsAccessAllowed( | 253 EXPECT_FALSE(provider.IsAccessAllowed( |
248 CreateFileSystemURL(extension, "removable/foo"))); | 254 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); |
249 | 255 |
250 fileapi::FileSystemURL internal_url(GURL("chrome://foo"), | 256 fileapi::FileSystemURL internal_url = FileSystemURL::CreateForTest( |
251 fileapi::kFileSystemTypeExternal, | 257 GURL("chrome://foo"), |
252 FilePath(FPL("removable/"))); | 258 fileapi::kFileSystemTypeExternal, |
| 259 FilePath(FPL("removable/"))); |
253 // Internal WebUI should have full access. | 260 // Internal WebUI should have full access. |
254 EXPECT_TRUE(provider.IsAccessAllowed(internal_url)); | 261 EXPECT_TRUE(provider.IsAccessAllowed(internal_url)); |
255 } | 262 } |
256 | 263 |
257 TEST(CrosMountPointProvider, GetVirtualPathConflictWithSystemPoints) { | 264 TEST(CrosMountPointProvider, GetVirtualPathConflictWithSystemPoints) { |
258 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = | 265 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = |
259 new quota::MockSpecialStoragePolicy(); | 266 new quota::MockSpecialStoragePolicy(); |
260 scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 267 scoped_refptr<fileapi::ExternalMountPoints> mount_points( |
261 fileapi::ExternalMountPoints::CreateRefCounted()); | 268 fileapi::ExternalMountPoints::CreateRefCounted()); |
262 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 269 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 continue; | 323 continue; |
317 | 324 |
318 FilePath expected_virtual_path(kTestCases[i].virtual_path); | 325 FilePath expected_virtual_path(kTestCases[i].virtual_path); |
319 EXPECT_EQ(expected_virtual_path, virtual_path) | 326 EXPECT_EQ(expected_virtual_path, virtual_path) |
320 << "Resolving " << kTestCases[i].local_path; | 327 << "Resolving " << kTestCases[i].local_path; |
321 } | 328 } |
322 } | 329 } |
323 | 330 |
324 } // namespace | 331 } // namespace |
325 | 332 |
OLD | NEW |