file_system_backend_unittest.cc revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
1eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chromeos/fileapi/file_system_backend.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <set> 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/path_service.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chromeos/dbus/cros_disks_client.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/url_util.h" 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "webkit/browser/fileapi/external_mount_points.h" 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "webkit/browser/fileapi/file_permission_policy.h" 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "webkit/browser/fileapi/file_system_url.h" 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "webkit/browser/fileapi/isolated_context.h" 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "webkit/browser/quota/mock_special_storage_policy.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define FPL(x) FILE_PATH_LITERAL(x) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using fileapi::ExternalMountPoints; 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using fileapi::FileSystemURL; 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)FileSystemURL CreateFileSystemURL(const std::string& extension, 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* path, 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ExternalMountPoints* mount_points) { 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return mount_points->CreateCrackedFileSystemURL( 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("chrome-extension://" + extension + "/"), 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeExternal, 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath::FromUTF8Unsafe(path)); 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 367dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) { 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new quota::MockSpecialStoragePolicy(); 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<fileapi::ExternalMountPoints> mount_points( 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::ExternalMountPoints::CreateRefCounted()); 417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chromeos::FileSystemBackend backend( 427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch NULL, // drive_delegate 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) storage_policy, 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points.get(), 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::ExternalMountPoints::GetSystemInstance()); 467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch backend.AddSystemMountPoints(); 477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // By default there should be 4 mount points (in system mount points): 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(4u, root_dirs.size()); 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::FilePath home_path; 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_TRUE(PathService::Get(base::DIR_HOME, &home_path)); 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(root_dirs_set.count(home_path.AppendASCII("Downloads"))); 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(root_dirs_set.count( 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(root_dirs_set.count( 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chromeos::CrosDisksClient::GetArchiveMountPoint())); 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 637dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST(ChromeOSFileSystemBackendTest, GetRootDirectories) { 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new quota::MockSpecialStoragePolicy(); 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<fileapi::ExternalMountPoints> mount_points( 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::ExternalMountPoints::CreateRefCounted()); 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::ExternalMountPoints::CreateRefCounted()); 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chromeos::FileSystemBackend backend( 737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch NULL, // drive_delegate 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) storage_policy, 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points.get(), 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) system_mount_points.get()); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const size_t initial_root_dirs_size = backend.GetRootDirectories().size(); 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Register 'local' test mount points. 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points->RegisterFileSystem("c", 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeNativeLocal, 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("/a/b/c"))); 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points->RegisterFileSystem("d", 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeNativeLocal, 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("/b/c/d"))); 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Register system test mount points. 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) system_mount_points->RegisterFileSystem("d", 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeNativeLocal, 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("/g/c/d"))); 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) system_mount_points->RegisterFileSystem("e", 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeNativeLocal, 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("/g/d/e"))); 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size()); 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c")))); 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d")))); 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d")))); 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1057dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST(ChromeOSFileSystemBackendTest, AccessPermissions) { 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) url_util::AddStandardScheme("chrome-extension"); 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new quota::MockSpecialStoragePolicy(); 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<fileapi::ExternalMountPoints> mount_points( 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::ExternalMountPoints::CreateRefCounted()); 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::ExternalMountPoints::CreateRefCounted()); 1147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chromeos::FileSystemBackend backend( 1157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch NULL, // drive_delegate 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) storage_policy, 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points.get(), 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) system_mount_points.get()); 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) storage_policy->AddFileHandler(extension); 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Initialize mount points. 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(system_mount_points->RegisterFileSystem( 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "system", 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeNativeLocal, 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("/g/system")))); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(mount_points->RegisterFileSystem( 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "removable", 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeNativeLocal, 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("/media/removable")))); 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(mount_points->RegisterFileSystem( 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "oem", 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeRestrictedNativeLocal, 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("/usr/share/oem")))); 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Backend specific mount point access. 1397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(backend.IsAccessAllowed( 140eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch backend.GrantFileAccessToExtension(extension, 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("removable/foo"))); 1447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(backend.IsAccessAllowed( 145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 1467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(backend.IsAccessAllowed( 147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "removable/foo1", mount_points.get()))); 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // System mount point access. 1507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(backend.IsAccessAllowed( 151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "system/foo", system_mount_points.get()))); 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch backend.GrantFileAccessToExtension(extension, 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("system/foo"))); 1557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(backend.IsAccessAllowed( 156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "system/foo", system_mount_points.get()))); 1577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(backend.IsAccessAllowed( 158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "system/foo1", 159eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch system_mount_points.get()))); 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // oem is restricted file system. 1627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch backend.GrantFileAccessToExtension( 16390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) extension, base::FilePath(FPL("oem/foo"))); 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The extension should not be able to access the file even if 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // GrantFileAccessToExtension was called. 1667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(backend.IsAccessAllowed( 167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "oem/foo", mount_points.get()))); 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch backend.GrantFullAccessToExtension(extension); 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The extension should be able to access restricted file system after it was 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // granted full access. 1727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(backend.IsAccessAllowed( 173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "oem/foo", mount_points.get()))); 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The extension which was granted full access should be able to access any 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // path on current file systems. 1767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(backend.IsAccessAllowed( 177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "removable/foo1", mount_points.get()))); 1787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(backend.IsAccessAllowed( 179eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "system/foo1", 180eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch system_mount_points.get()))); 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The extension cannot access new mount points. 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(tbarzic): This should probably be changed. 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(mount_points->RegisterFileSystem( 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "test", 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeNativeLocal, 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("/foo/test")))); 1887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(backend.IsAccessAllowed( 189eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "test_/foo", mount_points.get()))); 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch backend.RevokeAccessForExtension(extension); 1927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(backend.IsAccessAllowed( 193eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::FileSystemURL internal_url = FileSystemURL::CreateForTest( 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("chrome://foo"), 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::kFileSystemTypeExternal, 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FPL("removable/"))); 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Internal WebUI should have full access. 2007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_TRUE(backend.IsAccessAllowed(internal_url)); 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2037dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) { 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new quota::MockSpecialStoragePolicy(); 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<fileapi::ExternalMountPoints> mount_points( 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::ExternalMountPoints::CreateRefCounted()); 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fileapi::ExternalMountPoints::CreateRefCounted()); 2107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chromeos::FileSystemBackend backend( 2117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch NULL, // drive_delegate 2127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch storage_policy, 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points.get(), 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) system_mount_points.get()); 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const fileapi::FileSystemType type = fileapi::kFileSystemTypeNativeLocal; 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Backend specific mount points. 2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE( 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points->RegisterFileSystem("b", type, base::FilePath(FPL("/a/b")))); 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE( 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points->RegisterFileSystem("y", type, base::FilePath(FPL("/z/y")))); 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE( 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mount_points->RegisterFileSystem("n", type, base::FilePath(FPL("/m/n")))); 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // System mount points 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(system_mount_points->RegisterFileSystem( 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "gb", type, base::FilePath(FPL("/a/b")))); 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE( 23090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) system_mount_points->RegisterFileSystem( 23190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) "gz", type, base::FilePath(FPL("/z")))); 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(system_mount_points->RegisterFileSystem( 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "gp", type, base::FilePath(FPL("/m/n/o/p")))); 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct TestCase { 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath::CharType* const local_path; 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool success; 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath::CharType* const virtual_path; 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const TestCase kTestCases[] = { 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Same paths in both mount points. 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { FPL("/a/b/c/d"), true, FPL("b/c/d") }, 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // System mount points path more specific. 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { FPL("/m/n/o/p/r/s"), true, FPL("n/o/p/r/s") }, 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // System mount points path less specific. 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { FPL("/z/y/x"), true, FPL("y/x") }, 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Only system mount points path matches. 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { FPL("/z/q/r/s"), true, FPL("gz/q/r/s") }, 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // No match. 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { FPL("/foo/xxx"), false, FPL("") }, 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Initialize virtual path with a value. 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath virtual_path(FPL("/mount")); 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath local_path(kTestCases[i].local_path); 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(kTestCases[i].success, 2597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch backend.GetVirtualPath(local_path, &virtual_path)) 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) << "Resolving " << kTestCases[i].local_path; 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // There are no guarantees for |virtual_path| value if |GetVirtualPath| 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // fails. 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!kTestCases[i].success) 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) continue; 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath expected_virtual_path(kTestCases[i].virtual_path); 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_virtual_path, virtual_path) 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) << "Resolving " << kTestCases[i].local_path; 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 274