| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
|  | 2 // Use of this source code is governed by a BSD-style license that can be | 
|  | 3 // found in the LICENSE file. | 
|  | 4 | 
|  | 5 #include "base/file_path.h" | 
|  | 6 #include "googleurl/src/url_util.h" | 
|  | 7 #include "testing/gtest/include/gtest/gtest.h" | 
|  | 8 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 
|  | 9 #include "webkit/fileapi/external_mount_points.h" | 
|  | 10 #include "webkit/fileapi/file_system_url.h" | 
|  | 11 #include "webkit/fileapi/isolated_context.h" | 
|  | 12 #include "webkit/quota/mock_special_storage_policy.h" | 
|  | 13 | 
|  | 14 #define FPL(x) FILE_PATH_LITERAL(x) | 
|  | 15 | 
|  | 16 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 
|  | 17 #define DRIVE FPL("C:") | 
|  | 18 #else | 
|  | 19 #define DRIVE | 
|  | 20 #endif | 
|  | 21 | 
|  | 22 namespace { | 
|  | 23 | 
|  | 24 FilePath GetFilePath(const std::string& path_str) { | 
|  | 25   return FilePath(DRIVE FPL(path_str)); | 
|  | 26 } | 
|  | 27 | 
|  | 28 fileapi::FileSystemURL CreateFileSystemURL(const std::string& extension, | 
|  | 29                                            const std::string& path) { | 
|  | 30   return fileapi::FileSystemURL(GURL("chrome-extension://" + extension + "/"), | 
|  | 31                                 fileapi::kFileSystemTypeNativeLocal, | 
|  | 32                                 GetFilePath(path)); | 
|  | 33 } | 
|  | 34 | 
|  | 35 bool VectorHasPath(const std::vector<FilePath>& path_vector, | 
|  | 36                    const FilePath& path) { | 
|  | 37   for (size_t i = 0; i < path_vector.size(); ++i) { | 
|  | 38     if (path_vector[i] == path) { | 
|  | 39       return true; | 
|  | 40     } | 
|  | 41   } | 
|  | 42   return false; | 
|  | 43 } | 
|  | 44 | 
|  | 45 TEST(CrosMountPointProviderTest, DefaultMountPoints) { | 
|  | 46   scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 
|  | 47       new quota::MockSpecialStoragePolicy(); | 
|  | 48   scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 
|  | 49       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 50   chromeos::CrosMountPointProvider provider( | 
|  | 51       storage_policy, | 
|  | 52       mount_points.get(), | 
|  | 53       fileapi::ExternalMountPoints::GetSystemInstance()); | 
|  | 54   // By default there should be 4 mount points. | 
|  | 55   std::vector<FilePath> root_dirs = provider.GetRootDirectories(true); | 
|  | 56   EXPECT_EQ(4u, root_dirs.size()); | 
|  | 57   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/media/removable"))); | 
|  | 58   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/media/archive"))); | 
|  | 59   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/usr/share/oem"))); | 
|  | 60   // Fourth mount point is Downloads, but it's local path is device specific. | 
|  | 61 } | 
|  | 62 | 
|  | 63 TEST(CrosMountPointProviderTest, GetRootDirectories) { | 
|  | 64   scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 
|  | 65       new quota::MockSpecialStoragePolicy(); | 
|  | 66   scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 
|  | 67       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 68 | 
|  | 69   scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 
|  | 70       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 71 | 
|  | 72   chromeos::CrosMountPointProvider provider( | 
|  | 73       storage_policy, | 
|  | 74       mount_points.get(), | 
|  | 75       system_mount_points.get()); | 
|  | 76 | 
|  | 77   // Register 'local' test mount points. | 
|  | 78   mount_points->RegisterFileSystem("c", | 
|  | 79                                    fileapi::kFileSystemTypeNativeLocal, | 
|  | 80                                    GetFilePath("/a/b/c")); | 
|  | 81   mount_points->RegisterFileSystem("d", | 
|  | 82                                    fileapi::kFileSystemTypeNativeLocal, | 
|  | 83                                    GetFilePath("/b/c/d")); | 
|  | 84 | 
|  | 85   // Register system test mount points. | 
|  | 86   system_mount_points->RegisterFileSystem("d", | 
|  | 87                                           fileapi::kFileSystemTypeNativeLocal, | 
|  | 88                                           GetFilePath("/g/c/d")); | 
|  | 89   system_mount_points->RegisterFileSystem("e", | 
|  | 90                                           fileapi::kFileSystemTypeNativeLocal, | 
|  | 91                                           GetFilePath("/g/d/e")); | 
|  | 92 | 
|  | 93   std::vector<FilePath> root_dirs = | 
|  | 94       provider.GetRootDirectories(true /* include system points */); | 
|  | 95   EXPECT_EQ(4u, root_dirs.size()); | 
|  | 96   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/a/b/c"))); | 
|  | 97   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/b/c/d"))); | 
|  | 98   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/g/c/d"))); | 
|  | 99   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/g/d/e"))); | 
|  | 100 | 
|  | 101   root_dirs = provider.GetRootDirectories(false /* include system points */); | 
|  | 102   EXPECT_EQ(2u, root_dirs.size()); | 
|  | 103   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/a/b/c"))); | 
|  | 104   EXPECT_TRUE(VectorHasPath(root_dirs, GetFilePath("/b/c/d"))); | 
|  | 105 } | 
|  | 106 | 
|  | 107 TEST(CrosMountPointProviderTest, MountPointsVisibility) { | 
|  | 108   scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 
|  | 109       new quota::MockSpecialStoragePolicy(); | 
|  | 110   scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 
|  | 111       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 112   scoped_refptr<fileapi::ExternalMountPoints> sibling_mount_points( | 
|  | 113       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 114 | 
|  | 115   scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 
|  | 116       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 117 | 
|  | 118   chromeos::CrosMountPointProvider provider( | 
|  | 119       storage_policy, | 
|  | 120       mount_points.get(), | 
|  | 121       system_mount_points.get()); | 
|  | 122 | 
|  | 123   // A provider that shares system_mount_points with |provider|. | 
|  | 124   chromeos::CrosMountPointProvider sibling_provider( | 
|  | 125       storage_policy, | 
|  | 126       sibling_mount_points.get(), | 
|  | 127       system_mount_points.get()); | 
|  | 128 | 
|  | 129   FilePath ignored; | 
|  | 130 | 
|  | 131   // Add mount point to the provider. | 
|  | 132   EXPECT_TRUE(provider.AddLocalMountPoint(GetFilePath("/a/b/c"))); | 
|  | 133 | 
|  | 134   EXPECT_TRUE(provider.HasMountPoint(GetFilePath("/a/b/c"))); | 
|  | 135   EXPECT_FALSE(sibling_provider.HasMountPoint(GetFilePath("/a/b/c"))); | 
|  | 136   EXPECT_TRUE(mount_points->GetRegisteredPath("c", &ignored)); | 
|  | 137   EXPECT_FALSE(system_mount_points->GetRegisteredPath("c", &ignored)); | 
|  | 138 | 
|  | 139   // Add mount point directly to |mount_points|. It should be seen by | 
|  | 140   // |provider|. | 
|  | 141   EXPECT_TRUE(mount_points->RegisterFileSystem( | 
|  | 142       "d", fileapi::kFileSystemTypeNativeLocal, GetFilePath("/b/c/d"))); | 
|  | 143 | 
|  | 144   EXPECT_TRUE(provider.HasMountPoint(GetFilePath("/b/c/d"))); | 
|  | 145   EXPECT_FALSE(sibling_provider.HasMountPoint(GetFilePath("/b/c/d"))); | 
|  | 146 | 
|  | 147   // Add mount point to system mount points. | 
|  | 148   EXPECT_TRUE(system_mount_points->RegisterFileSystem( | 
|  | 149       "e", fileapi::kFileSystemTypeNativeLocal, GetFilePath("/g/c/d/e"))); | 
|  | 150 | 
|  | 151   EXPECT_FALSE(provider.HasMountPoint(GetFilePath("/g/c/d/e"))); | 
|  | 152   EXPECT_FALSE(sibling_provider.HasMountPoint(GetFilePath("/g/c/d/e"))); | 
|  | 153 | 
|  | 154   // Can't remove system nount point. | 
|  | 155   provider.RemoveMountPoint(GetFilePath("/g/c/d/e")); | 
|  | 156   EXPECT_TRUE(system_mount_points->GetRegisteredPath("e", &ignored)); | 
|  | 157 | 
|  | 158   // Add a mount points whose paths overlap with the system one's. | 
|  | 159   // The same path | 
|  | 160   EXPECT_TRUE(provider.AddLocalMountPoint(GetFilePath("/g/c/d/e"))); | 
|  | 161   EXPECT_TRUE(provider.HasMountPoint(GetFilePath("/g/c/d/e"))); | 
|  | 162   provider.RemoveMountPoint(GetFilePath("/g/c/d/e")); | 
|  | 163   // Parent path. | 
|  | 164   EXPECT_TRUE(provider.AddLocalMountPoint(GetFilePath("/g"))); | 
|  | 165   EXPECT_TRUE(provider.HasMountPoint(GetFilePath("/g"))); | 
|  | 166   provider.RemoveMountPoint(GetFilePath("/g")); | 
|  | 167   // Child path. | 
|  | 168   EXPECT_TRUE(provider.AddLocalMountPoint(GetFilePath("/g/c/d/e/f/g"))); | 
|  | 169   EXPECT_TRUE(provider.HasMountPoint(GetFilePath("/g/c/d/e/f/g"))); | 
|  | 170   provider.RemoveMountPoint(GetFilePath("/g/c/d/e/f/g")); | 
|  | 171 | 
|  | 172   // Add mount point with the same name as a global one. Should succeed. | 
|  | 173   EXPECT_TRUE(provider.AddLocalMountPoint(GetFilePath("/d/e"))); | 
|  | 174 | 
|  | 175   EXPECT_TRUE(provider.HasMountPoint(GetFilePath("/d/e"))); | 
|  | 176 | 
|  | 177   // Remove system mount point with the same name as the added one. | 
|  | 178   // Should fail. | 
|  | 179   provider.RemoveMountPoint(GetFilePath("/g/c/d/e")); | 
|  | 180 | 
|  | 181   EXPECT_TRUE(provider.HasMountPoint(GetFilePath("/d/e"))); | 
|  | 182   EXPECT_TRUE(system_mount_points->GetRegisteredPath("e", &ignored)); | 
|  | 183 | 
|  | 184   // Remove mount point. | 
|  | 185   provider.RemoveMountPoint(GetFilePath("/d/e")); | 
|  | 186 | 
|  | 187   EXPECT_FALSE(provider.HasMountPoint(GetFilePath("/d/e"))); | 
|  | 188 } | 
|  | 189 | 
|  | 190 TEST(CrosMountPointProviderTest, AddMountPoint) { | 
|  | 191   scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 
|  | 192       new quota::MockSpecialStoragePolicy(); | 
|  | 193   scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 
|  | 194       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 195   scoped_refptr<fileapi::ExternalMountPoints> ignored_mount_points( | 
|  | 196       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 197   chromeos::CrosMountPointProvider provider(storage_policy, | 
|  | 198       mount_points.get(), | 
|  | 199       ignored_mount_points); | 
|  | 200 | 
|  | 201   struct TestCase { | 
|  | 202     const char* const mount_point; | 
|  | 203     bool success; | 
|  | 204     bool should_exist_after_adding; | 
|  | 205   }; | 
|  | 206 | 
|  | 207   const TestCase kTestCases[] = { | 
|  | 208     // Valid mount point. | 
|  | 209     { "/foo/test", true, true }, | 
|  | 210     // Valid mount point with only one path component. | 
|  | 211     { "/bbb/", true, true }, | 
|  | 212     // Existing mount point path is substring of the mount points path. | 
|  | 213     { "/foo/test11", true, true }, | 
|  | 214     // Path substring of an existing path. | 
|  | 215     { "/foo/test1", true, true }, | 
|  | 216     // Empty mount point path. | 
|  | 217     { "", false, false }, | 
|  | 218     // Empty mount point name. | 
|  | 219     { "/", false, false }, | 
|  | 220     // References parent. | 
|  | 221     { "../foo/invalid", false, false }, | 
|  | 222     // Relative path. | 
|  | 223     { "foo/relative", false, false }, | 
|  | 224     // Existing mount point. | 
|  | 225     { "/foo/test", false, true }, | 
|  | 226     // Existing mount point with trailing /. | 
|  | 227     { "/foo/test/", false, false }, | 
|  | 228     // Mount point with the same name exists. | 
|  | 229     { "/foo/a/test", false, false }, | 
|  | 230     // Child of an existing mount point. | 
|  | 231     { "/foo/test/a", false, false }, | 
|  | 232     // Parent of an existing mount point. | 
|  | 233     { "/foo", false, false }, | 
|  | 234     // Bit bigger depth. | 
|  | 235     { "/foo/a/b/c/d/e/f/g", true, true }, | 
|  | 236     // Sibling mount point (with similar name) exists. | 
|  | 237     { "/foo/a/b/c/d/e/ff", true, true }, | 
|  | 238     // Lexicographically last among existing mount points. | 
|  | 239     { "/zzz/yyy", true, true }, | 
|  | 240     // Parent of the lexicographically last mount point. | 
|  | 241     { "/zzz/", false, false }, | 
|  | 242     // Child of the lexicographically last mount point. | 
|  | 243     { "/zzz/yyy/xxx", false, false }, | 
|  | 244     // Lexicographically first among existing mount points. | 
|  | 245     { "/a/b", true, true }, | 
|  | 246     // Parent of lexicographically first mount point. | 
|  | 247     { "/a", false, false }, | 
|  | 248     // Child of lexicographically last mount point. | 
|  | 249     { "/a/b/c", false, false }, | 
|  | 250   }; | 
|  | 251 | 
|  | 252   // Test adding mount points. | 
|  | 253   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 
|  | 254     FilePath mount_point = GetFilePath(kTestCases[i].mount_point); | 
|  | 255     EXPECT_EQ(kTestCases[i].success, | 
|  | 256               provider.AddLocalMountPoint(mount_point)) | 
|  | 257         << "Adding mount point: " << kTestCases[i].mount_point; | 
|  | 258   } | 
|  | 259 | 
|  | 260   // Test that final mount point presence state is as expected. | 
|  | 261   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 
|  | 262     FilePath mount_point = GetFilePath(kTestCases[i].mount_point); | 
|  | 263     EXPECT_EQ(kTestCases[i].should_exist_after_adding, | 
|  | 264               provider.HasMountPoint(mount_point)) | 
|  | 265         << "Has mount point: " << kTestCases[i].mount_point; | 
|  | 266   } | 
|  | 267 } | 
|  | 268 | 
|  | 269 TEST(CrosMountPointProviderTest, AccessPermissions) { | 
|  | 270   url_util::AddStandardScheme("chrome-extension"); | 
|  | 271 | 
|  | 272   scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = | 
|  | 273       new quota::MockSpecialStoragePolicy(); | 
|  | 274   scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 
|  | 275       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 276   scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 
|  | 277       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 278   chromeos::CrosMountPointProvider provider( | 
|  | 279       storage_policy, | 
|  | 280       mount_points.get(), | 
|  | 281       system_mount_points.get()); | 
|  | 282 | 
|  | 283   std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); | 
|  | 284 | 
|  | 285   storage_policy->AddFileHandler(extension); | 
|  | 286 | 
|  | 287   // Initialize mount points. | 
|  | 288   system_mount_points->RegisterFileSystem("system", | 
|  | 289                                           fileapi::kFileSystemTypeNativeLocal, | 
|  | 290                                           GetFilePath("/g/system")); | 
|  | 291   ASSERT_TRUE(provider.AddLocalMountPoint(GetFilePath("/media/removable"))); | 
|  | 292   ASSERT_TRUE(provider.AddRestrictedLocalMountPoint( | 
|  | 293       GetFilePath("/usr/share/oem"))); | 
|  | 294 | 
|  | 295   // Provider specific mount point access. | 
|  | 296   EXPECT_FALSE(provider.IsAccessAllowed(CreateFileSystemURL(extension, | 
|  | 297                                                             "removable/foo"))); | 
|  | 298 | 
|  | 299   provider.GrantFileAccessToExtension(extension, GetFilePath("removable/foo")); | 
|  | 300   EXPECT_TRUE(provider.IsAccessAllowed(CreateFileSystemURL(extension, | 
|  | 301                                                            "removable/foo"))); | 
|  | 302   EXPECT_FALSE(provider.IsAccessAllowed(CreateFileSystemURL(extension, | 
|  | 303                                                             "removable/foo1"))); | 
|  | 304 | 
|  | 305   // System mount point access. | 
|  | 306   EXPECT_FALSE( | 
|  | 307       provider.IsAccessAllowed(CreateFileSystemURL(extension, "system/foo"))); | 
|  | 308 | 
|  | 309   provider.GrantFileAccessToExtension(extension, GetFilePath("system/foo")); | 
|  | 310   EXPECT_TRUE( | 
|  | 311       provider.IsAccessAllowed(CreateFileSystemURL(extension, "system/foo"))); | 
|  | 312   EXPECT_FALSE( | 
|  | 313       provider.IsAccessAllowed(CreateFileSystemURL(extension, "system/foo1"))); | 
|  | 314 | 
|  | 315   // oem is restricted file system. | 
|  | 316   provider.GrantFileAccessToExtension(extension, GetFilePath("oem/foo")); | 
|  | 317   // The extension should not be able to access the file even if | 
|  | 318   // GrantFileAccessToExtension was called. | 
|  | 319   EXPECT_FALSE( | 
|  | 320       provider.IsAccessAllowed(CreateFileSystemURL(extension, "oem/foo"))); | 
|  | 321 | 
|  | 322   provider.GrantFullAccessToExtension(extension); | 
|  | 323   // The extension should be able to access restricted file system after it was | 
|  | 324   // granted full access. | 
|  | 325   EXPECT_TRUE( | 
|  | 326       provider.IsAccessAllowed(CreateFileSystemURL(extension, "oem/foo"))); | 
|  | 327   // The extension which was granted fulle access  should be able to access any | 
|  | 328   // path on curent file systems. | 
|  | 329   EXPECT_TRUE(provider.IsAccessAllowed( | 
|  | 330       CreateFileSystemURL(extension, "removable/foo1"))); | 
|  | 331   EXPECT_TRUE(provider.IsAccessAllowed( | 
|  | 332       CreateFileSystemURL(extension, "system/foo1"))); | 
|  | 333 | 
|  | 334   // The extension still cannot access new mount points. | 
|  | 335   ASSERT_TRUE(provider.AddLocalMountPoint(GetFilePath("/foo/test"))); | 
|  | 336   EXPECT_FALSE( | 
|  | 337       provider.IsAccessAllowed(CreateFileSystemURL(extension, "test_/foo"))); | 
|  | 338 | 
|  | 339   provider.RevokeAccessForExtension(extension); | 
|  | 340   EXPECT_FALSE(provider.IsAccessAllowed( | 
|  | 341       CreateFileSystemURL(extension,"removable/foo"))); | 
|  | 342 | 
|  | 343   fileapi::FileSystemURL internal_url(GURL("chrome://foo"), | 
|  | 344                                      fileapi::kFileSystemTypeExternal, | 
|  | 345                                      GetFilePath("removable/")); | 
|  | 346   // Internal WebUI should have full access. | 
|  | 347   EXPECT_TRUE(provider.IsAccessAllowed(internal_url)); | 
|  | 348 } | 
|  | 349 | 
|  | 350 // TODO(tbarzic): This could be moved to external_mount_points tests. | 
|  | 351 TEST(CrosMountPointProvider, GetVirtualPath) { | 
|  | 352   scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = | 
|  | 353       new quota::MockSpecialStoragePolicy(); | 
|  | 354   scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 
|  | 355       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 356   scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 
|  | 357       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 358   chromeos::CrosMountPointProvider provider(storage_policy, | 
|  | 359       system_mount_points.get(), | 
|  | 360       mount_points.get()); | 
|  | 361 | 
|  | 362   ASSERT_TRUE(provider.AddLocalMountPoint(GetFilePath("/a/b/c"))); | 
|  | 363   ASSERT_TRUE(provider.AddLocalMountPoint(GetFilePath("/z/y/x"))); | 
|  | 364   ASSERT_TRUE(provider.AddLocalMountPoint(GetFilePath("/m/n/o"))); | 
|  | 365 | 
|  | 366   // Register mount point whose name does not match its path base name. | 
|  | 367   ASSERT_TRUE( | 
|  | 368       mount_points->RegisterFileSystem("mount", | 
|  | 369                                        fileapi::kFileSystemTypeNativeLocal, | 
|  | 370                                        FilePath(DRIVE FPL("/root/foo")))); | 
|  | 371 | 
|  | 372   struct TestCase { | 
|  | 373     const char* const local_path; | 
|  | 374     bool success; | 
|  | 375     const char* const virtual_path; | 
|  | 376   }; | 
|  | 377 | 
|  | 378   const TestCase kTestCases[] = { | 
|  | 379     // Empty path. | 
|  | 380     { "", false, "" }, | 
|  | 381     // No registered mount point (but is parent to a mount point). | 
|  | 382     { "/a/b", false, ""}, | 
|  | 383     // No registered mount point (but is parent to a mount point). | 
|  | 384     { "/z/y", false, ""}, | 
|  | 385     // No registered mount point (but is parent to a mount point). | 
|  | 386     { "/m/n", false, ""}, | 
|  | 387     // No registered mount point. | 
|  | 388     { "/foo/mount", false, ""}, | 
|  | 389     // An existing mount point path is substring. | 
|  | 390     { "/a/b/c1", false, "" }, | 
|  | 391     // No leading /. | 
|  | 392     { "a/b/c", false, "" }, | 
|  | 393     // Sibling to a root path. | 
|  | 394     { "/a/b/d/e", false, ""}, | 
|  | 395     // Sibling to a root path. | 
|  | 396     { "/z/y/v/u", false, ""}, | 
|  | 397     // Sibling to a root path. | 
|  | 398     { "/m/n/p/q", false, ""}, | 
|  | 399     // Mount point root path. | 
|  | 400     { "/a/b/c", true, "c"}, | 
|  | 401     // Mount point root path. | 
|  | 402     { "/z/y/x", true, "x"}, | 
|  | 403     // Mount point root path. | 
|  | 404     { "/m/n/o", true, "o"}, | 
|  | 405     // Mount point child path. | 
|  | 406     { "/a/b/c/d/e", true, "c/d/e"}, | 
|  | 407     // Mount point child path. | 
|  | 408     { "/z/y/x/v/u", true, "x/v/u"}, | 
|  | 409     // Mount point child path. | 
|  | 410     { "/m/n/o/p/q", true, "o/p/q"}, | 
|  | 411     // Name doesn't match mount point path base name. | 
|  | 412     { "/root/foo/a/b/c", true, "mount/a/b/c" }, | 
|  | 413     { "/root/foo", true, "mount" }, | 
|  | 414   }; | 
|  | 415 | 
|  | 416   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 
|  | 417     // Init virtual path with a value. | 
|  | 418     FilePath virtual_path(DRIVE FPL("/mount")); | 
|  | 419     FilePath local_path(DRIVE FPL(kTestCases[i].local_path)); | 
|  | 420     EXPECT_EQ(kTestCases[i].success, | 
|  | 421               provider.GetVirtualPath(local_path, &virtual_path)) | 
|  | 422         << "Resolving " << kTestCases[i].local_path; | 
|  | 423 | 
|  | 424     // There are no guaranties for |virtual_path| value if |GetVirtualPath| | 
|  | 425     // fails. | 
|  | 426     if (!kTestCases[i].success) | 
|  | 427       continue; | 
|  | 428 | 
|  | 429     FilePath expected_virtual_path(DRIVE FPL(kTestCases[i].virtual_path)); | 
|  | 430     EXPECT_EQ(expected_virtual_path, virtual_path) | 
|  | 431         << "Resolving " << kTestCases[i].local_path; | 
|  | 432   } | 
|  | 433 } | 
|  | 434 | 
|  | 435 TEST(CrosMountPointProvider, GetVirtualPathConflictWithSystemPoints) { | 
|  | 436   scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy = | 
|  | 437       new quota::MockSpecialStoragePolicy(); | 
|  | 438   scoped_refptr<fileapi::ExternalMountPoints> mount_points( | 
|  | 439       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 440   scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( | 
|  | 441       fileapi::ExternalMountPoints::CreateRefCounted()); | 
|  | 442   chromeos::CrosMountPointProvider provider(storage_policy, | 
|  | 443       mount_points.get(), | 
|  | 444       system_mount_points.get()); | 
|  | 445 | 
|  | 446   const fileapi::FileSystemType type = fileapi::kFileSystemTypeNativeLocal; | 
|  | 447 | 
|  | 448   // Provider specific mount points. | 
|  | 449   ASSERT_TRUE( | 
|  | 450       mount_points->RegisterFileSystem("b", type, GetFilePath("/a/b"))); | 
|  | 451   ASSERT_TRUE( | 
|  | 452       mount_points->RegisterFileSystem("y", type, GetFilePath("/z/y"))); | 
|  | 453   ASSERT_TRUE( | 
|  | 454       mount_points->RegisterFileSystem("n", type, GetFilePath("/m/n"))); | 
|  | 455 | 
|  | 456   // System mount points | 
|  | 457   ASSERT_TRUE( | 
|  | 458       system_mount_points->RegisterFileSystem("gb", type, GetFilePath("/a/b"))); | 
|  | 459   ASSERT_TRUE( | 
|  | 460       system_mount_points->RegisterFileSystem("gz", type, GetFilePath("/z"))); | 
|  | 461   ASSERT_TRUE(system_mount_points->RegisterFileSystem("gp", type, | 
|  | 462                                                       GetFilePath("/m/n/o/p"))); | 
|  | 463   struct TestCase { | 
|  | 464     const char* const local_path; | 
|  | 465     bool success; | 
|  | 466     const char* const virtual_path; | 
|  | 467   }; | 
|  | 468 | 
|  | 469   const TestCase kTestCases[] = { | 
|  | 470     // Same paths in both mount points. | 
|  | 471     { "/a/b/c/d", true, "b/c/d" }, | 
|  | 472     // System mount points path more specific. | 
|  | 473     { "/m/n/o/p/r/s", true, "n/o/p/r/s" }, | 
|  | 474     // System mount points path less specific. | 
|  | 475     { "/z/y/x", true, "y/x"}, | 
|  | 476     // Only system mount points path matches. | 
|  | 477     { "/z/q/r/s", true, "gz/q/r/s"}, | 
|  | 478     // No match. | 
|  | 479     { "/foo/xxx", false, "" }, | 
|  | 480   }; | 
|  | 481 | 
|  | 482   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 
|  | 483     // Init virtual path with a value. | 
|  | 484     FilePath virtual_path(DRIVE FPL("/mount")); | 
|  | 485     FilePath local_path(DRIVE FPL(kTestCases[i].local_path)); | 
|  | 486     EXPECT_EQ(kTestCases[i].success, | 
|  | 487               provider.GetVirtualPath(local_path, &virtual_path)) | 
|  | 488         << "Resolving " << kTestCases[i].local_path; | 
|  | 489 | 
|  | 490     // There are no guaranties for |virtual_path| value if |GetVirtualPath| | 
|  | 491     // fails. | 
|  | 492     if (!kTestCases[i].success) | 
|  | 493       continue; | 
|  | 494 | 
|  | 495     FilePath expected_virtual_path(DRIVE FPL(kTestCases[i].virtual_path)); | 
|  | 496     EXPECT_EQ(expected_virtual_path, virtual_path) | 
|  | 497         << "Resolving " << kTestCases[i].local_path; | 
|  | 498   } | 
|  | 499 } | 
|  | 500 | 
|  | 501 }  // namespace | 
| OLD | NEW | 
|---|