OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "webkit/browser/fileapi/file_system_url.h" | 10 #include "storage/browser/fileapi/file_system_url.h" |
11 #include "webkit/browser/fileapi/isolated_context.h" | 11 #include "storage/browser/fileapi/isolated_context.h" |
12 | 12 |
13 #define FPL(x) FILE_PATH_LITERAL(x) | 13 #define FPL(x) FILE_PATH_LITERAL(x) |
14 | 14 |
15 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 15 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
16 #define DRIVE FPL("C:") | 16 #define DRIVE FPL("C:") |
17 #else | 17 #else |
18 #define DRIVE | 18 #define DRIVE |
19 #endif | 19 #endif |
20 | 20 |
21 using fileapi::FileSystemMountOption; | 21 using storage::FileSystemMountOption; |
22 using fileapi::FileSystemURL; | 22 using storage::FileSystemURL; |
23 using fileapi::IsolatedContext; | 23 using storage::IsolatedContext; |
24 using fileapi::kFileSystemTypeDragged; | 24 using storage::kFileSystemTypeDragged; |
25 using fileapi::kFileSystemTypeIsolated; | 25 using storage::kFileSystemTypeIsolated; |
26 using fileapi::kFileSystemTypeNativeLocal; | 26 using storage::kFileSystemTypeNativeLocal; |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 typedef IsolatedContext::MountPointInfo FileInfo; | 30 typedef IsolatedContext::MountPointInfo FileInfo; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const base::FilePath kTestPaths[] = { | 34 const base::FilePath kTestPaths[] = { |
35 base::FilePath(DRIVE FPL("/a/b.txt")), | 35 base::FilePath(DRIVE FPL("/a/b.txt")), |
36 base::FilePath(DRIVE FPL("/c/d/e")), | 36 base::FilePath(DRIVE FPL("/c/d/e")), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 // See if the name of each registered kTestPaths (that is what we | 97 // See if the name of each registered kTestPaths (that is what we |
98 // register in SetUp() by RegisterDraggedFileSystem) is properly cracked as | 98 // register in SetUp() by RegisterDraggedFileSystem) is properly cracked as |
99 // a valid virtual path in the isolated filesystem. | 99 // a valid virtual path in the isolated filesystem. |
100 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { | 100 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
101 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) | 101 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) |
102 .AppendASCII(names_[i]); | 102 .AppendASCII(names_[i]); |
103 std::string cracked_id; | 103 std::string cracked_id; |
104 base::FilePath cracked_path; | 104 base::FilePath cracked_path; |
105 std::string cracked_inner_id; | 105 std::string cracked_inner_id; |
106 fileapi::FileSystemType cracked_type; | 106 storage::FileSystemType cracked_type; |
107 FileSystemMountOption cracked_option; | 107 FileSystemMountOption cracked_option; |
108 ASSERT_TRUE(isolated_context()->CrackVirtualPath( | 108 ASSERT_TRUE(isolated_context()->CrackVirtualPath( |
109 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id, | 109 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id, |
110 &cracked_path, &cracked_option)); | 110 &cracked_path, &cracked_option)); |
111 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), | 111 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), |
112 cracked_path.value()); | 112 cracked_path.value()); |
113 ASSERT_EQ(id_, cracked_id); | 113 ASSERT_EQ(id_, cracked_id); |
114 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); | 114 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); |
115 EXPECT_TRUE(cracked_inner_id.empty()); | 115 EXPECT_TRUE(cracked_inner_id.empty()); |
116 } | 116 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { | 197 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
198 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { | 198 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { |
199 SCOPED_TRACE(testing::Message() << "Testing " | 199 SCOPED_TRACE(testing::Message() << "Testing " |
200 << kTestPaths[i].value() << " " << relatives[j].path); | 200 << kTestPaths[i].value() << " " << relatives[j].path); |
201 base::FilePath virtual_path = | 201 base::FilePath virtual_path = |
202 isolated_context()->CreateVirtualRootPath(id_).AppendASCII( | 202 isolated_context()->CreateVirtualRootPath(id_).AppendASCII( |
203 names_[i]).Append(relatives[j].path); | 203 names_[i]).Append(relatives[j].path); |
204 std::string cracked_id; | 204 std::string cracked_id; |
205 base::FilePath cracked_path; | 205 base::FilePath cracked_path; |
206 fileapi::FileSystemType cracked_type; | 206 storage::FileSystemType cracked_type; |
207 std::string cracked_inner_id; | 207 std::string cracked_inner_id; |
208 FileSystemMountOption cracked_option; | 208 FileSystemMountOption cracked_option; |
209 if (!relatives[j].valid) { | 209 if (!relatives[j].valid) { |
210 ASSERT_FALSE(isolated_context()->CrackVirtualPath( | 210 ASSERT_FALSE(isolated_context()->CrackVirtualPath( |
211 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id, | 211 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id, |
212 &cracked_path, &cracked_option)); | 212 &cracked_path, &cracked_option)); |
213 continue; | 213 continue; |
214 } | 214 } |
215 ASSERT_TRUE(isolated_context()->CrackVirtualPath( | 215 ASSERT_TRUE(isolated_context()->CrackVirtualPath( |
216 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id, | 216 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 ASSERT_FALSE(isolated_context()->CrackVirtualPath( | 292 ASSERT_FALSE(isolated_context()->CrackVirtualPath( |
293 virtual_path, &cracked_id, NULL, NULL, &cracked_path, &cracked_option)); | 293 virtual_path, &cracked_id, NULL, NULL, &cracked_path, &cracked_option)); |
294 } | 294 } |
295 | 295 |
296 TEST_F(IsolatedContextTest, CanHandleURL) { | 296 TEST_F(IsolatedContextTest, CanHandleURL) { |
297 const GURL test_origin("http://chromium.org"); | 297 const GURL test_origin("http://chromium.org"); |
298 const base::FilePath test_path(FPL("/mount")); | 298 const base::FilePath test_path(FPL("/mount")); |
299 | 299 |
300 // Should handle isolated file system. | 300 // Should handle isolated file system. |
301 EXPECT_TRUE(isolated_context()->HandlesFileSystemMountType( | 301 EXPECT_TRUE(isolated_context()->HandlesFileSystemMountType( |
302 fileapi::kFileSystemTypeIsolated)); | 302 storage::kFileSystemTypeIsolated)); |
303 | 303 |
304 // Shouldn't handle the rest. | 304 // Shouldn't handle the rest. |
305 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( | 305 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
306 fileapi::kFileSystemTypeExternal)); | 306 storage::kFileSystemTypeExternal)); |
307 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( | 307 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
308 fileapi::kFileSystemTypeTemporary)); | 308 storage::kFileSystemTypeTemporary)); |
309 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( | 309 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
310 fileapi::kFileSystemTypePersistent)); | 310 storage::kFileSystemTypePersistent)); |
311 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( | 311 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
312 fileapi::kFileSystemTypeTest)); | 312 storage::kFileSystemTypeTest)); |
313 // Not even if it's isolated subtype. | 313 // Not even if it's isolated subtype. |
314 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( | 314 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
315 fileapi::kFileSystemTypeNativeLocal)); | 315 storage::kFileSystemTypeNativeLocal)); |
316 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( | 316 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
317 fileapi::kFileSystemTypeDragged)); | 317 storage::kFileSystemTypeDragged)); |
318 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( | 318 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
319 fileapi::kFileSystemTypeNativeMedia)); | 319 storage::kFileSystemTypeNativeMedia)); |
320 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( | 320 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
321 fileapi::kFileSystemTypeDeviceMedia)); | 321 storage::kFileSystemTypeDeviceMedia)); |
322 } | 322 } |
323 | 323 |
324 TEST_F(IsolatedContextTest, VirtualFileSystemTests) { | 324 TEST_F(IsolatedContextTest, VirtualFileSystemTests) { |
325 // Should be able to register empty and non-absolute paths | 325 // Should be able to register empty and non-absolute paths |
326 std::string empty_fsid = isolated_context()->RegisterFileSystemForVirtualPath( | 326 std::string empty_fsid = isolated_context()->RegisterFileSystemForVirtualPath( |
327 fileapi::kFileSystemTypeIsolated, "_", base::FilePath()); | 327 storage::kFileSystemTypeIsolated, "_", base::FilePath()); |
328 std::string relative_fsid = | 328 std::string relative_fsid = |
329 isolated_context()->RegisterFileSystemForVirtualPath( | 329 isolated_context()->RegisterFileSystemForVirtualPath( |
330 fileapi::kFileSystemTypeIsolated, "_", | 330 storage::kFileSystemTypeIsolated, |
| 331 "_", |
331 base::FilePath(FPL("relpath"))); | 332 base::FilePath(FPL("relpath"))); |
332 ASSERT_FALSE(empty_fsid.empty()); | 333 ASSERT_FALSE(empty_fsid.empty()); |
333 ASSERT_FALSE(relative_fsid.empty()); | 334 ASSERT_FALSE(relative_fsid.empty()); |
334 | 335 |
335 // Make sure that filesystem root is not prepended to cracked virtual paths. | 336 // Make sure that filesystem root is not prepended to cracked virtual paths. |
336 base::FilePath database_root = base::FilePath(DRIVE FPL("/database_path")); | 337 base::FilePath database_root = base::FilePath(DRIVE FPL("/database_path")); |
337 std::string database_fsid = | 338 std::string database_fsid = |
338 isolated_context()->RegisterFileSystemForVirtualPath( | 339 isolated_context()->RegisterFileSystemForVirtualPath( |
339 fileapi::kFileSystemTypeIsolated, "_", database_root); | 340 storage::kFileSystemTypeIsolated, "_", database_root); |
340 | 341 |
341 base::FilePath test_virtual_path = | 342 base::FilePath test_virtual_path = |
342 base::FilePath().AppendASCII("virtualdir").AppendASCII("virtualfile.txt"); | 343 base::FilePath().AppendASCII("virtualdir").AppendASCII("virtualfile.txt"); |
343 | 344 |
344 base::FilePath whole_virtual_path = | 345 base::FilePath whole_virtual_path = |
345 isolated_context()->CreateVirtualRootPath(database_fsid) | 346 isolated_context()->CreateVirtualRootPath(database_fsid) |
346 .AppendASCII("_").Append(test_virtual_path); | 347 .AppendASCII("_").Append(test_virtual_path); |
347 | 348 |
348 std::string cracked_id; | 349 std::string cracked_id; |
349 base::FilePath cracked_path; | 350 base::FilePath cracked_path; |
350 std::string cracked_inner_id; | 351 std::string cracked_inner_id; |
351 FileSystemMountOption cracked_option; | 352 FileSystemMountOption cracked_option; |
352 ASSERT_TRUE(isolated_context()->CrackVirtualPath( | 353 ASSERT_TRUE(isolated_context()->CrackVirtualPath( |
353 whole_virtual_path, &cracked_id, NULL, &cracked_inner_id, | 354 whole_virtual_path, &cracked_id, NULL, &cracked_inner_id, |
354 &cracked_path, &cracked_option)); | 355 &cracked_path, &cracked_option)); |
355 ASSERT_EQ(database_fsid, cracked_id); | 356 ASSERT_EQ(database_fsid, cracked_id); |
356 ASSERT_EQ(test_virtual_path, cracked_path); | 357 ASSERT_EQ(test_virtual_path, cracked_path); |
357 EXPECT_TRUE(cracked_inner_id.empty()); | 358 EXPECT_TRUE(cracked_inner_id.empty()); |
358 } | 359 } |
359 | 360 |
360 } // namespace content | 361 } // namespace content |
OLD | NEW |