OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
14 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
15 #include "base/scoped_temp_dir.h" | |
16 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webkit/fileapi/file_system_context.h" | 18 #include "webkit/fileapi/file_system_context.h" |
19 #include "webkit/fileapi/file_system_operation_context.h" | 19 #include "webkit/fileapi/file_system_operation_context.h" |
20 #include "webkit/fileapi/file_system_task_runners.h" | 20 #include "webkit/fileapi/file_system_task_runners.h" |
21 #include "webkit/fileapi/file_system_usage_cache.h" | 21 #include "webkit/fileapi/file_system_usage_cache.h" |
22 #include "webkit/fileapi/file_util_helper.h" | 22 #include "webkit/fileapi/file_util_helper.h" |
23 #include "webkit/fileapi/local_file_system_test_helper.h" | 23 #include "webkit/fileapi/local_file_system_test_helper.h" |
24 #include "webkit/fileapi/mock_file_change_observer.h" | 24 #include "webkit/fileapi/mock_file_change_observer.h" |
25 #include "webkit/fileapi/mock_file_system_options.h" | 25 #include "webkit/fileapi/mock_file_system_options.h" |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 EXPECT_TRUE(change_observer()->HasNoChange()); | 488 EXPECT_TRUE(change_observer()->HasNoChange()); |
489 context.reset(NewContext(NULL)); | 489 context.reset(NewContext(NULL)); |
490 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( | 490 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
491 context.get(), url, &file_info, &local_path)); | 491 context.get(), url, &file_info, &local_path)); |
492 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); | 492 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
493 if (is_file) // Directories in OFU don't support atime. | 493 if (is_file) // Directories in OFU don't support atime. |
494 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT()); | 494 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT()); |
495 } | 495 } |
496 | 496 |
497 void TestCopyInForeignFileHelper(bool overwrite) { | 497 void TestCopyInForeignFileHelper(bool overwrite) { |
498 ScopedTempDir source_dir; | 498 base::ScopedTempDir source_dir; |
499 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 499 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
500 FilePath root_file_path = source_dir.path(); | 500 FilePath root_file_path = source_dir.path(); |
501 FilePath src_file_path = root_file_path.AppendASCII("file_name"); | 501 FilePath src_file_path = root_file_path.AppendASCII("file_name"); |
502 FileSystemURL dest_url = CreateURLFromUTF8("new file"); | 502 FileSystemURL dest_url = CreateURLFromUTF8("new file"); |
503 int64 src_file_length = 87; | 503 int64 src_file_length = 87; |
504 | 504 |
505 base::PlatformFileError error_code; | 505 base::PlatformFileError error_code; |
506 bool created = false; | 506 bool created = false; |
507 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 507 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
508 base::PlatformFile file_handle = | 508 base::PlatformFile file_handle = |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 int64 ComputeCurrentUsage() { | 627 int64 ComputeCurrentUsage() { |
628 return test_helper().ComputeCurrentOriginUsage() - | 628 return test_helper().ComputeCurrentOriginUsage() - |
629 test_helper().ComputeCurrentDirectoryDatabaseUsage(); | 629 test_helper().ComputeCurrentDirectoryDatabaseUsage(); |
630 } | 630 } |
631 | 631 |
632 const LocalFileSystemTestOriginHelper& test_helper() const { | 632 const LocalFileSystemTestOriginHelper& test_helper() const { |
633 return test_helper_; | 633 return test_helper_; |
634 } | 634 } |
635 | 635 |
636 private: | 636 private: |
637 ScopedTempDir data_dir_; | 637 base::ScopedTempDir data_dir_; |
638 MessageLoop message_loop_; | 638 MessageLoop message_loop_; |
639 ObfuscatedFileUtil* obfuscated_file_util_; | 639 ObfuscatedFileUtil* obfuscated_file_util_; |
640 scoped_refptr<quota::QuotaManager> quota_manager_; | 640 scoped_refptr<quota::QuotaManager> quota_manager_; |
641 scoped_refptr<FileSystemContext> file_system_context_; | 641 scoped_refptr<FileSystemContext> file_system_context_; |
642 GURL origin_; | 642 GURL origin_; |
643 fileapi::FileSystemType type_; | 643 fileapi::FileSystemType type_; |
644 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; | 644 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; |
645 LocalFileSystemTestOriginHelper test_helper_; | 645 LocalFileSystemTestOriginHelper test_helper_; |
646 quota::QuotaStatusCode quota_status_; | 646 quota::QuotaStatusCode quota_status_; |
647 int64 usage_; | 647 int64 usage_; |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 EXPECT_TRUE(DirectoryExists(dest_url)); | 1405 EXPECT_TRUE(DirectoryExists(dest_url)); |
1406 context.reset(NewContext(NULL)); | 1406 context.reset(NewContext(NULL)); |
1407 recursive = true; | 1407 recursive = true; |
1408 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1408 ASSERT_EQ(base::PLATFORM_FILE_OK, |
1409 FileUtilHelper::Delete(context.get(), ofu(), | 1409 FileUtilHelper::Delete(context.get(), ofu(), |
1410 dest_url, recursive)); | 1410 dest_url, recursive)); |
1411 EXPECT_FALSE(DirectoryExists(dest_url)); | 1411 EXPECT_FALSE(DirectoryExists(dest_url)); |
1412 } | 1412 } |
1413 | 1413 |
1414 TEST_F(ObfuscatedFileUtilTest, TestMigration) { | 1414 TEST_F(ObfuscatedFileUtilTest, TestMigration) { |
1415 ScopedTempDir source_dir; | 1415 base::ScopedTempDir source_dir; |
1416 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 1416 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
1417 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); | 1417 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); |
1418 ASSERT_TRUE(file_util::CreateDirectory(root_path)); | 1418 ASSERT_TRUE(file_util::CreateDirectory(root_path)); |
1419 | 1419 |
1420 test::SetUpRegularTestCases(root_path); | 1420 test::SetUpRegularTestCases(root_path); |
1421 | 1421 |
1422 EXPECT_TRUE(ofu()->MigrateFromOldSandbox(origin(), type(), root_path)); | 1422 EXPECT_TRUE(ofu()->MigrateFromOldSandbox(origin(), type(), root_path)); |
1423 | 1423 |
1424 FilePath new_root = | 1424 FilePath new_root = |
1425 test_directory().AppendASCII("File System").AppendASCII("000").Append( | 1425 test_directory().AppendASCII("File System").AppendASCII("000").Append( |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2270 ASSERT_EQ(base::PLATFORM_FILE_OK, | 2270 ASSERT_EQ(base::PLATFORM_FILE_OK, |
2271 ofu()->CreateOrOpen( | 2271 ofu()->CreateOrOpen( |
2272 AllowUsageIncrease(-length)->context(), file, | 2272 AllowUsageIncrease(-length)->context(), file, |
2273 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, | 2273 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, |
2274 &file_handle, &created)); | 2274 &file_handle, &created)); |
2275 ASSERT_EQ(0, ComputeTotalFileSize()); | 2275 ASSERT_EQ(0, ComputeTotalFileSize()); |
2276 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 2276 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
2277 } | 2277 } |
2278 | 2278 |
2279 } // namespace fileapi | 2279 } // namespace fileapi |
OLD | NEW |