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 // This test checks the entire behavior of FileSystem usage and quota, such as: | 5 // This test checks the entire behavior of FileSystem usage and quota, such as: |
| 6 // 1) the actual size of files on disk, | 6 // 1) the actual size of files on disk, |
| 7 // 2) the described size in .usage, and | 7 // 2) the described size in .usage, and |
| 8 // 3) the result of QuotaManager::GetUsageAndQuota. | 8 // 3) the result of QuotaManager::GetUsageAndQuota. |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 19 #include "webkit/fileapi/file_system_operation.h" | 18 #include "webkit/fileapi/file_system_operation.h" |
| 20 #include "webkit/fileapi/file_system_test_helper.h" | 19 #include "webkit/fileapi/file_system_test_helper.h" |
| 21 #include "webkit/fileapi/file_system_usage_cache.h" | 20 #include "webkit/fileapi/file_system_usage_cache.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" |
| 26 | 25 |
| 27 namespace fileapi { | 26 namespace fileapi { |
| 28 | 27 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 return CreateVirtualTemporaryDirInDir(FilePath()); | 108 return CreateVirtualTemporaryDirInDir(FilePath()); |
| 110 } | 109 } |
| 111 | 110 |
| 112 FilePath child_dir_path_; | 111 FilePath child_dir_path_; |
| 113 FilePath child_file1_path_; | 112 FilePath child_file1_path_; |
| 114 FilePath child_file2_path_; | 113 FilePath child_file2_path_; |
| 115 FilePath grandchild_file1_path_; | 114 FilePath grandchild_file1_path_; |
| 116 FilePath grandchild_file2_path_; | 115 FilePath grandchild_file2_path_; |
| 117 | 116 |
| 118 protected: | 117 protected: |
| 118 // Callback for recording test results. | |
| 119 FileSystemOperationInterface::StatusCallback RecordStatus() { | |
|
kinuko
2012/02/10 05:34:09
ditto.
kinaba
2012/02/10 08:22:58
Done.
| |
| 120 return base::Bind(&FileSystemQuotaTest::DidFinish, base::Unretained(this)); | |
| 121 } | |
| 122 | |
| 123 void DidFinish(base::PlatformFileError status) { | |
| 124 set_status(status); | |
| 125 } | |
| 126 | |
| 119 FileSystemTestOriginHelper test_helper_; | 127 FileSystemTestOriginHelper test_helper_; |
| 120 | 128 |
| 121 ScopedTempDir work_dir_; | 129 ScopedTempDir work_dir_; |
| 122 scoped_refptr<quota::QuotaManager> quota_manager_; | 130 scoped_refptr<quota::QuotaManager> quota_manager_; |
| 123 scoped_ptr<LocalFileUtil> local_file_util_; | 131 scoped_ptr<LocalFileUtil> local_file_util_; |
| 124 | 132 |
| 125 base::WeakPtrFactory<FileSystemQuotaTest> weak_factory_; | 133 base::WeakPtrFactory<FileSystemQuotaTest> weak_factory_; |
| 126 | 134 |
| 127 // For post-operation status. | 135 // For post-operation status. |
| 128 int status_; | 136 int status_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 139 | 147 |
| 140 int64 RevokeUsageCache() { | 148 int64 RevokeUsageCache() { |
| 141 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); | 149 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); |
| 142 return test_helper_.RevokeUsageCache(); | 150 return test_helper_.RevokeUsageCache(); |
| 143 } | 151 } |
| 144 | 152 |
| 145 private: | 153 private: |
| 146 scoped_refptr<FileSystemContext> file_system_context_; | 154 scoped_refptr<FileSystemContext> file_system_context_; |
| 147 }; | 155 }; |
| 148 | 156 |
| 149 namespace { | |
| 150 | |
| 151 class MockDispatcher : public FileSystemCallbackDispatcher { | |
| 152 public: | |
| 153 explicit MockDispatcher(FileSystemQuotaTest* test) : test_(test) { } | |
| 154 | |
| 155 virtual void DidFail(base::PlatformFileError status) { | |
| 156 test_->set_status(status); | |
| 157 } | |
| 158 | |
| 159 virtual void DidSucceed() { | |
| 160 test_->set_status(base::PLATFORM_FILE_OK); | |
| 161 } | |
| 162 | |
| 163 virtual void DidGetLocalPath(const FilePath& local_path) { | |
| 164 ADD_FAILURE(); | |
| 165 } | |
| 166 | |
| 167 virtual void DidReadMetadata( | |
| 168 const base::PlatformFileInfo& info, | |
| 169 const FilePath& platform_path) { | |
| 170 ADD_FAILURE(); | |
| 171 } | |
| 172 | |
| 173 virtual void DidReadDirectory( | |
| 174 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 175 bool /* has_more */) { | |
| 176 ADD_FAILURE(); | |
| 177 } | |
| 178 | |
| 179 virtual void DidOpenFileSystem(const std::string&, const GURL&) { | |
| 180 ADD_FAILURE(); | |
| 181 } | |
| 182 | |
| 183 virtual void DidWrite(int64 bytes, bool complete) { | |
| 184 ADD_FAILURE(); | |
| 185 } | |
| 186 | |
| 187 private: | |
| 188 FileSystemQuotaTest* test_; | |
| 189 }; | |
| 190 | |
| 191 } // namespace (anonymous) | |
| 192 | |
| 193 void FileSystemQuotaTest::SetUp() { | 157 void FileSystemQuotaTest::SetUp() { |
| 194 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); | 158 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); |
| 195 FilePath filesystem_dir_path = work_dir_.path().AppendASCII("filesystem"); | 159 FilePath filesystem_dir_path = work_dir_.path().AppendASCII("filesystem"); |
| 196 file_util::CreateDirectory(filesystem_dir_path); | 160 file_util::CreateDirectory(filesystem_dir_path); |
| 197 | 161 |
| 198 quota_manager_ = new quota::QuotaManager( | 162 quota_manager_ = new quota::QuotaManager( |
| 199 false /* is_incognito */, | 163 false /* is_incognito */, |
| 200 filesystem_dir_path, | 164 filesystem_dir_path, |
| 201 base::MessageLoopProxy::current(), | 165 base::MessageLoopProxy::current(), |
| 202 base::MessageLoopProxy::current(), | 166 base::MessageLoopProxy::current(), |
| 203 NULL); | 167 NULL); |
| 204 | 168 |
| 205 test_helper_.SetUp(filesystem_dir_path, | 169 test_helper_.SetUp(filesystem_dir_path, |
| 206 false /* unlimited quota */, | 170 false /* unlimited quota */, |
| 207 quota_manager_->proxy(), | 171 quota_manager_->proxy(), |
| 208 local_file_util_.get()); | 172 local_file_util_.get()); |
| 209 } | 173 } |
| 210 | 174 |
| 211 void FileSystemQuotaTest::TearDown() { | 175 void FileSystemQuotaTest::TearDown() { |
| 212 quota_manager_ = NULL; | 176 quota_manager_ = NULL; |
| 213 test_helper_.TearDown(); | 177 test_helper_.TearDown(); |
| 214 } | 178 } |
| 215 | 179 |
| 216 FileSystemOperation* FileSystemQuotaTest::operation() { | 180 FileSystemOperation* FileSystemQuotaTest::operation() { |
| 217 return test_helper_.NewOperation(new MockDispatcher(this)); | 181 return test_helper_.NewOperation(); |
| 218 } | 182 } |
| 219 | 183 |
| 220 void FileSystemQuotaTest::OnGetUsageAndQuota( | 184 void FileSystemQuotaTest::OnGetUsageAndQuota( |
| 221 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 185 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 222 quota_status_ = status; | 186 quota_status_ = status; |
| 223 usage_ = usage; | 187 usage_ = usage; |
| 224 quota_ = quota; | 188 quota_ = quota; |
| 225 } | 189 } |
| 226 | 190 |
| 227 void FileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) { | 191 void FileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) { |
| 228 child_dir_path_ = CreateVirtualTemporaryDirInDir(virtual_path); | 192 child_dir_path_ = CreateVirtualTemporaryDirInDir(virtual_path); |
| 229 child_file1_path_ = CreateVirtualTemporaryFileInDir(virtual_path); | 193 child_file1_path_ = CreateVirtualTemporaryFileInDir(virtual_path); |
| 230 child_file2_path_ = CreateVirtualTemporaryFileInDir(virtual_path); | 194 child_file2_path_ = CreateVirtualTemporaryFileInDir(virtual_path); |
| 231 grandchild_file1_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_); | 195 grandchild_file1_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_); |
| 232 grandchild_file2_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_); | 196 grandchild_file2_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_); |
| 233 } | 197 } |
| 234 | 198 |
| 235 TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { | 199 TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { |
| 236 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 200 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 237 PrepareFileSet(src_dir_path); | 201 PrepareFileSet(src_dir_path); |
| 238 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 202 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 239 | 203 |
| 240 EXPECT_EQ(0, ActualSize()); | 204 EXPECT_EQ(0, ActualSize()); |
| 241 | 205 |
| 242 operation()->Truncate(URLForPath(child_file1_path_), 5000); | 206 operation()->Truncate(URLForPath(child_file1_path_), 5000, RecordStatus()); |
| 243 operation()->Truncate(URLForPath(child_file2_path_), 400); | 207 operation()->Truncate(URLForPath(child_file2_path_), 400, RecordStatus()); |
| 244 operation()->Truncate(URLForPath(grandchild_file1_path_), 30); | 208 operation()->Truncate(URLForPath(grandchild_file1_path_), 30, RecordStatus()); |
| 245 operation()->Truncate(URLForPath(grandchild_file2_path_), 2); | 209 operation()->Truncate(URLForPath(grandchild_file2_path_), 2, RecordStatus()); |
| 246 MessageLoop::current()->RunAllPending(); | 210 MessageLoop::current()->RunAllPending(); |
| 247 | 211 |
| 248 const int64 all_file_size = 5000 + 400 + 30 + 2; | 212 const int64 all_file_size = 5000 + 400 + 30 + 2; |
| 249 | 213 |
| 250 EXPECT_EQ(all_file_size, ActualSize()); | 214 EXPECT_EQ(all_file_size, ActualSize()); |
| 251 EXPECT_EQ(all_file_size, SizeInUsageFile()); | 215 EXPECT_EQ(all_file_size, SizeInUsageFile()); |
| 252 GetUsageAndQuotaFromQuotaManager(); | 216 GetUsageAndQuotaFromQuotaManager(); |
| 253 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 217 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 254 EXPECT_EQ(all_file_size, usage()); | 218 EXPECT_EQ(all_file_size, usage()); |
| 255 ASSERT_LT(all_file_size, quota()); | 219 ASSERT_LT(all_file_size, quota()); |
| 256 | 220 |
| 257 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 221 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 222 RecordStatus()); | |
| 258 MessageLoop::current()->RunAllPending(); | 223 MessageLoop::current()->RunAllPending(); |
| 259 | 224 |
| 260 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 225 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 261 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( | 226 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( |
| 262 child_dir_path_.BaseName()))); | 227 child_dir_path_.BaseName()))); |
| 263 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( | 228 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( |
| 264 child_dir_path_.BaseName()).Append( | 229 child_dir_path_.BaseName()).Append( |
| 265 grandchild_file1_path_.BaseName()))); | 230 grandchild_file1_path_.BaseName()))); |
| 266 | 231 |
| 267 EXPECT_EQ(all_file_size, ActualSize()); | 232 EXPECT_EQ(all_file_size, ActualSize()); |
| 268 EXPECT_EQ(all_file_size, SizeInUsageFile()); | 233 EXPECT_EQ(all_file_size, SizeInUsageFile()); |
| 269 GetUsageAndQuotaFromQuotaManager(); | 234 GetUsageAndQuotaFromQuotaManager(); |
| 270 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 235 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 271 EXPECT_EQ(all_file_size, usage()); | 236 EXPECT_EQ(all_file_size, usage()); |
| 272 ASSERT_LT(all_file_size, quota()); | 237 ASSERT_LT(all_file_size, quota()); |
| 273 } | 238 } |
| 274 | 239 |
| 275 TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { | 240 TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { |
| 276 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 241 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 277 PrepareFileSet(src_dir_path); | 242 PrepareFileSet(src_dir_path); |
| 278 FilePath dest_dir1_path(CreateVirtualTemporaryDir()); | 243 FilePath dest_dir1_path(CreateVirtualTemporaryDir()); |
| 279 FilePath dest_dir2_path(CreateVirtualTemporaryDir()); | 244 FilePath dest_dir2_path(CreateVirtualTemporaryDir()); |
| 280 | 245 |
| 281 EXPECT_EQ(0, ActualSize()); | 246 EXPECT_EQ(0, ActualSize()); |
| 282 | 247 |
| 283 operation()->Truncate(URLForPath(child_file1_path_), 8000); | 248 operation()->Truncate(URLForPath(child_file1_path_), 8000, RecordStatus()); |
| 284 operation()->Truncate(URLForPath(child_file2_path_), 700); | 249 operation()->Truncate(URLForPath(child_file2_path_), 700, RecordStatus()); |
| 285 operation()->Truncate(URLForPath(grandchild_file1_path_), 60); | 250 operation()->Truncate(URLForPath(grandchild_file1_path_), 60, RecordStatus()); |
| 286 operation()->Truncate(URLForPath(grandchild_file2_path_), 5); | 251 operation()->Truncate(URLForPath(grandchild_file2_path_), 5, RecordStatus()); |
| 287 MessageLoop::current()->RunAllPending(); | 252 MessageLoop::current()->RunAllPending(); |
| 288 | 253 |
| 289 const int64 child_file_size = 8000 + 700; | 254 const int64 child_file_size = 8000 + 700; |
| 290 const int64 grandchild_file_size = 60 + 5; | 255 const int64 grandchild_file_size = 60 + 5; |
| 291 const int64 all_file_size = child_file_size + grandchild_file_size; | 256 const int64 all_file_size = child_file_size + grandchild_file_size; |
| 292 | 257 |
| 293 EXPECT_EQ(all_file_size, ActualSize()); | 258 EXPECT_EQ(all_file_size, ActualSize()); |
| 294 EXPECT_EQ(all_file_size, SizeInUsageFile()); | 259 EXPECT_EQ(all_file_size, SizeInUsageFile()); |
| 295 GetUsageAndQuotaFromQuotaManager(); | 260 GetUsageAndQuotaFromQuotaManager(); |
| 296 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 261 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 297 EXPECT_EQ(all_file_size, usage()); | 262 EXPECT_EQ(all_file_size, usage()); |
| 298 ASSERT_LT(all_file_size, quota()); | 263 ASSERT_LT(all_file_size, quota()); |
| 299 | 264 |
| 300 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path)); | 265 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path), |
| 266 RecordStatus()); | |
| 301 MessageLoop::current()->RunAllPending(); | 267 MessageLoop::current()->RunAllPending(); |
| 302 | 268 |
| 303 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 269 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 304 EXPECT_TRUE(VirtualDirectoryExists(src_dir_path.Append( | 270 EXPECT_TRUE(VirtualDirectoryExists(src_dir_path.Append( |
| 305 child_dir_path_.BaseName()))); | 271 child_dir_path_.BaseName()))); |
| 306 EXPECT_TRUE(VirtualFileExists(src_dir_path.Append( | 272 EXPECT_TRUE(VirtualFileExists(src_dir_path.Append( |
| 307 child_dir_path_.BaseName()).Append( | 273 child_dir_path_.BaseName()).Append( |
| 308 grandchild_file1_path_.BaseName()))); | 274 grandchild_file1_path_.BaseName()))); |
| 309 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 275 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 310 EXPECT_TRUE(VirtualDirectoryExists(dest_dir1_path.Append( | 276 EXPECT_TRUE(VirtualDirectoryExists(dest_dir1_path.Append( |
| 311 child_dir_path_.BaseName()))); | 277 child_dir_path_.BaseName()))); |
| 312 EXPECT_TRUE(VirtualFileExists(dest_dir1_path.Append( | 278 EXPECT_TRUE(VirtualFileExists(dest_dir1_path.Append( |
| 313 child_dir_path_.BaseName()).Append( | 279 child_dir_path_.BaseName()).Append( |
| 314 grandchild_file1_path_.BaseName()))); | 280 grandchild_file1_path_.BaseName()))); |
| 315 | 281 |
| 316 EXPECT_EQ(2 * all_file_size, ActualSize()); | 282 EXPECT_EQ(2 * all_file_size, ActualSize()); |
| 317 EXPECT_EQ(2 * all_file_size, SizeInUsageFile()); | 283 EXPECT_EQ(2 * all_file_size, SizeInUsageFile()); |
| 318 GetUsageAndQuotaFromQuotaManager(); | 284 GetUsageAndQuotaFromQuotaManager(); |
| 319 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 285 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 320 EXPECT_EQ(2 * all_file_size, usage()); | 286 EXPECT_EQ(2 * all_file_size, usage()); |
| 321 ASSERT_LT(2 * all_file_size, quota()); | 287 ASSERT_LT(2 * all_file_size, quota()); |
| 322 | 288 |
| 323 operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path)); | 289 operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path), |
| 290 RecordStatus()); | |
| 324 MessageLoop::current()->RunAllPending(); | 291 MessageLoop::current()->RunAllPending(); |
| 325 | 292 |
| 326 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 293 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 327 | 294 |
| 328 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualSize()); | 295 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualSize()); |
| 329 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, SizeInUsageFile()); | 296 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, SizeInUsageFile()); |
| 330 GetUsageAndQuotaFromQuotaManager(); | 297 GetUsageAndQuotaFromQuotaManager(); |
| 331 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 298 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
| 332 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, usage()); | 299 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, usage()); |
| 333 ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota()); | 300 ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota()); |
| 334 } | 301 } |
| 335 | 302 |
| 336 } // namespace fileapi | 303 } // namespace fileapi |
| OLD | NEW |