Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
| 12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 15 #include "webkit/fileapi/file_system_context.h" | 15 #include "webkit/fileapi/file_system_context.h" |
| 16 #include "webkit/fileapi/file_system_file_util.h" | 16 #include "webkit/fileapi/file_system_file_util.h" |
| 17 #include "webkit/fileapi/file_system_mount_point_provider.h" | 17 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 18 #include "webkit/fileapi/file_system_operation.h" | 18 #include "webkit/fileapi/file_system_operation.h" |
| 19 #include "webkit/fileapi/file_system_quota_util.h" | 19 #include "webkit/fileapi/file_system_quota_util.h" |
| 20 #include "webkit/fileapi/file_system_test_helper.h" | 20 #include "webkit/fileapi/file_system_test_helper.h" |
| 21 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
| 22 #include "webkit/fileapi/local_file_util.h" | 22 #include "webkit/fileapi/local_file_util.h" |
| 23 #include "webkit/fileapi/quota_file_util.h" | 23 #include "webkit/fileapi/quota_file_util.h" |
| 24 #include "webkit/quota/quota_manager.h" | 24 #include "webkit/quota/quota_manager.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 class FileSystemOperationTest : public testing::Test { | 153 class FileSystemOperationTest : public testing::Test { |
| 154 public: | 154 public: |
| 155 FileSystemOperationTest() | 155 FileSystemOperationTest() |
| 156 : status_(kFileOperationStatusNotSet), | 156 : status_(kFileOperationStatusNotSet), |
| 157 local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())) { | 157 local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())) { |
| 158 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 158 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 FileSystemOperation* operation(); | 161 FileSystemOperation* operation(); |
| 162 | 162 |
| 163 void set_status(int status) { status_ = status; } | 163 void set_status(int status) { status_ = status; } |
|
kinuko
2012/02/10 05:34:09
Now that all the callbacks became member methods p
kinaba
2012/02/10 08:22:58
Done.
| |
| 164 int status() const { return status_; } | 164 int status() const { return status_; } |
| 165 void set_info(const base::PlatformFileInfo& info) { info_ = info; } | 165 void set_info(const base::PlatformFileInfo& info) { info_ = info; } |
| 166 const base::PlatformFileInfo& info() const { return info_; } | 166 const base::PlatformFileInfo& info() const { return info_; } |
| 167 void set_path(const FilePath& path) { path_ = path; } | 167 void set_path(const FilePath& path) { path_ = path; } |
| 168 const FilePath& path() const { return path_; } | 168 const FilePath& path() const { return path_; } |
| 169 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { | 169 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { |
| 170 entries_ = entries; | 170 entries_ = entries; |
| 171 } | 171 } |
| 172 const std::vector<base::FileUtilProxy::Entry>& entries() const { | 172 const std::vector<base::FileUtilProxy::Entry>& entries() const { |
| 173 return entries_; | 173 return entries_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 else | 234 else |
| 235 return FilePath(); | 235 return FilePath(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 FilePath CreateVirtualTemporaryDir() { | 238 FilePath CreateVirtualTemporaryDir() { |
| 239 return CreateVirtualTemporaryDirInDir(FilePath()); | 239 return CreateVirtualTemporaryDirInDir(FilePath()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 FileSystemTestOriginHelper test_helper_; | 242 FileSystemTestOriginHelper test_helper_; |
| 243 | 243 |
| 244 // Callbacks for recording test results. | |
| 245 FileSystemOperationInterface::StatusCallback RecordStatus() { | |
|
kinuko
2012/02/10 05:34:09
naming-nit: RecordStatusCallback() might be slight
kinaba
2012/02/10 08:22:58
Done.
| |
| 246 return base::Bind(&FileSystemOperationTest::DidFinish, | |
| 247 base::Unretained(this)); | |
|
kinuko
2012/02/10 05:34:09
This should be safe in theory but maybe we could u
kinaba
2012/02/10 08:22:58
Done.
| |
| 248 } | |
| 249 | |
| 250 FileSystemOperationInterface::ReadDirectoryCallback RecordReadDirectory() { | |
| 251 return base::Bind(&FileSystemOperationTest::DidReadDirectory, | |
| 252 base::Unretained(this)); | |
| 253 } | |
| 254 | |
| 255 FileSystemOperationInterface::GetMetadataCallback RecordMetadata() { | |
| 256 return base::Bind(&FileSystemOperationTest::DidGetMetadata, | |
| 257 base::Unretained(this)); | |
| 258 } | |
| 259 | |
| 260 void DidFinish(base::PlatformFileError status) { | |
| 261 set_status(status); | |
| 262 } | |
| 263 | |
| 264 void DidReadDirectory( | |
| 265 base::PlatformFileError status, | |
| 266 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 267 bool /* has_more */) { | |
| 268 if (status == base::PLATFORM_FILE_OK) | |
|
kinuko
2012/02/10 05:34:09
Not really sure if we need this if/else's here?
kinaba
2012/02/10 08:22:58
Done.
I did in this way because TestReadDirSuccess
| |
| 269 set_entries(entries); | |
| 270 else | |
| 271 set_status(status); | |
| 272 } | |
| 273 | |
| 274 void DidGetMetadata(base::PlatformFileError status, | |
| 275 const base::PlatformFileInfo& info, | |
| 276 const FilePath& platform_path) { | |
| 277 if (status == base::PLATFORM_FILE_OK) { | |
|
kinuko
2012/02/10 05:34:09
ditto.
kinaba
2012/02/10 08:22:58
Done.
| |
| 278 set_info(info); | |
| 279 set_path(platform_path); | |
| 280 } | |
| 281 set_status(status); | |
| 282 } | |
| 283 | |
| 244 // For post-operation status. | 284 // For post-operation status. |
| 245 int status_; | 285 int status_; |
| 246 base::PlatformFileInfo info_; | 286 base::PlatformFileInfo info_; |
| 247 FilePath path_; | 287 FilePath path_; |
| 248 std::vector<base::FileUtilProxy::Entry> entries_; | 288 std::vector<base::FileUtilProxy::Entry> entries_; |
| 249 | 289 |
| 250 private: | 290 private: |
| 251 scoped_ptr<LocalFileUtil> local_file_util_; | 291 scoped_ptr<LocalFileUtil> local_file_util_; |
| 252 scoped_refptr<QuotaManager> quota_manager_; | 292 scoped_refptr<QuotaManager> quota_manager_; |
| 253 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 293 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
| 254 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); | 294 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); |
| 255 }; | 295 }; |
| 256 | 296 |
| 257 namespace { | |
| 258 | |
| 259 class MockDispatcher : public FileSystemCallbackDispatcher { | |
| 260 public: | |
| 261 explicit MockDispatcher(FileSystemOperationTest* test) : test_(test) { } | |
| 262 | |
| 263 virtual void DidFail(base::PlatformFileError status) { | |
| 264 test_->set_status(status); | |
| 265 } | |
| 266 | |
| 267 virtual void DidSucceed() { | |
| 268 test_->set_status(base::PLATFORM_FILE_OK); | |
| 269 } | |
| 270 | |
| 271 virtual void DidReadMetadata( | |
| 272 const base::PlatformFileInfo& info, | |
| 273 const FilePath& platform_path) { | |
| 274 test_->set_info(info); | |
| 275 test_->set_path(platform_path); | |
| 276 test_->set_status(base::PLATFORM_FILE_OK); | |
| 277 } | |
| 278 | |
| 279 virtual void DidReadDirectory( | |
| 280 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 281 bool /* has_more */) { | |
| 282 test_->set_entries(entries); | |
| 283 } | |
| 284 | |
| 285 virtual void DidOpenFileSystem(const std::string&, const GURL&) { | |
| 286 NOTREACHED(); | |
| 287 } | |
| 288 | |
| 289 virtual void DidWrite(int64 bytes, bool complete) { | |
| 290 NOTREACHED(); | |
| 291 } | |
| 292 | |
| 293 private: | |
| 294 FileSystemOperationTest* test_; | |
| 295 }; | |
| 296 | |
| 297 } // namespace (anonymous) | |
| 298 | |
| 299 void FileSystemOperationTest::SetUp() { | 297 void FileSystemOperationTest::SetUp() { |
| 300 FilePath base_dir = base_.path().AppendASCII("filesystem"); | 298 FilePath base_dir = base_.path().AppendASCII("filesystem"); |
| 301 quota_manager_ = new MockQuotaManager( | 299 quota_manager_ = new MockQuotaManager( |
| 302 base_dir, test_helper_.origin(), test_helper_.storage_type()); | 300 base_dir, test_helper_.origin(), test_helper_.storage_type()); |
| 303 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); | 301 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); |
| 304 test_helper_.SetUp(base_dir, | 302 test_helper_.SetUp(base_dir, |
| 305 false /* unlimited quota */, | 303 false /* unlimited quota */, |
| 306 quota_manager_proxy_.get(), | 304 quota_manager_proxy_.get(), |
| 307 local_file_util_.get()); | 305 local_file_util_.get()); |
| 308 } | 306 } |
| 309 | 307 |
| 310 void FileSystemOperationTest::TearDown() { | 308 void FileSystemOperationTest::TearDown() { |
| 311 // Let the client go away before dropping a ref of the quota manager proxy. | 309 // Let the client go away before dropping a ref of the quota manager proxy. |
| 312 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); | 310 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); |
| 313 quota_manager_ = NULL; | 311 quota_manager_ = NULL; |
| 314 quota_manager_proxy_ = NULL; | 312 quota_manager_proxy_ = NULL; |
| 315 test_helper_.TearDown(); | 313 test_helper_.TearDown(); |
| 316 } | 314 } |
| 317 | 315 |
| 318 FileSystemOperation* FileSystemOperationTest::operation() { | 316 FileSystemOperation* FileSystemOperationTest::operation() { |
| 319 return test_helper_.NewOperation(new MockDispatcher(this)); | 317 return test_helper_.NewOperation(); |
| 320 } | 318 } |
| 321 | 319 |
| 322 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { | 320 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { |
| 323 GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); | 321 GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); |
| 324 GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); | 322 GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); |
| 325 operation()->Move(src, dest); | 323 operation()->Move(src, dest, RecordStatus()); |
| 326 MessageLoop::current()->RunAllPending(); | 324 MessageLoop::current()->RunAllPending(); |
| 327 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 325 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 328 } | 326 } |
| 329 | 327 |
| 330 TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) { | 328 TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) { |
| 331 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 329 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 332 FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); | 330 FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); |
| 333 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 331 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 332 RecordStatus()); | |
| 334 MessageLoop::current()->RunAllPending(); | 333 MessageLoop::current()->RunAllPending(); |
| 335 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 334 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 336 } | 335 } |
| 337 | 336 |
| 338 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { | 337 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { |
| 339 // Src exists and is dir. Dest is a file. | 338 // Src exists and is dir. Dest is a file. |
| 340 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 339 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 341 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 340 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 342 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); | 341 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); |
| 343 | 342 |
| 344 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path)); | 343 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path), |
| 344 RecordStatus()); | |
| 345 MessageLoop::current()->RunAllPending(); | 345 MessageLoop::current()->RunAllPending(); |
| 346 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 346 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 347 } | 347 } |
| 348 | 348 |
| 349 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) { | 349 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) { |
| 350 // Src exists and is a directory. Dest is a non-empty directory. | 350 // Src exists and is a directory. Dest is a non-empty directory. |
| 351 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 351 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 352 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 352 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 353 FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); | 353 FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); |
| 354 | 354 |
| 355 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 355 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 356 RecordStatus()); | |
| 356 MessageLoop::current()->RunAllPending(); | 357 MessageLoop::current()->RunAllPending(); |
| 357 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 358 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
| 358 } | 359 } |
| 359 | 360 |
| 360 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { | 361 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { |
| 361 // Src exists and is a file. Dest is a directory. | 362 // Src exists and is a file. Dest is a directory. |
| 362 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 363 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 363 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 364 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
| 364 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 365 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 365 | 366 |
| 366 operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path)); | 367 operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path), |
| 368 RecordStatus()); | |
| 367 MessageLoop::current()->RunAllPending(); | 369 MessageLoop::current()->RunAllPending(); |
| 368 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 370 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 369 } | 371 } |
| 370 | 372 |
| 371 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { | 373 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { |
| 372 // Dest. parent path does not exist. | 374 // Dest. parent path does not exist. |
| 373 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 375 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 374 FilePath nonexisting_file = FilePath(FILE_PATH_LITERAL("NonexistingDir")). | 376 FilePath nonexisting_file = FilePath(FILE_PATH_LITERAL("NonexistingDir")). |
| 375 Append(FILE_PATH_LITERAL("NonexistingFile")); | 377 Append(FILE_PATH_LITERAL("NonexistingFile")); |
| 376 | 378 |
| 377 operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file)); | 379 operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file), |
| 380 RecordStatus()); | |
| 378 MessageLoop::current()->RunAllPending(); | 381 MessageLoop::current()->RunAllPending(); |
| 379 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 382 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 380 } | 383 } |
| 381 | 384 |
| 382 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { | 385 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { |
| 383 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 386 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 384 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 387 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
| 385 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 388 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 386 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); | 389 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); |
| 387 | 390 |
| 388 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path)); | 391 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), |
| 392 RecordStatus()); | |
| 389 MessageLoop::current()->RunAllPending(); | 393 MessageLoop::current()->RunAllPending(); |
| 390 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 394 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 391 EXPECT_TRUE(VirtualFileExists(dest_file_path)); | 395 EXPECT_TRUE(VirtualFileExists(dest_file_path)); |
| 392 | 396 |
| 393 // Move is considered 'write' access (for both side), and won't be counted | 397 // Move is considered 'write' access (for both side), and won't be counted |
| 394 // as read access. | 398 // as read access. |
| 395 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); | 399 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); |
| 396 } | 400 } |
| 397 | 401 |
| 398 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { | 402 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { |
| 399 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 403 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 400 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 404 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
| 401 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 405 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 402 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 406 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
| 403 | 407 |
| 404 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path)); | 408 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), |
| 409 RecordStatus()); | |
| 405 MessageLoop::current()->RunAllPending(); | 410 MessageLoop::current()->RunAllPending(); |
| 406 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 411 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 407 EXPECT_TRUE(VirtualFileExists(dest_file_path)); | 412 EXPECT_TRUE(VirtualFileExists(dest_file_path)); |
| 408 } | 413 } |
| 409 | 414 |
| 410 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { | 415 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { |
| 411 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 416 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 412 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 417 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 413 | 418 |
| 414 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 419 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 420 RecordStatus()); | |
| 415 MessageLoop::current()->RunAllPending(); | 421 MessageLoop::current()->RunAllPending(); |
| 416 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 422 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 417 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); | 423 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); |
| 418 | 424 |
| 419 // Make sure we've overwritten but not moved the source under the |dest_dir|. | 425 // Make sure we've overwritten but not moved the source under the |dest_dir|. |
| 420 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); | 426 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); |
| 421 EXPECT_FALSE(VirtualDirectoryExists( | 427 EXPECT_FALSE(VirtualDirectoryExists( |
| 422 dest_dir_path.Append(src_dir_path.BaseName()))); | 428 dest_dir_path.Append(src_dir_path.BaseName()))); |
| 423 } | 429 } |
| 424 | 430 |
| 425 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { | 431 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { |
| 426 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 432 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 427 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); | 433 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); |
| 428 FilePath dest_child_dir_path(dest_parent_dir_path. | 434 FilePath dest_child_dir_path(dest_parent_dir_path. |
| 429 Append(FILE_PATH_LITERAL("NewDirectory"))); | 435 Append(FILE_PATH_LITERAL("NewDirectory"))); |
| 430 | 436 |
| 431 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path)); | 437 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
| 438 RecordStatus()); | |
| 432 MessageLoop::current()->RunAllPending(); | 439 MessageLoop::current()->RunAllPending(); |
| 433 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 440 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 434 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); | 441 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); |
| 435 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); | 442 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); |
| 436 } | 443 } |
| 437 | 444 |
| 438 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { | 445 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { |
| 439 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 446 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 440 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); | 447 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); |
| 441 FilePath grandchild_file_path( | 448 FilePath grandchild_file_path( |
| 442 CreateVirtualTemporaryFileInDir(child_dir_path)); | 449 CreateVirtualTemporaryFileInDir(child_dir_path)); |
| 443 | 450 |
| 444 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 451 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 445 | 452 |
| 446 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 453 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 454 RecordStatus()); | |
| 447 MessageLoop::current()->RunAllPending(); | 455 MessageLoop::current()->RunAllPending(); |
| 448 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 456 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 449 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( | 457 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( |
| 450 child_dir_path.BaseName()))); | 458 child_dir_path.BaseName()))); |
| 451 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( | 459 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( |
| 452 child_dir_path.BaseName()).Append( | 460 child_dir_path.BaseName()).Append( |
| 453 grandchild_file_path.BaseName()))); | 461 grandchild_file_path.BaseName()))); |
| 454 } | 462 } |
| 455 | 463 |
| 456 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) { | 464 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) { |
| 457 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))), | 465 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))), |
| 458 URLForPath(FilePath(FILE_PATH_LITERAL("b")))); | 466 URLForPath(FilePath(FILE_PATH_LITERAL("b"))), |
| 467 RecordStatus()); | |
| 459 MessageLoop::current()->RunAllPending(); | 468 MessageLoop::current()->RunAllPending(); |
| 460 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 469 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 461 } | 470 } |
| 462 | 471 |
| 463 TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) { | 472 TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) { |
| 464 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 473 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 465 FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); | 474 FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); |
| 466 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 475 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 476 RecordStatus()); | |
| 467 MessageLoop::current()->RunAllPending(); | 477 MessageLoop::current()->RunAllPending(); |
| 468 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 478 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 469 } | 479 } |
| 470 | 480 |
| 471 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { | 481 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { |
| 472 // Src exists and is dir. Dest is a file. | 482 // Src exists and is dir. Dest is a file. |
| 473 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 483 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 474 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 484 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 475 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); | 485 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); |
| 476 | 486 |
| 477 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path)); | 487 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path), |
| 488 RecordStatus()); | |
| 478 MessageLoop::current()->RunAllPending(); | 489 MessageLoop::current()->RunAllPending(); |
| 479 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 490 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 480 } | 491 } |
| 481 | 492 |
| 482 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) { | 493 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) { |
| 483 // Src exists and is a directory. Dest is a non-empty directory. | 494 // Src exists and is a directory. Dest is a non-empty directory. |
| 484 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 495 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 485 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 496 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 486 FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); | 497 FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); |
| 487 | 498 |
| 488 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 499 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 500 RecordStatus()); | |
| 489 MessageLoop::current()->RunAllPending(); | 501 MessageLoop::current()->RunAllPending(); |
| 490 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 502 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
| 491 } | 503 } |
| 492 | 504 |
| 493 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { | 505 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { |
| 494 // Src exists and is a file. Dest is a directory. | 506 // Src exists and is a file. Dest is a directory. |
| 495 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 507 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 496 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 508 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
| 497 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 509 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 498 | 510 |
| 499 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path)); | 511 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path), |
| 512 RecordStatus()); | |
| 500 MessageLoop::current()->RunAllPending(); | 513 MessageLoop::current()->RunAllPending(); |
| 501 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 514 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 502 } | 515 } |
| 503 | 516 |
| 504 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { | 517 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { |
| 505 // Dest. parent path does not exist. | 518 // Dest. parent path does not exist. |
| 506 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 519 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 507 FilePath nonexisting_path = FilePath(FILE_PATH_LITERAL("DontExistDir")); | 520 FilePath nonexisting_path = FilePath(FILE_PATH_LITERAL("DontExistDir")); |
| 508 file_util::EnsureEndsWithSeparator(&nonexisting_path); | 521 file_util::EnsureEndsWithSeparator(&nonexisting_path); |
| 509 FilePath nonexisting_file_path(nonexisting_path.Append( | 522 FilePath nonexisting_file_path(nonexisting_path.Append( |
| 510 FILE_PATH_LITERAL("DontExistFile"))); | 523 FILE_PATH_LITERAL("DontExistFile"))); |
| 511 | 524 |
| 512 operation()->Copy(URLForPath(src_dir_path), | 525 operation()->Copy(URLForPath(src_dir_path), |
| 513 URLForPath(nonexisting_file_path)); | 526 URLForPath(nonexisting_file_path), |
| 527 RecordStatus()); | |
| 514 MessageLoop::current()->RunAllPending(); | 528 MessageLoop::current()->RunAllPending(); |
| 515 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 529 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 516 } | 530 } |
| 517 | 531 |
| 518 TEST_F(FileSystemOperationTest, TestCopyFailureByQuota) { | 532 TEST_F(FileSystemOperationTest, TestCopyFailureByQuota) { |
| 519 base::PlatformFileInfo info; | 533 base::PlatformFileInfo info; |
| 520 | 534 |
| 521 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 535 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 522 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 536 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
| 523 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 537 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 524 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 538 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
| 525 | 539 |
| 526 quota_manager_proxy()->SetQuota(test_helper_.origin(), | 540 quota_manager_proxy()->SetQuota(test_helper_.origin(), |
| 527 test_helper_.storage_type(), | 541 test_helper_.storage_type(), |
| 528 11); | 542 11); |
| 529 | 543 |
| 530 operation()->Truncate(URLForPath(src_file_path), 6); | 544 operation()->Truncate(URLForPath(src_file_path), 6, |
| 545 RecordStatus()); | |
| 531 MessageLoop::current()->RunAllPending(); | 546 MessageLoop::current()->RunAllPending(); |
| 532 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 547 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 533 | 548 |
| 534 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); | 549 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); |
| 535 EXPECT_EQ(6, info.size); | 550 EXPECT_EQ(6, info.size); |
| 536 | 551 |
| 537 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); | 552 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
| 553 RecordStatus()); | |
| 538 MessageLoop::current()->RunAllPending(); | 554 MessageLoop::current()->RunAllPending(); |
| 539 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 555 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 540 EXPECT_FALSE(VirtualFileExists(dest_file_path)); | 556 EXPECT_FALSE(VirtualFileExists(dest_file_path)); |
| 541 } | 557 } |
| 542 | 558 |
| 543 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { | 559 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { |
| 544 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 560 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 545 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 561 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
| 546 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 562 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 547 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); | 563 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); |
| 548 | 564 |
| 549 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); | 565 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
| 566 RecordStatus()); | |
| 550 MessageLoop::current()->RunAllPending(); | 567 MessageLoop::current()->RunAllPending(); |
| 551 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 568 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 552 EXPECT_TRUE(VirtualFileExists(dest_file_path)); | 569 EXPECT_TRUE(VirtualFileExists(dest_file_path)); |
| 553 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 570 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 554 } | 571 } |
| 555 | 572 |
| 556 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) { | 573 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) { |
| 557 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 574 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 558 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 575 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
| 559 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 576 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 560 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 577 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
| 561 | 578 |
| 562 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); | 579 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
| 580 RecordStatus()); | |
| 563 MessageLoop::current()->RunAllPending(); | 581 MessageLoop::current()->RunAllPending(); |
| 564 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 582 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 565 EXPECT_TRUE(VirtualFileExists(dest_file_path)); | 583 EXPECT_TRUE(VirtualFileExists(dest_file_path)); |
| 566 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 584 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 567 } | 585 } |
| 568 | 586 |
| 569 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { | 587 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { |
| 570 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 588 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 571 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 589 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 572 | 590 |
| 573 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 591 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 592 RecordStatus()); | |
| 574 MessageLoop::current()->RunAllPending(); | 593 MessageLoop::current()->RunAllPending(); |
| 575 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 594 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 576 | 595 |
| 577 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 596 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
| 578 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); | 597 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); |
| 579 EXPECT_FALSE(VirtualDirectoryExists( | 598 EXPECT_FALSE(VirtualDirectoryExists( |
| 580 dest_dir_path.Append(src_dir_path.BaseName()))); | 599 dest_dir_path.Append(src_dir_path.BaseName()))); |
| 581 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 600 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 582 } | 601 } |
| 583 | 602 |
| 584 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { | 603 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { |
| 585 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 604 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 586 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); | 605 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); |
| 587 FilePath dest_child_dir_path(dest_parent_dir_path. | 606 FilePath dest_child_dir_path(dest_parent_dir_path. |
| 588 Append(FILE_PATH_LITERAL("NewDirectory"))); | 607 Append(FILE_PATH_LITERAL("NewDirectory"))); |
| 589 | 608 |
| 590 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path)); | 609 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
| 610 RecordStatus()); | |
| 591 MessageLoop::current()->RunAllPending(); | 611 MessageLoop::current()->RunAllPending(); |
| 592 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 612 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 593 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); | 613 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); |
| 594 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 614 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 595 } | 615 } |
| 596 | 616 |
| 597 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) { | 617 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) { |
| 598 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 618 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 599 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); | 619 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); |
| 600 FilePath grandchild_file_path( | 620 FilePath grandchild_file_path( |
| 601 CreateVirtualTemporaryFileInDir(child_dir_path)); | 621 CreateVirtualTemporaryFileInDir(child_dir_path)); |
| 602 | 622 |
| 603 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 623 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 604 | 624 |
| 605 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 625 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 626 RecordStatus()); | |
| 606 MessageLoop::current()->RunAllPending(); | 627 MessageLoop::current()->RunAllPending(); |
| 607 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 628 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 608 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( | 629 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( |
| 609 child_dir_path.BaseName()))); | 630 child_dir_path.BaseName()))); |
| 610 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( | 631 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( |
| 611 child_dir_path.BaseName()).Append( | 632 child_dir_path.BaseName()).Append( |
| 612 grandchild_file_path.BaseName()))); | 633 grandchild_file_path.BaseName()))); |
| 613 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 634 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 614 } | 635 } |
| 615 | 636 |
| 616 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { | 637 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { |
| 617 // Already existing file and exclusive true. | 638 // Already existing file and exclusive true. |
| 618 FilePath dir_path(CreateVirtualTemporaryDir()); | 639 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 619 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 640 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 620 operation()->CreateFile(URLForPath(file_path), true); | 641 operation()->CreateFile(URLForPath(file_path), true, |
| 642 RecordStatus()); | |
| 621 MessageLoop::current()->RunAllPending(); | 643 MessageLoop::current()->RunAllPending(); |
| 622 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 644 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
| 623 } | 645 } |
| 624 | 646 |
| 625 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) { | 647 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) { |
| 626 // Already existing file and exclusive false. | 648 // Already existing file and exclusive false. |
| 627 FilePath dir_path(CreateVirtualTemporaryDir()); | 649 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 628 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 650 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 629 operation()->CreateFile(URLForPath(file_path), false); | 651 operation()->CreateFile(URLForPath(file_path), false, |
| 652 RecordStatus()); | |
| 630 MessageLoop::current()->RunAllPending(); | 653 MessageLoop::current()->RunAllPending(); |
| 631 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 654 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 632 EXPECT_TRUE(VirtualFileExists(file_path)); | 655 EXPECT_TRUE(VirtualFileExists(file_path)); |
| 633 } | 656 } |
| 634 | 657 |
| 635 TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) { | 658 TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) { |
| 636 // File doesn't exist but exclusive is true. | 659 // File doesn't exist but exclusive is true. |
| 637 FilePath dir_path(CreateVirtualTemporaryDir()); | 660 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 638 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); | 661 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); |
| 639 operation()->CreateFile(URLForPath(file_path), true); | 662 operation()->CreateFile(URLForPath(file_path), true, |
| 663 RecordStatus()); | |
| 640 MessageLoop::current()->RunAllPending(); | 664 MessageLoop::current()->RunAllPending(); |
| 641 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 665 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 642 EXPECT_TRUE(VirtualFileExists(file_path)); | 666 EXPECT_TRUE(VirtualFileExists(file_path)); |
| 643 } | 667 } |
| 644 | 668 |
| 645 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { | 669 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { |
| 646 // Non existing file. | 670 // Non existing file. |
| 647 FilePath dir_path(CreateVirtualTemporaryDir()); | 671 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 648 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); | 672 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); |
| 649 operation()->CreateFile(URLForPath(file_path), false); | 673 operation()->CreateFile(URLForPath(file_path), false, |
| 674 RecordStatus()); | |
| 650 MessageLoop::current()->RunAllPending(); | 675 MessageLoop::current()->RunAllPending(); |
| 651 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 676 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 652 } | 677 } |
| 653 | 678 |
| 654 TEST_F(FileSystemOperationTest, | 679 TEST_F(FileSystemOperationTest, |
| 655 TestCreateDirFailureDestParentDoesntExist) { | 680 TestCreateDirFailureDestParentDoesntExist) { |
| 656 // Dest. parent path does not exist. | 681 // Dest. parent path does not exist. |
| 657 FilePath nonexisting_path(FilePath( | 682 FilePath nonexisting_path(FilePath( |
| 658 FILE_PATH_LITERAL("DirDoesntExist"))); | 683 FILE_PATH_LITERAL("DirDoesntExist"))); |
| 659 FilePath nonexisting_file_path(nonexisting_path.Append( | 684 FilePath nonexisting_file_path(nonexisting_path.Append( |
| 660 FILE_PATH_LITERAL("FileDoesntExist"))); | 685 FILE_PATH_LITERAL("FileDoesntExist"))); |
| 661 operation()->CreateDirectory( | 686 operation()->CreateDirectory(URLForPath(nonexisting_file_path), false, false, |
| 662 URLForPath(nonexisting_file_path), false, false); | 687 RecordStatus()); |
| 663 MessageLoop::current()->RunAllPending(); | 688 MessageLoop::current()->RunAllPending(); |
| 664 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 689 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 665 } | 690 } |
| 666 | 691 |
| 667 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) { | 692 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) { |
| 668 // Exclusive and dir existing at path. | 693 // Exclusive and dir existing at path. |
| 669 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 694 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 670 operation()->CreateDirectory(URLForPath(src_dir_path), true, false); | 695 operation()->CreateDirectory(URLForPath(src_dir_path), true, false, |
| 696 RecordStatus()); | |
| 671 MessageLoop::current()->RunAllPending(); | 697 MessageLoop::current()->RunAllPending(); |
| 672 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 698 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
| 673 } | 699 } |
| 674 | 700 |
| 675 TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) { | 701 TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) { |
| 676 // Exclusive true and file existing at path. | 702 // Exclusive true and file existing at path. |
| 677 FilePath dir_path(CreateVirtualTemporaryDir()); | 703 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 678 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 704 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 679 operation()->CreateDirectory(URLForPath(file_path), true, false); | 705 operation()->CreateDirectory(URLForPath(file_path), true, false, |
| 706 RecordStatus()); | |
| 680 MessageLoop::current()->RunAllPending(); | 707 MessageLoop::current()->RunAllPending(); |
| 681 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 708 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
| 682 } | 709 } |
| 683 | 710 |
| 684 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) { | 711 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) { |
| 685 // Dir exists and exclusive is false. | 712 // Dir exists and exclusive is false. |
| 686 FilePath dir_path(CreateVirtualTemporaryDir()); | 713 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 687 operation()->CreateDirectory(URLForPath(dir_path), false, false); | 714 operation()->CreateDirectory(URLForPath(dir_path), false, false, |
| 715 RecordStatus()); | |
| 688 MessageLoop::current()->RunAllPending(); | 716 MessageLoop::current()->RunAllPending(); |
| 689 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 717 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 690 | 718 |
| 691 // Dir doesn't exist. | 719 // Dir doesn't exist. |
| 692 FilePath nonexisting_dir_path(FilePath( | 720 FilePath nonexisting_dir_path(FilePath( |
| 693 FILE_PATH_LITERAL("nonexistingdir"))); | 721 FILE_PATH_LITERAL("nonexistingdir"))); |
| 694 operation()->CreateDirectory( | 722 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false, |
| 695 URLForPath(nonexisting_dir_path), false, false); | 723 RecordStatus()); |
| 696 MessageLoop::current()->RunAllPending(); | 724 MessageLoop::current()->RunAllPending(); |
| 697 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 725 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 698 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); | 726 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); |
| 699 } | 727 } |
| 700 | 728 |
| 701 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) { | 729 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) { |
| 702 // Dir doesn't exist. | 730 // Dir doesn't exist. |
| 703 FilePath nonexisting_dir_path(FilePath( | 731 FilePath nonexisting_dir_path(FilePath( |
| 704 FILE_PATH_LITERAL("nonexistingdir"))); | 732 FILE_PATH_LITERAL("nonexistingdir"))); |
| 705 | 733 |
| 706 operation()->CreateDirectory( | 734 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false, |
| 707 URLForPath(nonexisting_dir_path), true, false); | 735 RecordStatus()); |
| 708 MessageLoop::current()->RunAllPending(); | 736 MessageLoop::current()->RunAllPending(); |
| 709 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 737 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 710 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); | 738 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); |
| 711 } | 739 } |
| 712 | 740 |
| 713 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) { | 741 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) { |
| 714 FilePath nonexisting_dir_path(FilePath( | 742 FilePath nonexisting_dir_path(FilePath( |
| 715 FILE_PATH_LITERAL("nonexistingdir"))); | 743 FILE_PATH_LITERAL("nonexistingdir"))); |
| 716 operation()->GetMetadata(URLForPath(nonexisting_dir_path)); | 744 operation()->GetMetadata(URLForPath(nonexisting_dir_path), RecordMetadata()); |
| 717 MessageLoop::current()->RunAllPending(); | 745 MessageLoop::current()->RunAllPending(); |
| 718 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 746 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 719 | 747 |
| 720 operation()->FileExists(URLForPath(nonexisting_dir_path)); | 748 operation()->FileExists(URLForPath(nonexisting_dir_path), RecordStatus()); |
| 721 MessageLoop::current()->RunAllPending(); | 749 MessageLoop::current()->RunAllPending(); |
| 722 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 750 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 723 | 751 |
| 724 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 752 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); |
| 725 operation()->DirectoryExists(URLForPath(nonexisting_dir_path)); | 753 operation()->DirectoryExists(URLForPath(nonexisting_dir_path), |
| 754 RecordStatus()); | |
| 726 MessageLoop::current()->RunAllPending(); | 755 MessageLoop::current()->RunAllPending(); |
| 727 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 756 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 728 } | 757 } |
| 729 | 758 |
| 730 TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) { | 759 TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) { |
| 731 FilePath dir_path(CreateVirtualTemporaryDir()); | 760 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 732 int read_access = 0; | 761 int read_access = 0; |
| 733 | 762 |
| 734 operation()->DirectoryExists(URLForPath(dir_path)); | 763 operation()->DirectoryExists(URLForPath(dir_path), |
| 764 RecordStatus()); | |
| 735 MessageLoop::current()->RunAllPending(); | 765 MessageLoop::current()->RunAllPending(); |
| 736 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 766 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 737 ++read_access; | 767 ++read_access; |
| 738 | 768 |
| 739 operation()->GetMetadata(URLForPath(dir_path)); | 769 operation()->GetMetadata(URLForPath(dir_path), RecordMetadata()); |
| 740 MessageLoop::current()->RunAllPending(); | 770 MessageLoop::current()->RunAllPending(); |
| 741 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 771 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 742 EXPECT_TRUE(info().is_directory); | 772 EXPECT_TRUE(info().is_directory); |
| 743 EXPECT_EQ(PlatformPath(dir_path), path()); | 773 EXPECT_EQ(PlatformPath(dir_path), path()); |
| 744 ++read_access; | 774 ++read_access; |
| 745 | 775 |
| 746 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 776 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 747 operation()->FileExists(URLForPath(file_path)); | 777 operation()->FileExists(URLForPath(file_path), RecordStatus()); |
| 748 MessageLoop::current()->RunAllPending(); | 778 MessageLoop::current()->RunAllPending(); |
| 749 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 779 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 750 ++read_access; | 780 ++read_access; |
| 751 | 781 |
| 752 operation()->GetMetadata(URLForPath(file_path)); | 782 operation()->GetMetadata(URLForPath(file_path), RecordMetadata()); |
| 753 MessageLoop::current()->RunAllPending(); | 783 MessageLoop::current()->RunAllPending(); |
| 754 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 784 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 755 EXPECT_FALSE(info().is_directory); | 785 EXPECT_FALSE(info().is_directory); |
| 756 EXPECT_EQ(PlatformPath(file_path), path()); | 786 EXPECT_EQ(PlatformPath(file_path), path()); |
| 757 ++read_access; | 787 ++read_access; |
| 758 | 788 |
| 759 EXPECT_EQ(read_access, quota_manager_proxy()->storage_accessed_count()); | 789 EXPECT_EQ(read_access, quota_manager_proxy()->storage_accessed_count()); |
| 760 } | 790 } |
| 761 | 791 |
| 762 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { | 792 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { |
| 763 FilePath dir_path(CreateVirtualTemporaryDir()); | 793 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 764 operation()->FileExists(URLForPath(dir_path)); | 794 operation()->FileExists(URLForPath(dir_path), RecordStatus()); |
| 765 MessageLoop::current()->RunAllPending(); | 795 MessageLoop::current()->RunAllPending(); |
| 766 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); | 796 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); |
| 767 | 797 |
| 768 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 798 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 769 ASSERT_FALSE(file_path.empty()); | 799 ASSERT_FALSE(file_path.empty()); |
| 770 operation()->DirectoryExists(URLForPath(file_path)); | 800 operation()->DirectoryExists(URLForPath(file_path), RecordStatus()); |
| 771 MessageLoop::current()->RunAllPending(); | 801 MessageLoop::current()->RunAllPending(); |
| 772 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); | 802 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); |
| 773 } | 803 } |
| 774 | 804 |
| 775 TEST_F(FileSystemOperationTest, TestReadDirFailure) { | 805 TEST_F(FileSystemOperationTest, TestReadDirFailure) { |
| 776 // Path doesn't exist | 806 // Path doesn't exist |
| 777 FilePath nonexisting_dir_path(FilePath( | 807 FilePath nonexisting_dir_path(FilePath( |
| 778 FILE_PATH_LITERAL("NonExistingDir"))); | 808 FILE_PATH_LITERAL("NonExistingDir"))); |
| 779 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 809 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); |
| 780 operation()->ReadDirectory(URLForPath(nonexisting_dir_path)); | 810 operation()->ReadDirectory(URLForPath(nonexisting_dir_path), |
| 811 RecordReadDirectory()); | |
| 781 MessageLoop::current()->RunAllPending(); | 812 MessageLoop::current()->RunAllPending(); |
| 782 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 813 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 783 | 814 |
| 784 // File exists. | 815 // File exists. |
| 785 FilePath dir_path(CreateVirtualTemporaryDir()); | 816 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 786 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 817 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 787 operation()->ReadDirectory(URLForPath(file_path)); | 818 operation()->ReadDirectory(URLForPath(file_path), RecordReadDirectory()); |
| 788 MessageLoop::current()->RunAllPending(); | 819 MessageLoop::current()->RunAllPending(); |
| 789 // TODO(kkanetkar) crbug.com/54309 to change the error code. | 820 // TODO(kkanetkar) crbug.com/54309 to change the error code. |
| 790 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 821 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 791 } | 822 } |
| 792 | 823 |
| 793 TEST_F(FileSystemOperationTest, TestReadDirSuccess) { | 824 TEST_F(FileSystemOperationTest, TestReadDirSuccess) { |
| 794 // parent_dir | 825 // parent_dir |
| 795 // | | | 826 // | | |
| 796 // child_dir child_file | 827 // child_dir child_file |
| 797 // Verify reading parent_dir. | 828 // Verify reading parent_dir. |
| 798 FilePath parent_dir_path(CreateVirtualTemporaryDir()); | 829 FilePath parent_dir_path(CreateVirtualTemporaryDir()); |
| 799 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); | 830 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); |
| 800 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); | 831 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); |
| 801 ASSERT_FALSE(child_dir_path.empty()); | 832 ASSERT_FALSE(child_dir_path.empty()); |
| 802 | 833 |
| 803 operation()->ReadDirectory(URLForPath(parent_dir_path)); | 834 operation()->ReadDirectory(URLForPath(parent_dir_path), |
| 835 RecordReadDirectory()); | |
| 804 MessageLoop::current()->RunAllPending(); | 836 MessageLoop::current()->RunAllPending(); |
| 805 EXPECT_EQ(kFileOperationStatusNotSet, status()); | 837 EXPECT_EQ(kFileOperationStatusNotSet, status()); |
| 806 EXPECT_EQ(2u, entries().size()); | 838 EXPECT_EQ(2u, entries().size()); |
| 807 | 839 |
| 808 for (size_t i = 0; i < entries().size(); ++i) { | 840 for (size_t i = 0; i < entries().size(); ++i) { |
| 809 if (entries()[i].is_directory) { | 841 if (entries()[i].is_directory) { |
| 810 EXPECT_EQ(child_dir_path.BaseName().value(), | 842 EXPECT_EQ(child_dir_path.BaseName().value(), |
| 811 entries()[i].name); | 843 entries()[i].name); |
| 812 } else { | 844 } else { |
| 813 EXPECT_EQ(child_file_path.BaseName().value(), | 845 EXPECT_EQ(child_file_path.BaseName().value(), |
| 814 entries()[i].name); | 846 entries()[i].name); |
| 815 } | 847 } |
| 816 } | 848 } |
| 817 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 849 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 818 } | 850 } |
| 819 | 851 |
| 820 TEST_F(FileSystemOperationTest, TestRemoveFailure) { | 852 TEST_F(FileSystemOperationTest, TestRemoveFailure) { |
| 821 // Path doesn't exist. | 853 // Path doesn't exist. |
| 822 FilePath nonexisting_path(FilePath( | 854 FilePath nonexisting_path(FilePath( |
| 823 FILE_PATH_LITERAL("NonExistingDir"))); | 855 FILE_PATH_LITERAL("NonExistingDir"))); |
| 824 file_util::EnsureEndsWithSeparator(&nonexisting_path); | 856 file_util::EnsureEndsWithSeparator(&nonexisting_path); |
| 825 | 857 |
| 826 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */); | 858 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */, |
| 859 RecordStatus()); | |
| 827 MessageLoop::current()->RunAllPending(); | 860 MessageLoop::current()->RunAllPending(); |
| 828 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 861 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 829 | 862 |
| 830 // It's an error to try to remove a non-empty directory if recursive flag | 863 // It's an error to try to remove a non-empty directory if recursive flag |
| 831 // is false. | 864 // is false. |
| 832 // parent_dir | 865 // parent_dir |
| 833 // | | | 866 // | | |
| 834 // child_dir child_file | 867 // child_dir child_file |
| 835 // Verify deleting parent_dir. | 868 // Verify deleting parent_dir. |
| 836 FilePath parent_dir_path(CreateVirtualTemporaryDir()); | 869 FilePath parent_dir_path(CreateVirtualTemporaryDir()); |
| 837 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); | 870 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); |
| 838 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); | 871 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); |
| 839 ASSERT_FALSE(child_dir_path.empty()); | 872 ASSERT_FALSE(child_dir_path.empty()); |
| 840 | 873 |
| 841 operation()->Remove(URLForPath(parent_dir_path), false /* recursive */); | 874 operation()->Remove(URLForPath(parent_dir_path), false /* recursive */, |
| 875 RecordStatus()); | |
| 842 MessageLoop::current()->RunAllPending(); | 876 MessageLoop::current()->RunAllPending(); |
| 843 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, | 877 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, |
| 844 status()); | 878 status()); |
| 845 } | 879 } |
| 846 | 880 |
| 847 TEST_F(FileSystemOperationTest, TestRemoveSuccess) { | 881 TEST_F(FileSystemOperationTest, TestRemoveSuccess) { |
| 848 FilePath empty_dir_path(CreateVirtualTemporaryDir()); | 882 FilePath empty_dir_path(CreateVirtualTemporaryDir()); |
| 849 EXPECT_TRUE(VirtualDirectoryExists(empty_dir_path)); | 883 EXPECT_TRUE(VirtualDirectoryExists(empty_dir_path)); |
| 850 | 884 |
| 851 operation()->Remove(URLForPath(empty_dir_path), false /* recursive */); | 885 operation()->Remove(URLForPath(empty_dir_path), false /* recursive */, |
| 886 RecordStatus()); | |
| 852 MessageLoop::current()->RunAllPending(); | 887 MessageLoop::current()->RunAllPending(); |
| 853 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 888 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 854 EXPECT_FALSE(VirtualDirectoryExists(empty_dir_path)); | 889 EXPECT_FALSE(VirtualDirectoryExists(empty_dir_path)); |
| 855 | 890 |
| 856 // Removing a non-empty directory with recursive flag == true should be ok. | 891 // Removing a non-empty directory with recursive flag == true should be ok. |
| 857 // parent_dir | 892 // parent_dir |
| 858 // | | | 893 // | | |
| 859 // child_dir child_file | 894 // child_dir child_file |
| 860 // Verify deleting parent_dir. | 895 // Verify deleting parent_dir. |
| 861 FilePath parent_dir_path(CreateVirtualTemporaryDir()); | 896 FilePath parent_dir_path(CreateVirtualTemporaryDir()); |
| 862 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); | 897 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); |
| 863 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); | 898 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); |
| 864 ASSERT_FALSE(child_dir_path.empty()); | 899 ASSERT_FALSE(child_dir_path.empty()); |
| 865 | 900 |
| 866 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */); | 901 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */, |
| 902 RecordStatus()); | |
| 867 MessageLoop::current()->RunAllPending(); | 903 MessageLoop::current()->RunAllPending(); |
| 868 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 904 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 869 EXPECT_FALSE(VirtualDirectoryExists(parent_dir_path)); | 905 EXPECT_FALSE(VirtualDirectoryExists(parent_dir_path)); |
| 870 | 906 |
| 871 // Remove is not a 'read' access. | 907 // Remove is not a 'read' access. |
| 872 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); | 908 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); |
| 873 } | 909 } |
| 874 | 910 |
| 875 TEST_F(FileSystemOperationTest, TestTruncate) { | 911 TEST_F(FileSystemOperationTest, TestTruncate) { |
| 876 FilePath dir_path(CreateVirtualTemporaryDir()); | 912 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 877 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 913 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 878 | 914 |
| 879 char test_data[] = "test data"; | 915 char test_data[] = "test data"; |
| 880 int data_size = static_cast<int>(sizeof(test_data)); | 916 int data_size = static_cast<int>(sizeof(test_data)); |
| 881 EXPECT_EQ(data_size, | 917 EXPECT_EQ(data_size, |
| 882 file_util::WriteFile(PlatformPath(file_path), | 918 file_util::WriteFile(PlatformPath(file_path), |
| 883 test_data, data_size)); | 919 test_data, data_size)); |
| 884 | 920 |
| 885 // Check that its length is the size of the data written. | 921 // Check that its length is the size of the data written. |
| 886 operation()->GetMetadata(URLForPath(file_path)); | 922 operation()->GetMetadata(URLForPath(file_path), RecordMetadata()); |
| 887 MessageLoop::current()->RunAllPending(); | 923 MessageLoop::current()->RunAllPending(); |
| 888 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 924 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 889 EXPECT_FALSE(info().is_directory); | 925 EXPECT_FALSE(info().is_directory); |
| 890 EXPECT_EQ(data_size, info().size); | 926 EXPECT_EQ(data_size, info().size); |
| 891 | 927 |
| 892 // Extend the file by truncating it. | 928 // Extend the file by truncating it. |
| 893 int length = 17; | 929 int length = 17; |
| 894 operation()->Truncate(URLForPath(file_path), length); | 930 operation()->Truncate(URLForPath(file_path), length, RecordStatus()); |
| 895 MessageLoop::current()->RunAllPending(); | 931 MessageLoop::current()->RunAllPending(); |
| 896 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 932 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 897 | 933 |
| 898 // Check that its length is now 17 and that it's all zeroes after the test | 934 // Check that its length is now 17 and that it's all zeroes after the test |
| 899 // data. | 935 // data. |
| 900 base::PlatformFileInfo info; | 936 base::PlatformFileInfo info; |
| 901 | 937 |
| 902 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 938 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
| 903 EXPECT_EQ(length, info.size); | 939 EXPECT_EQ(length, info.size); |
| 904 char data[100]; | 940 char data[100]; |
| 905 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); | 941 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); |
| 906 for (int i = 0; i < length; ++i) { | 942 for (int i = 0; i < length; ++i) { |
| 907 if (i < static_cast<int>(sizeof(test_data))) | 943 if (i < static_cast<int>(sizeof(test_data))) |
| 908 EXPECT_EQ(test_data[i], data[i]); | 944 EXPECT_EQ(test_data[i], data[i]); |
| 909 else | 945 else |
| 910 EXPECT_EQ(0, data[i]); | 946 EXPECT_EQ(0, data[i]); |
| 911 } | 947 } |
| 912 | 948 |
| 913 // Shorten the file by truncating it. | 949 // Shorten the file by truncating it. |
| 914 length = 3; | 950 length = 3; |
| 915 operation()->Truncate(URLForPath(file_path), length); | 951 operation()->Truncate(URLForPath(file_path), length, RecordStatus()); |
| 916 MessageLoop::current()->RunAllPending(); | 952 MessageLoop::current()->RunAllPending(); |
| 917 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 953 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 918 | 954 |
| 919 // Check that its length is now 3 and that it contains only bits of test data. | 955 // Check that its length is now 3 and that it contains only bits of test data. |
| 920 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 956 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
| 921 EXPECT_EQ(length, info.size); | 957 EXPECT_EQ(length, info.size); |
| 922 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); | 958 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); |
| 923 for (int i = 0; i < length; ++i) | 959 for (int i = 0; i < length; ++i) |
| 924 EXPECT_EQ(test_data[i], data[i]); | 960 EXPECT_EQ(test_data[i], data[i]); |
| 925 | 961 |
| 926 // Truncate is not a 'read' access. (Here expected access count is 1 | 962 // Truncate is not a 'read' access. (Here expected access count is 1 |
| 927 // since we made 1 read access for GetMetadata.) | 963 // since we made 1 read access for GetMetadata.) |
| 928 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 964 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 929 } | 965 } |
| 930 | 966 |
| 931 TEST_F(FileSystemOperationTest, TestTruncateFailureByQuota) { | 967 TEST_F(FileSystemOperationTest, TestTruncateFailureByQuota) { |
| 932 base::PlatformFileInfo info; | 968 base::PlatformFileInfo info; |
| 933 | 969 |
| 934 FilePath dir_path(CreateVirtualTemporaryDir()); | 970 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 935 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 971 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 936 | 972 |
| 937 quota_manager_proxy()->SetQuota(test_helper_.origin(), | 973 quota_manager_proxy()->SetQuota(test_helper_.origin(), |
| 938 test_helper_.storage_type(), | 974 test_helper_.storage_type(), |
| 939 10); | 975 10); |
| 940 | 976 |
| 941 operation()->Truncate(URLForPath(file_path), 10); | 977 operation()->Truncate(URLForPath(file_path), 10, RecordStatus()); |
| 942 MessageLoop::current()->RunAllPending(); | 978 MessageLoop::current()->RunAllPending(); |
| 943 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 979 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 944 | 980 |
| 945 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 981 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
| 946 EXPECT_EQ(10, info.size); | 982 EXPECT_EQ(10, info.size); |
| 947 | 983 |
| 948 operation()->Truncate(URLForPath(file_path), 11); | 984 operation()->Truncate(URLForPath(file_path), 11, RecordStatus()); |
| 949 MessageLoop::current()->RunAllPending(); | 985 MessageLoop::current()->RunAllPending(); |
| 950 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 986 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 951 | 987 |
| 952 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 988 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
| 953 EXPECT_EQ(10, info.size); | 989 EXPECT_EQ(10, info.size); |
| 954 } | 990 } |
| 955 | 991 |
| 956 TEST_F(FileSystemOperationTest, TestTouchFile) { | 992 TEST_F(FileSystemOperationTest, TestTouchFile) { |
| 957 FilePath file_path(CreateVirtualTemporaryFileInDir(FilePath())); | 993 FilePath file_path(CreateVirtualTemporaryFileInDir(FilePath())); |
| 958 FilePath platform_path = PlatformPath(file_path); | 994 FilePath platform_path = PlatformPath(file_path); |
| 959 | 995 |
| 960 base::PlatformFileInfo info; | 996 base::PlatformFileInfo info; |
| 961 | 997 |
| 962 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); | 998 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); |
| 963 EXPECT_FALSE(info.is_directory); | 999 EXPECT_FALSE(info.is_directory); |
| 964 EXPECT_EQ(0, info.size); | 1000 EXPECT_EQ(0, info.size); |
| 965 const base::Time last_modified = info.last_modified; | 1001 const base::Time last_modified = info.last_modified; |
| 966 const base::Time last_accessed = info.last_accessed; | 1002 const base::Time last_accessed = info.last_accessed; |
| 967 | 1003 |
| 968 const base::Time new_modified_time = base::Time::UnixEpoch(); | 1004 const base::Time new_modified_time = base::Time::UnixEpoch(); |
| 969 const base::Time new_accessed_time = new_modified_time + | 1005 const base::Time new_accessed_time = new_modified_time + |
| 970 base::TimeDelta::FromHours(77);; | 1006 base::TimeDelta::FromHours(77);; |
| 971 ASSERT_NE(last_modified, new_modified_time); | 1007 ASSERT_NE(last_modified, new_modified_time); |
| 972 ASSERT_NE(last_accessed, new_accessed_time); | 1008 ASSERT_NE(last_accessed, new_accessed_time); |
| 973 | 1009 |
| 974 operation()->TouchFile(URLForPath(file_path), new_accessed_time, | 1010 operation()->TouchFile( |
| 975 new_modified_time); | 1011 URLForPath(file_path), new_accessed_time, new_modified_time, |
| 1012 RecordStatus()); | |
| 976 MessageLoop::current()->RunAllPending(); | 1013 MessageLoop::current()->RunAllPending(); |
| 977 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1014 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 978 | 1015 |
| 979 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); | 1016 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); |
| 980 // We compare as time_t here to lower our resolution, to avoid false | 1017 // We compare as time_t here to lower our resolution, to avoid false |
| 981 // negatives caused by conversion to the local filesystem's native | 1018 // negatives caused by conversion to the local filesystem's native |
| 982 // representation and back. | 1019 // representation and back. |
| 983 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); | 1020 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); |
| 984 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); | 1021 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); |
| 985 } | 1022 } |
| 986 | 1023 |
| 987 } // namespace fileapi | 1024 } // namespace fileapi |
| OLD | NEW |