Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/fileapi/file_system_operation_impl.h" | 5 #include "webkit/browser/fileapi/file_system_operation_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 using storage::QuotaManager; | 37 using storage::QuotaManager; |
| 38 using storage::QuotaManagerProxy; | 38 using storage::QuotaManagerProxy; |
| 39 using storage::ShareableFileReference; | 39 using storage::ShareableFileReference; |
| 40 | 40 |
| 41 namespace content { | 41 namespace content { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 const int kFileOperationStatusNotSet = 1; | 45 const int kFileOperationStatusNotSet = 1; |
| 46 | 46 |
| 47 void AssertFileErrorEq(const tracked_objects::Location& from_here, | |
| 48 base::File::Error expected, | |
| 49 base::File::Error actual) { | |
| 50 ASSERT_EQ(expected, actual) << from_here.ToString(); | |
| 51 } | |
| 52 | |
| 53 void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here, | |
| 54 base::File::Error expected, | |
| 55 base::Closure closure, | |
| 56 base::File::Error actual) { | |
| 57 ASSERT_EQ(expected, actual) << from_here.ToString(); | |
| 58 closure.Run(); | |
| 59 } | |
| 60 | |
| 61 } // namespace | 47 } // namespace |
| 62 | 48 |
| 63 // Test class for FileSystemOperationImpl. | 49 // Test class for FileSystemOperationImpl. |
| 64 class FileSystemOperationImplTest | 50 class FileSystemOperationImplTest |
| 65 : public testing::Test { | 51 : public testing::Test { |
| 66 public: | 52 public: |
| 67 FileSystemOperationImplTest() | 53 FileSystemOperationImplTest() |
| 68 : status_(kFileOperationStatusNotSet), | 54 : status_(kFileOperationStatusNotSet), |
| 69 weak_factory_(this) {} | 55 weak_factory_(this) {} |
| 70 | 56 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 return url; | 159 return url; |
| 174 } | 160 } |
| 175 | 161 |
| 176 int64 GetFileSize(const std::string& path) { | 162 int64 GetFileSize(const std::string& path) { |
| 177 base::File::Info info; | 163 base::File::Info info; |
| 178 EXPECT_TRUE(base::GetFileInfo(PlatformPath(path), &info)); | 164 EXPECT_TRUE(base::GetFileInfo(PlatformPath(path), &info)); |
| 179 return info.size; | 165 return info.size; |
| 180 } | 166 } |
| 181 | 167 |
| 182 // Callbacks for recording test results. | 168 // Callbacks for recording test results. |
| 183 FileSystemOperation::StatusCallback RecordStatusCallback() { | 169 FileSystemOperation::StatusCallback RecordStatusCallback( |
| 170 const base::Closure& closure) { | |
|
tzik
2014/09/11 03:30:09
These *Callback() functions seems simple enough.
C
iseki
2014/09/11 06:03:13
Done.
| |
| 184 return base::Bind(&FileSystemOperationImplTest::DidFinish, | 171 return base::Bind(&FileSystemOperationImplTest::DidFinish, |
| 185 weak_factory_.GetWeakPtr()); | 172 weak_factory_.GetWeakPtr(), |
| 173 closure); | |
| 186 } | 174 } |
| 187 | 175 |
| 188 FileSystemOperation::ReadDirectoryCallback | 176 FileSystemOperation::ReadDirectoryCallback RecordReadDirectoryCallback( |
| 189 RecordReadDirectoryCallback() { | 177 const base::Closure& closure) { |
| 190 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory, | 178 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory, |
| 191 weak_factory_.GetWeakPtr()); | 179 weak_factory_.GetWeakPtr(), |
| 180 closure); | |
| 192 } | 181 } |
| 193 | 182 |
| 194 FileSystemOperation::GetMetadataCallback RecordMetadataCallback() { | 183 FileSystemOperation::GetMetadataCallback RecordMetadataCallback( |
| 184 const base::Closure& closure) { | |
| 195 return base::Bind(&FileSystemOperationImplTest::DidGetMetadata, | 185 return base::Bind(&FileSystemOperationImplTest::DidGetMetadata, |
| 196 weak_factory_.GetWeakPtr()); | 186 weak_factory_.GetWeakPtr(), |
| 187 closure); | |
| 197 } | 188 } |
| 198 | 189 |
| 199 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() { | 190 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback( |
| 191 const base::Closure& closure) { | |
| 200 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, | 192 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, |
| 201 weak_factory_.GetWeakPtr()); | 193 weak_factory_.GetWeakPtr(), |
| 194 closure); | |
| 202 } | 195 } |
| 203 | 196 |
| 204 void DidFinish(base::File::Error status) { | 197 void DidFinish(const base::Closure& closure, base::File::Error status) { |
| 205 status_ = status; | 198 status_ = status; |
| 199 closure.Run(); | |
| 206 } | 200 } |
| 207 | 201 |
| 208 void DidReadDirectory(base::File::Error status, | 202 void DidReadDirectory(const base::Closure& closure, |
| 203 base::File::Error status, | |
| 209 const std::vector<storage::DirectoryEntry>& entries, | 204 const std::vector<storage::DirectoryEntry>& entries, |
| 210 bool /* has_more */) { | 205 bool /* has_more */) { |
| 211 entries_ = entries; | 206 entries_ = entries; |
| 212 status_ = status; | 207 status_ = status; |
| 208 closure.Run(); | |
| 213 } | 209 } |
| 214 | 210 |
| 215 void DidGetMetadata(base::File::Error status, | 211 void DidGetMetadata(const base::Closure& closure, |
| 212 base::File::Error status, | |
| 216 const base::File::Info& info) { | 213 const base::File::Info& info) { |
| 217 info_ = info; | 214 info_ = info; |
| 218 status_ = status; | 215 status_ = status; |
| 216 closure.Run(); | |
| 219 } | 217 } |
| 220 | 218 |
| 221 void DidCreateSnapshotFile( | 219 void DidCreateSnapshotFile( |
| 220 const base::Closure& closure, | |
| 222 base::File::Error status, | 221 base::File::Error status, |
| 223 const base::File::Info& info, | 222 const base::File::Info& info, |
| 224 const base::FilePath& platform_path, | 223 const base::FilePath& platform_path, |
| 225 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { | 224 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { |
| 226 info_ = info; | 225 info_ = info; |
| 227 path_ = platform_path; | 226 path_ = platform_path; |
| 228 status_ = status; | 227 status_ = status; |
| 229 shareable_file_ref_ = shareable_file_ref; | 228 shareable_file_ref_ = shareable_file_ref; |
| 229 closure.Run(); | |
| 230 } | 230 } |
| 231 | 231 |
| 232 int64 GetDataSizeOnDisk() { | 232 int64 GetDataSizeOnDisk() { |
| 233 return sandbox_file_system_.ComputeCurrentOriginUsage() - | 233 return sandbox_file_system_.ComputeCurrentOriginUsage() - |
| 234 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); | 234 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void GetUsageAndQuota(int64* usage, int64* quota) { | 237 void GetUsageAndQuota(int64* usage, int64* quota) { |
| 238 storage::QuotaStatusCode status = | 238 storage::QuotaStatusCode status = |
| 239 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), | 239 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), |
| 240 sandbox_file_system_.origin(), | 240 sandbox_file_system_.origin(), |
| 241 sandbox_file_system_.type(), | 241 sandbox_file_system_.type(), |
| 242 usage, | 242 usage, |
| 243 quota); | 243 quota); |
| 244 base::RunLoop().RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
| 245 ASSERT_EQ(storage::kQuotaStatusOk, status); | 245 ASSERT_EQ(storage::kQuotaStatusOk, status); |
| 246 } | 246 } |
| 247 | 247 |
| 248 int64 ComputePathCost(const FileSystemURL& url) { | 248 int64 ComputePathCost(const FileSystemURL& url) { |
| 249 int64 base_usage; | 249 int64 base_usage; |
| 250 GetUsageAndQuota(&base_usage, NULL); | 250 GetUsageAndQuota(&base_usage, NULL); |
| 251 | 251 |
| 252 AsyncFileTestHelper::CreateFile( | 252 AsyncFileTestHelper::CreateFile( |
| 253 sandbox_file_system_.file_system_context(), url); | 253 sandbox_file_system_.file_system_context(), url); |
| 254 operation_runner()->Remove(url, false /* recursive */, | 254 EXPECT_EQ(RemoveTest(url, false /* recursive */), base::File::FILE_OK); |
|
tzik
2014/09/11 03:30:09
For better macro output, please swap RemoveTest()
iseki
2014/09/11 06:03:13
Done.
| |
| 255 base::Bind(&AssertFileErrorEq, FROM_HERE, | 255 |
| 256 base::File::FILE_OK)); | |
| 257 base::RunLoop().RunUntilIdle(); | |
| 258 change_observer()->ResetCount(); | 256 change_observer()->ResetCount(); |
| 259 | 257 |
| 260 int64 total_usage; | 258 int64 total_usage; |
| 261 GetUsageAndQuota(&total_usage, NULL); | 259 GetUsageAndQuota(&total_usage, NULL); |
| 262 return total_usage - base_usage; | 260 return total_usage - base_usage; |
| 263 } | 261 } |
| 264 | 262 |
| 265 void GrantQuotaForCurrentUsage() { | 263 void GrantQuotaForCurrentUsage() { |
| 266 int64 usage; | 264 int64 usage; |
| 267 GetUsageAndQuota(&usage, NULL); | 265 GetUsageAndQuota(&usage, NULL); |
| 268 quota_manager()->SetQuota(sandbox_file_system_.origin(), | 266 quota_manager()->SetQuota(sandbox_file_system_.origin(), |
| 269 sandbox_file_system_.storage_type(), | 267 sandbox_file_system_.storage_type(), |
| 270 usage); | 268 usage); |
| 271 } | 269 } |
| 272 | 270 |
| 273 int64 GetUsage() { | 271 int64 GetUsage() { |
| 274 int64 usage = 0; | 272 int64 usage = 0; |
| 275 GetUsageAndQuota(&usage, NULL); | 273 GetUsageAndQuota(&usage, NULL); |
| 276 return usage; | 274 return usage; |
| 277 } | 275 } |
| 278 | 276 |
| 279 void AddQuota(int64 quota_delta) { | 277 void AddQuota(int64 quota_delta) { |
| 280 int64 quota; | 278 int64 quota; |
| 281 GetUsageAndQuota(NULL, "a); | 279 GetUsageAndQuota(NULL, "a); |
| 282 quota_manager()->SetQuota(sandbox_file_system_.origin(), | 280 quota_manager()->SetQuota(sandbox_file_system_.origin(), |
| 283 sandbox_file_system_.storage_type(), | 281 sandbox_file_system_.storage_type(), |
| 284 quota + quota_delta); | 282 quota + quota_delta); |
| 285 } | 283 } |
| 286 | 284 |
| 285 int MoveTest(const FileSystemURL& src, | |
|
tzik
2014/09/11 03:30:09
s/int/base::File::Error/?
Could you remove "Test"
iseki
2014/09/11 06:03:13
Done.
| |
| 286 const FileSystemURL& dest, | |
| 287 storage::FileSystemOperation::CopyOrMoveOption option) { | |
| 288 base::RunLoop run_loop; | |
| 289 operation_runner()->Move( | |
| 290 src, dest, option, RecordStatusCallback(run_loop.QuitClosure())); | |
|
tzik
2014/09/11 03:30:09
How about:
- Define a local variable for |status|
iseki
2014/09/11 06:03:13
Done.
| |
| 291 run_loop.Run(); | |
| 292 return status_; | |
| 293 } | |
| 294 | |
| 295 int CopyTest(const FileSystemURL& src, | |
| 296 const FileSystemURL& dest, | |
| 297 storage::FileSystemOperation::CopyOrMoveOption option) { | |
| 298 base::RunLoop run_loop; | |
| 299 operation_runner()->Copy(src, | |
| 300 dest, | |
| 301 option, | |
| 302 FileSystemOperationRunner::CopyProgressCallback(), | |
| 303 RecordStatusCallback(run_loop.QuitClosure())); | |
| 304 run_loop.Run(); | |
| 305 return status_; | |
| 306 } | |
| 307 | |
| 308 int CopyInForeignFileTest(const base::FilePath& src, | |
| 309 const FileSystemURL& dest) { | |
| 310 base::RunLoop run_loop; | |
| 311 operation_runner()->CopyInForeignFile( | |
| 312 src, dest, RecordStatusCallback(run_loop.QuitClosure())); | |
| 313 run_loop.Run(); | |
| 314 return status_; | |
| 315 } | |
| 316 | |
| 317 int TruncateTest(const FileSystemURL& url, int size) { | |
| 318 base::RunLoop run_loop; | |
| 319 operation_runner()->Truncate( | |
| 320 url, size, RecordStatusCallback(run_loop.QuitClosure())); | |
| 321 run_loop.Run(); | |
| 322 return status_; | |
| 323 } | |
| 324 | |
| 325 int CreateFileTest(const FileSystemURL& url, bool exclusive) { | |
| 326 base::RunLoop run_loop; | |
| 327 operation_runner()->CreateFile( | |
| 328 url, exclusive, RecordStatusCallback(run_loop.QuitClosure())); | |
| 329 run_loop.Run(); | |
| 330 return status_; | |
| 331 } | |
| 332 | |
| 333 int RemoveTest(const FileSystemURL& url, bool recursive) { | |
| 334 base::RunLoop run_loop; | |
| 335 operation_runner()->Remove( | |
| 336 url, recursive, RecordStatusCallback(run_loop.QuitClosure())); | |
| 337 run_loop.Run(); | |
| 338 return status_; | |
| 339 } | |
| 340 | |
| 341 int CreateDirectoryTest(const FileSystemURL& url, | |
| 342 bool exclusive, | |
| 343 bool recursive) { | |
| 344 base::RunLoop run_loop; | |
| 345 operation_runner()->CreateDirectory( | |
| 346 url, | |
| 347 exclusive, | |
| 348 recursive, | |
| 349 RecordStatusCallback(run_loop.QuitClosure())); | |
| 350 run_loop.Run(); | |
| 351 return status_; | |
| 352 } | |
| 353 | |
| 354 int GetMetadataTest(const FileSystemURL& url) { | |
| 355 base::RunLoop run_loop; | |
| 356 operation_runner()->GetMetadata( | |
| 357 url, RecordMetadataCallback(run_loop.QuitClosure())); | |
| 358 run_loop.Run(); | |
| 359 return status_; | |
| 360 } | |
| 361 | |
| 362 int ReadDirectoryTest(const FileSystemURL& url) { | |
| 363 base::RunLoop run_loop; | |
| 364 operation_runner()->ReadDirectory( | |
| 365 url, RecordReadDirectoryCallback(run_loop.QuitClosure())); | |
| 366 run_loop.Run(); | |
| 367 return status_; | |
| 368 } | |
| 369 | |
| 370 int CreateSnapshotFileTest(const FileSystemURL& url) { | |
| 371 base::RunLoop run_loop; | |
| 372 operation_runner()->CreateSnapshotFile( | |
| 373 url, RecordSnapshotFileCallback(run_loop.QuitClosure())); | |
| 374 run_loop.Run(); | |
| 375 return status_; | |
| 376 } | |
| 377 | |
| 378 int FileExistsTest(const FileSystemURL& url) { | |
| 379 base::RunLoop run_loop; | |
| 380 operation_runner()->FileExists( | |
| 381 url, RecordStatusCallback(run_loop.QuitClosure())); | |
| 382 run_loop.Run(); | |
| 383 return status_; | |
| 384 } | |
| 385 | |
| 386 int DirectoryExistsTest(const FileSystemURL& url) { | |
| 387 base::RunLoop run_loop; | |
| 388 operation_runner()->DirectoryExists( | |
| 389 url, RecordStatusCallback(run_loop.QuitClosure())); | |
| 390 run_loop.Run(); | |
| 391 return status_; | |
| 392 } | |
| 393 | |
| 394 int TouchFileTest(const FileSystemURL& url, | |
| 395 const base::Time& last_access_time, | |
| 396 const base::Time& last_modified_time) { | |
| 397 base::RunLoop run_loop; | |
| 398 operation_runner()->TouchFile(url, | |
| 399 last_access_time, | |
| 400 last_modified_time, | |
| 401 RecordStatusCallback(run_loop.QuitClosure())); | |
| 402 run_loop.Run(); | |
| 403 return status_; | |
| 404 } | |
| 405 | |
| 287 private: | 406 private: |
| 288 base::MessageLoopForIO message_loop_; | 407 base::MessageLoopForIO message_loop_; |
| 289 scoped_refptr<QuotaManager> quota_manager_; | 408 scoped_refptr<QuotaManager> quota_manager_; |
| 290 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 409 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
| 291 | 410 |
| 292 // Common temp base for nondestructive uses. | 411 // Common temp base for nondestructive uses. |
| 293 base::ScopedTempDir base_; | 412 base::ScopedTempDir base_; |
| 294 | 413 |
| 295 SandboxFileSystemTestHelper sandbox_file_system_; | 414 SandboxFileSystemTestHelper sandbox_file_system_; |
| 296 | 415 |
| 297 // For post-operation status. | 416 // For post-operation status. |
| 298 int status_; | 417 int status_; |
| 299 base::File::Info info_; | 418 base::File::Info info_; |
| 300 base::FilePath path_; | 419 base::FilePath path_; |
| 301 std::vector<storage::DirectoryEntry> entries_; | 420 std::vector<storage::DirectoryEntry> entries_; |
| 302 scoped_refptr<ShareableFileReference> shareable_file_ref_; | 421 scoped_refptr<ShareableFileReference> shareable_file_ref_; |
| 303 | 422 |
| 304 storage::MockFileChangeObserver change_observer_; | 423 storage::MockFileChangeObserver change_observer_; |
| 305 storage::ChangeObserverList change_observers_; | 424 storage::ChangeObserverList change_observers_; |
| 306 | 425 |
| 307 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; | 426 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; |
| 308 | 427 |
| 309 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); | 428 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); |
| 310 }; | 429 }; |
| 311 | 430 |
| 312 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { | 431 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { |
| 313 change_observer()->ResetCount(); | 432 change_observer()->ResetCount(); |
| 314 operation_runner()->Move(URLForPath("a"), URLForPath("b"), | 433 EXPECT_EQ( |
| 315 FileSystemOperation::OPTION_NONE, | 434 MoveTest( |
| 316 RecordStatusCallback()); | 435 URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE), |
| 317 base::RunLoop().RunUntilIdle(); | 436 base::File::FILE_ERROR_NOT_FOUND); |
| 318 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 319 EXPECT_TRUE(change_observer()->HasNoChange()); | 437 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 320 } | 438 } |
| 321 | 439 |
| 322 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { | 440 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { |
| 323 FileSystemURL src_dir(CreateDirectory("src")); | 441 FileSystemURL src_dir(CreateDirectory("src")); |
| 324 FileSystemURL dest_dir(CreateDirectory("src/dest")); | 442 FileSystemURL dest_dir(CreateDirectory("src/dest")); |
| 325 | 443 |
| 326 operation_runner()->Move(src_dir, dest_dir, | 444 EXPECT_EQ(MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE), |
| 327 FileSystemOperation::OPTION_NONE, | 445 base::File::FILE_ERROR_INVALID_OPERATION); |
| 328 RecordStatusCallback()); | |
| 329 base::RunLoop().RunUntilIdle(); | |
| 330 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
| 331 EXPECT_TRUE(change_observer()->HasNoChange()); | 446 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 332 } | 447 } |
| 333 | 448 |
| 334 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { | 449 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { |
| 335 // Src exists and is dir. Dest is a file. | 450 // Src exists and is dir. Dest is a file. |
| 336 FileSystemURL src_dir(CreateDirectory("src")); | 451 FileSystemURL src_dir(CreateDirectory("src")); |
| 337 FileSystemURL dest_dir(CreateDirectory("dest")); | 452 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 338 FileSystemURL dest_file(CreateFile("dest/file")); | 453 FileSystemURL dest_file(CreateFile("dest/file")); |
| 339 | 454 |
| 340 operation_runner()->Move(src_dir, dest_file, | 455 EXPECT_EQ(MoveTest(src_dir, dest_file, FileSystemOperation::OPTION_NONE), |
| 341 FileSystemOperation::OPTION_NONE, | 456 base::File::FILE_ERROR_INVALID_OPERATION); |
| 342 RecordStatusCallback()); | |
| 343 base::RunLoop().RunUntilIdle(); | |
| 344 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
| 345 EXPECT_TRUE(change_observer()->HasNoChange()); | 457 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 346 } | 458 } |
| 347 | 459 |
| 348 TEST_F(FileSystemOperationImplTest, | 460 TEST_F(FileSystemOperationImplTest, |
| 349 TestMoveFailureSrcFileExistsDestNonEmptyDir) { | 461 TestMoveFailureSrcFileExistsDestNonEmptyDir) { |
| 350 // Src exists and is a directory. Dest is a non-empty directory. | 462 // Src exists and is a directory. Dest is a non-empty directory. |
| 351 FileSystemURL src_dir(CreateDirectory("src")); | 463 FileSystemURL src_dir(CreateDirectory("src")); |
| 352 FileSystemURL dest_dir(CreateDirectory("dest")); | 464 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 353 FileSystemURL dest_file(CreateFile("dest/file")); | 465 FileSystemURL dest_file(CreateFile("dest/file")); |
| 354 | 466 |
| 355 operation_runner()->Move(src_dir, dest_dir, | 467 EXPECT_EQ(MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE), |
| 356 FileSystemOperation::OPTION_NONE, | 468 base::File::FILE_ERROR_NOT_EMPTY); |
| 357 RecordStatusCallback()); | |
| 358 base::RunLoop().RunUntilIdle(); | |
| 359 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); | |
| 360 EXPECT_TRUE(change_observer()->HasNoChange()); | 469 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 361 } | 470 } |
| 362 | 471 |
| 363 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { | 472 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { |
| 364 // Src exists and is a file. Dest is a directory. | 473 // Src exists and is a file. Dest is a directory. |
| 365 FileSystemURL src_dir(CreateDirectory("src")); | 474 FileSystemURL src_dir(CreateDirectory("src")); |
| 366 FileSystemURL src_file(CreateFile("src/file")); | 475 FileSystemURL src_file(CreateFile("src/file")); |
| 367 FileSystemURL dest_dir(CreateDirectory("dest")); | 476 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 368 | 477 |
| 369 operation_runner()->Move(src_file, dest_dir, | 478 EXPECT_EQ(MoveTest(src_file, dest_dir, FileSystemOperation::OPTION_NONE), |
| 370 FileSystemOperation::OPTION_NONE, | 479 base::File::FILE_ERROR_INVALID_OPERATION); |
| 371 RecordStatusCallback()); | |
| 372 base::RunLoop().RunUntilIdle(); | |
| 373 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
| 374 EXPECT_TRUE(change_observer()->HasNoChange()); | 480 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 375 } | 481 } |
| 376 | 482 |
| 377 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { | 483 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { |
| 378 // Dest. parent path does not exist. | 484 // Dest. parent path does not exist. |
| 379 FileSystemURL src_dir(CreateDirectory("src")); | 485 FileSystemURL src_dir(CreateDirectory("src")); |
| 380 operation_runner()->Move(src_dir, URLForPath("nonexistent/deset"), | 486 EXPECT_EQ(MoveTest(src_dir, |
| 381 FileSystemOperation::OPTION_NONE, | 487 URLForPath("nonexistent/deset"), |
| 382 RecordStatusCallback()); | 488 FileSystemOperation::OPTION_NONE), |
| 383 base::RunLoop().RunUntilIdle(); | 489 base::File::FILE_ERROR_NOT_FOUND); |
| 384 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 385 EXPECT_TRUE(change_observer()->HasNoChange()); | 490 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 386 } | 491 } |
| 387 | 492 |
| 388 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { | 493 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { |
| 389 FileSystemURL src_file(CreateFile("src")); | 494 FileSystemURL src_file(CreateFile("src")); |
| 390 FileSystemURL dest_file(CreateFile("dest")); | 495 FileSystemURL dest_file(CreateFile("dest")); |
| 391 | 496 |
| 392 operation_runner()->Move(src_file, dest_file, | 497 EXPECT_EQ(MoveTest(src_file, dest_file, FileSystemOperation::OPTION_NONE), |
| 393 FileSystemOperation::OPTION_NONE, | 498 base::File::FILE_OK); |
| 394 RecordStatusCallback()); | |
| 395 base::RunLoop().RunUntilIdle(); | |
| 396 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 397 EXPECT_TRUE(FileExists("dest")); | 499 EXPECT_TRUE(FileExists("dest")); |
| 398 | 500 |
| 399 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 501 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 400 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 502 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 401 EXPECT_TRUE(change_observer()->HasNoChange()); | 503 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 402 | 504 |
| 403 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 505 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 404 } | 506 } |
| 405 | 507 |
| 406 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { | 508 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { |
| 407 FileSystemURL src_file(CreateFile("src")); | 509 FileSystemURL src_file(CreateFile("src")); |
| 408 | 510 |
| 409 operation_runner()->Move(src_file, URLForPath("new"), | 511 EXPECT_EQ( |
| 410 FileSystemOperation::OPTION_NONE, | 512 MoveTest(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE), |
| 411 RecordStatusCallback()); | 513 base::File::FILE_OK); |
| 412 base::RunLoop().RunUntilIdle(); | |
| 413 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 414 EXPECT_TRUE(FileExists("new")); | 514 EXPECT_TRUE(FileExists("new")); |
| 415 | 515 |
| 416 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 516 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| 417 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 517 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 418 EXPECT_TRUE(change_observer()->HasNoChange()); | 518 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 419 } | 519 } |
| 420 | 520 |
| 421 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { | 521 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { |
| 422 FileSystemURL src_dir(CreateDirectory("src")); | 522 FileSystemURL src_dir(CreateDirectory("src")); |
| 423 FileSystemURL dest_dir(CreateDirectory("dest")); | 523 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 424 | 524 |
| 425 operation_runner()->Move(src_dir, dest_dir, | 525 EXPECT_EQ(MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE), |
| 426 FileSystemOperation::OPTION_NONE, | 526 base::File::FILE_OK); |
| 427 RecordStatusCallback()); | |
| 428 base::RunLoop().RunUntilIdle(); | |
| 429 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 430 EXPECT_FALSE(DirectoryExists("src")); | 527 EXPECT_FALSE(DirectoryExists("src")); |
| 431 | 528 |
| 432 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 529 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 433 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 530 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
| 434 EXPECT_TRUE(change_observer()->HasNoChange()); | 531 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 435 | 532 |
| 436 // Make sure we've overwritten but not moved the source under the |dest_dir|. | 533 // Make sure we've overwritten but not moved the source under the |dest_dir|. |
| 437 EXPECT_TRUE(DirectoryExists("dest")); | 534 EXPECT_TRUE(DirectoryExists("dest")); |
| 438 EXPECT_FALSE(DirectoryExists("dest/src")); | 535 EXPECT_FALSE(DirectoryExists("dest/src")); |
| 439 } | 536 } |
| 440 | 537 |
| 441 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { | 538 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { |
| 442 FileSystemURL src_dir(CreateDirectory("src")); | 539 FileSystemURL src_dir(CreateDirectory("src")); |
| 443 FileSystemURL dest_dir(CreateDirectory("dest")); | 540 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 444 | 541 |
| 445 operation_runner()->Move(src_dir, URLForPath("dest/new"), | 542 EXPECT_EQ( |
| 446 FileSystemOperation::OPTION_NONE, | 543 MoveTest( |
| 447 RecordStatusCallback()); | 544 src_dir, URLForPath("dest/new"), FileSystemOperation::OPTION_NONE), |
| 448 base::RunLoop().RunUntilIdle(); | 545 base::File::FILE_OK); |
| 449 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 450 EXPECT_FALSE(DirectoryExists("src")); | 546 EXPECT_FALSE(DirectoryExists("src")); |
| 451 EXPECT_TRUE(DirectoryExists("dest/new")); | 547 EXPECT_TRUE(DirectoryExists("dest/new")); |
| 452 | 548 |
| 453 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 549 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 454 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 550 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 455 EXPECT_TRUE(change_observer()->HasNoChange()); | 551 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 456 } | 552 } |
| 457 | 553 |
| 458 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { | 554 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { |
| 459 FileSystemURL src_dir(CreateDirectory("src")); | 555 FileSystemURL src_dir(CreateDirectory("src")); |
| 460 CreateDirectory("src/dir"); | 556 CreateDirectory("src/dir"); |
| 461 CreateFile("src/dir/sub"); | 557 CreateFile("src/dir/sub"); |
| 462 | 558 |
| 463 FileSystemURL dest_dir(CreateDirectory("dest")); | 559 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 464 | 560 |
| 465 operation_runner()->Move(src_dir, dest_dir, | 561 EXPECT_EQ(MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE), |
| 466 FileSystemOperation::OPTION_NONE, | 562 base::File::FILE_OK); |
| 467 RecordStatusCallback()); | |
| 468 base::RunLoop().RunUntilIdle(); | |
| 469 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 470 EXPECT_TRUE(DirectoryExists("dest/dir")); | 563 EXPECT_TRUE(DirectoryExists("dest/dir")); |
| 471 EXPECT_TRUE(FileExists("dest/dir/sub")); | 564 EXPECT_TRUE(FileExists("dest/dir/sub")); |
| 472 | 565 |
| 473 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); | 566 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); |
| 474 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 567 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
| 475 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 568 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 476 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 569 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| 477 EXPECT_TRUE(change_observer()->HasNoChange()); | 570 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 478 } | 571 } |
| 479 | 572 |
| 480 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { | 573 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { |
| 481 FileSystemURL src_dir(CreateDirectory("src")); | 574 FileSystemURL src_dir(CreateDirectory("src")); |
| 482 CreateDirectory("src/dir"); | 575 CreateDirectory("src/dir"); |
| 483 CreateFile("src/dir/sub"); | 576 CreateFile("src/dir/sub"); |
| 484 | 577 |
| 485 operation_runner()->Move(src_dir, src_dir, | 578 EXPECT_EQ(MoveTest(src_dir, src_dir, FileSystemOperation::OPTION_NONE), |
| 486 FileSystemOperation::OPTION_NONE, | 579 base::File::FILE_OK); |
| 487 RecordStatusCallback()); | |
| 488 base::RunLoop().RunUntilIdle(); | |
| 489 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 490 EXPECT_TRUE(DirectoryExists("src/dir")); | 580 EXPECT_TRUE(DirectoryExists("src/dir")); |
| 491 EXPECT_TRUE(FileExists("src/dir/sub")); | 581 EXPECT_TRUE(FileExists("src/dir/sub")); |
| 492 | 582 |
| 493 EXPECT_EQ(0, change_observer()->get_and_reset_remove_directory_count()); | 583 EXPECT_EQ(0, change_observer()->get_and_reset_remove_directory_count()); |
| 494 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); | 584 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); |
| 495 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); | 585 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); |
| 496 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); | 586 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); |
| 497 EXPECT_TRUE(change_observer()->HasNoChange()); | 587 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 498 } | 588 } |
| 499 | 589 |
| 500 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { | 590 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { |
| 501 operation_runner()->Copy(URLForPath("a"), URLForPath("b"), | 591 EXPECT_EQ( |
| 502 FileSystemOperation::OPTION_NONE, | 592 CopyTest( |
| 503 FileSystemOperationRunner::CopyProgressCallback(), | 593 URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE), |
| 504 RecordStatusCallback()); | 594 base::File::FILE_ERROR_NOT_FOUND); |
| 505 base::RunLoop().RunUntilIdle(); | |
| 506 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 507 EXPECT_TRUE(change_observer()->HasNoChange()); | 595 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 508 } | 596 } |
| 509 | 597 |
| 510 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { | 598 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { |
| 511 FileSystemURL src_dir(CreateDirectory("src")); | 599 FileSystemURL src_dir(CreateDirectory("src")); |
| 512 FileSystemURL dest_dir(CreateDirectory("src/dir")); | 600 FileSystemURL dest_dir(CreateDirectory("src/dir")); |
| 513 | 601 |
| 514 operation_runner()->Copy(src_dir, dest_dir, | 602 EXPECT_EQ(CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE), |
| 515 FileSystemOperation::OPTION_NONE, | 603 base::File::FILE_ERROR_INVALID_OPERATION); |
| 516 FileSystemOperationRunner::CopyProgressCallback(), | |
| 517 RecordStatusCallback()); | |
| 518 base::RunLoop().RunUntilIdle(); | |
| 519 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
| 520 EXPECT_TRUE(change_observer()->HasNoChange()); | 604 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 521 } | 605 } |
| 522 | 606 |
| 523 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { | 607 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { |
| 524 // Src exists and is dir. Dest is a file. | 608 // Src exists and is dir. Dest is a file. |
| 525 FileSystemURL src_dir(CreateDirectory("src")); | 609 FileSystemURL src_dir(CreateDirectory("src")); |
| 526 FileSystemURL dest_dir(CreateDirectory("dest")); | 610 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 527 FileSystemURL dest_file(CreateFile("dest/file")); | 611 FileSystemURL dest_file(CreateFile("dest/file")); |
| 528 | 612 |
| 529 operation_runner()->Copy(src_dir, dest_file, | 613 EXPECT_EQ(CopyTest(src_dir, dest_file, FileSystemOperation::OPTION_NONE), |
| 530 FileSystemOperation::OPTION_NONE, | 614 base::File::FILE_ERROR_INVALID_OPERATION); |
| 531 FileSystemOperationRunner::CopyProgressCallback(), | |
| 532 RecordStatusCallback()); | |
| 533 base::RunLoop().RunUntilIdle(); | |
| 534 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
| 535 EXPECT_TRUE(change_observer()->HasNoChange()); | 615 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 536 } | 616 } |
| 537 | 617 |
| 538 TEST_F(FileSystemOperationImplTest, | 618 TEST_F(FileSystemOperationImplTest, |
| 539 TestCopyFailureSrcFileExistsDestNonEmptyDir) { | 619 TestCopyFailureSrcFileExistsDestNonEmptyDir) { |
| 540 // Src exists and is a directory. Dest is a non-empty directory. | 620 // Src exists and is a directory. Dest is a non-empty directory. |
| 541 FileSystemURL src_dir(CreateDirectory("src")); | 621 FileSystemURL src_dir(CreateDirectory("src")); |
| 542 FileSystemURL dest_dir(CreateDirectory("dest")); | 622 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 543 FileSystemURL dest_file(CreateFile("dest/file")); | 623 FileSystemURL dest_file(CreateFile("dest/file")); |
| 544 | 624 |
| 545 operation_runner()->Copy(src_dir, dest_dir, | 625 EXPECT_EQ(CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE), |
| 546 FileSystemOperation::OPTION_NONE, | 626 base::File::FILE_ERROR_NOT_EMPTY); |
| 547 FileSystemOperationRunner::CopyProgressCallback(), | |
| 548 RecordStatusCallback()); | |
| 549 base::RunLoop().RunUntilIdle(); | |
| 550 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); | |
| 551 EXPECT_TRUE(change_observer()->HasNoChange()); | 627 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 552 } | 628 } |
| 553 | 629 |
| 554 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { | 630 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { |
| 555 // Src exists and is a file. Dest is a directory. | 631 // Src exists and is a file. Dest is a directory. |
| 556 FileSystemURL src_file(CreateFile("src")); | 632 FileSystemURL src_file(CreateFile("src")); |
| 557 FileSystemURL dest_dir(CreateDirectory("dest")); | 633 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 558 | 634 |
| 559 operation_runner()->Copy(src_file, dest_dir, | 635 EXPECT_EQ(CopyTest(src_file, dest_dir, FileSystemOperation::OPTION_NONE), |
| 560 FileSystemOperation::OPTION_NONE, | 636 base::File::FILE_ERROR_INVALID_OPERATION); |
| 561 FileSystemOperationRunner::CopyProgressCallback(), | |
| 562 RecordStatusCallback()); | |
| 563 base::RunLoop().RunUntilIdle(); | |
| 564 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
| 565 EXPECT_TRUE(change_observer()->HasNoChange()); | 637 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 566 } | 638 } |
| 567 | 639 |
| 568 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { | 640 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { |
| 569 // Dest. parent path does not exist. | 641 // Dest. parent path does not exist. |
| 570 FileSystemURL src_dir(CreateDirectory("src")); | 642 FileSystemURL src_dir(CreateDirectory("src")); |
| 571 | 643 |
| 572 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), | 644 EXPECT_EQ(CopyTest(src_dir, |
| 573 FileSystemOperation::OPTION_NONE, | 645 URLForPath("nonexistent/dest"), |
| 574 FileSystemOperationRunner::CopyProgressCallback(), | 646 FileSystemOperation::OPTION_NONE), |
| 575 RecordStatusCallback()); | 647 base::File::FILE_ERROR_NOT_FOUND); |
| 576 base::RunLoop().RunUntilIdle(); | |
| 577 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 578 EXPECT_TRUE(change_observer()->HasNoChange()); | 648 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 579 } | 649 } |
| 580 | 650 |
| 581 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { | 651 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { |
| 582 FileSystemURL src_dir(CreateDirectory("src")); | 652 FileSystemURL src_dir(CreateDirectory("src")); |
| 583 FileSystemURL src_file(CreateFile("src/file")); | 653 FileSystemURL src_file(CreateFile("src/file")); |
| 584 FileSystemURL dest_dir(CreateDirectory("dest")); | 654 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 585 operation_runner()->Truncate(src_file, 6, RecordStatusCallback()); | 655 EXPECT_EQ(TruncateTest(src_file, 6), base::File::FILE_OK); |
| 586 base::RunLoop().RunUntilIdle(); | |
| 587 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 588 EXPECT_EQ(6, GetFileSize("src/file")); | 656 EXPECT_EQ(6, GetFileSize("src/file")); |
| 589 | 657 |
| 590 FileSystemURL dest_file(URLForPath("dest/file")); | 658 FileSystemURL dest_file(URLForPath("dest/file")); |
| 591 int64 dest_path_cost = ComputePathCost(dest_file); | 659 int64 dest_path_cost = ComputePathCost(dest_file); |
| 592 GrantQuotaForCurrentUsage(); | 660 GrantQuotaForCurrentUsage(); |
| 593 AddQuota(6 + dest_path_cost - 1); | 661 AddQuota(6 + dest_path_cost - 1); |
| 594 | 662 |
| 595 operation_runner()->Copy(src_file, dest_file, | 663 EXPECT_EQ(CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE), |
| 596 FileSystemOperation::OPTION_NONE, | 664 base::File::FILE_ERROR_NO_SPACE); |
| 597 FileSystemOperationRunner::CopyProgressCallback(), | |
| 598 RecordStatusCallback()); | |
| 599 base::RunLoop().RunUntilIdle(); | |
| 600 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); | |
| 601 EXPECT_FALSE(FileExists("dest/file")); | 665 EXPECT_FALSE(FileExists("dest/file")); |
| 602 } | 666 } |
| 603 | 667 |
| 604 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { | 668 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { |
| 605 FileSystemURL src_file(CreateFile("src")); | 669 FileSystemURL src_file(CreateFile("src")); |
| 606 FileSystemURL dest_file(CreateFile("dest")); | 670 FileSystemURL dest_file(CreateFile("dest")); |
| 607 | 671 |
| 608 operation_runner()->Copy(src_file, dest_file, | 672 EXPECT_EQ(CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE), |
| 609 FileSystemOperation::OPTION_NONE, | 673 base::File::FILE_OK); |
| 610 FileSystemOperationRunner::CopyProgressCallback(), | 674 |
| 611 RecordStatusCallback()); | |
| 612 base::RunLoop().RunUntilIdle(); | |
| 613 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 614 EXPECT_TRUE(FileExists("dest")); | 675 EXPECT_TRUE(FileExists("dest")); |
| 615 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); | 676 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
| 616 EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count()); | 677 EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count()); |
| 617 | 678 |
| 618 EXPECT_TRUE(change_observer()->HasNoChange()); | 679 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 619 } | 680 } |
| 620 | 681 |
| 621 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { | 682 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { |
| 622 FileSystemURL src_file(CreateFile("src")); | 683 FileSystemURL src_file(CreateFile("src")); |
| 623 | 684 |
| 624 operation_runner()->Copy(src_file, URLForPath("new"), | 685 EXPECT_EQ( |
| 625 FileSystemOperation::OPTION_NONE, | 686 CopyTest(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE), |
| 626 FileSystemOperationRunner::CopyProgressCallback(), | 687 base::File::FILE_OK); |
| 627 RecordStatusCallback()); | |
| 628 base::RunLoop().RunUntilIdle(); | |
| 629 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 630 EXPECT_TRUE(FileExists("new")); | 688 EXPECT_TRUE(FileExists("new")); |
| 631 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); | 689 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
| 632 | 690 |
| 633 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 691 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| 634 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 692 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 635 EXPECT_TRUE(change_observer()->HasNoChange()); | 693 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 636 } | 694 } |
| 637 | 695 |
| 638 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { | 696 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { |
| 639 FileSystemURL src_dir(CreateDirectory("src")); | 697 FileSystemURL src_dir(CreateDirectory("src")); |
| 640 FileSystemURL dest_dir(CreateDirectory("dest")); | 698 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 641 | 699 |
| 642 operation_runner()->Copy(src_dir, dest_dir, | 700 EXPECT_EQ(CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE), |
| 643 FileSystemOperation::OPTION_NONE, | 701 base::File::FILE_OK); |
| 644 FileSystemOperationRunner::CopyProgressCallback(), | |
| 645 RecordStatusCallback()); | |
| 646 base::RunLoop().RunUntilIdle(); | |
| 647 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 648 | 702 |
| 649 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 703 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
| 650 EXPECT_TRUE(DirectoryExists("dest")); | 704 EXPECT_TRUE(DirectoryExists("dest")); |
| 651 EXPECT_FALSE(DirectoryExists("dest/src")); | 705 EXPECT_FALSE(DirectoryExists("dest/src")); |
| 652 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); | 706 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); |
| 653 | 707 |
| 654 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 708 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 655 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 709 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 656 EXPECT_TRUE(change_observer()->HasNoChange()); | 710 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 657 } | 711 } |
| 658 | 712 |
| 659 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { | 713 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { |
| 660 FileSystemURL src_dir(CreateDirectory("src")); | 714 FileSystemURL src_dir(CreateDirectory("src")); |
| 661 FileSystemURL dest_dir_new(URLForPath("dest")); | 715 FileSystemURL dest_dir_new(URLForPath("dest")); |
| 662 | 716 |
| 663 operation_runner()->Copy(src_dir, dest_dir_new, | 717 EXPECT_EQ(CopyTest(src_dir, dest_dir_new, FileSystemOperation::OPTION_NONE), |
| 664 FileSystemOperation::OPTION_NONE, | 718 base::File::FILE_OK); |
| 665 FileSystemOperationRunner::CopyProgressCallback(), | |
| 666 RecordStatusCallback()); | |
| 667 base::RunLoop().RunUntilIdle(); | |
| 668 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 669 EXPECT_TRUE(DirectoryExists("dest")); | 719 EXPECT_TRUE(DirectoryExists("dest")); |
| 670 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); | 720 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); |
| 671 | 721 |
| 672 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 722 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 673 EXPECT_TRUE(change_observer()->HasNoChange()); | 723 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 674 } | 724 } |
| 675 | 725 |
| 676 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { | 726 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { |
| 677 FileSystemURL src_dir(CreateDirectory("src")); | 727 FileSystemURL src_dir(CreateDirectory("src")); |
| 678 CreateDirectory("src/dir"); | 728 CreateDirectory("src/dir"); |
| 679 CreateFile("src/dir/sub"); | 729 CreateFile("src/dir/sub"); |
| 680 | 730 |
| 681 FileSystemURL dest_dir(CreateDirectory("dest")); | 731 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 682 | 732 |
| 683 operation_runner()->Copy(src_dir, dest_dir, | 733 EXPECT_EQ(CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE), |
| 684 FileSystemOperation::OPTION_NONE, | 734 base::File::FILE_OK); |
| 685 FileSystemOperationRunner::CopyProgressCallback(), | |
| 686 RecordStatusCallback()); | |
| 687 base::RunLoop().RunUntilIdle(); | |
| 688 | 735 |
| 689 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 690 EXPECT_TRUE(DirectoryExists("dest/dir")); | 736 EXPECT_TRUE(DirectoryExists("dest/dir")); |
| 691 EXPECT_TRUE(FileExists("dest/dir/sub")); | 737 EXPECT_TRUE(FileExists("dest/dir/sub")); |
| 692 | 738 |
| 693 // For recursive copy we may record multiple read access. | 739 // For recursive copy we may record multiple read access. |
| 694 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); | 740 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); |
| 695 | 741 |
| 696 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 742 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
| 697 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 743 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 698 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 744 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| 699 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 745 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 700 EXPECT_TRUE(change_observer()->HasNoChange()); | 746 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 701 } | 747 } |
| 702 | 748 |
| 703 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { | 749 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { |
| 704 FileSystemURL src_dir(CreateDirectory("src")); | 750 FileSystemURL src_dir(CreateDirectory("src")); |
| 705 CreateDirectory("src/dir"); | 751 CreateDirectory("src/dir"); |
| 706 CreateFile("src/dir/sub"); | 752 CreateFile("src/dir/sub"); |
| 707 | 753 |
| 708 operation_runner()->Copy(src_dir, src_dir, | 754 EXPECT_EQ(CopyTest(src_dir, src_dir, FileSystemOperation::OPTION_NONE), |
| 709 FileSystemOperation::OPTION_NONE, | 755 base::File::FILE_OK); |
| 710 FileSystemOperationRunner::CopyProgressCallback(), | |
| 711 RecordStatusCallback()); | |
| 712 base::RunLoop().RunUntilIdle(); | |
| 713 | 756 |
| 714 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 715 EXPECT_TRUE(DirectoryExists("src/dir")); | 757 EXPECT_TRUE(DirectoryExists("src/dir")); |
| 716 EXPECT_TRUE(FileExists("src/dir/sub")); | 758 EXPECT_TRUE(FileExists("src/dir/sub")); |
| 717 | 759 |
| 718 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); | 760 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); |
| 719 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); | 761 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); |
| 720 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); | 762 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); |
| 721 EXPECT_TRUE(change_observer()->HasNoChange()); | 763 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 722 } | 764 } |
| 723 | 765 |
| 724 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) { | 766 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) { |
| 725 base::FilePath src_local_disk_file_path; | 767 base::FilePath src_local_disk_file_path; |
| 726 base::CreateTemporaryFile(&src_local_disk_file_path); | 768 base::CreateTemporaryFile(&src_local_disk_file_path); |
| 727 const char test_data[] = "foo"; | 769 const char test_data[] = "foo"; |
| 728 int data_size = ARRAYSIZE_UNSAFE(test_data); | 770 int data_size = ARRAYSIZE_UNSAFE(test_data); |
| 729 base::WriteFile(src_local_disk_file_path, test_data, data_size); | 771 base::WriteFile(src_local_disk_file_path, test_data, data_size); |
| 730 | 772 |
| 731 FileSystemURL dest_dir(CreateDirectory("dest")); | 773 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 732 | 774 |
| 733 int64 before_usage; | 775 int64 before_usage; |
| 734 GetUsageAndQuota(&before_usage, NULL); | 776 GetUsageAndQuota(&before_usage, NULL); |
| 735 | 777 |
| 736 // Check that the file copied and corresponding usage increased. | 778 // Check that the file copied and corresponding usage increased. |
| 737 operation_runner()->CopyInForeignFile(src_local_disk_file_path, | 779 EXPECT_EQ( |
| 738 URLForPath("dest/file"), | 780 CopyInForeignFileTest(src_local_disk_file_path, URLForPath("dest/file")), |
| 739 RecordStatusCallback()); | 781 base::File::FILE_OK); |
| 740 base::RunLoop().RunUntilIdle(); | |
| 741 | 782 |
| 742 EXPECT_EQ(1, change_observer()->create_file_count()); | 783 EXPECT_EQ(1, change_observer()->create_file_count()); |
| 743 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 744 EXPECT_TRUE(FileExists("dest/file")); | 784 EXPECT_TRUE(FileExists("dest/file")); |
| 745 int64 after_usage; | 785 int64 after_usage; |
| 746 GetUsageAndQuota(&after_usage, NULL); | 786 GetUsageAndQuota(&after_usage, NULL); |
| 747 EXPECT_GT(after_usage, before_usage); | 787 EXPECT_GT(after_usage, before_usage); |
| 748 | 788 |
| 749 // Compare contents of src and copied file. | 789 // Compare contents of src and copied file. |
| 750 char buffer[100]; | 790 char buffer[100]; |
| 751 EXPECT_EQ(data_size, base::ReadFile(PlatformPath("dest/file"), | 791 EXPECT_EQ(data_size, base::ReadFile(PlatformPath("dest/file"), |
| 752 buffer, data_size)); | 792 buffer, data_size)); |
| 753 for (int i = 0; i < data_size; ++i) | 793 for (int i = 0; i < data_size; ++i) |
| 754 EXPECT_EQ(test_data[i], buffer[i]); | 794 EXPECT_EQ(test_data[i], buffer[i]); |
| 755 } | 795 } |
| 756 | 796 |
| 757 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) { | 797 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) { |
| 758 base::FilePath src_local_disk_file_path; | 798 base::FilePath src_local_disk_file_path; |
| 759 base::CreateTemporaryFile(&src_local_disk_file_path); | 799 base::CreateTemporaryFile(&src_local_disk_file_path); |
| 760 const char test_data[] = "foo"; | 800 const char test_data[] = "foo"; |
| 761 base::WriteFile(src_local_disk_file_path, test_data, | 801 base::WriteFile(src_local_disk_file_path, test_data, |
| 762 ARRAYSIZE_UNSAFE(test_data)); | 802 ARRAYSIZE_UNSAFE(test_data)); |
| 763 | 803 |
| 764 FileSystemURL dest_dir(CreateDirectory("dest")); | 804 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 765 | 805 |
| 766 GrantQuotaForCurrentUsage(); | 806 GrantQuotaForCurrentUsage(); |
| 767 operation_runner()->CopyInForeignFile(src_local_disk_file_path, | 807 EXPECT_EQ( |
| 768 URLForPath("dest/file"), | 808 CopyInForeignFileTest(src_local_disk_file_path, URLForPath("dest/file")), |
| 769 RecordStatusCallback()); | 809 base::File::FILE_ERROR_NO_SPACE); |
| 770 base::RunLoop().RunUntilIdle(); | |
| 771 | 810 |
| 772 EXPECT_FALSE(FileExists("dest/file")); | 811 EXPECT_FALSE(FileExists("dest/file")); |
| 773 EXPECT_EQ(0, change_observer()->create_file_count()); | 812 EXPECT_EQ(0, change_observer()->create_file_count()); |
| 774 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); | |
| 775 } | 813 } |
| 776 | 814 |
| 777 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) { | 815 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) { |
| 778 // Already existing file and exclusive true. | 816 // Already existing file and exclusive true. |
| 779 FileSystemURL file(CreateFile("file")); | 817 FileSystemURL file(CreateFile("file")); |
| 780 operation_runner()->CreateFile(file, true, RecordStatusCallback()); | 818 EXPECT_EQ(CreateFileTest(file, true), base::File::FILE_ERROR_EXISTS); |
| 781 base::RunLoop().RunUntilIdle(); | |
| 782 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); | |
| 783 EXPECT_TRUE(change_observer()->HasNoChange()); | 819 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 784 } | 820 } |
| 785 | 821 |
| 786 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { | 822 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { |
| 787 // Already existing file and exclusive false. | 823 // Already existing file and exclusive false. |
| 788 FileSystemURL file(CreateFile("file")); | 824 FileSystemURL file(CreateFile("file")); |
| 789 operation_runner()->CreateFile(file, false, RecordStatusCallback()); | 825 EXPECT_EQ(CreateFileTest(file, false), base::File::FILE_OK); |
| 790 base::RunLoop().RunUntilIdle(); | |
| 791 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 792 EXPECT_TRUE(FileExists("file")); | 826 EXPECT_TRUE(FileExists("file")); |
| 793 | 827 |
| 794 // The file was already there; did nothing. | 828 // The file was already there; did nothing. |
| 795 EXPECT_TRUE(change_observer()->HasNoChange()); | 829 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 796 } | 830 } |
| 797 | 831 |
| 798 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) { | 832 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) { |
| 799 // File doesn't exist but exclusive is true. | 833 // File doesn't exist but exclusive is true. |
| 800 operation_runner()->CreateFile(URLForPath("new"), true, | 834 EXPECT_EQ(CreateFileTest(URLForPath("new"), true), base::File::FILE_OK); |
| 801 RecordStatusCallback()); | |
| 802 base::RunLoop().RunUntilIdle(); | |
| 803 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 804 EXPECT_TRUE(FileExists("new")); | 835 EXPECT_TRUE(FileExists("new")); |
| 805 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 836 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| 806 } | 837 } |
| 807 | 838 |
| 808 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) { | 839 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) { |
| 809 // Non existing file. | 840 // Non existing file. |
| 810 operation_runner()->CreateFile(URLForPath("nonexistent"), false, | 841 EXPECT_EQ(CreateFileTest(URLForPath("nonexistent"), false), |
| 811 RecordStatusCallback()); | 842 base::File::FILE_OK); |
| 812 base::RunLoop().RunUntilIdle(); | |
| 813 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 814 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 843 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| 815 } | 844 } |
| 816 | 845 |
| 817 TEST_F(FileSystemOperationImplTest, | 846 TEST_F(FileSystemOperationImplTest, |
| 818 TestCreateDirFailureDestParentDoesntExist) { | 847 TestCreateDirFailureDestParentDoesntExist) { |
| 819 // Dest. parent path does not exist. | 848 // Dest. parent path does not exist. |
| 820 operation_runner()->CreateDirectory( | 849 EXPECT_EQ(CreateDirectoryTest(URLForPath("nonexistent/dir"), false, false), |
| 821 URLForPath("nonexistent/dir"), false, false, | 850 base::File::FILE_ERROR_NOT_FOUND); |
| 822 RecordStatusCallback()); | |
| 823 base::RunLoop().RunUntilIdle(); | |
| 824 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 825 EXPECT_TRUE(change_observer()->HasNoChange()); | 851 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 826 } | 852 } |
| 827 | 853 |
| 828 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) { | 854 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) { |
| 829 // Exclusive and dir existing at path. | 855 // Exclusive and dir existing at path. |
| 830 FileSystemURL dir(CreateDirectory("dir")); | 856 FileSystemURL dir(CreateDirectory("dir")); |
| 831 operation_runner()->CreateDirectory(dir, true, false, | 857 EXPECT_EQ(CreateDirectoryTest(dir, true, false), |
| 832 RecordStatusCallback()); | 858 base::File::FILE_ERROR_EXISTS); |
| 833 base::RunLoop().RunUntilIdle(); | |
| 834 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); | |
| 835 EXPECT_TRUE(change_observer()->HasNoChange()); | 859 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 836 } | 860 } |
| 837 | 861 |
| 838 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) { | 862 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) { |
| 839 // Exclusive true and file existing at path. | 863 // Exclusive true and file existing at path. |
| 840 FileSystemURL file(CreateFile("file")); | 864 FileSystemURL file(CreateFile("file")); |
| 841 operation_runner()->CreateDirectory(file, true, false, | 865 EXPECT_EQ(CreateDirectoryTest(file, true, false), |
| 842 RecordStatusCallback()); | 866 base::File::FILE_ERROR_EXISTS); |
| 843 base::RunLoop().RunUntilIdle(); | |
| 844 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); | |
| 845 EXPECT_TRUE(change_observer()->HasNoChange()); | 867 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 846 } | 868 } |
| 847 | 869 |
| 848 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) { | 870 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) { |
| 849 // Dir exists and exclusive is false. | 871 // Dir exists and exclusive is false. |
| 850 FileSystemURL dir(CreateDirectory("dir")); | 872 FileSystemURL dir(CreateDirectory("dir")); |
| 851 operation_runner()->CreateDirectory(dir, false, false, | 873 EXPECT_EQ(CreateDirectoryTest(dir, false, false), base::File::FILE_OK); |
| 852 RecordStatusCallback()); | |
| 853 base::RunLoop().RunUntilIdle(); | |
| 854 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 855 EXPECT_TRUE(change_observer()->HasNoChange()); | 874 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 856 | 875 |
| 857 // Dir doesn't exist. | 876 // Dir doesn't exist. |
| 858 operation_runner()->CreateDirectory(URLForPath("new"), false, false, | 877 EXPECT_EQ(CreateDirectoryTest(URLForPath("new"), false, false), |
| 859 RecordStatusCallback()); | 878 base::File::FILE_OK); |
| 860 base::RunLoop().RunUntilIdle(); | |
| 861 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 862 EXPECT_TRUE(DirectoryExists("new")); | 879 EXPECT_TRUE(DirectoryExists("new")); |
| 863 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 880 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 864 } | 881 } |
| 865 | 882 |
| 866 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) { | 883 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) { |
| 867 // Dir doesn't exist. | 884 // Dir doesn't exist. |
| 868 operation_runner()->CreateDirectory(URLForPath("new"), true, false, | 885 EXPECT_EQ(CreateDirectoryTest(URLForPath("new"), true, false), |
| 869 RecordStatusCallback()); | 886 base::File::FILE_OK); |
| 870 base::RunLoop().RunUntilIdle(); | |
| 871 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 872 EXPECT_TRUE(DirectoryExists("new")); | 887 EXPECT_TRUE(DirectoryExists("new")); |
| 873 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 888 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 874 EXPECT_TRUE(change_observer()->HasNoChange()); | 889 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 875 } | 890 } |
| 876 | 891 |
| 877 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { | 892 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { |
| 878 operation_runner()->GetMetadata(URLForPath("nonexistent"), | 893 GetMetadataTest(URLForPath("nonexistent")); |
| 879 RecordMetadataCallback()); | |
| 880 base::RunLoop().RunUntilIdle(); | |
| 881 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | 894 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| 882 | 895 |
| 883 operation_runner()->FileExists(URLForPath("nonexistent"), | 896 EXPECT_EQ(FileExistsTest(URLForPath("nonexistent")), |
| 884 RecordStatusCallback()); | 897 base::File::FILE_ERROR_NOT_FOUND); |
| 885 base::RunLoop().RunUntilIdle(); | |
| 886 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 887 | 898 |
| 888 operation_runner()->DirectoryExists(URLForPath("nonexistent"), | 899 EXPECT_EQ(DirectoryExistsTest(URLForPath("nonexistent")), |
| 889 RecordStatusCallback()); | 900 base::File::FILE_ERROR_NOT_FOUND); |
| 890 base::RunLoop().RunUntilIdle(); | |
| 891 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 892 EXPECT_TRUE(change_observer()->HasNoChange()); | 901 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 893 } | 902 } |
| 894 | 903 |
| 895 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { | 904 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { |
| 896 FileSystemURL dir(CreateDirectory("dir")); | 905 FileSystemURL dir(CreateDirectory("dir")); |
| 897 FileSystemURL file(CreateFile("dir/file")); | 906 FileSystemURL file(CreateFile("dir/file")); |
| 898 int read_access = 0; | 907 int read_access = 0; |
| 899 | 908 |
| 900 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); | 909 EXPECT_EQ(DirectoryExistsTest(dir), base::File::FILE_OK); |
| 901 base::RunLoop().RunUntilIdle(); | |
| 902 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 903 ++read_access; | 910 ++read_access; |
| 904 | 911 |
| 905 operation_runner()->GetMetadata(dir, RecordMetadataCallback()); | 912 EXPECT_EQ(GetMetadataTest(dir), base::File::FILE_OK); |
| 906 base::RunLoop().RunUntilIdle(); | |
| 907 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 908 EXPECT_TRUE(info().is_directory); | 913 EXPECT_TRUE(info().is_directory); |
| 909 ++read_access; | 914 ++read_access; |
| 910 | 915 |
| 911 operation_runner()->FileExists(file, RecordStatusCallback()); | 916 EXPECT_EQ(FileExistsTest(file), base::File::FILE_OK); |
| 912 base::RunLoop().RunUntilIdle(); | |
| 913 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 914 ++read_access; | 917 ++read_access; |
| 915 | 918 |
| 916 operation_runner()->GetMetadata(file, RecordMetadataCallback()); | 919 EXPECT_EQ(GetMetadataTest(file), base::File::FILE_OK); |
| 917 base::RunLoop().RunUntilIdle(); | |
| 918 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 919 EXPECT_FALSE(info().is_directory); | 920 EXPECT_FALSE(info().is_directory); |
| 920 ++read_access; | 921 ++read_access; |
| 921 | 922 |
| 922 EXPECT_EQ(read_access, | 923 EXPECT_EQ(read_access, |
| 923 quota_manager_proxy()->notify_storage_accessed_count()); | 924 quota_manager_proxy()->notify_storage_accessed_count()); |
| 924 EXPECT_TRUE(change_observer()->HasNoChange()); | 925 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 925 } | 926 } |
| 926 | 927 |
| 927 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { | 928 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { |
| 928 FileSystemURL dir(CreateDirectory("dir")); | 929 FileSystemURL dir(CreateDirectory("dir")); |
| 929 operation_runner()->FileExists(dir, RecordStatusCallback()); | 930 EXPECT_EQ(FileExistsTest(dir), base::File::FILE_ERROR_NOT_A_FILE); |
| 930 base::RunLoop().RunUntilIdle(); | |
| 931 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, status()); | |
| 932 | 931 |
| 933 FileSystemURL file(CreateFile("file")); | 932 FileSystemURL file(CreateFile("file")); |
| 934 operation_runner()->DirectoryExists(file, RecordStatusCallback()); | 933 EXPECT_EQ(DirectoryExistsTest(file), base::File::FILE_ERROR_NOT_A_DIRECTORY); |
| 935 base::RunLoop().RunUntilIdle(); | |
| 936 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); | |
| 937 } | 934 } |
| 938 | 935 |
| 939 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) { | 936 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) { |
| 940 // Path doesn't exist | 937 // Path doesn't exist |
| 941 operation_runner()->ReadDirectory(URLForPath("nonexistent"), | 938 EXPECT_EQ(ReadDirectoryTest(URLForPath("nonexistent")), |
| 942 RecordReadDirectoryCallback()); | 939 base::File::FILE_ERROR_NOT_FOUND); |
| 943 base::RunLoop().RunUntilIdle(); | |
| 944 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 945 | 940 |
| 946 // File exists. | 941 // File exists. |
| 947 FileSystemURL file(CreateFile("file")); | 942 FileSystemURL file(CreateFile("file")); |
| 948 operation_runner()->ReadDirectory(file, RecordReadDirectoryCallback()); | 943 EXPECT_EQ(ReadDirectoryTest(file), base::File::FILE_ERROR_NOT_A_DIRECTORY); |
| 949 base::RunLoop().RunUntilIdle(); | |
| 950 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); | |
| 951 EXPECT_TRUE(change_observer()->HasNoChange()); | 944 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 952 } | 945 } |
| 953 | 946 |
| 954 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { | 947 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { |
| 955 // parent_dir | 948 // parent_dir |
| 956 // | | | 949 // | | |
| 957 // child_dir child_file | 950 // child_dir child_file |
| 958 // Verify reading parent_dir. | 951 // Verify reading parent_dir. |
| 959 FileSystemURL parent_dir(CreateDirectory("dir")); | 952 FileSystemURL parent_dir(CreateDirectory("dir")); |
| 960 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 953 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
| 961 FileSystemURL child_file(CreateFile("dir/child_file")); | 954 FileSystemURL child_file(CreateFile("dir/child_file")); |
| 962 | 955 |
| 963 operation_runner()->ReadDirectory(parent_dir, RecordReadDirectoryCallback()); | 956 EXPECT_EQ(ReadDirectoryTest(parent_dir), base::File::FILE_OK); |
| 964 base::RunLoop().RunUntilIdle(); | |
| 965 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 966 EXPECT_EQ(2u, entries().size()); | 957 EXPECT_EQ(2u, entries().size()); |
| 967 | 958 |
| 968 for (size_t i = 0; i < entries().size(); ++i) { | 959 for (size_t i = 0; i < entries().size(); ++i) { |
| 969 if (entries()[i].is_directory) | 960 if (entries()[i].is_directory) |
| 970 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name); | 961 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name); |
| 971 else | 962 else |
| 972 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name); | 963 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name); |
| 973 } | 964 } |
| 974 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 965 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 975 EXPECT_TRUE(change_observer()->HasNoChange()); | 966 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 976 } | 967 } |
| 977 | 968 |
| 978 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { | 969 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { |
| 979 // Path doesn't exist. | 970 // Path doesn't exist. |
| 980 operation_runner()->Remove(URLForPath("nonexistent"), false /* recursive */, | 971 EXPECT_EQ(RemoveTest(URLForPath("nonexistent"), false /* recursive */), |
| 981 RecordStatusCallback()); | 972 base::File::FILE_ERROR_NOT_FOUND); |
| 982 base::RunLoop().RunUntilIdle(); | |
| 983 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
| 984 | 973 |
| 985 // It's an error to try to remove a non-empty directory if recursive flag | 974 // It's an error to try to remove a non-empty directory if recursive flag |
| 986 // is false. | 975 // is false. |
| 987 // parent_dir | 976 // parent_dir |
| 988 // | | | 977 // | | |
| 989 // child_dir child_file | 978 // child_dir child_file |
| 990 // Verify deleting parent_dir. | 979 // Verify deleting parent_dir. |
| 991 FileSystemURL parent_dir(CreateDirectory("dir")); | 980 FileSystemURL parent_dir(CreateDirectory("dir")); |
| 992 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 981 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
| 993 FileSystemURL child_file(CreateFile("dir/child_file")); | 982 FileSystemURL child_file(CreateFile("dir/child_file")); |
| 994 | 983 |
| 995 operation_runner()->Remove(parent_dir, false /* recursive */, | 984 EXPECT_EQ(RemoveTest(parent_dir, false /* recursive */), |
| 996 RecordStatusCallback()); | 985 base::File::FILE_ERROR_NOT_EMPTY); |
| 997 base::RunLoop().RunUntilIdle(); | |
| 998 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); | |
| 999 EXPECT_TRUE(change_observer()->HasNoChange()); | 986 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1000 } | 987 } |
| 1001 | 988 |
| 1002 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) { | 989 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) { |
| 1003 FileSystemURL empty_dir(CreateDirectory("empty_dir")); | 990 FileSystemURL empty_dir(CreateDirectory("empty_dir")); |
| 1004 EXPECT_TRUE(DirectoryExists("empty_dir")); | 991 EXPECT_TRUE(DirectoryExists("empty_dir")); |
| 1005 operation_runner()->Remove(empty_dir, false /* recursive */, | 992 EXPECT_EQ(RemoveTest(empty_dir, false /* recursive */), base::File::FILE_OK); |
| 1006 RecordStatusCallback()); | |
| 1007 base::RunLoop().RunUntilIdle(); | |
| 1008 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1009 EXPECT_FALSE(DirectoryExists("empty_dir")); | 993 EXPECT_FALSE(DirectoryExists("empty_dir")); |
| 1010 | 994 |
| 1011 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 995 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 1012 EXPECT_TRUE(change_observer()->HasNoChange()); | 996 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1013 } | 997 } |
| 1014 | 998 |
| 1015 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) { | 999 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) { |
| 1016 // Removing a non-empty directory with recursive flag == true should be ok. | 1000 // Removing a non-empty directory with recursive flag == true should be ok. |
| 1017 // parent_dir | 1001 // parent_dir |
| 1018 // | | | 1002 // | | |
| 1019 // child_dir child_files | 1003 // child_dir child_files |
| 1020 // | | 1004 // | |
| 1021 // child_files | 1005 // child_files |
| 1022 // | 1006 // |
| 1023 // Verify deleting parent_dir. | 1007 // Verify deleting parent_dir. |
| 1024 FileSystemURL parent_dir(CreateDirectory("dir")); | 1008 FileSystemURL parent_dir(CreateDirectory("dir")); |
| 1025 for (int i = 0; i < 8; ++i) | 1009 for (int i = 0; i < 8; ++i) |
| 1026 CreateFile(base::StringPrintf("dir/file-%d", i)); | 1010 CreateFile(base::StringPrintf("dir/file-%d", i)); |
| 1027 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 1011 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
| 1028 for (int i = 0; i < 8; ++i) | 1012 for (int i = 0; i < 8; ++i) |
| 1029 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); | 1013 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); |
| 1030 | 1014 |
| 1031 operation_runner()->Remove(parent_dir, true /* recursive */, | 1015 EXPECT_EQ(RemoveTest(parent_dir, true /* recursive */), base::File::FILE_OK); |
| 1032 RecordStatusCallback()); | |
| 1033 base::RunLoop().RunUntilIdle(); | |
| 1034 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1035 EXPECT_FALSE(DirectoryExists("parent_dir")); | 1016 EXPECT_FALSE(DirectoryExists("parent_dir")); |
| 1036 | 1017 |
| 1037 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 1018 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
| 1038 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count()); | 1019 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count()); |
| 1039 EXPECT_TRUE(change_observer()->HasNoChange()); | 1020 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1040 } | 1021 } |
| 1041 | 1022 |
| 1042 TEST_F(FileSystemOperationImplTest, TestTruncate) { | 1023 TEST_F(FileSystemOperationImplTest, TestTruncate) { |
| 1043 FileSystemURL file(CreateFile("file")); | 1024 FileSystemURL file(CreateFile("file")); |
| 1044 base::FilePath platform_path = PlatformPath("file"); | 1025 base::FilePath platform_path = PlatformPath("file"); |
| 1045 | 1026 |
| 1046 char test_data[] = "test data"; | 1027 char test_data[] = "test data"; |
| 1047 int data_size = static_cast<int>(sizeof(test_data)); | 1028 int data_size = static_cast<int>(sizeof(test_data)); |
| 1048 EXPECT_EQ(data_size, | 1029 EXPECT_EQ(data_size, |
| 1049 base::WriteFile(platform_path, test_data, data_size)); | 1030 base::WriteFile(platform_path, test_data, data_size)); |
| 1050 | 1031 |
| 1051 // Check that its length is the size of the data written. | 1032 // Check that its length is the size of the data written. |
| 1052 operation_runner()->GetMetadata(file, RecordMetadataCallback()); | 1033 EXPECT_EQ(GetMetadataTest(file), base::File::FILE_OK); |
| 1053 base::RunLoop().RunUntilIdle(); | |
| 1054 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1055 EXPECT_FALSE(info().is_directory); | 1034 EXPECT_FALSE(info().is_directory); |
| 1056 EXPECT_EQ(data_size, info().size); | 1035 EXPECT_EQ(data_size, info().size); |
| 1057 | 1036 |
| 1058 // Extend the file by truncating it. | 1037 // Extend the file by truncating it. |
| 1059 int length = 17; | 1038 int length = 17; |
| 1060 operation_runner()->Truncate(file, length, RecordStatusCallback()); | 1039 EXPECT_EQ(TruncateTest(file, length), base::File::FILE_OK); |
| 1061 base::RunLoop().RunUntilIdle(); | |
| 1062 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1063 | 1040 |
| 1064 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1041 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 1065 EXPECT_TRUE(change_observer()->HasNoChange()); | 1042 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1066 | 1043 |
| 1067 // Check that its length is now 17 and that it's all zeroes after the test | 1044 // Check that its length is now 17 and that it's all zeroes after the test |
| 1068 // data. | 1045 // data. |
| 1069 EXPECT_EQ(length, GetFileSize("file")); | 1046 EXPECT_EQ(length, GetFileSize("file")); |
| 1070 char data[100]; | 1047 char data[100]; |
| 1071 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); | 1048 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); |
| 1072 for (int i = 0; i < length; ++i) { | 1049 for (int i = 0; i < length; ++i) { |
| 1073 if (i < static_cast<int>(sizeof(test_data))) | 1050 if (i < static_cast<int>(sizeof(test_data))) |
| 1074 EXPECT_EQ(test_data[i], data[i]); | 1051 EXPECT_EQ(test_data[i], data[i]); |
| 1075 else | 1052 else |
| 1076 EXPECT_EQ(0, data[i]); | 1053 EXPECT_EQ(0, data[i]); |
| 1077 } | 1054 } |
| 1078 | 1055 |
| 1079 // Shorten the file by truncating it. | 1056 // Shorten the file by truncating it. |
| 1080 length = 3; | 1057 length = 3; |
| 1081 operation_runner()->Truncate(file, length, RecordStatusCallback()); | 1058 EXPECT_EQ(TruncateTest(file, length), base::File::FILE_OK); |
| 1082 base::RunLoop().RunUntilIdle(); | |
| 1083 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1084 | 1059 |
| 1085 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1060 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 1086 EXPECT_TRUE(change_observer()->HasNoChange()); | 1061 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1087 | 1062 |
| 1088 // Check that its length is now 3 and that it contains only bits of test data. | 1063 // Check that its length is now 3 and that it contains only bits of test data. |
| 1089 EXPECT_EQ(length, GetFileSize("file")); | 1064 EXPECT_EQ(length, GetFileSize("file")); |
| 1090 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); | 1065 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); |
| 1091 for (int i = 0; i < length; ++i) | 1066 for (int i = 0; i < length; ++i) |
| 1092 EXPECT_EQ(test_data[i], data[i]); | 1067 EXPECT_EQ(test_data[i], data[i]); |
| 1093 | 1068 |
| 1094 // Truncate is not a 'read' access. (Here expected access count is 1 | 1069 // Truncate is not a 'read' access. (Here expected access count is 1 |
| 1095 // since we made 1 read access for GetMetadata.) | 1070 // since we made 1 read access for GetMetadata.) |
| 1096 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 1071 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 1097 } | 1072 } |
| 1098 | 1073 |
| 1099 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) { | 1074 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) { |
| 1100 FileSystemURL dir(CreateDirectory("dir")); | 1075 FileSystemURL dir(CreateDirectory("dir")); |
| 1101 FileSystemURL file(CreateFile("dir/file")); | 1076 FileSystemURL file(CreateFile("dir/file")); |
| 1102 | 1077 |
| 1103 GrantQuotaForCurrentUsage(); | 1078 GrantQuotaForCurrentUsage(); |
| 1104 AddQuota(10); | 1079 AddQuota(10); |
| 1105 | 1080 |
| 1106 operation_runner()->Truncate(file, 10, RecordStatusCallback()); | 1081 EXPECT_EQ(TruncateTest(file, 10), base::File::FILE_OK); |
| 1107 base::RunLoop().RunUntilIdle(); | |
| 1108 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1109 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1082 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 1110 EXPECT_TRUE(change_observer()->HasNoChange()); | 1083 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1111 | 1084 |
| 1112 EXPECT_EQ(10, GetFileSize("dir/file")); | 1085 EXPECT_EQ(10, GetFileSize("dir/file")); |
| 1113 | 1086 |
| 1114 operation_runner()->Truncate(file, 11, RecordStatusCallback()); | 1087 EXPECT_EQ(TruncateTest(file, 11), base::File::FILE_ERROR_NO_SPACE); |
| 1115 base::RunLoop().RunUntilIdle(); | |
| 1116 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); | |
| 1117 EXPECT_TRUE(change_observer()->HasNoChange()); | 1088 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1118 | 1089 |
| 1119 EXPECT_EQ(10, GetFileSize("dir/file")); | 1090 EXPECT_EQ(10, GetFileSize("dir/file")); |
| 1120 } | 1091 } |
| 1121 | 1092 |
| 1122 TEST_F(FileSystemOperationImplTest, TestTouchFile) { | 1093 TEST_F(FileSystemOperationImplTest, TestTouchFile) { |
| 1123 FileSystemURL file(CreateFile("file")); | 1094 FileSystemURL file(CreateFile("file")); |
| 1124 base::FilePath platform_path = PlatformPath("file"); | 1095 base::FilePath platform_path = PlatformPath("file"); |
| 1125 | 1096 |
| 1126 base::File::Info info; | 1097 base::File::Info info; |
| 1127 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); | 1098 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); |
| 1128 EXPECT_FALSE(info.is_directory); | 1099 EXPECT_FALSE(info.is_directory); |
| 1129 EXPECT_EQ(0, info.size); | 1100 EXPECT_EQ(0, info.size); |
| 1130 const base::Time last_modified = info.last_modified; | 1101 const base::Time last_modified = info.last_modified; |
| 1131 const base::Time last_accessed = info.last_accessed; | 1102 const base::Time last_accessed = info.last_accessed; |
| 1132 | 1103 |
| 1133 const base::Time new_modified_time = base::Time::UnixEpoch(); | 1104 const base::Time new_modified_time = base::Time::UnixEpoch(); |
| 1134 const base::Time new_accessed_time = new_modified_time + | 1105 const base::Time new_accessed_time = new_modified_time + |
| 1135 base::TimeDelta::FromHours(77); | 1106 base::TimeDelta::FromHours(77); |
| 1136 ASSERT_NE(last_modified, new_modified_time); | 1107 ASSERT_NE(last_modified, new_modified_time); |
| 1137 ASSERT_NE(last_accessed, new_accessed_time); | 1108 ASSERT_NE(last_accessed, new_accessed_time); |
| 1138 | 1109 |
| 1139 operation_runner()->TouchFile(file, new_accessed_time, new_modified_time, | 1110 EXPECT_EQ(TouchFileTest(file, new_accessed_time, new_modified_time), |
| 1140 RecordStatusCallback()); | 1111 base::File::FILE_OK); |
| 1141 base::RunLoop().RunUntilIdle(); | |
| 1142 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1143 EXPECT_TRUE(change_observer()->HasNoChange()); | 1112 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1144 | 1113 |
| 1145 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); | 1114 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); |
| 1146 // We compare as time_t here to lower our resolution, to avoid false | 1115 // We compare as time_t here to lower our resolution, to avoid false |
| 1147 // negatives caused by conversion to the local filesystem's native | 1116 // negatives caused by conversion to the local filesystem's native |
| 1148 // representation and back. | 1117 // representation and back. |
| 1149 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); | 1118 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); |
| 1150 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); | 1119 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); |
| 1151 } | 1120 } |
| 1152 | 1121 |
| 1153 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) { | 1122 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) { |
| 1154 FileSystemURL dir(CreateDirectory("dir")); | 1123 FileSystemURL dir(CreateDirectory("dir")); |
| 1155 | 1124 |
| 1156 // Create a file for the testing. | 1125 // Create a file for the testing. |
| 1157 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); | 1126 EXPECT_EQ(DirectoryExistsTest(dir), base::File::FILE_OK); |
| 1158 FileSystemURL file(CreateFile("dir/file")); | 1127 FileSystemURL file(CreateFile("dir/file")); |
| 1159 operation_runner()->FileExists(file, RecordStatusCallback()); | 1128 EXPECT_EQ(FileExistsTest(file), base::File::FILE_OK); |
| 1160 base::RunLoop().RunUntilIdle(); | |
| 1161 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1162 | 1129 |
| 1163 // See if we can get a 'snapshot' file info for the file. | 1130 // See if we can get a 'snapshot' file info for the file. |
| 1164 // Since FileSystemOperationImpl assumes the file exists in the local | 1131 // Since FileSystemOperationImpl assumes the file exists in the local |
| 1165 // directory it should just returns the same metadata and platform_path | 1132 // directory it should just returns the same metadata and platform_path |
| 1166 // as the file itself. | 1133 // as the file itself. |
| 1167 operation_runner()->CreateSnapshotFile(file, RecordSnapshotFileCallback()); | 1134 EXPECT_EQ(CreateSnapshotFileTest(file), base::File::FILE_OK); |
| 1168 base::RunLoop().RunUntilIdle(); | |
| 1169 EXPECT_EQ(base::File::FILE_OK, status()); | |
| 1170 EXPECT_FALSE(info().is_directory); | 1135 EXPECT_FALSE(info().is_directory); |
| 1171 EXPECT_EQ(PlatformPath("dir/file"), path()); | 1136 EXPECT_EQ(PlatformPath("dir/file"), path()); |
| 1172 EXPECT_TRUE(change_observer()->HasNoChange()); | 1137 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1173 | 1138 |
| 1174 // The FileSystemOpration implementation does not create a | 1139 // The FileSystemOpration implementation does not create a |
| 1175 // shareable file reference. | 1140 // shareable file reference. |
| 1176 EXPECT_EQ(NULL, shareable_file_ref()); | 1141 EXPECT_EQ(NULL, shareable_file_ref()); |
| 1177 } | 1142 } |
| 1178 | 1143 |
| 1179 TEST_F(FileSystemOperationImplTest, | 1144 TEST_F(FileSystemOperationImplTest, |
| 1180 TestMoveSuccessSrcDirRecursiveWithQuota) { | 1145 TestMoveSuccessSrcDirRecursiveWithQuota) { |
| 1181 FileSystemURL src(CreateDirectory("src")); | 1146 FileSystemURL src(CreateDirectory("src")); |
| 1182 int src_path_cost = GetUsage(); | 1147 int src_path_cost = GetUsage(); |
| 1183 | 1148 |
| 1184 FileSystemURL dest(CreateDirectory("dest")); | 1149 FileSystemURL dest(CreateDirectory("dest")); |
| 1185 FileSystemURL child_file1(CreateFile("src/file1")); | 1150 FileSystemURL child_file1(CreateFile("src/file1")); |
| 1186 FileSystemURL child_file2(CreateFile("src/file2")); | 1151 FileSystemURL child_file2(CreateFile("src/file2")); |
| 1187 FileSystemURL child_dir(CreateDirectory("src/dir")); | 1152 FileSystemURL child_dir(CreateDirectory("src/dir")); |
| 1188 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); | 1153 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); |
| 1189 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); | 1154 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); |
| 1190 | 1155 |
| 1191 int total_path_cost = GetUsage(); | 1156 int total_path_cost = GetUsage(); |
| 1192 EXPECT_EQ(0, GetDataSizeOnDisk()); | 1157 EXPECT_EQ(0, GetDataSizeOnDisk()); |
| 1193 | 1158 |
| 1194 operation_runner()->Truncate( | 1159 EXPECT_EQ(TruncateTest(child_file1, 5000), base::File::FILE_OK); |
| 1195 child_file1, 5000, | 1160 EXPECT_EQ(TruncateTest(child_file2, 400), base::File::FILE_OK); |
| 1196 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | 1161 EXPECT_EQ(TruncateTest(grandchild_file1, 30), base::File::FILE_OK); |
| 1197 operation_runner()->Truncate( | 1162 EXPECT_EQ(TruncateTest(grandchild_file2, 2), base::File::FILE_OK); |
| 1198 child_file2, 400, | |
| 1199 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
| 1200 operation_runner()->Truncate( | |
| 1201 grandchild_file1, 30, | |
| 1202 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
| 1203 operation_runner()->Truncate( | |
| 1204 grandchild_file2, 2, | |
| 1205 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
| 1206 base::RunLoop().RunUntilIdle(); | |
| 1207 | 1163 |
| 1208 const int64 all_file_size = 5000 + 400 + 30 + 2; | 1164 const int64 all_file_size = 5000 + 400 + 30 + 2; |
| 1209 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1165 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
| 1210 EXPECT_EQ(all_file_size + total_path_cost, GetUsage()); | 1166 EXPECT_EQ(all_file_size + total_path_cost, GetUsage()); |
| 1211 | 1167 |
| 1212 operation_runner()->Move( | 1168 EXPECT_EQ(MoveTest(src, dest, FileSystemOperation::OPTION_NONE), |
| 1213 src, dest, FileSystemOperation::OPTION_NONE, | 1169 base::File::FILE_OK); |
| 1214 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
| 1215 base::RunLoop().RunUntilIdle(); | |
| 1216 | 1170 |
| 1217 EXPECT_FALSE(DirectoryExists("src/dir")); | 1171 EXPECT_FALSE(DirectoryExists("src/dir")); |
| 1218 EXPECT_FALSE(FileExists("src/dir/file2")); | 1172 EXPECT_FALSE(FileExists("src/dir/file2")); |
| 1219 EXPECT_TRUE(DirectoryExists("dest/dir")); | 1173 EXPECT_TRUE(DirectoryExists("dest/dir")); |
| 1220 EXPECT_TRUE(FileExists("dest/dir/file2")); | 1174 EXPECT_TRUE(FileExists("dest/dir/file2")); |
| 1221 | 1175 |
| 1222 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1176 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
| 1223 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, | 1177 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, |
| 1224 GetUsage()); | 1178 GetUsage()); |
| 1225 } | 1179 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1237 int64 child_path_cost = GetUsage() - usage; | 1191 int64 child_path_cost = GetUsage() - usage; |
| 1238 usage += child_path_cost; | 1192 usage += child_path_cost; |
| 1239 | 1193 |
| 1240 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); | 1194 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); |
| 1241 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); | 1195 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); |
| 1242 int64 total_path_cost = GetUsage(); | 1196 int64 total_path_cost = GetUsage(); |
| 1243 int64 grandchild_path_cost = total_path_cost - usage; | 1197 int64 grandchild_path_cost = total_path_cost - usage; |
| 1244 | 1198 |
| 1245 EXPECT_EQ(0, GetDataSizeOnDisk()); | 1199 EXPECT_EQ(0, GetDataSizeOnDisk()); |
| 1246 | 1200 |
| 1247 operation_runner()->Truncate( | 1201 EXPECT_EQ(TruncateTest(child_file1, 8000), base::File::FILE_OK); |
| 1248 child_file1, 8000, | 1202 EXPECT_EQ(TruncateTest(child_file2, 700), base::File::FILE_OK); |
| 1249 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | 1203 EXPECT_EQ(TruncateTest(grandchild_file1, 60), base::File::FILE_OK); |
| 1250 operation_runner()->Truncate( | 1204 EXPECT_EQ(TruncateTest(grandchild_file2, 5), base::File::FILE_OK); |
| 1251 child_file2, 700, | |
| 1252 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
| 1253 operation_runner()->Truncate( | |
| 1254 grandchild_file1, 60, | |
| 1255 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
| 1256 operation_runner()->Truncate( | |
| 1257 grandchild_file2, 5, | |
| 1258 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
| 1259 base::RunLoop().RunUntilIdle(); | |
| 1260 | 1205 |
| 1261 const int64 child_file_size = 8000 + 700; | 1206 const int64 child_file_size = 8000 + 700; |
| 1262 const int64 grandchild_file_size = 60 + 5; | 1207 const int64 grandchild_file_size = 60 + 5; |
| 1263 const int64 all_file_size = child_file_size + grandchild_file_size; | 1208 const int64 all_file_size = child_file_size + grandchild_file_size; |
| 1264 int64 expected_usage = all_file_size + total_path_cost; | 1209 int64 expected_usage = all_file_size + total_path_cost; |
| 1265 | 1210 |
| 1266 usage = GetUsage(); | 1211 usage = GetUsage(); |
| 1267 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1212 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
| 1268 EXPECT_EQ(expected_usage, usage); | 1213 EXPECT_EQ(expected_usage, usage); |
| 1269 | 1214 |
| 1270 { | 1215 EXPECT_EQ(CopyTest(src, dest1, FileSystemOperation::OPTION_NONE), |
| 1271 base::RunLoop run_loop; | 1216 base::File::FILE_OK); |
| 1272 // Copy src to dest1. | |
| 1273 operation_runner()->Copy(src, | |
| 1274 dest1, | |
| 1275 FileSystemOperation::OPTION_NONE, | |
| 1276 FileSystemOperationRunner::CopyProgressCallback(), | |
| 1277 base::Bind(&AssertFileErrorEqWithClosure, | |
| 1278 FROM_HERE, | |
| 1279 base::File::FILE_OK, | |
| 1280 run_loop.QuitClosure())); | |
| 1281 run_loop.Run(); | |
| 1282 } | |
| 1283 | 1217 |
| 1284 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; | 1218 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; |
| 1285 EXPECT_TRUE(DirectoryExists("src/dir")); | 1219 EXPECT_TRUE(DirectoryExists("src/dir")); |
| 1286 EXPECT_TRUE(FileExists("src/dir/file2")); | 1220 EXPECT_TRUE(FileExists("src/dir/file2")); |
| 1287 EXPECT_TRUE(DirectoryExists("dest1/dir")); | 1221 EXPECT_TRUE(DirectoryExists("dest1/dir")); |
| 1288 EXPECT_TRUE(FileExists("dest1/dir/file2")); | 1222 EXPECT_TRUE(FileExists("dest1/dir/file2")); |
| 1289 | 1223 |
| 1290 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); | 1224 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); |
| 1291 EXPECT_EQ(expected_usage, GetUsage()); | 1225 EXPECT_EQ(expected_usage, GetUsage()); |
| 1292 | 1226 |
| 1293 { | 1227 EXPECT_EQ(CopyTest(child_dir, dest2, FileSystemOperation::OPTION_NONE), |
| 1294 base::RunLoop run_loop; | 1228 base::File::FILE_OK); |
| 1295 // Copy src/dir to dest2. | |
| 1296 operation_runner()->Copy(child_dir, | |
| 1297 dest2, | |
| 1298 FileSystemOperation::OPTION_NONE, | |
| 1299 FileSystemOperationRunner::CopyProgressCallback(), | |
| 1300 base::Bind(&AssertFileErrorEqWithClosure, | |
| 1301 FROM_HERE, | |
| 1302 base::File::FILE_OK, | |
| 1303 run_loop.QuitClosure())); | |
| 1304 run_loop.Run(); | |
| 1305 } | |
| 1306 | 1229 |
| 1307 expected_usage += grandchild_file_size + grandchild_path_cost; | 1230 expected_usage += grandchild_file_size + grandchild_path_cost; |
| 1308 usage = GetUsage(); | 1231 usage = GetUsage(); |
| 1309 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, | 1232 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, |
| 1310 GetDataSizeOnDisk()); | 1233 GetDataSizeOnDisk()); |
| 1311 EXPECT_EQ(expected_usage, usage); | 1234 EXPECT_EQ(expected_usage, usage); |
| 1312 } | 1235 } |
| 1313 | 1236 |
| 1314 TEST_F(FileSystemOperationImplTest, | 1237 TEST_F(FileSystemOperationImplTest, |
| 1315 TestCopySuccessSrcFileWithDifferentFileSize) { | 1238 TestCopySuccessSrcFileWithDifferentFileSize) { |
| 1316 FileSystemURL src_file(CreateFile("src")); | 1239 FileSystemURL src_file(CreateFile("src")); |
| 1317 FileSystemURL dest_file(CreateFile("dest")); | 1240 FileSystemURL dest_file(CreateFile("dest")); |
| 1318 | 1241 |
| 1319 { | 1242 EXPECT_EQ(TruncateTest(dest_file, 6), base::File::FILE_OK); |
| 1320 base::RunLoop run_loop; | 1243 EXPECT_EQ(CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE), |
| 1321 operation_runner()->Truncate( | 1244 base::File::FILE_OK); |
| 1322 dest_file, 6, | |
| 1323 base::Bind(&AssertFileErrorEqWithClosure, | |
| 1324 FROM_HERE, | |
| 1325 base::File::FILE_OK, | |
| 1326 run_loop.QuitClosure())); | |
| 1327 run_loop.Run(); | |
| 1328 } | |
| 1329 | |
| 1330 { | |
| 1331 base::RunLoop run_loop; | |
| 1332 operation_runner()->Copy( | |
| 1333 src_file, dest_file, FileSystemOperation::OPTION_NONE, | |
| 1334 FileSystemOperationRunner::CopyProgressCallback(), | |
| 1335 base::Bind(&AssertFileErrorEqWithClosure, | |
| 1336 FROM_HERE, | |
| 1337 base::File::FILE_OK, | |
| 1338 run_loop.QuitClosure())); | |
| 1339 run_loop.Run(); | |
| 1340 } | |
| 1341 EXPECT_EQ(0, GetFileSize("dest")); | 1245 EXPECT_EQ(0, GetFileSize("dest")); |
| 1342 } | 1246 } |
| 1343 | 1247 |
| 1344 } // namespace content | 1248 } // namespace content |
| OLD | NEW |