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/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webkit/blob/shareable_file_reference.h" | 16 #include "webkit/blob/shareable_file_reference.h" |
| 17 #include "webkit/fileapi/file_system_context.h" | 17 #include "webkit/fileapi/file_system_context.h" |
| 18 #include "webkit/fileapi/file_system_file_util.h" | 18 #include "webkit/fileapi/file_system_file_util.h" |
| 19 #include "webkit/fileapi/file_system_mount_point_provider.h" | 19 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 20 #include "webkit/fileapi/file_system_quota_util.h" | 20 #include "webkit/fileapi/file_system_quota_util.h" |
| 21 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
| 22 #include "webkit/fileapi/file_util_helper.h" | 22 #include "webkit/fileapi/file_util_helper.h" |
| 23 #include "webkit/fileapi/local_file_system_test_helper.h" | 23 #include "webkit/fileapi/local_file_system_test_helper.h" |
| 24 #include "webkit/fileapi/mock_file_change_observer.h" | 24 #include "webkit/fileapi/mock_file_change_observer.h" |
| 25 #include "webkit/quota/quota_manager.h" | 25 #include "webkit/quota/quota_manager.h" |
| 26 #include "webkit/quota/mock_quota_manager.h" | |
|
tzik
2012/09/12 07:25:39
sort?
| |
| 26 | 27 |
| 27 using quota::QuotaClient; | |
| 28 using quota::QuotaManager; | 28 using quota::QuotaManager; |
| 29 using quota::QuotaManagerProxy; | 29 using quota::QuotaManagerProxy; |
| 30 using quota::StorageType; | |
| 31 using webkit_blob::ShareableFileReference; | 30 using webkit_blob::ShareableFileReference; |
| 32 | 31 |
| 33 namespace fileapi { | 32 namespace fileapi { |
| 34 | 33 |
| 35 namespace { | 34 namespace { |
| 36 | 35 |
| 37 const int kFileOperationStatusNotSet = 1; | 36 const int kFileOperationStatusNotSet = 1; |
| 38 | 37 |
| 39 void AssertFileErrorEq(base::PlatformFileError expected, | 38 void AssertFileErrorEq(base::PlatformFileError expected, |
| 40 base::PlatformFileError actual) { | 39 base::PlatformFileError actual) { |
| 41 ASSERT_EQ(expected, actual); | 40 ASSERT_EQ(expected, actual); |
| 42 } | 41 } |
| 43 | 42 |
| 44 class MockQuotaManager : public QuotaManager { | |
| 45 public: | |
| 46 MockQuotaManager(const FilePath& base_dir, | |
| 47 const GURL& origin, | |
| 48 StorageType type) | |
| 49 : QuotaManager(false /* is_incognito */, base_dir, | |
| 50 base::MessageLoopProxy::current(), | |
| 51 base::MessageLoopProxy::current(), | |
| 52 NULL), | |
| 53 origin_(origin), | |
| 54 type_(type), | |
| 55 usage_(0), | |
| 56 quota_(kint64max), | |
| 57 accessed_(0) {} | |
| 58 | |
| 59 virtual void GetUsageAndQuota( | |
| 60 const GURL& origin, quota::StorageType type, | |
| 61 const GetUsageAndQuotaCallback& callback) OVERRIDE { | |
| 62 EXPECT_EQ(origin_, origin); | |
| 63 EXPECT_EQ(type_, type); | |
| 64 callback.Run(quota::kQuotaStatusOk, usage_, quota_); | |
| 65 } | |
| 66 | |
| 67 protected: | |
| 68 virtual ~MockQuotaManager() {} | |
| 69 | |
| 70 private: | |
| 71 friend class MockQuotaManagerProxy; | |
| 72 | |
| 73 void SetQuota(const GURL& origin, StorageType type, int64 quota) { | |
| 74 EXPECT_EQ(origin_, origin); | |
| 75 EXPECT_EQ(type_, type); | |
| 76 quota_ = quota; | |
| 77 } | |
| 78 | |
| 79 void RecordStorageAccessed(const GURL& origin, StorageType type) { | |
| 80 EXPECT_EQ(origin_, origin); | |
| 81 EXPECT_EQ(type_, type); | |
| 82 ++accessed_; | |
| 83 } | |
| 84 | |
| 85 void UpdateUsage(const GURL& origin, StorageType type, int64 delta) { | |
| 86 EXPECT_EQ(origin_, origin); | |
| 87 EXPECT_EQ(type_, type); | |
| 88 usage_ += delta; | |
| 89 } | |
| 90 | |
| 91 const GURL& origin_; | |
| 92 const StorageType type_; | |
| 93 int64 usage_; | |
| 94 int64 quota_; | |
| 95 int accessed_; | |
| 96 }; | |
| 97 | |
| 98 class MockQuotaManagerProxy : public QuotaManagerProxy { | |
| 99 public: | |
| 100 explicit MockQuotaManagerProxy(QuotaManager* quota_manager) | |
| 101 : QuotaManagerProxy(quota_manager, | |
| 102 base::MessageLoopProxy::current()), | |
| 103 registered_client_(NULL) { | |
| 104 } | |
| 105 | |
| 106 virtual void RegisterClient(QuotaClient* client) OVERRIDE { | |
| 107 EXPECT_FALSE(registered_client_); | |
| 108 registered_client_ = client; | |
| 109 } | |
| 110 | |
| 111 void SimulateQuotaManagerDestroyed() { | |
| 112 if (registered_client_) { | |
| 113 // We cannot call this in the destructor as the client (indirectly) | |
| 114 // holds a refptr of the proxy. | |
| 115 registered_client_->OnQuotaManagerDestroyed(); | |
| 116 registered_client_ = NULL; | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 // We don't mock them. | |
| 121 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} | |
| 122 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} | |
| 123 | |
| 124 virtual void NotifyStorageAccessed(QuotaClient::ID client_id, | |
| 125 const GURL& origin, | |
| 126 StorageType type) OVERRIDE { | |
| 127 mock_manager()->RecordStorageAccessed(origin, type); | |
| 128 } | |
| 129 | |
| 130 virtual void NotifyStorageModified(QuotaClient::ID client_id, | |
| 131 const GURL& origin, | |
| 132 StorageType type, | |
| 133 int64 delta) OVERRIDE { | |
| 134 mock_manager()->UpdateUsage(origin, type, delta); | |
| 135 } | |
| 136 | |
| 137 int storage_accessed_count() const { | |
| 138 return mock_manager()->accessed_; | |
| 139 } | |
| 140 | |
| 141 void SetQuota(const GURL& origin, StorageType type, int64 quota) { | |
| 142 mock_manager()->SetQuota(origin, type, quota); | |
| 143 } | |
| 144 | |
| 145 protected: | |
| 146 virtual ~MockQuotaManagerProxy() { | |
| 147 EXPECT_FALSE(registered_client_); | |
| 148 } | |
| 149 | |
| 150 private: | |
| 151 MockQuotaManager* mock_manager() const { | |
| 152 return static_cast<MockQuotaManager*>(quota_manager()); | |
| 153 } | |
| 154 | |
| 155 QuotaClient* registered_client_; | |
| 156 }; | |
| 157 | |
| 158 FilePath ASCIIToFilePath(const std::string& str) { | 43 FilePath ASCIIToFilePath(const std::string& str) { |
| 159 return FilePath().AppendASCII(str); | 44 return FilePath().AppendASCII(str); |
| 160 } | 45 } |
| 161 | 46 |
| 162 } // namespace (anonymous) | 47 } // namespace (anonymous) |
| 163 | 48 |
| 164 // Test class for LocalFileSystemOperation. | 49 // Test class for LocalFileSystemOperation. |
| 165 class LocalFileSystemOperationTest | 50 class LocalFileSystemOperationTest |
| 166 : public testing::Test, | 51 : public testing::Test, |
| 167 public base::SupportsWeakPtr<LocalFileSystemOperationTest> { | 52 public base::SupportsWeakPtr<LocalFileSystemOperationTest> { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 185 return shareable_file_ref_; | 70 return shareable_file_ref_; |
| 186 } | 71 } |
| 187 | 72 |
| 188 virtual void SetUp() OVERRIDE; | 73 virtual void SetUp() OVERRIDE; |
| 189 virtual void TearDown() OVERRIDE; | 74 virtual void TearDown() OVERRIDE; |
| 190 | 75 |
| 191 protected: | 76 protected: |
| 192 // Common temp base for nondestructive uses. | 77 // Common temp base for nondestructive uses. |
| 193 ScopedTempDir base_; | 78 ScopedTempDir base_; |
| 194 | 79 |
| 195 MockQuotaManagerProxy* quota_manager_proxy() { | 80 quota::MockQuotaManager* quota_manager() { |
| 196 return static_cast<MockQuotaManagerProxy*>(quota_manager_proxy_.get()); | 81 return static_cast<quota::MockQuotaManager*>(quota_manager_.get()); |
| 82 } | |
| 83 | |
| 84 quota::MockQuotaManagerProxy* quota_manager_proxy() { | |
| 85 return static_cast<quota::MockQuotaManagerProxy*>( | |
| 86 quota_manager_proxy_.get()); | |
| 197 } | 87 } |
| 198 | 88 |
| 199 FileSystemFileUtil* file_util() { | 89 FileSystemFileUtil* file_util() { |
| 200 return test_helper_.file_util(); | 90 return test_helper_.file_util(); |
| 201 } | 91 } |
| 202 | 92 |
| 203 const ChangeObserverList& change_observers() const { | 93 const ChangeObserverList& change_observers() const { |
| 204 return change_observers_; | 94 return change_observers_; |
| 205 } | 95 } |
| 206 | 96 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 MessageLoop::current()->RunAllPending(); | 253 MessageLoop::current()->RunAllPending(); |
| 364 | 254 |
| 365 int64 total_usage; | 255 int64 total_usage; |
| 366 GetUsageAndQuota(&total_usage, NULL); | 256 GetUsageAndQuota(&total_usage, NULL); |
| 367 *path_cost = total_usage - base_usage; | 257 *path_cost = total_usage - base_usage; |
| 368 } | 258 } |
| 369 | 259 |
| 370 void GrantQuotaForCurrentUsage() { | 260 void GrantQuotaForCurrentUsage() { |
| 371 int64 usage; | 261 int64 usage; |
| 372 GetUsageAndQuota(&usage, NULL); | 262 GetUsageAndQuota(&usage, NULL); |
| 373 quota_manager_proxy()->SetQuota(test_helper_.origin(), | 263 quota_manager()->SetQuota(test_helper_.origin(), |
| 374 test_helper_.storage_type(), | 264 test_helper_.storage_type(), |
| 375 usage); | 265 usage); |
| 376 } | 266 } |
| 377 | 267 |
| 378 void AddQuota(int64 quota_delta) { | 268 void AddQuota(int64 quota_delta) { |
| 379 int64 quota; | 269 int64 quota; |
| 380 GetUsageAndQuota(NULL, "a); | 270 GetUsageAndQuota(NULL, "a); |
| 381 quota_manager_proxy()->SetQuota(test_helper_.origin(), | 271 quota_manager()->SetQuota(test_helper_.origin(), |
| 382 test_helper_.storage_type(), | 272 test_helper_.storage_type(), |
| 383 quota + quota_delta); | 273 quota + quota_delta); |
| 384 } | 274 } |
| 385 | 275 |
| 386 // For post-operation status. | 276 // For post-operation status. |
| 387 int status_; | 277 int status_; |
| 388 base::PlatformFileInfo info_; | 278 base::PlatformFileInfo info_; |
| 389 FilePath path_; | 279 FilePath path_; |
| 390 std::vector<base::FileUtilProxy::Entry> entries_; | 280 std::vector<base::FileUtilProxy::Entry> entries_; |
| 391 scoped_refptr<ShareableFileReference> shareable_file_ref_; | 281 scoped_refptr<ShareableFileReference> shareable_file_ref_; |
| 392 | 282 |
| 393 private: | 283 private: |
| 394 MessageLoop message_loop_; | 284 MessageLoop message_loop_; |
| 395 scoped_refptr<QuotaManager> quota_manager_; | 285 scoped_refptr<QuotaManager> quota_manager_; |
| 396 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 286 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
| 397 | 287 |
| 398 MockFileChangeObserver change_observer_; | 288 MockFileChangeObserver change_observer_; |
| 399 ChangeObserverList change_observers_; | 289 ChangeObserverList change_observers_; |
| 400 | 290 |
| 401 int next_unique_path_suffix_; | 291 int next_unique_path_suffix_; |
| 402 | 292 |
| 403 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperationTest); | 293 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperationTest); |
| 404 }; | 294 }; |
| 405 | 295 |
| 406 void LocalFileSystemOperationTest::SetUp() { | 296 void LocalFileSystemOperationTest::SetUp() { |
| 407 FilePath base_dir = base_.path().AppendASCII("filesystem"); | 297 FilePath base_dir = base_.path().AppendASCII("filesystem"); |
| 408 quota_manager_ = new MockQuotaManager( | 298 quota_manager_ = new quota::MockQuotaManager( |
| 409 base_dir, test_helper_.origin(), test_helper_.storage_type()); | 299 false /* is_incognito */, base_dir, |
| 410 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); | 300 base::MessageLoopProxy::current(), |
| 301 base::MessageLoopProxy::current(), | |
| 302 NULL /* special storage policy */); | |
| 303 quota_manager_proxy_ = new quota::MockQuotaManagerProxy( | |
| 304 quota_manager(), | |
| 305 base::MessageLoopProxy::current()); | |
| 411 test_helper_.SetUp(base_dir, | 306 test_helper_.SetUp(base_dir, |
| 412 false /* unlimited quota */, | 307 false /* unlimited quota */, |
| 413 quota_manager_proxy_.get(), | 308 quota_manager_proxy_.get(), |
| 414 NULL); | 309 NULL); |
| 415 } | 310 } |
| 416 | 311 |
| 417 void LocalFileSystemOperationTest::TearDown() { | 312 void LocalFileSystemOperationTest::TearDown() { |
| 418 // Let the client go away before dropping a ref of the quota manager proxy. | 313 // Let the client go away before dropping a ref of the quota manager proxy. |
| 419 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); | 314 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); |
| 420 quota_manager_ = NULL; | 315 quota_manager_ = NULL; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 MessageLoop::current()->RunAllPending(); | 407 MessageLoop::current()->RunAllPending(); |
| 513 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 408 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 514 EXPECT_TRUE(FileExists(dest_file_path)); | 409 EXPECT_TRUE(FileExists(dest_file_path)); |
| 515 | 410 |
| 516 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 411 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 517 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 412 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 518 EXPECT_TRUE(change_observer()->HasNoChange()); | 413 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 519 | 414 |
| 520 // Move is considered 'write' access (for both side), and won't be counted | 415 // Move is considered 'write' access (for both side), and won't be counted |
| 521 // as read access. | 416 // as read access. |
| 522 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); | 417 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count()); |
| 523 } | 418 } |
| 524 | 419 |
| 525 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { | 420 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { |
| 526 FilePath src_dir_path(CreateUniqueDir()); | 421 FilePath src_dir_path(CreateUniqueDir()); |
| 527 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 422 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
| 528 FilePath dest_dir_path(CreateUniqueDir()); | 423 FilePath dest_dir_path(CreateUniqueDir()); |
| 529 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 424 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
| 530 | 425 |
| 531 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), | 426 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), |
| 532 RecordStatusCallback()); | 427 RecordStatusCallback()); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 FilePath src_dir_path(CreateUniqueDir()); | 607 FilePath src_dir_path(CreateUniqueDir()); |
| 713 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 608 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
| 714 FilePath dest_dir_path(CreateUniqueDir()); | 609 FilePath dest_dir_path(CreateUniqueDir()); |
| 715 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 610 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
| 716 | 611 |
| 717 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), | 612 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
| 718 RecordStatusCallback()); | 613 RecordStatusCallback()); |
| 719 MessageLoop::current()->RunAllPending(); | 614 MessageLoop::current()->RunAllPending(); |
| 720 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 615 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 721 EXPECT_TRUE(FileExists(dest_file_path)); | 616 EXPECT_TRUE(FileExists(dest_file_path)); |
| 722 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 617 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 723 | 618 |
| 724 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 619 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 725 EXPECT_TRUE(change_observer()->HasNoChange()); | 620 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 726 } | 621 } |
| 727 | 622 |
| 728 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) { | 623 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) { |
| 729 FilePath src_dir_path(CreateUniqueDir()); | 624 FilePath src_dir_path(CreateUniqueDir()); |
| 730 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 625 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
| 731 FilePath dest_dir_path(CreateUniqueDir()); | 626 FilePath dest_dir_path(CreateUniqueDir()); |
| 732 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 627 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
| 733 | 628 |
| 734 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), | 629 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
| 735 RecordStatusCallback()); | 630 RecordStatusCallback()); |
| 736 MessageLoop::current()->RunAllPending(); | 631 MessageLoop::current()->RunAllPending(); |
| 737 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 632 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 738 EXPECT_TRUE(FileExists(dest_file_path)); | 633 EXPECT_TRUE(FileExists(dest_file_path)); |
| 739 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 634 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 740 | 635 |
| 741 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 636 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| 742 EXPECT_TRUE(change_observer()->HasNoChange()); | 637 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 743 } | 638 } |
| 744 | 639 |
| 745 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { | 640 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { |
| 746 FilePath src_dir_path(CreateUniqueDir()); | 641 FilePath src_dir_path(CreateUniqueDir()); |
| 747 FilePath dest_dir_path(CreateUniqueDir()); | 642 FilePath dest_dir_path(CreateUniqueDir()); |
| 748 | 643 |
| 749 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 644 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 750 RecordStatusCallback()); | 645 RecordStatusCallback()); |
| 751 MessageLoop::current()->RunAllPending(); | 646 MessageLoop::current()->RunAllPending(); |
| 752 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 647 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 753 | 648 |
| 754 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 649 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
| 755 EXPECT_TRUE(DirectoryExists(dest_dir_path)); | 650 EXPECT_TRUE(DirectoryExists(dest_dir_path)); |
| 756 EXPECT_FALSE(DirectoryExists( | 651 EXPECT_FALSE(DirectoryExists( |
| 757 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); | 652 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); |
| 758 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 653 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 759 | 654 |
| 760 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 655 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 761 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 656 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 762 EXPECT_TRUE(change_observer()->HasNoChange()); | 657 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 763 } | 658 } |
| 764 | 659 |
| 765 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) { | 660 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) { |
| 766 FilePath src_dir_path(CreateUniqueDir()); | 661 FilePath src_dir_path(CreateUniqueDir()); |
| 767 FilePath dest_parent_dir_path(CreateUniqueDir()); | 662 FilePath dest_parent_dir_path(CreateUniqueDir()); |
| 768 FilePath dest_child_dir_path(dest_parent_dir_path. | 663 FilePath dest_child_dir_path(dest_parent_dir_path. |
| 769 Append(FILE_PATH_LITERAL("NewDirectory"))); | 664 Append(FILE_PATH_LITERAL("NewDirectory"))); |
| 770 | 665 |
| 771 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), | 666 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
| 772 RecordStatusCallback()); | 667 RecordStatusCallback()); |
| 773 MessageLoop::current()->RunAllPending(); | 668 MessageLoop::current()->RunAllPending(); |
| 774 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 669 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 775 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); | 670 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); |
| 776 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 671 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 777 | 672 |
| 778 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 673 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 779 EXPECT_TRUE(change_observer()->HasNoChange()); | 674 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 780 } | 675 } |
| 781 | 676 |
| 782 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) { | 677 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) { |
| 783 FilePath src_dir_path(CreateUniqueDir()); | 678 FilePath src_dir_path(CreateUniqueDir()); |
| 784 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); | 679 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); |
| 785 FilePath grandchild_file_path( | 680 FilePath grandchild_file_path( |
| 786 CreateUniqueFileInDir(child_dir_path)); | 681 CreateUniqueFileInDir(child_dir_path)); |
| 787 | 682 |
| 788 FilePath dest_dir_path(CreateUniqueDir()); | 683 FilePath dest_dir_path(CreateUniqueDir()); |
| 789 | 684 |
| 790 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 685 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 791 RecordStatusCallback()); | 686 RecordStatusCallback()); |
| 792 MessageLoop::current()->RunAllPending(); | 687 MessageLoop::current()->RunAllPending(); |
| 793 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 688 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 794 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( | 689 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( |
| 795 VirtualPath::BaseName(child_dir_path)))); | 690 VirtualPath::BaseName(child_dir_path)))); |
| 796 EXPECT_TRUE(FileExists(dest_dir_path.Append( | 691 EXPECT_TRUE(FileExists(dest_dir_path.Append( |
| 797 VirtualPath::BaseName(child_dir_path)).Append( | 692 VirtualPath::BaseName(child_dir_path)).Append( |
| 798 VirtualPath::BaseName(grandchild_file_path)))); | 693 VirtualPath::BaseName(grandchild_file_path)))); |
| 799 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 694 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 800 | 695 |
| 801 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 696 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
| 802 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 697 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 803 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 698 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| 804 EXPECT_TRUE(change_observer()->HasNoChange()); | 699 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 805 } | 700 } |
| 806 | 701 |
| 807 TEST_F(LocalFileSystemOperationTest, TestCreateFileFailure) { | 702 TEST_F(LocalFileSystemOperationTest, TestCreateFileFailure) { |
| 808 // Already existing file and exclusive true. | 703 // Already existing file and exclusive true. |
| 809 FilePath dir_path(CreateUniqueDir()); | 704 FilePath dir_path(CreateUniqueDir()); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 860 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 966 ++read_access; | 861 ++read_access; |
| 967 | 862 |
| 968 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); | 863 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); |
| 969 MessageLoop::current()->RunAllPending(); | 864 MessageLoop::current()->RunAllPending(); |
| 970 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 865 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 971 EXPECT_FALSE(info().is_directory); | 866 EXPECT_FALSE(info().is_directory); |
| 972 EXPECT_EQ(PlatformPath(file_path), path()); | 867 EXPECT_EQ(PlatformPath(file_path), path()); |
| 973 ++read_access; | 868 ++read_access; |
| 974 | 869 |
| 975 EXPECT_EQ(read_access, quota_manager_proxy()->storage_accessed_count()); | 870 EXPECT_EQ(read_access, |
| 871 quota_manager_proxy()->notify_storage_accessed_count()); | |
| 976 EXPECT_TRUE(change_observer()->HasNoChange()); | 872 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 977 } | 873 } |
| 978 | 874 |
| 979 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) { | 875 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) { |
| 980 FilePath dir_path(CreateUniqueDir()); | 876 FilePath dir_path(CreateUniqueDir()); |
| 981 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback()); | 877 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback()); |
| 982 MessageLoop::current()->RunAllPending(); | 878 MessageLoop::current()->RunAllPending(); |
| 983 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); | 879 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); |
| 984 | 880 |
| 985 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 881 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1028 | 924 |
| 1029 for (size_t i = 0; i < entries().size(); ++i) { | 925 for (size_t i = 0; i < entries().size(); ++i) { |
| 1030 if (entries()[i].is_directory) { | 926 if (entries()[i].is_directory) { |
| 1031 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(), | 927 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(), |
| 1032 entries()[i].name); | 928 entries()[i].name); |
| 1033 } else { | 929 } else { |
| 1034 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(), | 930 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(), |
| 1035 entries()[i].name); | 931 entries()[i].name); |
| 1036 } | 932 } |
| 1037 } | 933 } |
| 1038 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 934 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 1039 EXPECT_TRUE(change_observer()->HasNoChange()); | 935 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1040 } | 936 } |
| 1041 | 937 |
| 1042 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { | 938 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { |
| 1043 // Path doesn't exist. | 939 // Path doesn't exist. |
| 1044 FilePath nonexisting_path(FilePath( | 940 FilePath nonexisting_path(FilePath( |
| 1045 FILE_PATH_LITERAL("NonExistingDir"))); | 941 FILE_PATH_LITERAL("NonExistingDir"))); |
| 1046 file_util::EnsureEndsWithSeparator(&nonexisting_path); | 942 file_util::EnsureEndsWithSeparator(&nonexisting_path); |
| 1047 | 943 |
| 1048 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */, | 944 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); | 988 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); |
| 1093 ASSERT_FALSE(child_dir_path.empty()); | 989 ASSERT_FALSE(child_dir_path.empty()); |
| 1094 | 990 |
| 1095 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */, | 991 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */, |
| 1096 RecordStatusCallback()); | 992 RecordStatusCallback()); |
| 1097 MessageLoop::current()->RunAllPending(); | 993 MessageLoop::current()->RunAllPending(); |
| 1098 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 994 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 1099 EXPECT_FALSE(DirectoryExists(parent_dir_path)); | 995 EXPECT_FALSE(DirectoryExists(parent_dir_path)); |
| 1100 | 996 |
| 1101 // Remove is not a 'read' access. | 997 // Remove is not a 'read' access. |
| 1102 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); | 998 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count()); |
| 1103 | 999 |
| 1104 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 1000 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
| 1105 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 1001 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 1106 EXPECT_TRUE(change_observer()->HasNoChange()); | 1002 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1107 } | 1003 } |
| 1108 | 1004 |
| 1109 TEST_F(LocalFileSystemOperationTest, TestTruncate) { | 1005 TEST_F(LocalFileSystemOperationTest, TestTruncate) { |
| 1110 FilePath dir_path(CreateUniqueDir()); | 1006 FilePath dir_path(CreateUniqueDir()); |
| 1111 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 1007 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
| 1112 | 1008 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1158 | 1054 |
| 1159 // Check that its length is now 3 and that it contains only bits of test data. | 1055 // Check that its length is now 3 and that it contains only bits of test data. |
| 1160 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 1056 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
| 1161 EXPECT_EQ(length, info.size); | 1057 EXPECT_EQ(length, info.size); |
| 1162 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); | 1058 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); |
| 1163 for (int i = 0; i < length; ++i) | 1059 for (int i = 0; i < length; ++i) |
| 1164 EXPECT_EQ(test_data[i], data[i]); | 1060 EXPECT_EQ(test_data[i], data[i]); |
| 1165 | 1061 |
| 1166 // Truncate is not a 'read' access. (Here expected access count is 1 | 1062 // Truncate is not a 'read' access. (Here expected access count is 1 |
| 1167 // since we made 1 read access for GetMetadata.) | 1063 // since we made 1 read access for GetMetadata.) |
| 1168 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 1064 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 1169 } | 1065 } |
| 1170 | 1066 |
| 1171 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) { | 1067 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) { |
| 1172 base::PlatformFileInfo info; | 1068 base::PlatformFileInfo info; |
| 1173 | 1069 |
| 1174 FilePath dir_path(CreateUniqueDir()); | 1070 FilePath dir_path(CreateUniqueDir()); |
| 1175 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 1071 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
| 1176 | 1072 |
| 1177 GrantQuotaForCurrentUsage(); | 1073 GrantQuotaForCurrentUsage(); |
| 1178 AddQuota(10); | 1074 AddQuota(10); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 EXPECT_FALSE(info().is_directory); | 1146 EXPECT_FALSE(info().is_directory); |
| 1251 EXPECT_EQ(PlatformPath(file_path), path()); | 1147 EXPECT_EQ(PlatformPath(file_path), path()); |
| 1252 EXPECT_TRUE(change_observer()->HasNoChange()); | 1148 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1253 | 1149 |
| 1254 // The FileSystemOpration implementation does not create a | 1150 // The FileSystemOpration implementation does not create a |
| 1255 // shareable file reference. | 1151 // shareable file reference. |
| 1256 EXPECT_EQ(NULL, shareable_file_ref()); | 1152 EXPECT_EQ(NULL, shareable_file_ref()); |
| 1257 } | 1153 } |
| 1258 | 1154 |
| 1259 } // namespace fileapi | 1155 } // namespace fileapi |
| OLD | NEW |