Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.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/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 const StorageType type_; | 81 const StorageType type_; |
| 82 int64 usage_; | 82 int64 usage_; |
| 83 int64 quota_; | 83 int64 quota_; |
| 84 int accessed_; | 84 int accessed_; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class MockQuotaManagerProxy : public QuotaManagerProxy { | 87 class MockQuotaManagerProxy : public QuotaManagerProxy { |
| 88 public: | 88 public: |
| 89 explicit MockQuotaManagerProxy(QuotaManager* quota_manager) | 89 explicit MockQuotaManagerProxy(QuotaManager* quota_manager) |
| 90 : QuotaManagerProxy(quota_manager, | 90 : QuotaManagerProxy(quota_manager, |
| 91 base::MessageLoopProxy::CreateForCurrentThread()) {} | 91 base::MessageLoopProxy::CreateForCurrentThread()), |
| 92 registered_client_(NULL) { | |
| 93 } | |
| 94 | |
| 95 virtual ~MockQuotaManagerProxy() { | |
| 96 EXPECT_FALSE(registered_client_); | |
|
oshima
2011/05/26 01:17:07
Any reason not deleting here? (deletion order matt
kinuko
2011/05/26 02:19:25
Yes there's an ordering issue. I added a comment.
| |
| 97 } | |
| 98 | |
| 99 virtual void RegisterClient(QuotaClient* client) { | |
| 100 EXPECT_FALSE(registered_client_); | |
| 101 registered_client_ = client; | |
| 102 } | |
| 103 | |
| 104 void SimulateQuotaManagerDestroyed() { | |
| 105 if (registered_client_) { | |
| 106 registered_client_->OnQuotaManagerDestroyed(); | |
| 107 registered_client_ = NULL; | |
| 108 } | |
| 109 } | |
| 92 | 110 |
| 93 // We don't mock them. | 111 // We don't mock them. |
| 94 virtual void RegisterClient(QuotaClient* client) OVERRIDE {} | |
| 95 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} | 112 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} |
| 96 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} | 113 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} |
| 97 | 114 |
| 98 virtual void NotifyStorageAccessed(QuotaClient::ID client_id, | 115 virtual void NotifyStorageAccessed(QuotaClient::ID client_id, |
| 99 const GURL& origin, | 116 const GURL& origin, |
| 100 StorageType type) OVERRIDE { | 117 StorageType type) OVERRIDE { |
| 101 mock_manager()->RecordStorageAccessed(origin, type); | 118 mock_manager()->RecordStorageAccessed(origin, type); |
| 102 } | 119 } |
| 103 | 120 |
| 104 virtual void NotifyStorageModified(QuotaClient::ID client_id, | 121 virtual void NotifyStorageModified(QuotaClient::ID client_id, |
| 105 const GURL& origin, | 122 const GURL& origin, |
| 106 StorageType type, | 123 StorageType type, |
| 107 int64 delta) OVERRIDE { | 124 int64 delta) OVERRIDE { |
| 108 mock_manager()->UpdateUsage(origin, type, delta); | 125 mock_manager()->UpdateUsage(origin, type, delta); |
| 109 } | 126 } |
| 110 | 127 |
| 111 int storage_accessed_count() const { | 128 int storage_accessed_count() const { |
| 112 return mock_manager()->accessed_; | 129 return mock_manager()->accessed_; |
| 113 } | 130 } |
| 114 | 131 |
| 115 void SetQuota(const GURL& origin, StorageType type, int64 quota) { | 132 void SetQuota(const GURL& origin, StorageType type, int64 quota) { |
| 116 mock_manager()->SetQuota(origin, type, quota); | 133 mock_manager()->SetQuota(origin, type, quota); |
| 117 } | 134 } |
| 118 | 135 |
| 119 private: | 136 private: |
| 120 MockQuotaManager* mock_manager() const { | 137 MockQuotaManager* mock_manager() const { |
| 121 return static_cast<MockQuotaManager*>(quota_manager()); | 138 return static_cast<MockQuotaManager*>(quota_manager()); |
| 122 } | 139 } |
| 140 QuotaClient* registered_client_; | |
| 123 }; | 141 }; |
| 124 | 142 |
| 125 FilePath ASCIIToFilePath(const std::string& str) { | 143 FilePath ASCIIToFilePath(const std::string& str) { |
| 126 return FilePath().AppendASCII(str); | 144 return FilePath().AppendASCII(str); |
| 127 } | 145 } |
| 128 | 146 |
| 129 } // namespace (anonymous) | 147 } // namespace (anonymous) |
| 130 | 148 |
| 131 // Test class for FileSystemOperation. Note that this just tests low-level | 149 // Test class for FileSystemOperation. Note that this just tests low-level |
| 132 // operations but doesn't test OpenFileSystem. | 150 // operations but doesn't test OpenFileSystem. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 base_dir, test_helper_.origin(), test_helper_.storage_type()); | 298 base_dir, test_helper_.origin(), test_helper_.storage_type()); |
| 281 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); | 299 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); |
| 282 test_helper_.SetUp(base_dir, | 300 test_helper_.SetUp(base_dir, |
| 283 false /* incognito */, | 301 false /* incognito */, |
| 284 false /* unlimited quota */, | 302 false /* unlimited quota */, |
| 285 quota_manager_proxy_.get(), | 303 quota_manager_proxy_.get(), |
| 286 LocalFileSystemFileUtil::GetInstance()); | 304 LocalFileSystemFileUtil::GetInstance()); |
| 287 } | 305 } |
| 288 | 306 |
| 289 void FileSystemOperationTest::TearDown() { | 307 void FileSystemOperationTest::TearDown() { |
| 308 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); | |
| 290 quota_manager_ = NULL; | 309 quota_manager_ = NULL; |
| 291 quota_manager_proxy_ = NULL; | 310 quota_manager_proxy_ = NULL; |
| 292 test_helper_.TearDown(); | 311 test_helper_.TearDown(); |
| 293 } | 312 } |
| 294 | 313 |
| 295 FileSystemOperation* FileSystemOperationTest::operation() { | 314 FileSystemOperation* FileSystemOperationTest::operation() { |
| 296 return test_helper_.NewOperation(new MockDispatcher(this)); | 315 return test_helper_.NewOperation(new MockDispatcher(this)); |
| 297 } | 316 } |
| 298 | 317 |
| 299 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { | 318 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 | 943 |
| 925 operation()->Truncate(URLForPath(file_path), 11); | 944 operation()->Truncate(URLForPath(file_path), 11); |
| 926 MessageLoop::current()->RunAllPending(); | 945 MessageLoop::current()->RunAllPending(); |
| 927 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 946 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 928 | 947 |
| 929 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 948 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
| 930 EXPECT_EQ(10, info.size); | 949 EXPECT_EQ(10, info.size); |
| 931 } | 950 } |
| 932 | 951 |
| 933 } // namespace fileapi | 952 } // namespace fileapi |
| OLD | NEW |