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

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

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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/file_system_backend.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 "content/public/test/mock_special_storage_policy.h" 12 #include "content/public/test/mock_special_storage_policy.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "url/url_util.h" 14 #include "url/url_util.h"
15 #include "webkit/browser/fileapi/external_mount_points.h" 15 #include "storage/browser/fileapi/external_mount_points.h"
16 #include "webkit/browser/fileapi/file_system_url.h" 16 #include "storage/browser/fileapi/file_system_url.h"
17 17
18 #define FPL(x) FILE_PATH_LITERAL(x) 18 #define FPL(x) FILE_PATH_LITERAL(x)
19 19
20 using fileapi::ExternalMountPoints; 20 using storage::ExternalMountPoints;
21 using fileapi::FileSystemURL; 21 using storage::FileSystemURL;
22 22
23 namespace { 23 namespace {
24 24
25 FileSystemURL CreateFileSystemURL(const std::string& extension, 25 FileSystemURL CreateFileSystemURL(const std::string& extension,
26 const char* path, 26 const char* path,
27 ExternalMountPoints* mount_points) { 27 ExternalMountPoints* mount_points) {
28 return mount_points->CreateCrackedFileSystemURL( 28 return mount_points->CreateCrackedFileSystemURL(
29 GURL("chrome-extension://" + extension + "/"), 29 GURL("chrome-extension://" + extension + "/"),
30 fileapi::kFileSystemTypeExternal, 30 storage::kFileSystemTypeExternal,
31 base::FilePath::FromUTF8Unsafe(path)); 31 base::FilePath::FromUTF8Unsafe(path));
32 } 32 }
33 33
34 TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) { 34 TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) {
35 // Make sure no system-level mount points are registered before testing 35 // Make sure no system-level mount points are registered before testing
36 // to avoid flakiness. 36 // to avoid flakiness.
37 fileapi::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); 37 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems();
38 38
39 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 39 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
40 new content::MockSpecialStoragePolicy(); 40 new content::MockSpecialStoragePolicy();
41 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 41 scoped_refptr<storage::ExternalMountPoints> mount_points(
42 fileapi::ExternalMountPoints::CreateRefCounted()); 42 storage::ExternalMountPoints::CreateRefCounted());
43 chromeos::FileSystemBackend backend( 43 chromeos::FileSystemBackend backend(
44 NULL, // drive_delegate 44 NULL, // drive_delegate
45 NULL, // file_system_provider_delegate 45 NULL, // file_system_provider_delegate
46 NULL, // mtp_delegate 46 NULL, // mtp_delegate
47 storage_policy, 47 storage_policy,
48 mount_points.get(), 48 mount_points.get(),
49 fileapi::ExternalMountPoints::GetSystemInstance()); 49 storage::ExternalMountPoints::GetSystemInstance());
50 backend.AddSystemMountPoints(); 50 backend.AddSystemMountPoints();
51 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); 51 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories();
52 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); 52 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end());
53 53
54 // By default there should be 3 mount points (in system mount points): 54 // By default there should be 3 mount points (in system mount points):
55 EXPECT_EQ(3u, root_dirs.size()); 55 EXPECT_EQ(3u, root_dirs.size());
56 56
57 EXPECT_TRUE(root_dirs_set.count( 57 EXPECT_TRUE(root_dirs_set.count(
58 chromeos::CrosDisksClient::GetRemovableDiskMountPoint())); 58 chromeos::CrosDisksClient::GetRemovableDiskMountPoint()));
59 EXPECT_TRUE(root_dirs_set.count( 59 EXPECT_TRUE(root_dirs_set.count(
60 chromeos::CrosDisksClient::GetArchiveMountPoint())); 60 chromeos::CrosDisksClient::GetArchiveMountPoint()));
61 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem")))); 61 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/usr/share/oem"))));
62 } 62 }
63 63
64 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) { 64 TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) {
65 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 65 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
66 new content::MockSpecialStoragePolicy(); 66 new content::MockSpecialStoragePolicy();
67 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 67 scoped_refptr<storage::ExternalMountPoints> mount_points(
68 fileapi::ExternalMountPoints::CreateRefCounted()); 68 storage::ExternalMountPoints::CreateRefCounted());
69 69
70 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 70 scoped_refptr<storage::ExternalMountPoints> system_mount_points(
71 fileapi::ExternalMountPoints::CreateRefCounted()); 71 storage::ExternalMountPoints::CreateRefCounted());
72 72
73 chromeos::FileSystemBackend backend(NULL, // drive_delegate 73 chromeos::FileSystemBackend backend(NULL, // drive_delegate
74 NULL, // file_system_provider_delegate 74 NULL, // file_system_provider_delegate
75 NULL, // mtp_delegate 75 NULL, // mtp_delegate
76 storage_policy, 76 storage_policy,
77 mount_points.get(), 77 mount_points.get(),
78 system_mount_points.get()); 78 system_mount_points.get());
79 79
80 const size_t initial_root_dirs_size = backend.GetRootDirectories().size(); 80 const size_t initial_root_dirs_size = backend.GetRootDirectories().size();
81 81
82 // Register 'local' test mount points. 82 // Register 'local' test mount points.
83 mount_points->RegisterFileSystem("c", 83 mount_points->RegisterFileSystem("c",
84 fileapi::kFileSystemTypeNativeLocal, 84 storage::kFileSystemTypeNativeLocal,
85 fileapi::FileSystemMountOption(), 85 storage::FileSystemMountOption(),
86 base::FilePath(FPL("/a/b/c"))); 86 base::FilePath(FPL("/a/b/c")));
87 mount_points->RegisterFileSystem("d", 87 mount_points->RegisterFileSystem("d",
88 fileapi::kFileSystemTypeNativeLocal, 88 storage::kFileSystemTypeNativeLocal,
89 fileapi::FileSystemMountOption(), 89 storage::FileSystemMountOption(),
90 base::FilePath(FPL("/b/c/d"))); 90 base::FilePath(FPL("/b/c/d")));
91 91
92 // Register system test mount points. 92 // Register system test mount points.
93 system_mount_points->RegisterFileSystem("d", 93 system_mount_points->RegisterFileSystem("d",
94 fileapi::kFileSystemTypeNativeLocal, 94 storage::kFileSystemTypeNativeLocal,
95 fileapi::FileSystemMountOption(), 95 storage::FileSystemMountOption(),
96 base::FilePath(FPL("/g/c/d"))); 96 base::FilePath(FPL("/g/c/d")));
97 system_mount_points->RegisterFileSystem("e", 97 system_mount_points->RegisterFileSystem("e",
98 fileapi::kFileSystemTypeNativeLocal, 98 storage::kFileSystemTypeNativeLocal,
99 fileapi::FileSystemMountOption(), 99 storage::FileSystemMountOption(),
100 base::FilePath(FPL("/g/d/e"))); 100 base::FilePath(FPL("/g/d/e")));
101 101
102 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories(); 102 std::vector<base::FilePath> root_dirs = backend.GetRootDirectories();
103 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end()); 103 std::set<base::FilePath> root_dirs_set(root_dirs.begin(), root_dirs.end());
104 EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size()); 104 EXPECT_EQ(initial_root_dirs_size + 4, root_dirs.size());
105 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c")))); 105 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/a/b/c"))));
106 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d")))); 106 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/b/c/d"))));
107 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d")))); 107 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/c/d"))));
108 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e")))); 108 EXPECT_TRUE(root_dirs_set.count(base::FilePath(FPL("/g/d/e"))));
109 } 109 }
110 110
111 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) { 111 TEST(ChromeOSFileSystemBackendTest, AccessPermissions) {
112 url::AddStandardScheme("chrome-extension"); 112 url::AddStandardScheme("chrome-extension");
113 113
114 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = 114 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy =
115 new content::MockSpecialStoragePolicy(); 115 new content::MockSpecialStoragePolicy();
116 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 116 scoped_refptr<storage::ExternalMountPoints> mount_points(
117 fileapi::ExternalMountPoints::CreateRefCounted()); 117 storage::ExternalMountPoints::CreateRefCounted());
118 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 118 scoped_refptr<storage::ExternalMountPoints> system_mount_points(
119 fileapi::ExternalMountPoints::CreateRefCounted()); 119 storage::ExternalMountPoints::CreateRefCounted());
120 chromeos::FileSystemBackend backend(NULL, // drive_delegate 120 chromeos::FileSystemBackend backend(NULL, // drive_delegate
121 NULL, // file_system_provider_delegate 121 NULL, // file_system_provider_delegate
122 NULL, // mtp_delegate 122 NULL, // mtp_delegate
123 storage_policy, 123 storage_policy,
124 mount_points.get(), 124 mount_points.get(),
125 system_mount_points.get()); 125 system_mount_points.get());
126 126
127 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla"); 127 std::string extension("ddammdhioacbehjngdmkjcjbnfginlla");
128 128
129 storage_policy->AddFileHandler(extension); 129 storage_policy->AddFileHandler(extension);
130 130
131 // Initialize mount points. 131 // Initialize mount points.
132 ASSERT_TRUE(system_mount_points->RegisterFileSystem( 132 ASSERT_TRUE(system_mount_points->RegisterFileSystem(
133 "system", 133 "system",
134 fileapi::kFileSystemTypeNativeLocal, 134 storage::kFileSystemTypeNativeLocal,
135 fileapi::FileSystemMountOption(), 135 storage::FileSystemMountOption(),
136 base::FilePath(FPL("/g/system")))); 136 base::FilePath(FPL("/g/system"))));
137 ASSERT_TRUE(mount_points->RegisterFileSystem( 137 ASSERT_TRUE(mount_points->RegisterFileSystem(
138 "removable", 138 "removable",
139 fileapi::kFileSystemTypeNativeLocal, 139 storage::kFileSystemTypeNativeLocal,
140 fileapi::FileSystemMountOption(), 140 storage::FileSystemMountOption(),
141 base::FilePath(FPL("/media/removable")))); 141 base::FilePath(FPL("/media/removable"))));
142 ASSERT_TRUE(mount_points->RegisterFileSystem( 142 ASSERT_TRUE(mount_points->RegisterFileSystem(
143 "oem", 143 "oem",
144 fileapi::kFileSystemTypeRestrictedNativeLocal, 144 storage::kFileSystemTypeRestrictedNativeLocal,
145 fileapi::FileSystemMountOption(), 145 storage::FileSystemMountOption(),
146 base::FilePath(FPL("/usr/share/oem")))); 146 base::FilePath(FPL("/usr/share/oem"))));
147 147
148 // Backend specific mount point access. 148 // Backend specific mount point access.
149 EXPECT_FALSE(backend.IsAccessAllowed( 149 EXPECT_FALSE(backend.IsAccessAllowed(
150 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 150 CreateFileSystemURL(extension, "removable/foo", mount_points.get())));
151 151
152 backend.GrantFileAccessToExtension(extension, 152 backend.GrantFileAccessToExtension(extension,
153 base::FilePath(FPL("removable/foo"))); 153 base::FilePath(FPL("removable/foo")));
154 EXPECT_TRUE(backend.IsAccessAllowed( 154 EXPECT_TRUE(backend.IsAccessAllowed(
155 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 155 CreateFileSystemURL(extension, "removable/foo", mount_points.get())));
(...skipping 28 matching lines...) Expand all
184 // The extension which was granted full access should be able to access any 184 // The extension which was granted full access should be able to access any
185 // path on current file systems. 185 // path on current file systems.
186 EXPECT_TRUE(backend.IsAccessAllowed( 186 EXPECT_TRUE(backend.IsAccessAllowed(
187 CreateFileSystemURL(extension, "removable/foo1", mount_points.get()))); 187 CreateFileSystemURL(extension, "removable/foo1", mount_points.get())));
188 EXPECT_TRUE(backend.IsAccessAllowed( 188 EXPECT_TRUE(backend.IsAccessAllowed(
189 CreateFileSystemURL(extension, "system/foo1", 189 CreateFileSystemURL(extension, "system/foo1",
190 system_mount_points.get()))); 190 system_mount_points.get())));
191 191
192 // The extension cannot access new mount points. 192 // The extension cannot access new mount points.
193 // TODO(tbarzic): This should probably be changed. 193 // TODO(tbarzic): This should probably be changed.
194 ASSERT_TRUE(mount_points->RegisterFileSystem( 194 ASSERT_TRUE(
195 "test", 195 mount_points->RegisterFileSystem("test",
196 fileapi::kFileSystemTypeNativeLocal, 196 storage::kFileSystemTypeNativeLocal,
197 fileapi::FileSystemMountOption(), 197 storage::FileSystemMountOption(),
198 base::FilePath(FPL("/foo/test")))); 198 base::FilePath(FPL("/foo/test"))));
199 EXPECT_FALSE(backend.IsAccessAllowed( 199 EXPECT_FALSE(backend.IsAccessAllowed(
200 CreateFileSystemURL(extension, "test_/foo", mount_points.get()))); 200 CreateFileSystemURL(extension, "test_/foo", mount_points.get())));
201 201
202 backend.RevokeAccessForExtension(extension); 202 backend.RevokeAccessForExtension(extension);
203 EXPECT_FALSE(backend.IsAccessAllowed( 203 EXPECT_FALSE(backend.IsAccessAllowed(
204 CreateFileSystemURL(extension, "removable/foo", mount_points.get()))); 204 CreateFileSystemURL(extension, "removable/foo", mount_points.get())));
205 } 205 }
206 206
207 TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) { 207 TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) {
208 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy = 208 scoped_refptr<content::MockSpecialStoragePolicy> storage_policy =
209 new content::MockSpecialStoragePolicy(); 209 new content::MockSpecialStoragePolicy();
210 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 210 scoped_refptr<storage::ExternalMountPoints> mount_points(
211 fileapi::ExternalMountPoints::CreateRefCounted()); 211 storage::ExternalMountPoints::CreateRefCounted());
212 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points( 212 scoped_refptr<storage::ExternalMountPoints> system_mount_points(
213 fileapi::ExternalMountPoints::CreateRefCounted()); 213 storage::ExternalMountPoints::CreateRefCounted());
214 chromeos::FileSystemBackend backend(NULL, // drive_delegate 214 chromeos::FileSystemBackend backend(NULL, // drive_delegate
215 NULL, // file_system_provider_delegate 215 NULL, // file_system_provider_delegate
216 NULL, // mtp_delegate 216 NULL, // mtp_delegate
217 storage_policy, 217 storage_policy,
218 mount_points.get(), 218 mount_points.get(),
219 system_mount_points.get()); 219 system_mount_points.get());
220 220
221 const fileapi::FileSystemType type = fileapi::kFileSystemTypeNativeLocal; 221 const storage::FileSystemType type = storage::kFileSystemTypeNativeLocal;
222 const fileapi::FileSystemMountOption option = 222 const storage::FileSystemMountOption option =
223 fileapi::FileSystemMountOption(); 223 storage::FileSystemMountOption();
224 224
225 // Backend specific mount points. 225 // Backend specific mount points.
226 ASSERT_TRUE(mount_points->RegisterFileSystem( 226 ASSERT_TRUE(mount_points->RegisterFileSystem(
227 "b", type, option, base::FilePath(FPL("/a/b")))); 227 "b", type, option, base::FilePath(FPL("/a/b"))));
228 ASSERT_TRUE(mount_points->RegisterFileSystem( 228 ASSERT_TRUE(mount_points->RegisterFileSystem(
229 "y", type, option, base::FilePath(FPL("/z/y")))); 229 "y", type, option, base::FilePath(FPL("/z/y"))));
230 ASSERT_TRUE(mount_points->RegisterFileSystem( 230 ASSERT_TRUE(mount_points->RegisterFileSystem(
231 "n", type, option, base::FilePath(FPL("/m/n")))); 231 "n", type, option, base::FilePath(FPL("/m/n"))));
232 232
233 // System mount points 233 // System mount points
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (!kTestCases[i].success) 271 if (!kTestCases[i].success)
272 continue; 272 continue;
273 273
274 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); 274 base::FilePath expected_virtual_path(kTestCases[i].virtual_path);
275 EXPECT_EQ(expected_virtual_path, virtual_path) 275 EXPECT_EQ(expected_virtual_path, virtual_path)
276 << "Resolving " << kTestCases[i].local_path; 276 << "Resolving " << kTestCases[i].local_path;
277 } 277 }
278 } 278 }
279 279
280 } // namespace 280 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698