| 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 // This test checks the entire behavior of FileSystem usage and quota, such as: | 5 // This test checks the entire behavior of FileSystem usage and quota, such as: |
| 6 // 1) the actual size of files on disk, | 6 // 1) the actual size of files on disk, |
| 7 // 2) the described size in .usage, and | 7 // 2) the described size in .usage, and |
| 8 // 3) the result of QuotaManager::GetUsageAndQuota. | 8 // 3) the result of QuotaManager::GetUsageAndQuota. |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_callback_factory.h" | 12 #include "base/memory/scoped_callback_factory.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 "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 18 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 19 #include "webkit/fileapi/file_system_context.h" | |
| 20 #include "webkit/fileapi/file_system_operation.h" | 19 #include "webkit/fileapi/file_system_operation.h" |
| 21 #include "webkit/fileapi/file_system_test_helper.h" | 20 #include "webkit/fileapi/file_system_test_helper.h" |
| 22 #include "webkit/fileapi/file_system_usage_cache.h" | 21 #include "webkit/fileapi/file_system_usage_cache.h" |
| 23 #include "webkit/fileapi/file_system_util.h" | 22 #include "webkit/fileapi/file_system_util.h" |
| 24 #include "webkit/fileapi/local_file_system_file_util.h" | 23 #include "webkit/fileapi/local_file_system_file_util.h" |
| 25 #include "webkit/fileapi/quota_file_util.h" | 24 #include "webkit/fileapi/quota_file_util.h" |
| 26 #include "webkit/quota/mock_special_storage_policy.h" | |
| 27 #include "webkit/quota/quota_manager.h" | 25 #include "webkit/quota/quota_manager.h" |
| 28 | 26 |
| 29 namespace fileapi { | 27 namespace fileapi { |
| 30 | 28 |
| 31 const int kFileOperationStatusNotSet = 1; | 29 const int kFileOperationStatusNotSet = 1; |
| 32 | 30 |
| 33 class FileSystemQuotaTest : public testing::Test { | 31 class FileSystemQuotaTest : public testing::Test { |
| 34 public: | 32 public: |
| 35 FileSystemQuotaTest() | 33 FileSystemQuotaTest() |
| 36 : quota_file_util_(QuotaFileUtil::CreateDefault()), | 34 : local_file_util_( |
| 37 local_file_util_(new LocalFileSystemFileUtil(quota_file_util_)), | 35 new LocalFileSystemFileUtil(QuotaFileUtil::CreateDefault())), |
| 38 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 36 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 39 file_path_cost_(0), | |
| 40 status_(kFileOperationStatusNotSet), | 37 status_(kFileOperationStatusNotSet), |
| 41 quota_status_(quota::kQuotaStatusUnknown), | 38 quota_status_(quota::kQuotaStatusUnknown), |
| 42 usage_(-1), | 39 usage_(-1), |
| 43 quota_(-1) {} | 40 quota_(-1) {} |
| 44 | 41 |
| 45 FileSystemOperation* operation(); | 42 FileSystemOperation* operation(); |
| 46 | 43 |
| 47 void set_status(int status) { status_ = status; } | 44 void set_status(int status) { status_ = status; } |
| 48 int status() const { return status_; } | 45 int status() const { return status_; } |
| 49 quota::QuotaStatusCode quota_status() const { return quota_status_; } | 46 quota::QuotaStatusCode quota_status() const { return quota_status_; } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 82 |
| 86 bool VirtualFileExists(const FilePath& virtual_path) { | 83 bool VirtualFileExists(const FilePath& virtual_path) { |
| 87 return file_util::PathExists(PlatformPath(virtual_path)) && | 84 return file_util::PathExists(PlatformPath(virtual_path)) && |
| 88 !file_util::DirectoryExists(PlatformPath(virtual_path)); | 85 !file_util::DirectoryExists(PlatformPath(virtual_path)); |
| 89 } | 86 } |
| 90 | 87 |
| 91 bool VirtualDirectoryExists(const FilePath& virtual_path) { | 88 bool VirtualDirectoryExists(const FilePath& virtual_path) { |
| 92 return file_util::DirectoryExists(PlatformPath(virtual_path)); | 89 return file_util::DirectoryExists(PlatformPath(virtual_path)); |
| 93 } | 90 } |
| 94 | 91 |
| 95 int64 ComputeFilePathCost(const FilePath& file_path) { | 92 FilePath CreateVirtualTemporaryFileInDir(const FilePath& virtual_dir_path) { |
| 96 return quota_file_util_->ComputeFilePathCost(file_path); | 93 FilePath absolute_dir_path(PlatformPath(virtual_dir_path)); |
| 94 FilePath absolute_file_path; |
| 95 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(absolute_dir_path, |
| 96 &absolute_file_path)); |
| 97 return virtual_dir_path.Append(absolute_file_path.BaseName()); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void CreateVirtualDirectory(const FilePath& virtual_path) { | 100 FilePath CreateVirtualTemporaryDirInDir(const FilePath& virtual_dir_path) { |
| 100 operation()->CreateDirectory(URLForPath(virtual_path), false, false); | 101 FilePath absolute_parent_dir_path(PlatformPath(virtual_dir_path)); |
| 101 MessageLoop::current()->RunAllPending(); | 102 FilePath absolute_child_dir_path; |
| 102 file_path_cost_ += ComputeFilePathCost(virtual_path); | 103 EXPECT_TRUE(file_util::CreateTemporaryDirInDir(absolute_parent_dir_path, |
| 104 FILE_PATH_LITERAL(""), |
| 105 &absolute_child_dir_path)); |
| 106 return virtual_dir_path.Append(absolute_child_dir_path.BaseName()); |
| 103 } | 107 } |
| 104 | 108 |
| 105 void CreateVirtualFile(const FilePath& virtual_path) { | 109 FilePath CreateVirtualTemporaryDir() { |
| 106 operation()->CreateFile(URLForPath(virtual_path), false); | 110 return CreateVirtualTemporaryDirInDir(FilePath()); |
| 107 MessageLoop::current()->RunAllPending(); | |
| 108 file_path_cost_ += ComputeFilePathCost(virtual_path); | |
| 109 } | |
| 110 | |
| 111 void set_file_path_cost(int64 file_path_cost) { | |
| 112 file_path_cost_ = file_path_cost; | |
| 113 } | |
| 114 | |
| 115 int64 file_path_cost() const { | |
| 116 return file_path_cost_; | |
| 117 } | |
| 118 | |
| 119 void AddToFilePathCost(int64 addition) { | |
| 120 file_path_cost_ += addition; | |
| 121 } | 111 } |
| 122 | 112 |
| 123 FilePath child_dir_path_; | 113 FilePath child_dir_path_; |
| 124 FilePath child_file1_path_; | 114 FilePath child_file1_path_; |
| 125 FilePath child_file2_path_; | 115 FilePath child_file2_path_; |
| 126 FilePath grandchild_file1_path_; | 116 FilePath grandchild_file1_path_; |
| 127 FilePath grandchild_file2_path_; | 117 FilePath grandchild_file2_path_; |
| 128 | 118 |
| 129 protected: | 119 protected: |
| 130 FileSystemTestOriginHelper test_helper_; | 120 FileSystemTestOriginHelper test_helper_; |
| 131 | 121 |
| 132 ScopedTempDir work_dir_; | 122 ScopedTempDir work_dir_; |
| 133 scoped_refptr<quota::QuotaManager> quota_manager_; | 123 scoped_refptr<quota::QuotaManager> quota_manager_; |
| 134 QuotaFileUtil* quota_file_util_; | |
| 135 scoped_ptr<LocalFileSystemFileUtil> local_file_util_; | 124 scoped_ptr<LocalFileSystemFileUtil> local_file_util_; |
| 136 | 125 |
| 137 base::ScopedCallbackFactory<FileSystemQuotaTest> callback_factory_; | 126 base::ScopedCallbackFactory<FileSystemQuotaTest> callback_factory_; |
| 138 | 127 |
| 139 int64 file_path_cost_; | |
| 140 | |
| 141 // For post-operation status. | 128 // For post-operation status. |
| 142 int status_; | 129 int status_; |
| 143 quota::QuotaStatusCode quota_status_; | 130 quota::QuotaStatusCode quota_status_; |
| 144 int64 usage_; | 131 int64 usage_; |
| 145 int64 quota_; | 132 int64 quota_; |
| 146 | 133 |
| 147 private: | |
| 148 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaTest); | 134 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaTest); |
| 149 }; | 135 }; |
| 150 | 136 |
| 151 class FileSystemObfuscatedQuotaTest : public FileSystemQuotaTest { | 137 class FileSystemObfuscatedQuotaTest : public FileSystemQuotaTest { |
| 152 public: | 138 public: |
| 153 virtual void SetUp(); | 139 virtual void SetUp(); |
| 154 | 140 |
| 155 int64 RevokeUsageCache() { | 141 int64 RevokeUsageCache() { |
| 156 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); | 142 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); |
| 157 return test_helper_.RevokeUsageCache(); | 143 return test_helper_.RevokeUsageCache(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 220 } |
| 235 | 221 |
| 236 void FileSystemQuotaTest::OnGetUsageAndQuota( | 222 void FileSystemQuotaTest::OnGetUsageAndQuota( |
| 237 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 223 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 238 quota_status_ = status; | 224 quota_status_ = status; |
| 239 usage_ = usage; | 225 usage_ = usage; |
| 240 quota_ = quota; | 226 quota_ = quota; |
| 241 } | 227 } |
| 242 | 228 |
| 243 void FileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) { | 229 void FileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) { |
| 244 child_dir_path_ = virtual_path.AppendASCII("childdir"); | 230 child_dir_path_ = CreateVirtualTemporaryDirInDir(virtual_path); |
| 245 CreateVirtualDirectory(child_dir_path_); | 231 child_file1_path_ = CreateVirtualTemporaryFileInDir(virtual_path); |
| 246 child_file1_path_ = virtual_path.AppendASCII("childfile1"); | 232 child_file2_path_ = CreateVirtualTemporaryFileInDir(virtual_path); |
| 247 CreateVirtualFile(child_file1_path_); | 233 grandchild_file1_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_); |
| 248 child_file2_path_ = virtual_path.AppendASCII("childlongfile2"); | 234 grandchild_file2_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_); |
| 249 CreateVirtualFile(child_file2_path_); | |
| 250 grandchild_file1_path_ = child_dir_path_.AppendASCII("grchildfile1"); | |
| 251 CreateVirtualFile(grandchild_file1_path_); | |
| 252 grandchild_file2_path_ = child_dir_path_.AppendASCII("grchildlongfile2"); | |
| 253 CreateVirtualFile(grandchild_file2_path_); | |
| 254 } | 235 } |
| 255 | 236 |
| 256 TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { | 237 TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { |
| 257 FilePath src_dir_path = FilePath(FILE_PATH_LITERAL("src")); | 238 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 258 CreateVirtualDirectory(src_dir_path); | |
| 259 PrepareFileSet(src_dir_path); | 239 PrepareFileSet(src_dir_path); |
| 260 FilePath dest_dir_path = FilePath(FILE_PATH_LITERAL("dest")); | 240 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 261 CreateVirtualDirectory(dest_dir_path); | |
| 262 | 241 |
| 263 EXPECT_EQ(0, ActualSize()); | 242 EXPECT_EQ(0, ActualSize()); |
| 264 | 243 |
| 265 operation()->Truncate(URLForPath(child_file1_path_), 5000); | 244 operation()->Truncate(URLForPath(child_file1_path_), 5000); |
| 266 operation()->Truncate(URLForPath(child_file2_path_), 400); | 245 operation()->Truncate(URLForPath(child_file2_path_), 400); |
| 267 operation()->Truncate(URLForPath(grandchild_file1_path_), 30); | 246 operation()->Truncate(URLForPath(grandchild_file1_path_), 30); |
| 268 operation()->Truncate(URLForPath(grandchild_file2_path_), 2); | 247 operation()->Truncate(URLForPath(grandchild_file2_path_), 2); |
| 269 MessageLoop::current()->RunAllPending(); | 248 MessageLoop::current()->RunAllPending(); |
| 270 | 249 |
| 271 const int64 all_file_size = 5000 + 400 + 30 + 2; | 250 const int64 all_file_size = 5000 + 400 + 30 + 2; |
| 272 const int64 usage_file_size = FileSystemUsageCache::kUsageFileSize; | |
| 273 | 251 |
| 274 EXPECT_EQ(all_file_size, ActualSize()); | 252 EXPECT_EQ(all_file_size, ActualSize()); |
| 275 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), | 253 EXPECT_EQ(all_file_size, SizeInUsageFile()); |
| 276 SizeInUsageFile()); | |
| 277 GetUsageAndQuotaFromQuotaManager(); | 254 GetUsageAndQuotaFromQuotaManager(); |
| 278 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 255 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 279 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage()); | 256 EXPECT_EQ(all_file_size, usage()); |
| 280 ASSERT_LT(all_file_size, quota()); | 257 ASSERT_LT(all_file_size, quota()); |
| 281 | 258 |
| 282 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 259 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); |
| 283 MessageLoop::current()->RunAllPending(); | 260 MessageLoop::current()->RunAllPending(); |
| 284 AddToFilePathCost(-ComputeFilePathCost(src_dir_path)); | |
| 285 | 261 |
| 286 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 262 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 287 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( | 263 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( |
| 288 child_dir_path_.BaseName()))); | 264 child_dir_path_.BaseName()))); |
| 289 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( | 265 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( |
| 290 child_dir_path_.BaseName()).Append( | 266 child_dir_path_.BaseName()).Append( |
| 291 grandchild_file1_path_.BaseName()))); | 267 grandchild_file1_path_.BaseName()))); |
| 292 | 268 |
| 293 EXPECT_EQ(all_file_size, ActualSize()); | 269 EXPECT_EQ(all_file_size, ActualSize()); |
| 294 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), | 270 EXPECT_EQ(all_file_size, SizeInUsageFile()); |
| 295 SizeInUsageFile()); | |
| 296 GetUsageAndQuotaFromQuotaManager(); | 271 GetUsageAndQuotaFromQuotaManager(); |
| 297 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 272 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 298 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage()); | 273 EXPECT_EQ(all_file_size, usage()); |
| 299 ASSERT_LT(all_file_size, quota()); | 274 ASSERT_LT(all_file_size, quota()); |
| 300 } | 275 } |
| 301 | 276 |
| 302 TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { | 277 TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { |
| 303 FilePath src_dir_path = FilePath(FILE_PATH_LITERAL("src")); | 278 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 304 CreateVirtualDirectory(src_dir_path); | |
| 305 PrepareFileSet(src_dir_path); | 279 PrepareFileSet(src_dir_path); |
| 306 FilePath dest_dir1_path = FilePath(FILE_PATH_LITERAL("dest1")); | 280 FilePath dest_dir1_path(CreateVirtualTemporaryDir()); |
| 307 CreateVirtualDirectory(dest_dir1_path); | 281 FilePath dest_dir2_path(CreateVirtualTemporaryDir()); |
| 308 FilePath dest_dir2_path = FilePath(FILE_PATH_LITERAL("destnonexisting2")); | |
| 309 | 282 |
| 310 EXPECT_EQ(0, ActualSize()); | 283 EXPECT_EQ(0, ActualSize()); |
| 311 | 284 |
| 312 operation()->Truncate(URLForPath(child_file1_path_), 8000); | 285 operation()->Truncate(URLForPath(child_file1_path_), 8000); |
| 313 operation()->Truncate(URLForPath(child_file2_path_), 700); | 286 operation()->Truncate(URLForPath(child_file2_path_), 700); |
| 314 operation()->Truncate(URLForPath(grandchild_file1_path_), 60); | 287 operation()->Truncate(URLForPath(grandchild_file1_path_), 60); |
| 315 operation()->Truncate(URLForPath(grandchild_file2_path_), 5); | 288 operation()->Truncate(URLForPath(grandchild_file2_path_), 5); |
| 316 MessageLoop::current()->RunAllPending(); | 289 MessageLoop::current()->RunAllPending(); |
| 317 | 290 |
| 318 const int64 child_file_size = 8000 + 700; | 291 const int64 child_file_size = 8000 + 700; |
| 319 const int64 grandchild_file_size = 60 + 5; | 292 const int64 grandchild_file_size = 60 + 5; |
| 320 const int64 all_file_size = child_file_size + grandchild_file_size; | 293 const int64 all_file_size = child_file_size + grandchild_file_size; |
| 321 const int64 usage_file_size = FileSystemUsageCache::kUsageFileSize; | |
| 322 | 294 |
| 323 EXPECT_EQ(all_file_size, ActualSize()); | 295 EXPECT_EQ(all_file_size, ActualSize()); |
| 324 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), | 296 EXPECT_EQ(all_file_size, SizeInUsageFile()); |
| 325 SizeInUsageFile()); | |
| 326 GetUsageAndQuotaFromQuotaManager(); | 297 GetUsageAndQuotaFromQuotaManager(); |
| 327 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 298 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 328 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage()); | 299 EXPECT_EQ(all_file_size, usage()); |
| 329 ASSERT_LT(all_file_size, quota()); | 300 ASSERT_LT(all_file_size, quota()); |
| 330 | 301 |
| 331 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path)); | 302 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path)); |
| 332 MessageLoop::current()->RunAllPending(); | 303 MessageLoop::current()->RunAllPending(); |
| 333 AddToFilePathCost(ComputeFilePathCost(child_dir_path_) + | |
| 334 ComputeFilePathCost(child_file1_path_) + | |
| 335 ComputeFilePathCost(child_file2_path_) + | |
| 336 ComputeFilePathCost(grandchild_file1_path_) + | |
| 337 ComputeFilePathCost(grandchild_file2_path_)); | |
| 338 | 304 |
| 339 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 305 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 340 EXPECT_TRUE(VirtualDirectoryExists(src_dir_path.Append( | 306 EXPECT_TRUE(VirtualDirectoryExists(src_dir_path.Append( |
| 341 child_dir_path_.BaseName()))); | 307 child_dir_path_.BaseName()))); |
| 342 EXPECT_TRUE(VirtualFileExists(src_dir_path.Append( | 308 EXPECT_TRUE(VirtualFileExists(src_dir_path.Append( |
| 343 child_dir_path_.BaseName()).Append( | 309 child_dir_path_.BaseName()).Append( |
| 344 grandchild_file1_path_.BaseName()))); | 310 grandchild_file1_path_.BaseName()))); |
| 345 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 311 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 346 EXPECT_TRUE(VirtualDirectoryExists(dest_dir1_path.Append( | 312 EXPECT_TRUE(VirtualDirectoryExists(dest_dir1_path.Append( |
| 347 child_dir_path_.BaseName()))); | 313 child_dir_path_.BaseName()))); |
| 348 EXPECT_TRUE(VirtualFileExists(dest_dir1_path.Append( | 314 EXPECT_TRUE(VirtualFileExists(dest_dir1_path.Append( |
| 349 child_dir_path_.BaseName()).Append( | 315 child_dir_path_.BaseName()).Append( |
| 350 grandchild_file1_path_.BaseName()))); | 316 grandchild_file1_path_.BaseName()))); |
| 351 | 317 |
| 352 EXPECT_EQ(2 * all_file_size, ActualSize()); | 318 EXPECT_EQ(2 * all_file_size, ActualSize()); |
| 353 EXPECT_EQ(2 * all_file_size + usage_file_size + file_path_cost(), | 319 EXPECT_EQ(2 * all_file_size, SizeInUsageFile()); |
| 354 SizeInUsageFile()); | |
| 355 GetUsageAndQuotaFromQuotaManager(); | 320 GetUsageAndQuotaFromQuotaManager(); |
| 356 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 321 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 357 EXPECT_EQ(2 * all_file_size + usage_file_size + file_path_cost(), usage()); | 322 EXPECT_EQ(2 * all_file_size, usage()); |
| 358 ASSERT_LT(2 * all_file_size, quota()); | 323 ASSERT_LT(2 * all_file_size, quota()); |
| 359 | 324 |
| 360 operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path)); | 325 operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path)); |
| 361 MessageLoop::current()->RunAllPending(); | 326 MessageLoop::current()->RunAllPending(); |
| 362 AddToFilePathCost(ComputeFilePathCost(dest_dir2_path) + | |
| 363 ComputeFilePathCost(grandchild_file1_path_) + | |
| 364 ComputeFilePathCost(grandchild_file2_path_)); | |
| 365 | 327 |
| 366 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 328 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 367 | 329 |
| 368 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, | 330 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualSize()); |
| 369 ActualSize()); | 331 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, SizeInUsageFile()); |
| 370 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size + | |
| 371 file_path_cost(), SizeInUsageFile()); | |
| 372 GetUsageAndQuotaFromQuotaManager(); | 332 GetUsageAndQuotaFromQuotaManager(); |
| 373 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 333 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 374 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size + | 334 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, usage()); |
| 375 file_path_cost(), usage()); | |
| 376 ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota()); | 335 ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota()); |
| 377 } | 336 } |
| 378 | 337 |
| 379 void FileSystemObfuscatedQuotaTest::SetUp() { | |
| 380 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); | |
| 381 FilePath filesystem_dir_path = work_dir_.path().AppendASCII("filesystem"); | |
| 382 file_util::CreateDirectory(filesystem_dir_path); | |
| 383 | |
| 384 quota_manager_ = new quota::QuotaManager( | |
| 385 false /* is_incognito */, | |
| 386 filesystem_dir_path, | |
| 387 base::MessageLoopProxy::current(), | |
| 388 base::MessageLoopProxy::current(), | |
| 389 NULL); | |
| 390 | |
| 391 file_system_context_ = new FileSystemContext( | |
| 392 base::MessageLoopProxy::current(), | |
| 393 base::MessageLoopProxy::current(), | |
| 394 new quota::MockSpecialStoragePolicy(), | |
| 395 quota_manager_->proxy(), | |
| 396 filesystem_dir_path, | |
| 397 false /* incognito */, | |
| 398 true /* allow_file_access_from_files */, | |
| 399 false /* unlimitedquota */, | |
| 400 NULL); | |
| 401 | |
| 402 test_helper_.SetUp(file_system_context_, | |
| 403 NULL /* sandbox_provider's internal file_util */); | |
| 404 } | |
| 405 | |
| 406 TEST_F(FileSystemObfuscatedQuotaTest, TestRevokeUsageCache) { | |
| 407 FilePath dir_path = FilePath(FILE_PATH_LITERAL("test")); | |
| 408 CreateVirtualDirectory(dir_path); | |
| 409 PrepareFileSet(dir_path); | |
| 410 | |
| 411 operation()->Truncate(URLForPath(child_file1_path_), 3000); | |
| 412 operation()->Truncate(URLForPath(child_file2_path_), 400); | |
| 413 operation()->Truncate(URLForPath(grandchild_file1_path_), 10); | |
| 414 operation()->Truncate(URLForPath(grandchild_file2_path_), 6); | |
| 415 MessageLoop::current()->RunAllPending(); | |
| 416 | |
| 417 const int64 all_file_size = 3000 + 400 + 10 + 6; | |
| 418 | |
| 419 EXPECT_EQ(all_file_size + file_path_cost(), SizeInUsageFile()); | |
| 420 GetUsageAndQuotaFromQuotaManager(); | |
| 421 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | |
| 422 EXPECT_EQ(all_file_size + file_path_cost(), usage()); | |
| 423 ASSERT_LT(all_file_size, quota()); | |
| 424 | |
| 425 RevokeUsageCache(); | |
| 426 EXPECT_EQ(-1, SizeInUsageFile()); | |
| 427 | |
| 428 GetUsageAndQuotaFromQuotaManager(); | |
| 429 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | |
| 430 EXPECT_EQ(all_file_size + file_path_cost(), SizeInUsageFile()); | |
| 431 EXPECT_EQ(all_file_size + file_path_cost(), usage()); | |
| 432 ASSERT_LT(all_file_size, quota()); | |
| 433 } | |
| 434 | |
| 435 } // namespace fileapi | 338 } // namespace fileapi |
| OLD | NEW |