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