| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 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/files/scoped_temp_dir.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webkit/fileapi/async_file_test_helper.h" |
| 17 #include "webkit/fileapi/external_mount_points.h" | 18 #include "webkit/fileapi/external_mount_points.h" |
| 18 #include "webkit/fileapi/file_system_context.h" | 19 #include "webkit/fileapi/file_system_context.h" |
| 19 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/fileapi/file_system_task_runners.h" | 21 #include "webkit/fileapi/file_system_task_runners.h" |
| 21 #include "webkit/fileapi/file_system_usage_cache.h" | 22 #include "webkit/fileapi/file_system_usage_cache.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" |
| 26 #include "webkit/fileapi/obfuscated_file_util.h" | 26 #include "webkit/fileapi/obfuscated_file_util.h" |
| 27 #include "webkit/fileapi/test_file_set.h" | 27 #include "webkit/fileapi/test_file_set.h" |
| 28 #include "webkit/quota/mock_special_storage_policy.h" | 28 #include "webkit/quota/mock_special_storage_policy.h" |
| 29 #include "webkit/quota/quota_manager.h" | 29 #include "webkit/quota/quota_manager.h" |
| 30 #include "webkit/quota/quota_types.h" | 30 #include "webkit/quota/quota_types.h" |
| 31 | 31 |
| 32 namespace fileapi { | 32 namespace fileapi { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 fileapi::FileSystemType type() const { | 202 fileapi::FileSystemType type() const { |
| 203 return type_; | 203 return type_; |
| 204 } | 204 } |
| 205 | 205 |
| 206 int64 ComputeTotalFileSize() { | 206 int64 ComputeTotalFileSize() { |
| 207 return test_helper_.ComputeCurrentOriginUsage() - | 207 return test_helper_.ComputeCurrentOriginUsage() - |
| 208 test_helper_.ComputeCurrentDirectoryDatabaseUsage(); | 208 test_helper_.ComputeCurrentDirectoryDatabaseUsage(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void GetUsageFromQuotaManager() { | 211 void GetUsageFromQuotaManager() { |
| 212 quota_manager_->GetUsageAndQuota( | 212 int64 quota = -1; |
| 213 origin(), test_helper_.storage_type(), | 213 quota_status_ = AsyncFileTestHelper::GetUsageAndQuota( |
| 214 base::Bind(&ObfuscatedFileUtilTest::OnGetUsage, | 214 quota_manager_, origin(), test_helper_.type(), |
| 215 weak_factory_.GetWeakPtr())); | 215 &usage_, "a); |
| 216 MessageLoop::current()->RunUntilIdle(); | |
| 217 EXPECT_EQ(quota::kQuotaStatusOk, quota_status_); | 216 EXPECT_EQ(quota::kQuotaStatusOk, quota_status_); |
| 218 } | 217 } |
| 219 | 218 |
| 220 void RevokeUsageCache() { | 219 void RevokeUsageCache() { |
| 221 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); | 220 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); |
| 222 file_util::Delete(test_helper_.GetUsageCachePath(), false); | 221 file_util::Delete(test_helper_.GetUsageCachePath(), false); |
| 223 } | 222 } |
| 224 | 223 |
| 225 int64 SizeByQuotaUtil() { | 224 int64 SizeByQuotaUtil() { |
| 226 return test_helper_.GetCachedOriginUsage(); | 225 return test_helper_.GetCachedOriginUsage(); |
| 227 } | 226 } |
| 228 | 227 |
| 229 int64 SizeInUsageFile() { | 228 int64 SizeInUsageFile() { |
| 230 MessageLoop::current()->RunUntilIdle(); | 229 MessageLoop::current()->RunUntilIdle(); |
| 231 return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath()); | 230 return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath()); |
| 232 } | 231 } |
| 233 | 232 |
| 234 bool PathExists(const FileSystemURL& url) { | 233 bool PathExists(const FileSystemURL& url) { |
| 235 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 234 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 236 base::PlatformFileInfo file_info; | 235 base::PlatformFileInfo file_info; |
| 237 base::FilePath platform_path; | 236 base::FilePath platform_path; |
| 238 base::PlatformFileError error = ofu()->GetFileInfo( | 237 base::PlatformFileError error = ofu()->GetFileInfo( |
| 239 context.get(), url, &file_info, &platform_path); | 238 context.get(), url, &file_info, &platform_path); |
| 240 return error == base::PLATFORM_FILE_OK; | 239 return error == base::PLATFORM_FILE_OK; |
| 241 } | 240 } |
| 242 | 241 |
| 243 bool DirectoryExists(const FileSystemURL& url) { | 242 bool DirectoryExists(const FileSystemURL& url) { |
| 244 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 243 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url); |
| 245 return FileUtilHelper::DirectoryExists(context.get(), ofu(), url); | |
| 246 } | 244 } |
| 247 | 245 |
| 248 int64 usage() const { return usage_; } | 246 int64 usage() const { return usage_; } |
| 249 | 247 |
| 250 FileSystemURL CreateURLFromUTF8(const std::string& path) { | 248 FileSystemURL CreateURLFromUTF8(const std::string& path) { |
| 251 return test_helper_.CreateURLFromUTF8(path); | 249 return test_helper_.CreateURLFromUTF8(path); |
| 252 } | 250 } |
| 253 | 251 |
| 254 int64 PathCost(const FileSystemURL& url) { | 252 int64 PathCost(const FileSystemURL& url) { |
| 255 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); | 253 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); |
| 256 } | 254 } |
| 257 | 255 |
| 258 FileSystemURL CreateURL(const base::FilePath& path) { | 256 FileSystemURL CreateURL(const base::FilePath& path) { |
| 259 return test_helper_.CreateURL(path); | 257 return test_helper_.CreateURL(path); |
| 260 } | 258 } |
| 261 | 259 |
| 262 void OnGetUsage(quota::QuotaStatusCode status, int64 usage, int64 unused) { | |
| 263 EXPECT_EQ(quota::kQuotaStatusOk, status); | |
| 264 quota_status_ = status; | |
| 265 usage_ = usage; | |
| 266 } | |
| 267 | |
| 268 void CheckFileAndCloseHandle( | 260 void CheckFileAndCloseHandle( |
| 269 const FileSystemURL& url, base::PlatformFile file_handle) { | 261 const FileSystemURL& url, base::PlatformFile file_handle) { |
| 270 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 262 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 271 base::FilePath local_path; | 263 base::FilePath local_path; |
| 272 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( | 264 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( |
| 273 context.get(), url, &local_path)); | 265 context.get(), url, &local_path)); |
| 274 | 266 |
| 275 base::PlatformFileInfo file_info0; | 267 base::PlatformFileInfo file_info0; |
| 276 base::FilePath data_path; | 268 base::FilePath data_path; |
| 277 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( | 269 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 int64 usage = test_helper_.GetCachedOriginUsage(); | 378 int64 usage = test_helper_.GetCachedOriginUsage(); |
| 387 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( | 379 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( |
| 388 LimitedContext(requested_growth - 1), &test_helper_, usage)); | 380 LimitedContext(requested_growth - 1), &test_helper_, usage)); |
| 389 } | 381 } |
| 390 | 382 |
| 391 void FillTestDirectory( | 383 void FillTestDirectory( |
| 392 const FileSystemURL& root_url, | 384 const FileSystemURL& root_url, |
| 393 std::set<base::FilePath::StringType>* files, | 385 std::set<base::FilePath::StringType>* files, |
| 394 std::set<base::FilePath::StringType>* directories) { | 386 std::set<base::FilePath::StringType>* directories) { |
| 395 scoped_ptr<FileSystemOperationContext> context; | 387 scoped_ptr<FileSystemOperationContext> context; |
| 396 context.reset(NewContext(NULL)); | |
| 397 std::vector<base::FileUtilProxy::Entry> entries; | 388 std::vector<base::FileUtilProxy::Entry> entries; |
| 398 EXPECT_EQ(base::PLATFORM_FILE_OK, | 389 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 399 FileUtilHelper::ReadDirectory( | 390 AsyncFileTestHelper::ReadDirectory( |
| 400 context.get(), ofu(), root_url, &entries)); | 391 file_system_context(), root_url, &entries)); |
| 401 EXPECT_EQ(0UL, entries.size()); | 392 EXPECT_EQ(0UL, entries.size()); |
| 402 | 393 |
| 403 files->clear(); | 394 files->clear(); |
| 404 files->insert(FILE_PATH_LITERAL("first")); | 395 files->insert(FILE_PATH_LITERAL("first")); |
| 405 files->insert(FILE_PATH_LITERAL("second")); | 396 files->insert(FILE_PATH_LITERAL("second")); |
| 406 files->insert(FILE_PATH_LITERAL("third")); | 397 files->insert(FILE_PATH_LITERAL("third")); |
| 407 directories->clear(); | 398 directories->clear(); |
| 408 directories->insert(FILE_PATH_LITERAL("fourth")); | 399 directories->insert(FILE_PATH_LITERAL("fourth")); |
| 409 directories->insert(FILE_PATH_LITERAL("fifth")); | 400 directories->insert(FILE_PATH_LITERAL("fifth")); |
| 410 directories->insert(FILE_PATH_LITERAL("sixth")); | 401 directories->insert(FILE_PATH_LITERAL("sixth")); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 433 | 424 |
| 434 void TestReadDirectoryHelper(const FileSystemURL& root_url) { | 425 void TestReadDirectoryHelper(const FileSystemURL& root_url) { |
| 435 std::set<base::FilePath::StringType> files; | 426 std::set<base::FilePath::StringType> files; |
| 436 std::set<base::FilePath::StringType> directories; | 427 std::set<base::FilePath::StringType> directories; |
| 437 FillTestDirectory(root_url, &files, &directories); | 428 FillTestDirectory(root_url, &files, &directories); |
| 438 | 429 |
| 439 scoped_ptr<FileSystemOperationContext> context; | 430 scoped_ptr<FileSystemOperationContext> context; |
| 440 std::vector<base::FileUtilProxy::Entry> entries; | 431 std::vector<base::FileUtilProxy::Entry> entries; |
| 441 context.reset(NewContext(NULL)); | 432 context.reset(NewContext(NULL)); |
| 442 EXPECT_EQ(base::PLATFORM_FILE_OK, | 433 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 443 FileUtilHelper::ReadDirectory( | 434 AsyncFileTestHelper::ReadDirectory( |
| 444 context.get(), ofu(), root_url, &entries)); | 435 file_system_context(), root_url, &entries)); |
| 445 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; | 436 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; |
| 446 EXPECT_EQ(files.size() + directories.size(), entries.size()); | 437 EXPECT_EQ(files.size() + directories.size(), entries.size()); |
| 447 EXPECT_TRUE(change_observer()->HasNoChange()); | 438 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 448 for (entry_iter = entries.begin(); entry_iter != entries.end(); | 439 for (entry_iter = entries.begin(); entry_iter != entries.end(); |
| 449 ++entry_iter) { | 440 ++entry_iter) { |
| 450 const base::FileUtilProxy::Entry& entry = *entry_iter; | 441 const base::FileUtilProxy::Entry& entry = *entry_iter; |
| 451 std::set<base::FilePath::StringType>::iterator iter = files.find(entry.nam
e); | 442 std::set<base::FilePath::StringType>::iterator iter = files.find(entry.nam
e); |
| 452 if (iter != files.end()) { | 443 if (iter != files.end()) { |
| 453 EXPECT_FALSE(entry.is_directory); | 444 EXPECT_FALSE(entry.is_directory); |
| 454 files.erase(iter); | 445 files.erase(iter); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 619 |
| 629 int64 ComputeCurrentUsage() { | 620 int64 ComputeCurrentUsage() { |
| 630 return test_helper().ComputeCurrentOriginUsage() - | 621 return test_helper().ComputeCurrentOriginUsage() - |
| 631 test_helper().ComputeCurrentDirectoryDatabaseUsage(); | 622 test_helper().ComputeCurrentDirectoryDatabaseUsage(); |
| 632 } | 623 } |
| 633 | 624 |
| 634 const LocalFileSystemTestOriginHelper& test_helper() const { | 625 const LocalFileSystemTestOriginHelper& test_helper() const { |
| 635 return test_helper_; | 626 return test_helper_; |
| 636 } | 627 } |
| 637 | 628 |
| 629 FileSystemContext* file_system_context() { |
| 630 return test_helper_.file_system_context(); |
| 631 } |
| 632 |
| 638 private: | 633 private: |
| 639 base::ScopedTempDir data_dir_; | 634 base::ScopedTempDir data_dir_; |
| 640 MessageLoop message_loop_; | 635 MessageLoop message_loop_; |
| 641 scoped_refptr<quota::QuotaManager> quota_manager_; | 636 scoped_refptr<quota::QuotaManager> quota_manager_; |
| 642 scoped_refptr<FileSystemContext> file_system_context_; | 637 scoped_refptr<FileSystemContext> file_system_context_; |
| 643 GURL origin_; | 638 GURL origin_; |
| 644 fileapi::FileSystemType type_; | 639 fileapi::FileSystemType type_; |
| 645 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; | 640 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; |
| 646 LocalFileSystemTestOriginHelper test_helper_; | 641 LocalFileSystemTestOriginHelper test_helper_; |
| 647 quota::QuotaStatusCode quota_status_; | 642 quota::QuotaStatusCode quota_status_; |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 | 1066 |
| 1072 TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) { | 1067 TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) { |
| 1073 FileSystemURL url = CreateURLFromUTF8("file"); | 1068 FileSystemURL url = CreateURLFromUTF8("file"); |
| 1074 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1069 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1075 | 1070 |
| 1076 bool created = false; | 1071 bool created = false; |
| 1077 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1072 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1078 ofu()->EnsureFileExists(context.get(), url, &created)); | 1073 ofu()->EnsureFileExists(context.get(), url, &created)); |
| 1079 ASSERT_TRUE(created); | 1074 ASSERT_TRUE(created); |
| 1080 | 1075 |
| 1081 context.reset(NewContext(NULL)); | |
| 1082 std::vector<base::FileUtilProxy::Entry> entries; | 1076 std::vector<base::FileUtilProxy::Entry> entries; |
| 1083 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, | 1077 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, |
| 1084 FileUtilHelper::ReadDirectory( | 1078 AsyncFileTestHelper::ReadDirectory( |
| 1085 context.get(), ofu(), url, &entries)); | 1079 file_system_context(), url, &entries)); |
| 1086 | 1080 |
| 1087 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), url)); | 1081 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), url)); |
| 1088 } | 1082 } |
| 1089 | 1083 |
| 1090 TEST_F(ObfuscatedFileUtilTest, TestTouch) { | 1084 TEST_F(ObfuscatedFileUtilTest, TestTouch) { |
| 1091 FileSystemURL url = CreateURLFromUTF8("file"); | 1085 FileSystemURL url = CreateURLFromUTF8("file"); |
| 1092 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1086 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1093 | 1087 |
| 1094 base::Time last_access_time = base::Time::Now(); | 1088 base::Time last_access_time = base::Time::Now(); |
| 1095 base::Time last_modified_time = base::Time::Now(); | 1089 base::Time last_modified_time = base::Time::Now(); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( | 1383 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 1390 context.get(), src_url, exclusive, recursive)); | 1384 context.get(), src_url, exclusive, recursive)); |
| 1391 | 1385 |
| 1392 std::set<base::FilePath::StringType> files; | 1386 std::set<base::FilePath::StringType> files; |
| 1393 std::set<base::FilePath::StringType> directories; | 1387 std::set<base::FilePath::StringType> directories; |
| 1394 FillTestDirectory(src_url, &files, &directories); | 1388 FillTestDirectory(src_url, &files, &directories); |
| 1395 | 1389 |
| 1396 FileSystemURL dest_url = CreateURLFromUTF8("destination dir"); | 1390 FileSystemURL dest_url = CreateURLFromUTF8("destination dir"); |
| 1397 | 1391 |
| 1398 EXPECT_FALSE(DirectoryExists(dest_url)); | 1392 EXPECT_FALSE(DirectoryExists(dest_url)); |
| 1399 context.reset(NewContext(NULL)); | |
| 1400 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1393 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1401 test_helper().SameFileUtilCopy(context.get(), src_url, dest_url)); | 1394 AsyncFileTestHelper::Copy( |
| 1395 test_helper().file_system_context(), src_url, dest_url)); |
| 1402 | 1396 |
| 1403 ValidateTestDirectory(dest_url, files, directories); | 1397 ValidateTestDirectory(dest_url, files, directories); |
| 1404 EXPECT_TRUE(DirectoryExists(src_url)); | 1398 EXPECT_TRUE(DirectoryExists(src_url)); |
| 1405 EXPECT_TRUE(DirectoryExists(dest_url)); | 1399 EXPECT_TRUE(DirectoryExists(dest_url)); |
| 1406 context.reset(NewContext(NULL)); | |
| 1407 recursive = true; | 1400 recursive = true; |
| 1408 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1401 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1409 FileUtilHelper::Delete(context.get(), ofu(), | 1402 AsyncFileTestHelper::Remove( |
| 1410 dest_url, recursive)); | 1403 file_system_context(), dest_url, recursive)); |
| 1411 EXPECT_FALSE(DirectoryExists(dest_url)); | 1404 EXPECT_FALSE(DirectoryExists(dest_url)); |
| 1412 } | 1405 } |
| 1413 | 1406 |
| 1414 TEST_F(ObfuscatedFileUtilTest, TestOriginEnumerator) { | 1407 TEST_F(ObfuscatedFileUtilTest, TestOriginEnumerator) { |
| 1415 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> | 1408 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> |
| 1416 enumerator(ofu()->CreateOriginEnumerator()); | 1409 enumerator(ofu()->CreateOriginEnumerator()); |
| 1417 // The test helper starts out with a single filesystem. | 1410 // The test helper starts out with a single filesystem. |
| 1418 EXPECT_TRUE(enumerator.get()); | 1411 EXPECT_TRUE(enumerator.get()); |
| 1419 EXPECT_EQ(origin(), enumerator->Next()); | 1412 EXPECT_EQ(origin(), enumerator->Next()); |
| 1420 ASSERT_TRUE(type() == kFileSystemTypeTemporary); | 1413 ASSERT_TRUE(type() == kFileSystemTypeTemporary); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1629 scoped_ptr<FileSystemOperationContext> context; | 1622 scoped_ptr<FileSystemOperationContext> context; |
| 1630 | 1623 |
| 1631 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) { | 1624 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) { |
| 1632 bool created = false; | 1625 bool created = false; |
| 1633 context.reset(NewContext(NULL)); | 1626 context.reset(NewContext(NULL)); |
| 1634 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1627 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1635 ofu()->EnsureFileExists(context.get(), kPath[i], &created)); | 1628 ofu()->EnsureFileExists(context.get(), kPath[i], &created)); |
| 1636 EXPECT_TRUE(created); | 1629 EXPECT_TRUE(created); |
| 1637 } | 1630 } |
| 1638 | 1631 |
| 1639 context.reset(NewContext(NULL)); | |
| 1640 std::vector<base::FileUtilProxy::Entry> entries; | 1632 std::vector<base::FileUtilProxy::Entry> entries; |
| 1641 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1633 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1642 FileUtilHelper::ReadDirectory( | 1634 AsyncFileTestHelper::ReadDirectory( |
| 1643 context.get(), ofu(), empty_path, &entries)); | 1635 file_system_context(), empty_path, &entries)); |
| 1644 EXPECT_EQ(3u, entries.size()); | 1636 EXPECT_EQ(3u, entries.size()); |
| 1645 | 1637 |
| 1646 context.reset(NewContext(NULL)); | |
| 1647 base::FilePath local_path; | 1638 base::FilePath local_path; |
| 1648 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1639 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1649 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path)); | 1640 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path)); |
| 1650 EXPECT_TRUE(file_util::Delete(local_path, false)); | 1641 EXPECT_TRUE(file_util::Delete(local_path, false)); |
| 1651 | 1642 |
| 1652 context.reset(NewContext(NULL)); | |
| 1653 entries.clear(); | 1643 entries.clear(); |
| 1654 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1644 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1655 FileUtilHelper::ReadDirectory( | 1645 AsyncFileTestHelper::ReadDirectory( |
| 1656 context.get(), ofu(), empty_path, &entries)); | 1646 file_system_context(), empty_path, &entries)); |
| 1657 EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size()); | 1647 EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size()); |
| 1658 } | 1648 } |
| 1659 | 1649 |
| 1660 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) { | 1650 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) { |
| 1661 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1651 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1662 const FileSystemURL dir_url = CreateURLFromUTF8("foo_dir"); | 1652 const FileSystemURL dir_url = CreateURLFromUTF8("foo_dir"); |
| 1663 | 1653 |
| 1664 // Create working directory. | 1654 // Create working directory. |
| 1665 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1655 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1666 ofu()->CreateDirectory(context.get(), dir_url, false, false)); | 1656 ofu()->CreateDirectory(context.get(), dir_url, false, false)); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2162 dfile2, 120)); | 2152 dfile2, 120)); |
| 2163 ASSERT_EQ(1480, ComputeTotalFileSize()); | 2153 ASSERT_EQ(1480, ComputeTotalFileSize()); |
| 2164 | 2154 |
| 2165 ASSERT_EQ(base::PLATFORM_FILE_OK, | 2155 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 2166 ofu()->DeleteFile( | 2156 ofu()->DeleteFile( |
| 2167 AllowUsageIncrease(-PathCost(file) - 340)->context(), | 2157 AllowUsageIncrease(-PathCost(file) - 340)->context(), |
| 2168 file)); | 2158 file)); |
| 2169 ASSERT_EQ(1140, ComputeTotalFileSize()); | 2159 ASSERT_EQ(1140, ComputeTotalFileSize()); |
| 2170 | 2160 |
| 2171 ASSERT_EQ(base::PLATFORM_FILE_OK, | 2161 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 2172 FileUtilHelper::Delete( | 2162 AsyncFileTestHelper::Remove( |
| 2173 AllowUsageIncrease(-PathCost(dir) - | 2163 file_system_context(), dir, true /* recursive */)); |
| 2174 PathCost(dfile1) - | |
| 2175 PathCost(dfile2) - | |
| 2176 1020 - 120)->context(), | |
| 2177 ofu(), dir, true)); | |
| 2178 ASSERT_EQ(0, ComputeTotalFileSize()); | 2164 ASSERT_EQ(0, ComputeTotalFileSize()); |
| 2179 } | 2165 } |
| 2180 | 2166 |
| 2181 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnOpen) { | 2167 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnOpen) { |
| 2182 FileSystemURL file(CreateURLFromUTF8("file")); | 2168 FileSystemURL file(CreateURLFromUTF8("file")); |
| 2183 base::PlatformFile file_handle; | 2169 base::PlatformFile file_handle; |
| 2184 bool created; | 2170 bool created; |
| 2185 | 2171 |
| 2186 // Creating a file. | 2172 // Creating a file. |
| 2187 ASSERT_EQ(base::PLATFORM_FILE_OK, | 2173 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2225 ASSERT_EQ(base::PLATFORM_FILE_OK, | 2211 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 2226 ofu()->CreateOrOpen( | 2212 ofu()->CreateOrOpen( |
| 2227 AllowUsageIncrease(-length)->context(), file, | 2213 AllowUsageIncrease(-length)->context(), file, |
| 2228 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, | 2214 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, |
| 2229 &file_handle, &created)); | 2215 &file_handle, &created)); |
| 2230 ASSERT_EQ(0, ComputeTotalFileSize()); | 2216 ASSERT_EQ(0, ComputeTotalFileSize()); |
| 2231 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 2217 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
| 2232 } | 2218 } |
| 2233 | 2219 |
| 2234 } // namespace fileapi | 2220 } // namespace fileapi |
| OLD | NEW |