OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/fileapi/file_system_path_manager.h" | 5 #include "webkit/fileapi/file_system_path_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/command_line.h" // TODO(ericu): Remove this. |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_callback_factory.h" | 14 #include "base/memory/scoped_callback_factory.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
16 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
17 #include "base/scoped_temp_dir.h" | 18 #include "base/scoped_temp_dir.h" |
18 #include "base/sys_string_conversions.h" | 19 #include "base/sys_string_conversions.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "webkit/fileapi/file_system_util.h" | 23 #include "webkit/fileapi/file_system_util.h" |
23 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 24 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
24 #include "webkit/quota/special_storage_policy.h" | 25 #include "webkit/quota/special_storage_policy.h" |
25 | 26 |
26 namespace fileapi { | 27 namespace fileapi { |
27 namespace { | 28 namespace { |
28 | 29 |
| 30 // TODO(ericu): Remove this. |
| 31 static const char kObfuscationFlag[] = "use-obfuscated-file-system"; |
| 32 |
29 // PS stands for path separator. | 33 // PS stands for path separator. |
30 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 34 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
31 #define PS "\\" | 35 #define PS "\\" |
32 #else | 36 #else |
33 #define PS "/" | 37 #define PS "/" |
34 #endif | 38 #endif |
35 | 39 |
36 struct RootPathTestCase { | 40 struct RootPathTestCase { |
37 fileapi::FileSystemType type; | 41 fileapi::FileSystemType type; |
38 const char* origin_url; | 42 const char* origin_url; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " " | 289 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " " |
286 << kRootPathTestCases[i].expected_path); | 290 << kRootPathTestCases[i].expected_path); |
287 | 291 |
288 FilePath root_path; | 292 FilePath root_path; |
289 EXPECT_TRUE(GetRootPath(manager.get(), | 293 EXPECT_TRUE(GetRootPath(manager.get(), |
290 GURL(kRootPathTestCases[i].origin_url), | 294 GURL(kRootPathTestCases[i].origin_url), |
291 kRootPathTestCases[i].type, | 295 kRootPathTestCases[i].type, |
292 true /* create */, &root_path)); | 296 true /* create */, &root_path)); |
293 | 297 |
294 if (kRootPathTestCases[i].type != fileapi::kFileSystemTypeExternal) { | 298 if (kRootPathTestCases[i].type != fileapi::kFileSystemTypeExternal) { |
295 FilePath expected = file_system_path().AppendASCII( | 299 // TODO(ericu): Put this test back, with new expectations, when we've |
296 kRootPathTestCases[i].expected_path); | 300 // switched over to the obfuscated filesystem. |
297 EXPECT_EQ(expected.value(), root_path.DirName().value()); | 301 if (!CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) { |
| 302 FilePath expected = file_system_path().AppendASCII( |
| 303 kRootPathTestCases[i].expected_path); |
| 304 EXPECT_EQ(expected.value(), root_path.DirName().value()); |
| 305 } |
298 EXPECT_TRUE(file_util::DirectoryExists(root_path)); | 306 EXPECT_TRUE(file_util::DirectoryExists(root_path)); |
299 } else { | 307 } else { |
300 // External file system root path is virtual one and does not match | 308 // External file system root path is virtual one and does not match |
301 // anything from the actual file system. | 309 // anything from the actual file system. |
302 EXPECT_EQ(external_file_system_path().value(), | 310 EXPECT_EQ(external_file_system_path().value(), |
303 root_path.value()); | 311 root_path.value()); |
304 } | 312 } |
305 ASSERT_TRUE(returned_root_path.size() > i); | 313 ASSERT_TRUE(returned_root_path.size() > i); |
306 returned_root_path[i] = root_path; | 314 returned_root_path[i] = root_path; |
307 } | 315 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" | 396 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" |
389 << i << " " << kRootPathFileURITestCases[i].expected_path); | 397 << i << " " << kRootPathFileURITestCases[i].expected_path); |
390 FilePath root_path; | 398 FilePath root_path; |
391 EXPECT_TRUE(GetRootPath(manager.get(), | 399 EXPECT_TRUE(GetRootPath(manager.get(), |
392 GURL(kRootPathFileURITestCases[i].origin_url), | 400 GURL(kRootPathFileURITestCases[i].origin_url), |
393 kRootPathFileURITestCases[i].type, | 401 kRootPathFileURITestCases[i].type, |
394 true /* create */, &root_path)); | 402 true /* create */, &root_path)); |
395 if (kRootPathFileURITestCases[i].type != fileapi::kFileSystemTypeExternal) { | 403 if (kRootPathFileURITestCases[i].type != fileapi::kFileSystemTypeExternal) { |
396 FilePath expected = file_system_path().AppendASCII( | 404 FilePath expected = file_system_path().AppendASCII( |
397 kRootPathFileURITestCases[i].expected_path); | 405 kRootPathFileURITestCases[i].expected_path); |
398 EXPECT_EQ(expected.value(), root_path.DirName().value()); | 406 // TODO(ericu): Put this test back, with new expectations, when we've |
| 407 // switched over to the obfuscated filesystem. |
| 408 if (!CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) |
| 409 EXPECT_EQ(expected.value(), root_path.DirName().value()); |
399 EXPECT_TRUE(file_util::DirectoryExists(root_path)); | 410 EXPECT_TRUE(file_util::DirectoryExists(root_path)); |
400 } else { | 411 } else { |
401 EXPECT_EQ(external_file_path_root().value(), root_path.value()); | 412 EXPECT_EQ(external_file_path_root().value(), root_path.value()); |
402 } | 413 } |
403 } | 414 } |
404 } | 415 } |
405 | 416 |
406 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { | 417 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { |
407 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | 418 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); |
408 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { | 419 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { |
409 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " | 420 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " |
410 << kIsRestrictedNameTestCases[i].name); | 421 << kIsRestrictedNameTestCases[i].name); |
411 FilePath name(kIsRestrictedNameTestCases[i].name); | 422 FilePath name(kIsRestrictedNameTestCases[i].name); |
412 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, | 423 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, |
413 manager->IsRestrictedFileName(kFileSystemTypeTemporary, name)); | 424 manager->IsRestrictedFileName(kFileSystemTypeTemporary, name)); |
414 } | 425 } |
415 } | 426 } |
416 | 427 |
417 } // namespace fileapi | 428 } // namespace fileapi |
OLD | NEW |