OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/fileapi/file_system_operation_impl.h" | 5 #include "webkit/browser/fileapi/file_system_operation_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 using storage::FileSystemOperation; | 33 using storage::FileSystemOperation; |
34 using storage::FileSystemOperationContext; | 34 using storage::FileSystemOperationContext; |
35 using storage::FileSystemOperationRunner; | 35 using storage::FileSystemOperationRunner; |
36 using storage::FileSystemURL; | 36 using storage::FileSystemURL; |
37 using storage::QuotaManager; | 37 using storage::QuotaManager; |
38 using storage::QuotaManagerProxy; | 38 using storage::QuotaManagerProxy; |
39 using storage::ShareableFileReference; | 39 using storage::ShareableFileReference; |
40 | 40 |
41 namespace content { | 41 namespace content { |
42 | 42 |
43 namespace { | |
44 | |
45 const int kFileOperationStatusNotSet = 1; | |
46 | |
47 void AssertFileErrorEq(const tracked_objects::Location& from_here, | |
48 base::File::Error expected, | |
49 base::File::Error actual) { | |
50 ASSERT_EQ(expected, actual) << from_here.ToString(); | |
51 } | |
52 | |
53 void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here, | |
54 base::File::Error expected, | |
55 base::Closure closure, | |
56 base::File::Error actual) { | |
57 ASSERT_EQ(expected, actual) << from_here.ToString(); | |
58 closure.Run(); | |
59 } | |
60 | |
61 } // namespace | |
62 | |
63 // Test class for FileSystemOperationImpl. | 43 // Test class for FileSystemOperationImpl. |
64 class FileSystemOperationImplTest | 44 class FileSystemOperationImplTest |
65 : public testing::Test { | 45 : public testing::Test { |
66 public: | 46 public: |
67 FileSystemOperationImplTest() | 47 FileSystemOperationImplTest() : weak_factory_(this) {} |
68 : status_(kFileOperationStatusNotSet), | |
69 weak_factory_(this) {} | |
70 | 48 |
71 protected: | 49 protected: |
72 virtual void SetUp() OVERRIDE { | 50 virtual void SetUp() OVERRIDE { |
73 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 51 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
74 change_observers_ = | 52 change_observers_ = |
75 storage::MockFileChangeObserver::CreateList(&change_observer_); | 53 storage::MockFileChangeObserver::CreateList(&change_observer_); |
76 | 54 |
77 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); | 55 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); |
78 quota_manager_ = | 56 quota_manager_ = |
79 new MockQuotaManager(false /* is_incognito */, | 57 new MockQuotaManager(false /* is_incognito */, |
(...skipping 12 matching lines...) Expand all Loading... |
92 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); | 70 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); |
93 quota_manager_ = NULL; | 71 quota_manager_ = NULL; |
94 quota_manager_proxy_ = NULL; | 72 quota_manager_proxy_ = NULL; |
95 sandbox_file_system_.TearDown(); | 73 sandbox_file_system_.TearDown(); |
96 } | 74 } |
97 | 75 |
98 FileSystemOperationRunner* operation_runner() { | 76 FileSystemOperationRunner* operation_runner() { |
99 return sandbox_file_system_.operation_runner(); | 77 return sandbox_file_system_.operation_runner(); |
100 } | 78 } |
101 | 79 |
102 int status() const { return status_; } | |
103 const base::File::Info& info() const { return info_; } | 80 const base::File::Info& info() const { return info_; } |
104 const base::FilePath& path() const { return path_; } | 81 const base::FilePath& path() const { return path_; } |
105 const std::vector<storage::DirectoryEntry>& entries() const { | 82 const std::vector<storage::DirectoryEntry>& entries() const { |
106 return entries_; | 83 return entries_; |
107 } | 84 } |
108 | 85 |
109 const ShareableFileReference* shareable_file_ref() const { | 86 const ShareableFileReference* shareable_file_ref() const { |
110 return shareable_file_ref_.get(); | 87 return shareable_file_ref_.get(); |
111 } | 88 } |
112 | 89 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 return url; | 150 return url; |
174 } | 151 } |
175 | 152 |
176 int64 GetFileSize(const std::string& path) { | 153 int64 GetFileSize(const std::string& path) { |
177 base::File::Info info; | 154 base::File::Info info; |
178 EXPECT_TRUE(base::GetFileInfo(PlatformPath(path), &info)); | 155 EXPECT_TRUE(base::GetFileInfo(PlatformPath(path), &info)); |
179 return info.size; | 156 return info.size; |
180 } | 157 } |
181 | 158 |
182 // Callbacks for recording test results. | 159 // Callbacks for recording test results. |
183 FileSystemOperation::StatusCallback RecordStatusCallback() { | 160 FileSystemOperation::StatusCallback RecordStatusCallback( |
| 161 const base::Closure& closure, |
| 162 base::File::Error* status) { |
184 return base::Bind(&FileSystemOperationImplTest::DidFinish, | 163 return base::Bind(&FileSystemOperationImplTest::DidFinish, |
185 weak_factory_.GetWeakPtr()); | 164 weak_factory_.GetWeakPtr(), |
| 165 closure, |
| 166 status); |
186 } | 167 } |
187 | 168 |
188 FileSystemOperation::ReadDirectoryCallback | 169 FileSystemOperation::ReadDirectoryCallback RecordReadDirectoryCallback( |
189 RecordReadDirectoryCallback() { | 170 const base::Closure& closure, |
| 171 base::File::Error* status) { |
190 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory, | 172 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory, |
191 weak_factory_.GetWeakPtr()); | 173 weak_factory_.GetWeakPtr(), |
| 174 closure, |
| 175 status); |
192 } | 176 } |
193 | 177 |
194 FileSystemOperation::GetMetadataCallback RecordMetadataCallback() { | 178 FileSystemOperation::GetMetadataCallback RecordMetadataCallback( |
| 179 const base::Closure& closure, |
| 180 base::File::Error* status) { |
195 return base::Bind(&FileSystemOperationImplTest::DidGetMetadata, | 181 return base::Bind(&FileSystemOperationImplTest::DidGetMetadata, |
196 weak_factory_.GetWeakPtr()); | 182 weak_factory_.GetWeakPtr(), |
| 183 closure, |
| 184 status); |
197 } | 185 } |
198 | 186 |
199 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() { | 187 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback( |
| 188 const base::Closure& closure, |
| 189 base::File::Error* status) { |
200 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, | 190 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, |
201 weak_factory_.GetWeakPtr()); | 191 weak_factory_.GetWeakPtr(), |
| 192 closure, |
| 193 status); |
202 } | 194 } |
203 | 195 |
204 void DidFinish(base::File::Error status) { | 196 void DidFinish(const base::Closure& closure, |
205 status_ = status; | 197 base::File::Error* status, |
| 198 base::File::Error actual) { |
| 199 *status = actual; |
| 200 closure.Run(); |
206 } | 201 } |
207 | 202 |
208 void DidReadDirectory(base::File::Error status, | 203 void DidReadDirectory(const base::Closure& closure, |
| 204 base::File::Error* status, |
| 205 base::File::Error actual, |
209 const std::vector<storage::DirectoryEntry>& entries, | 206 const std::vector<storage::DirectoryEntry>& entries, |
210 bool /* has_more */) { | 207 bool /* has_more */) { |
211 entries_ = entries; | 208 entries_ = entries; |
212 status_ = status; | 209 *status = actual; |
| 210 closure.Run(); |
213 } | 211 } |
214 | 212 |
215 void DidGetMetadata(base::File::Error status, | 213 void DidGetMetadata(const base::Closure& closure, |
| 214 base::File::Error* status, |
| 215 base::File::Error actual, |
216 const base::File::Info& info) { | 216 const base::File::Info& info) { |
217 info_ = info; | 217 info_ = info; |
218 status_ = status; | 218 *status = actual; |
| 219 closure.Run(); |
219 } | 220 } |
220 | 221 |
221 void DidCreateSnapshotFile( | 222 void DidCreateSnapshotFile( |
222 base::File::Error status, | 223 const base::Closure& closure, |
| 224 base::File::Error* status, |
| 225 base::File::Error actual, |
223 const base::File::Info& info, | 226 const base::File::Info& info, |
224 const base::FilePath& platform_path, | 227 const base::FilePath& platform_path, |
225 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { | 228 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { |
226 info_ = info; | 229 info_ = info; |
227 path_ = platform_path; | 230 path_ = platform_path; |
228 status_ = status; | 231 *status = actual; |
229 shareable_file_ref_ = shareable_file_ref; | 232 shareable_file_ref_ = shareable_file_ref; |
| 233 closure.Run(); |
230 } | 234 } |
231 | 235 |
232 int64 GetDataSizeOnDisk() { | 236 int64 GetDataSizeOnDisk() { |
233 return sandbox_file_system_.ComputeCurrentOriginUsage() - | 237 return sandbox_file_system_.ComputeCurrentOriginUsage() - |
234 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); | 238 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); |
235 } | 239 } |
236 | 240 |
237 void GetUsageAndQuota(int64* usage, int64* quota) { | 241 void GetUsageAndQuota(int64* usage, int64* quota) { |
238 storage::QuotaStatusCode status = | 242 storage::QuotaStatusCode status = |
239 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), | 243 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), |
240 sandbox_file_system_.origin(), | 244 sandbox_file_system_.origin(), |
241 sandbox_file_system_.type(), | 245 sandbox_file_system_.type(), |
242 usage, | 246 usage, |
243 quota); | 247 quota); |
244 base::RunLoop().RunUntilIdle(); | 248 base::RunLoop().RunUntilIdle(); |
245 ASSERT_EQ(storage::kQuotaStatusOk, status); | 249 ASSERT_EQ(storage::kQuotaStatusOk, status); |
246 } | 250 } |
247 | 251 |
248 int64 ComputePathCost(const FileSystemURL& url) { | 252 int64 ComputePathCost(const FileSystemURL& url) { |
249 int64 base_usage; | 253 int64 base_usage; |
250 GetUsageAndQuota(&base_usage, NULL); | 254 GetUsageAndQuota(&base_usage, NULL); |
251 | 255 |
252 AsyncFileTestHelper::CreateFile( | 256 AsyncFileTestHelper::CreateFile( |
253 sandbox_file_system_.file_system_context(), url); | 257 sandbox_file_system_.file_system_context(), url); |
254 operation_runner()->Remove(url, false /* recursive */, | 258 EXPECT_EQ(base::File::FILE_OK, Remove(url, false /* recursive */)); |
255 base::Bind(&AssertFileErrorEq, FROM_HERE, | 259 |
256 base::File::FILE_OK)); | |
257 base::RunLoop().RunUntilIdle(); | |
258 change_observer()->ResetCount(); | 260 change_observer()->ResetCount(); |
259 | 261 |
260 int64 total_usage; | 262 int64 total_usage; |
261 GetUsageAndQuota(&total_usage, NULL); | 263 GetUsageAndQuota(&total_usage, NULL); |
262 return total_usage - base_usage; | 264 return total_usage - base_usage; |
263 } | 265 } |
264 | 266 |
265 void GrantQuotaForCurrentUsage() { | 267 void GrantQuotaForCurrentUsage() { |
266 int64 usage; | 268 int64 usage; |
267 GetUsageAndQuota(&usage, NULL); | 269 GetUsageAndQuota(&usage, NULL); |
268 quota_manager()->SetQuota(sandbox_file_system_.origin(), | 270 quota_manager()->SetQuota(sandbox_file_system_.origin(), |
269 sandbox_file_system_.storage_type(), | 271 sandbox_file_system_.storage_type(), |
270 usage); | 272 usage); |
271 } | 273 } |
272 | 274 |
273 int64 GetUsage() { | 275 int64 GetUsage() { |
274 int64 usage = 0; | 276 int64 usage = 0; |
275 GetUsageAndQuota(&usage, NULL); | 277 GetUsageAndQuota(&usage, NULL); |
276 return usage; | 278 return usage; |
277 } | 279 } |
278 | 280 |
279 void AddQuota(int64 quota_delta) { | 281 void AddQuota(int64 quota_delta) { |
280 int64 quota; | 282 int64 quota; |
281 GetUsageAndQuota(NULL, "a); | 283 GetUsageAndQuota(NULL, "a); |
282 quota_manager()->SetQuota(sandbox_file_system_.origin(), | 284 quota_manager()->SetQuota(sandbox_file_system_.origin(), |
283 sandbox_file_system_.storage_type(), | 285 sandbox_file_system_.storage_type(), |
284 quota + quota_delta); | 286 quota + quota_delta); |
285 } | 287 } |
286 | 288 |
| 289 base::File::Error Move( |
| 290 const FileSystemURL& src, |
| 291 const FileSystemURL& dest, |
| 292 storage::FileSystemOperation::CopyOrMoveOption option) { |
| 293 base::File::Error status; |
| 294 base::RunLoop run_loop; |
| 295 operation_runner()->Move( |
| 296 src, |
| 297 dest, |
| 298 option, |
| 299 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 300 run_loop.Run(); |
| 301 return status; |
| 302 } |
| 303 |
| 304 base::File::Error Copy( |
| 305 const FileSystemURL& src, |
| 306 const FileSystemURL& dest, |
| 307 storage::FileSystemOperation::CopyOrMoveOption option) { |
| 308 base::File::Error status; |
| 309 base::RunLoop run_loop; |
| 310 operation_runner()->Copy( |
| 311 src, |
| 312 dest, |
| 313 option, |
| 314 FileSystemOperationRunner::CopyProgressCallback(), |
| 315 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 316 run_loop.Run(); |
| 317 return status; |
| 318 } |
| 319 |
| 320 base::File::Error CopyInForeignFile(const base::FilePath& src, |
| 321 const FileSystemURL& dest) { |
| 322 base::File::Error status; |
| 323 base::RunLoop run_loop; |
| 324 operation_runner()->CopyInForeignFile( |
| 325 src, dest, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 326 run_loop.Run(); |
| 327 return status; |
| 328 } |
| 329 |
| 330 base::File::Error Truncate(const FileSystemURL& url, int size) { |
| 331 base::File::Error status; |
| 332 base::RunLoop run_loop; |
| 333 operation_runner()->Truncate( |
| 334 url, size, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 335 run_loop.Run(); |
| 336 return status; |
| 337 } |
| 338 |
| 339 base::File::Error CreateFile(const FileSystemURL& url, bool exclusive) { |
| 340 base::File::Error status; |
| 341 base::RunLoop run_loop; |
| 342 operation_runner()->CreateFile( |
| 343 url, exclusive, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 344 run_loop.Run(); |
| 345 return status; |
| 346 } |
| 347 |
| 348 base::File::Error Remove(const FileSystemURL& url, bool recursive) { |
| 349 base::File::Error status; |
| 350 base::RunLoop run_loop; |
| 351 operation_runner()->Remove( |
| 352 url, recursive, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 353 run_loop.Run(); |
| 354 return status; |
| 355 } |
| 356 |
| 357 base::File::Error CreateDirectory(const FileSystemURL& url, |
| 358 bool exclusive, |
| 359 bool recursive) { |
| 360 base::File::Error status; |
| 361 base::RunLoop run_loop; |
| 362 operation_runner()->CreateDirectory( |
| 363 url, |
| 364 exclusive, |
| 365 recursive, |
| 366 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 367 run_loop.Run(); |
| 368 return status; |
| 369 } |
| 370 |
| 371 base::File::Error GetMetadata(const FileSystemURL& url) { |
| 372 base::File::Error status; |
| 373 base::RunLoop run_loop; |
| 374 operation_runner()->GetMetadata( |
| 375 url, RecordMetadataCallback(run_loop.QuitClosure(), &status)); |
| 376 run_loop.Run(); |
| 377 return status; |
| 378 } |
| 379 |
| 380 base::File::Error ReadDirectory(const FileSystemURL& url) { |
| 381 base::File::Error status; |
| 382 base::RunLoop run_loop; |
| 383 operation_runner()->ReadDirectory( |
| 384 url, RecordReadDirectoryCallback(run_loop.QuitClosure(), &status)); |
| 385 run_loop.Run(); |
| 386 return status; |
| 387 } |
| 388 |
| 389 base::File::Error CreateSnapshotFile(const FileSystemURL& url) { |
| 390 base::File::Error status; |
| 391 base::RunLoop run_loop; |
| 392 operation_runner()->CreateSnapshotFile( |
| 393 url, RecordSnapshotFileCallback(run_loop.QuitClosure(), &status)); |
| 394 run_loop.Run(); |
| 395 return status; |
| 396 } |
| 397 |
| 398 base::File::Error FileExists(const FileSystemURL& url) { |
| 399 base::File::Error status; |
| 400 base::RunLoop run_loop; |
| 401 operation_runner()->FileExists( |
| 402 url, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 403 run_loop.Run(); |
| 404 return status; |
| 405 } |
| 406 |
| 407 base::File::Error DirectoryExists(const FileSystemURL& url) { |
| 408 base::File::Error status; |
| 409 base::RunLoop run_loop; |
| 410 operation_runner()->DirectoryExists( |
| 411 url, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 412 run_loop.Run(); |
| 413 return status; |
| 414 } |
| 415 |
| 416 base::File::Error TouchFile(const FileSystemURL& url, |
| 417 const base::Time& last_access_time, |
| 418 const base::Time& last_modified_time) { |
| 419 base::File::Error status; |
| 420 base::RunLoop run_loop; |
| 421 operation_runner()->TouchFile( |
| 422 url, |
| 423 last_access_time, |
| 424 last_modified_time, |
| 425 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
| 426 run_loop.Run(); |
| 427 return status; |
| 428 } |
| 429 |
287 private: | 430 private: |
288 base::MessageLoopForIO message_loop_; | 431 base::MessageLoopForIO message_loop_; |
289 scoped_refptr<QuotaManager> quota_manager_; | 432 scoped_refptr<QuotaManager> quota_manager_; |
290 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 433 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
291 | 434 |
292 // Common temp base for nondestructive uses. | 435 // Common temp base for nondestructive uses. |
293 base::ScopedTempDir base_; | 436 base::ScopedTempDir base_; |
294 | 437 |
295 SandboxFileSystemTestHelper sandbox_file_system_; | 438 SandboxFileSystemTestHelper sandbox_file_system_; |
296 | 439 |
297 // For post-operation status. | 440 // For post-operation status. |
298 int status_; | |
299 base::File::Info info_; | 441 base::File::Info info_; |
300 base::FilePath path_; | 442 base::FilePath path_; |
301 std::vector<storage::DirectoryEntry> entries_; | 443 std::vector<storage::DirectoryEntry> entries_; |
302 scoped_refptr<ShareableFileReference> shareable_file_ref_; | 444 scoped_refptr<ShareableFileReference> shareable_file_ref_; |
303 | 445 |
304 storage::MockFileChangeObserver change_observer_; | 446 storage::MockFileChangeObserver change_observer_; |
305 storage::ChangeObserverList change_observers_; | 447 storage::ChangeObserverList change_observers_; |
306 | 448 |
307 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; | 449 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; |
308 | 450 |
309 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); | 451 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); |
310 }; | 452 }; |
311 | 453 |
312 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { | 454 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { |
313 change_observer()->ResetCount(); | 455 change_observer()->ResetCount(); |
314 operation_runner()->Move(URLForPath("a"), URLForPath("b"), | 456 EXPECT_EQ( |
315 FileSystemOperation::OPTION_NONE, | 457 base::File::FILE_ERROR_NOT_FOUND, |
316 RecordStatusCallback()); | 458 Move(URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE)); |
317 base::RunLoop().RunUntilIdle(); | |
318 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
319 EXPECT_TRUE(change_observer()->HasNoChange()); | 459 EXPECT_TRUE(change_observer()->HasNoChange()); |
320 } | 460 } |
321 | 461 |
322 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { | 462 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { |
323 FileSystemURL src_dir(CreateDirectory("src")); | 463 FileSystemURL src_dir(CreateDirectory("src")); |
324 FileSystemURL dest_dir(CreateDirectory("src/dest")); | 464 FileSystemURL dest_dir(CreateDirectory("src/dest")); |
325 | 465 |
326 operation_runner()->Move(src_dir, dest_dir, | 466 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, |
327 FileSystemOperation::OPTION_NONE, | 467 Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); |
328 RecordStatusCallback()); | |
329 base::RunLoop().RunUntilIdle(); | |
330 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
331 EXPECT_TRUE(change_observer()->HasNoChange()); | 468 EXPECT_TRUE(change_observer()->HasNoChange()); |
332 } | 469 } |
333 | 470 |
334 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { | 471 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { |
335 // Src exists and is dir. Dest is a file. | 472 // Src exists and is dir. Dest is a file. |
336 FileSystemURL src_dir(CreateDirectory("src")); | 473 FileSystemURL src_dir(CreateDirectory("src")); |
337 FileSystemURL dest_dir(CreateDirectory("dest")); | 474 FileSystemURL dest_dir(CreateDirectory("dest")); |
338 FileSystemURL dest_file(CreateFile("dest/file")); | 475 FileSystemURL dest_file(CreateFile("dest/file")); |
339 | 476 |
340 operation_runner()->Move(src_dir, dest_file, | 477 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, |
341 FileSystemOperation::OPTION_NONE, | 478 Move(src_dir, dest_file, FileSystemOperation::OPTION_NONE)); |
342 RecordStatusCallback()); | |
343 base::RunLoop().RunUntilIdle(); | |
344 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
345 EXPECT_TRUE(change_observer()->HasNoChange()); | 479 EXPECT_TRUE(change_observer()->HasNoChange()); |
346 } | 480 } |
347 | 481 |
348 TEST_F(FileSystemOperationImplTest, | 482 TEST_F(FileSystemOperationImplTest, |
349 TestMoveFailureSrcFileExistsDestNonEmptyDir) { | 483 TestMoveFailureSrcFileExistsDestNonEmptyDir) { |
350 // Src exists and is a directory. Dest is a non-empty directory. | 484 // Src exists and is a directory. Dest is a non-empty directory. |
351 FileSystemURL src_dir(CreateDirectory("src")); | 485 FileSystemURL src_dir(CreateDirectory("src")); |
352 FileSystemURL dest_dir(CreateDirectory("dest")); | 486 FileSystemURL dest_dir(CreateDirectory("dest")); |
353 FileSystemURL dest_file(CreateFile("dest/file")); | 487 FileSystemURL dest_file(CreateFile("dest/file")); |
354 | 488 |
355 operation_runner()->Move(src_dir, dest_dir, | 489 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, |
356 FileSystemOperation::OPTION_NONE, | 490 Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); |
357 RecordStatusCallback()); | |
358 base::RunLoop().RunUntilIdle(); | |
359 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); | |
360 EXPECT_TRUE(change_observer()->HasNoChange()); | 491 EXPECT_TRUE(change_observer()->HasNoChange()); |
361 } | 492 } |
362 | 493 |
363 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { | 494 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { |
364 // Src exists and is a file. Dest is a directory. | 495 // Src exists and is a file. Dest is a directory. |
365 FileSystemURL src_dir(CreateDirectory("src")); | 496 FileSystemURL src_dir(CreateDirectory("src")); |
366 FileSystemURL src_file(CreateFile("src/file")); | 497 FileSystemURL src_file(CreateFile("src/file")); |
367 FileSystemURL dest_dir(CreateDirectory("dest")); | 498 FileSystemURL dest_dir(CreateDirectory("dest")); |
368 | 499 |
369 operation_runner()->Move(src_file, dest_dir, | 500 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, |
370 FileSystemOperation::OPTION_NONE, | 501 Move(src_file, dest_dir, FileSystemOperation::OPTION_NONE)); |
371 RecordStatusCallback()); | |
372 base::RunLoop().RunUntilIdle(); | |
373 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
374 EXPECT_TRUE(change_observer()->HasNoChange()); | 502 EXPECT_TRUE(change_observer()->HasNoChange()); |
375 } | 503 } |
376 | 504 |
377 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { | 505 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { |
378 // Dest. parent path does not exist. | 506 // Dest. parent path does not exist. |
379 FileSystemURL src_dir(CreateDirectory("src")); | 507 FileSystemURL src_dir(CreateDirectory("src")); |
380 operation_runner()->Move(src_dir, URLForPath("nonexistent/deset"), | 508 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
381 FileSystemOperation::OPTION_NONE, | 509 Move(src_dir, |
382 RecordStatusCallback()); | 510 URLForPath("nonexistent/deset"), |
383 base::RunLoop().RunUntilIdle(); | 511 FileSystemOperation::OPTION_NONE)); |
384 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
385 EXPECT_TRUE(change_observer()->HasNoChange()); | 512 EXPECT_TRUE(change_observer()->HasNoChange()); |
386 } | 513 } |
387 | 514 |
388 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { | 515 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { |
389 FileSystemURL src_file(CreateFile("src")); | 516 FileSystemURL src_file(CreateFile("src")); |
390 FileSystemURL dest_file(CreateFile("dest")); | 517 FileSystemURL dest_file(CreateFile("dest")); |
391 | 518 |
392 operation_runner()->Move(src_file, dest_file, | 519 EXPECT_EQ(base::File::FILE_OK, |
393 FileSystemOperation::OPTION_NONE, | 520 Move(src_file, dest_file, FileSystemOperation::OPTION_NONE)); |
394 RecordStatusCallback()); | |
395 base::RunLoop().RunUntilIdle(); | |
396 EXPECT_EQ(base::File::FILE_OK, status()); | |
397 EXPECT_TRUE(FileExists("dest")); | 521 EXPECT_TRUE(FileExists("dest")); |
398 | 522 |
399 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 523 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
400 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 524 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
401 EXPECT_TRUE(change_observer()->HasNoChange()); | 525 EXPECT_TRUE(change_observer()->HasNoChange()); |
402 | 526 |
403 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 527 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
404 } | 528 } |
405 | 529 |
406 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { | 530 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { |
407 FileSystemURL src_file(CreateFile("src")); | 531 FileSystemURL src_file(CreateFile("src")); |
408 | 532 |
409 operation_runner()->Move(src_file, URLForPath("new"), | 533 EXPECT_EQ( |
410 FileSystemOperation::OPTION_NONE, | 534 base::File::FILE_OK, |
411 RecordStatusCallback()); | 535 Move(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE)); |
412 base::RunLoop().RunUntilIdle(); | |
413 EXPECT_EQ(base::File::FILE_OK, status()); | |
414 EXPECT_TRUE(FileExists("new")); | 536 EXPECT_TRUE(FileExists("new")); |
415 | 537 |
416 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 538 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
417 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 539 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
418 EXPECT_TRUE(change_observer()->HasNoChange()); | 540 EXPECT_TRUE(change_observer()->HasNoChange()); |
419 } | 541 } |
420 | 542 |
421 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { | 543 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { |
422 FileSystemURL src_dir(CreateDirectory("src")); | 544 FileSystemURL src_dir(CreateDirectory("src")); |
423 FileSystemURL dest_dir(CreateDirectory("dest")); | 545 FileSystemURL dest_dir(CreateDirectory("dest")); |
424 | 546 |
425 operation_runner()->Move(src_dir, dest_dir, | 547 EXPECT_EQ(base::File::FILE_OK, |
426 FileSystemOperation::OPTION_NONE, | 548 Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); |
427 RecordStatusCallback()); | |
428 base::RunLoop().RunUntilIdle(); | |
429 EXPECT_EQ(base::File::FILE_OK, status()); | |
430 EXPECT_FALSE(DirectoryExists("src")); | 549 EXPECT_FALSE(DirectoryExists("src")); |
431 | 550 |
432 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 551 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
433 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 552 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
434 EXPECT_TRUE(change_observer()->HasNoChange()); | 553 EXPECT_TRUE(change_observer()->HasNoChange()); |
435 | 554 |
436 // Make sure we've overwritten but not moved the source under the |dest_dir|. | 555 // Make sure we've overwritten but not moved the source under the |dest_dir|. |
437 EXPECT_TRUE(DirectoryExists("dest")); | 556 EXPECT_TRUE(DirectoryExists("dest")); |
438 EXPECT_FALSE(DirectoryExists("dest/src")); | 557 EXPECT_FALSE(DirectoryExists("dest/src")); |
439 } | 558 } |
440 | 559 |
441 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { | 560 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { |
442 FileSystemURL src_dir(CreateDirectory("src")); | 561 FileSystemURL src_dir(CreateDirectory("src")); |
443 FileSystemURL dest_dir(CreateDirectory("dest")); | 562 FileSystemURL dest_dir(CreateDirectory("dest")); |
444 | 563 |
445 operation_runner()->Move(src_dir, URLForPath("dest/new"), | 564 EXPECT_EQ( |
446 FileSystemOperation::OPTION_NONE, | 565 base::File::FILE_OK, |
447 RecordStatusCallback()); | 566 Move(src_dir, URLForPath("dest/new"), FileSystemOperation::OPTION_NONE)); |
448 base::RunLoop().RunUntilIdle(); | |
449 EXPECT_EQ(base::File::FILE_OK, status()); | |
450 EXPECT_FALSE(DirectoryExists("src")); | 567 EXPECT_FALSE(DirectoryExists("src")); |
451 EXPECT_TRUE(DirectoryExists("dest/new")); | 568 EXPECT_TRUE(DirectoryExists("dest/new")); |
452 | 569 |
453 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 570 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
454 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 571 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
455 EXPECT_TRUE(change_observer()->HasNoChange()); | 572 EXPECT_TRUE(change_observer()->HasNoChange()); |
456 } | 573 } |
457 | 574 |
458 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { | 575 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { |
459 FileSystemURL src_dir(CreateDirectory("src")); | 576 FileSystemURL src_dir(CreateDirectory("src")); |
460 CreateDirectory("src/dir"); | 577 CreateDirectory("src/dir"); |
461 CreateFile("src/dir/sub"); | 578 CreateFile("src/dir/sub"); |
462 | 579 |
463 FileSystemURL dest_dir(CreateDirectory("dest")); | 580 FileSystemURL dest_dir(CreateDirectory("dest")); |
464 | 581 |
465 operation_runner()->Move(src_dir, dest_dir, | 582 EXPECT_EQ(base::File::FILE_OK, |
466 FileSystemOperation::OPTION_NONE, | 583 Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); |
467 RecordStatusCallback()); | |
468 base::RunLoop().RunUntilIdle(); | |
469 EXPECT_EQ(base::File::FILE_OK, status()); | |
470 EXPECT_TRUE(DirectoryExists("dest/dir")); | 584 EXPECT_TRUE(DirectoryExists("dest/dir")); |
471 EXPECT_TRUE(FileExists("dest/dir/sub")); | 585 EXPECT_TRUE(FileExists("dest/dir/sub")); |
472 | 586 |
473 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); | 587 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); |
474 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 588 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
475 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 589 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
476 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 590 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
477 EXPECT_TRUE(change_observer()->HasNoChange()); | 591 EXPECT_TRUE(change_observer()->HasNoChange()); |
478 } | 592 } |
479 | 593 |
480 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { | 594 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { |
481 FileSystemURL src_dir(CreateDirectory("src")); | 595 FileSystemURL src_dir(CreateDirectory("src")); |
482 CreateDirectory("src/dir"); | 596 CreateDirectory("src/dir"); |
483 CreateFile("src/dir/sub"); | 597 CreateFile("src/dir/sub"); |
484 | 598 |
485 operation_runner()->Move(src_dir, src_dir, | 599 EXPECT_EQ(base::File::FILE_OK, |
486 FileSystemOperation::OPTION_NONE, | 600 Move(src_dir, src_dir, FileSystemOperation::OPTION_NONE)); |
487 RecordStatusCallback()); | |
488 base::RunLoop().RunUntilIdle(); | |
489 EXPECT_EQ(base::File::FILE_OK, status()); | |
490 EXPECT_TRUE(DirectoryExists("src/dir")); | 601 EXPECT_TRUE(DirectoryExists("src/dir")); |
491 EXPECT_TRUE(FileExists("src/dir/sub")); | 602 EXPECT_TRUE(FileExists("src/dir/sub")); |
492 | 603 |
493 EXPECT_EQ(0, change_observer()->get_and_reset_remove_directory_count()); | 604 EXPECT_EQ(0, change_observer()->get_and_reset_remove_directory_count()); |
494 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); | 605 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); |
495 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); | 606 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); |
496 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); | 607 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); |
497 EXPECT_TRUE(change_observer()->HasNoChange()); | 608 EXPECT_TRUE(change_observer()->HasNoChange()); |
498 } | 609 } |
499 | 610 |
500 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { | 611 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { |
501 operation_runner()->Copy(URLForPath("a"), URLForPath("b"), | 612 EXPECT_EQ( |
502 FileSystemOperation::OPTION_NONE, | 613 base::File::FILE_ERROR_NOT_FOUND, |
503 FileSystemOperationRunner::CopyProgressCallback(), | 614 Copy(URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE)); |
504 RecordStatusCallback()); | |
505 base::RunLoop().RunUntilIdle(); | |
506 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
507 EXPECT_TRUE(change_observer()->HasNoChange()); | 615 EXPECT_TRUE(change_observer()->HasNoChange()); |
508 } | 616 } |
509 | 617 |
510 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { | 618 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { |
511 FileSystemURL src_dir(CreateDirectory("src")); | 619 FileSystemURL src_dir(CreateDirectory("src")); |
512 FileSystemURL dest_dir(CreateDirectory("src/dir")); | 620 FileSystemURL dest_dir(CreateDirectory("src/dir")); |
513 | 621 |
514 operation_runner()->Copy(src_dir, dest_dir, | 622 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, |
515 FileSystemOperation::OPTION_NONE, | 623 Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); |
516 FileSystemOperationRunner::CopyProgressCallback(), | |
517 RecordStatusCallback()); | |
518 base::RunLoop().RunUntilIdle(); | |
519 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
520 EXPECT_TRUE(change_observer()->HasNoChange()); | 624 EXPECT_TRUE(change_observer()->HasNoChange()); |
521 } | 625 } |
522 | 626 |
523 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { | 627 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { |
524 // Src exists and is dir. Dest is a file. | 628 // Src exists and is dir. Dest is a file. |
525 FileSystemURL src_dir(CreateDirectory("src")); | 629 FileSystemURL src_dir(CreateDirectory("src")); |
526 FileSystemURL dest_dir(CreateDirectory("dest")); | 630 FileSystemURL dest_dir(CreateDirectory("dest")); |
527 FileSystemURL dest_file(CreateFile("dest/file")); | 631 FileSystemURL dest_file(CreateFile("dest/file")); |
528 | 632 |
529 operation_runner()->Copy(src_dir, dest_file, | 633 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, |
530 FileSystemOperation::OPTION_NONE, | 634 Copy(src_dir, dest_file, FileSystemOperation::OPTION_NONE)); |
531 FileSystemOperationRunner::CopyProgressCallback(), | |
532 RecordStatusCallback()); | |
533 base::RunLoop().RunUntilIdle(); | |
534 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
535 EXPECT_TRUE(change_observer()->HasNoChange()); | 635 EXPECT_TRUE(change_observer()->HasNoChange()); |
536 } | 636 } |
537 | 637 |
538 TEST_F(FileSystemOperationImplTest, | 638 TEST_F(FileSystemOperationImplTest, |
539 TestCopyFailureSrcFileExistsDestNonEmptyDir) { | 639 TestCopyFailureSrcFileExistsDestNonEmptyDir) { |
540 // Src exists and is a directory. Dest is a non-empty directory. | 640 // Src exists and is a directory. Dest is a non-empty directory. |
541 FileSystemURL src_dir(CreateDirectory("src")); | 641 FileSystemURL src_dir(CreateDirectory("src")); |
542 FileSystemURL dest_dir(CreateDirectory("dest")); | 642 FileSystemURL dest_dir(CreateDirectory("dest")); |
543 FileSystemURL dest_file(CreateFile("dest/file")); | 643 FileSystemURL dest_file(CreateFile("dest/file")); |
544 | 644 |
545 operation_runner()->Copy(src_dir, dest_dir, | 645 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, |
546 FileSystemOperation::OPTION_NONE, | 646 Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); |
547 FileSystemOperationRunner::CopyProgressCallback(), | |
548 RecordStatusCallback()); | |
549 base::RunLoop().RunUntilIdle(); | |
550 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); | |
551 EXPECT_TRUE(change_observer()->HasNoChange()); | 647 EXPECT_TRUE(change_observer()->HasNoChange()); |
552 } | 648 } |
553 | 649 |
554 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { | 650 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { |
555 // Src exists and is a file. Dest is a directory. | 651 // Src exists and is a file. Dest is a directory. |
556 FileSystemURL src_file(CreateFile("src")); | 652 FileSystemURL src_file(CreateFile("src")); |
557 FileSystemURL dest_dir(CreateDirectory("dest")); | 653 FileSystemURL dest_dir(CreateDirectory("dest")); |
558 | 654 |
559 operation_runner()->Copy(src_file, dest_dir, | 655 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, |
560 FileSystemOperation::OPTION_NONE, | 656 Copy(src_file, dest_dir, FileSystemOperation::OPTION_NONE)); |
561 FileSystemOperationRunner::CopyProgressCallback(), | |
562 RecordStatusCallback()); | |
563 base::RunLoop().RunUntilIdle(); | |
564 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | |
565 EXPECT_TRUE(change_observer()->HasNoChange()); | 657 EXPECT_TRUE(change_observer()->HasNoChange()); |
566 } | 658 } |
567 | 659 |
568 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { | 660 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { |
569 // Dest. parent path does not exist. | 661 // Dest. parent path does not exist. |
570 FileSystemURL src_dir(CreateDirectory("src")); | 662 FileSystemURL src_dir(CreateDirectory("src")); |
571 | 663 |
572 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), | 664 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
573 FileSystemOperation::OPTION_NONE, | 665 Copy(src_dir, |
574 FileSystemOperationRunner::CopyProgressCallback(), | 666 URLForPath("nonexistent/dest"), |
575 RecordStatusCallback()); | 667 FileSystemOperation::OPTION_NONE)); |
576 base::RunLoop().RunUntilIdle(); | |
577 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
578 EXPECT_TRUE(change_observer()->HasNoChange()); | 668 EXPECT_TRUE(change_observer()->HasNoChange()); |
579 } | 669 } |
580 | 670 |
581 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { | 671 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { |
582 FileSystemURL src_dir(CreateDirectory("src")); | 672 FileSystemURL src_dir(CreateDirectory("src")); |
583 FileSystemURL src_file(CreateFile("src/file")); | 673 FileSystemURL src_file(CreateFile("src/file")); |
584 FileSystemURL dest_dir(CreateDirectory("dest")); | 674 FileSystemURL dest_dir(CreateDirectory("dest")); |
585 operation_runner()->Truncate(src_file, 6, RecordStatusCallback()); | 675 EXPECT_EQ(base::File::FILE_OK, Truncate(src_file, 6)); |
586 base::RunLoop().RunUntilIdle(); | |
587 EXPECT_EQ(base::File::FILE_OK, status()); | |
588 EXPECT_EQ(6, GetFileSize("src/file")); | 676 EXPECT_EQ(6, GetFileSize("src/file")); |
589 | 677 |
590 FileSystemURL dest_file(URLForPath("dest/file")); | 678 FileSystemURL dest_file(URLForPath("dest/file")); |
591 int64 dest_path_cost = ComputePathCost(dest_file); | 679 int64 dest_path_cost = ComputePathCost(dest_file); |
592 GrantQuotaForCurrentUsage(); | 680 GrantQuotaForCurrentUsage(); |
593 AddQuota(6 + dest_path_cost - 1); | 681 AddQuota(6 + dest_path_cost - 1); |
594 | 682 |
595 operation_runner()->Copy(src_file, dest_file, | 683 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, |
596 FileSystemOperation::OPTION_NONE, | 684 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); |
597 FileSystemOperationRunner::CopyProgressCallback(), | |
598 RecordStatusCallback()); | |
599 base::RunLoop().RunUntilIdle(); | |
600 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); | |
601 EXPECT_FALSE(FileExists("dest/file")); | 685 EXPECT_FALSE(FileExists("dest/file")); |
602 } | 686 } |
603 | 687 |
604 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { | 688 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { |
605 FileSystemURL src_file(CreateFile("src")); | 689 FileSystemURL src_file(CreateFile("src")); |
606 FileSystemURL dest_file(CreateFile("dest")); | 690 FileSystemURL dest_file(CreateFile("dest")); |
607 | 691 |
608 operation_runner()->Copy(src_file, dest_file, | 692 EXPECT_EQ(base::File::FILE_OK, |
609 FileSystemOperation::OPTION_NONE, | 693 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); |
610 FileSystemOperationRunner::CopyProgressCallback(), | 694 |
611 RecordStatusCallback()); | |
612 base::RunLoop().RunUntilIdle(); | |
613 EXPECT_EQ(base::File::FILE_OK, status()); | |
614 EXPECT_TRUE(FileExists("dest")); | 695 EXPECT_TRUE(FileExists("dest")); |
615 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); | 696 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
616 EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count()); | 697 EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count()); |
617 | 698 |
618 EXPECT_TRUE(change_observer()->HasNoChange()); | 699 EXPECT_TRUE(change_observer()->HasNoChange()); |
619 } | 700 } |
620 | 701 |
621 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { | 702 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { |
622 FileSystemURL src_file(CreateFile("src")); | 703 FileSystemURL src_file(CreateFile("src")); |
623 | 704 |
624 operation_runner()->Copy(src_file, URLForPath("new"), | 705 EXPECT_EQ( |
625 FileSystemOperation::OPTION_NONE, | 706 base::File::FILE_OK, |
626 FileSystemOperationRunner::CopyProgressCallback(), | 707 Copy(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE)); |
627 RecordStatusCallback()); | |
628 base::RunLoop().RunUntilIdle(); | |
629 EXPECT_EQ(base::File::FILE_OK, status()); | |
630 EXPECT_TRUE(FileExists("new")); | 708 EXPECT_TRUE(FileExists("new")); |
631 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); | 709 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
632 | 710 |
633 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 711 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
634 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 712 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
635 EXPECT_TRUE(change_observer()->HasNoChange()); | 713 EXPECT_TRUE(change_observer()->HasNoChange()); |
636 } | 714 } |
637 | 715 |
638 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { | 716 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { |
639 FileSystemURL src_dir(CreateDirectory("src")); | 717 FileSystemURL src_dir(CreateDirectory("src")); |
640 FileSystemURL dest_dir(CreateDirectory("dest")); | 718 FileSystemURL dest_dir(CreateDirectory("dest")); |
641 | 719 |
642 operation_runner()->Copy(src_dir, dest_dir, | 720 EXPECT_EQ(base::File::FILE_OK, |
643 FileSystemOperation::OPTION_NONE, | 721 Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); |
644 FileSystemOperationRunner::CopyProgressCallback(), | |
645 RecordStatusCallback()); | |
646 base::RunLoop().RunUntilIdle(); | |
647 EXPECT_EQ(base::File::FILE_OK, status()); | |
648 | 722 |
649 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 723 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
650 EXPECT_TRUE(DirectoryExists("dest")); | 724 EXPECT_TRUE(DirectoryExists("dest")); |
651 EXPECT_FALSE(DirectoryExists("dest/src")); | 725 EXPECT_FALSE(DirectoryExists("dest/src")); |
652 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); | 726 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); |
653 | 727 |
654 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 728 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
655 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 729 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
656 EXPECT_TRUE(change_observer()->HasNoChange()); | 730 EXPECT_TRUE(change_observer()->HasNoChange()); |
657 } | 731 } |
658 | 732 |
659 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { | 733 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { |
660 FileSystemURL src_dir(CreateDirectory("src")); | 734 FileSystemURL src_dir(CreateDirectory("src")); |
661 FileSystemURL dest_dir_new(URLForPath("dest")); | 735 FileSystemURL dest_dir_new(URLForPath("dest")); |
662 | 736 |
663 operation_runner()->Copy(src_dir, dest_dir_new, | 737 EXPECT_EQ(base::File::FILE_OK, |
664 FileSystemOperation::OPTION_NONE, | 738 Copy(src_dir, dest_dir_new, FileSystemOperation::OPTION_NONE)); |
665 FileSystemOperationRunner::CopyProgressCallback(), | |
666 RecordStatusCallback()); | |
667 base::RunLoop().RunUntilIdle(); | |
668 EXPECT_EQ(base::File::FILE_OK, status()); | |
669 EXPECT_TRUE(DirectoryExists("dest")); | 739 EXPECT_TRUE(DirectoryExists("dest")); |
670 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); | 740 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); |
671 | 741 |
672 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 742 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
673 EXPECT_TRUE(change_observer()->HasNoChange()); | 743 EXPECT_TRUE(change_observer()->HasNoChange()); |
674 } | 744 } |
675 | 745 |
676 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { | 746 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { |
677 FileSystemURL src_dir(CreateDirectory("src")); | 747 FileSystemURL src_dir(CreateDirectory("src")); |
678 CreateDirectory("src/dir"); | 748 CreateDirectory("src/dir"); |
679 CreateFile("src/dir/sub"); | 749 CreateFile("src/dir/sub"); |
680 | 750 |
681 FileSystemURL dest_dir(CreateDirectory("dest")); | 751 FileSystemURL dest_dir(CreateDirectory("dest")); |
682 | 752 |
683 operation_runner()->Copy(src_dir, dest_dir, | 753 EXPECT_EQ(base::File::FILE_OK, |
684 FileSystemOperation::OPTION_NONE, | 754 Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); |
685 FileSystemOperationRunner::CopyProgressCallback(), | |
686 RecordStatusCallback()); | |
687 base::RunLoop().RunUntilIdle(); | |
688 | 755 |
689 EXPECT_EQ(base::File::FILE_OK, status()); | |
690 EXPECT_TRUE(DirectoryExists("dest/dir")); | 756 EXPECT_TRUE(DirectoryExists("dest/dir")); |
691 EXPECT_TRUE(FileExists("dest/dir/sub")); | 757 EXPECT_TRUE(FileExists("dest/dir/sub")); |
692 | 758 |
693 // For recursive copy we may record multiple read access. | 759 // For recursive copy we may record multiple read access. |
694 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); | 760 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); |
695 | 761 |
696 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 762 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
697 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 763 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
698 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 764 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
699 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 765 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
700 EXPECT_TRUE(change_observer()->HasNoChange()); | 766 EXPECT_TRUE(change_observer()->HasNoChange()); |
701 } | 767 } |
702 | 768 |
703 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { | 769 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { |
704 FileSystemURL src_dir(CreateDirectory("src")); | 770 FileSystemURL src_dir(CreateDirectory("src")); |
705 CreateDirectory("src/dir"); | 771 CreateDirectory("src/dir"); |
706 CreateFile("src/dir/sub"); | 772 CreateFile("src/dir/sub"); |
707 | 773 |
708 operation_runner()->Copy(src_dir, src_dir, | 774 EXPECT_EQ(base::File::FILE_OK, |
709 FileSystemOperation::OPTION_NONE, | 775 Copy(src_dir, src_dir, FileSystemOperation::OPTION_NONE)); |
710 FileSystemOperationRunner::CopyProgressCallback(), | |
711 RecordStatusCallback()); | |
712 base::RunLoop().RunUntilIdle(); | |
713 | 776 |
714 EXPECT_EQ(base::File::FILE_OK, status()); | |
715 EXPECT_TRUE(DirectoryExists("src/dir")); | 777 EXPECT_TRUE(DirectoryExists("src/dir")); |
716 EXPECT_TRUE(FileExists("src/dir/sub")); | 778 EXPECT_TRUE(FileExists("src/dir/sub")); |
717 | 779 |
718 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); | 780 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); |
719 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); | 781 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); |
720 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); | 782 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); |
721 EXPECT_TRUE(change_observer()->HasNoChange()); | 783 EXPECT_TRUE(change_observer()->HasNoChange()); |
722 } | 784 } |
723 | 785 |
724 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) { | 786 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) { |
725 base::FilePath src_local_disk_file_path; | 787 base::FilePath src_local_disk_file_path; |
726 base::CreateTemporaryFile(&src_local_disk_file_path); | 788 base::CreateTemporaryFile(&src_local_disk_file_path); |
727 const char test_data[] = "foo"; | 789 const char test_data[] = "foo"; |
728 int data_size = ARRAYSIZE_UNSAFE(test_data); | 790 int data_size = ARRAYSIZE_UNSAFE(test_data); |
729 base::WriteFile(src_local_disk_file_path, test_data, data_size); | 791 base::WriteFile(src_local_disk_file_path, test_data, data_size); |
730 | 792 |
731 FileSystemURL dest_dir(CreateDirectory("dest")); | 793 FileSystemURL dest_dir(CreateDirectory("dest")); |
732 | 794 |
733 int64 before_usage; | 795 int64 before_usage; |
734 GetUsageAndQuota(&before_usage, NULL); | 796 GetUsageAndQuota(&before_usage, NULL); |
735 | 797 |
736 // Check that the file copied and corresponding usage increased. | 798 // Check that the file copied and corresponding usage increased. |
737 operation_runner()->CopyInForeignFile(src_local_disk_file_path, | 799 EXPECT_EQ( |
738 URLForPath("dest/file"), | 800 base::File::FILE_OK, |
739 RecordStatusCallback()); | 801 CopyInForeignFile(src_local_disk_file_path, URLForPath("dest/file"))); |
740 base::RunLoop().RunUntilIdle(); | |
741 | 802 |
742 EXPECT_EQ(1, change_observer()->create_file_count()); | 803 EXPECT_EQ(1, change_observer()->create_file_count()); |
743 EXPECT_EQ(base::File::FILE_OK, status()); | |
744 EXPECT_TRUE(FileExists("dest/file")); | 804 EXPECT_TRUE(FileExists("dest/file")); |
745 int64 after_usage; | 805 int64 after_usage; |
746 GetUsageAndQuota(&after_usage, NULL); | 806 GetUsageAndQuota(&after_usage, NULL); |
747 EXPECT_GT(after_usage, before_usage); | 807 EXPECT_GT(after_usage, before_usage); |
748 | 808 |
749 // Compare contents of src and copied file. | 809 // Compare contents of src and copied file. |
750 char buffer[100]; | 810 char buffer[100]; |
751 EXPECT_EQ(data_size, base::ReadFile(PlatformPath("dest/file"), | 811 EXPECT_EQ(data_size, base::ReadFile(PlatformPath("dest/file"), |
752 buffer, data_size)); | 812 buffer, data_size)); |
753 for (int i = 0; i < data_size; ++i) | 813 for (int i = 0; i < data_size; ++i) |
754 EXPECT_EQ(test_data[i], buffer[i]); | 814 EXPECT_EQ(test_data[i], buffer[i]); |
755 } | 815 } |
756 | 816 |
757 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) { | 817 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) { |
758 base::FilePath src_local_disk_file_path; | 818 base::FilePath src_local_disk_file_path; |
759 base::CreateTemporaryFile(&src_local_disk_file_path); | 819 base::CreateTemporaryFile(&src_local_disk_file_path); |
760 const char test_data[] = "foo"; | 820 const char test_data[] = "foo"; |
761 base::WriteFile(src_local_disk_file_path, test_data, | 821 base::WriteFile(src_local_disk_file_path, test_data, |
762 ARRAYSIZE_UNSAFE(test_data)); | 822 ARRAYSIZE_UNSAFE(test_data)); |
763 | 823 |
764 FileSystemURL dest_dir(CreateDirectory("dest")); | 824 FileSystemURL dest_dir(CreateDirectory("dest")); |
765 | 825 |
766 GrantQuotaForCurrentUsage(); | 826 GrantQuotaForCurrentUsage(); |
767 operation_runner()->CopyInForeignFile(src_local_disk_file_path, | 827 EXPECT_EQ( |
768 URLForPath("dest/file"), | 828 base::File::FILE_ERROR_NO_SPACE, |
769 RecordStatusCallback()); | 829 CopyInForeignFile(src_local_disk_file_path, URLForPath("dest/file"))); |
770 base::RunLoop().RunUntilIdle(); | |
771 | 830 |
772 EXPECT_FALSE(FileExists("dest/file")); | 831 EXPECT_FALSE(FileExists("dest/file")); |
773 EXPECT_EQ(0, change_observer()->create_file_count()); | 832 EXPECT_EQ(0, change_observer()->create_file_count()); |
774 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); | |
775 } | 833 } |
776 | 834 |
777 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) { | 835 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) { |
778 // Already existing file and exclusive true. | 836 // Already existing file and exclusive true. |
779 FileSystemURL file(CreateFile("file")); | 837 FileSystemURL file(CreateFile("file")); |
780 operation_runner()->CreateFile(file, true, RecordStatusCallback()); | 838 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, CreateFile(file, true)); |
781 base::RunLoop().RunUntilIdle(); | |
782 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); | |
783 EXPECT_TRUE(change_observer()->HasNoChange()); | 839 EXPECT_TRUE(change_observer()->HasNoChange()); |
784 } | 840 } |
785 | 841 |
786 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { | 842 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { |
787 // Already existing file and exclusive false. | 843 // Already existing file and exclusive false. |
788 FileSystemURL file(CreateFile("file")); | 844 FileSystemURL file(CreateFile("file")); |
789 operation_runner()->CreateFile(file, false, RecordStatusCallback()); | 845 EXPECT_EQ(base::File::FILE_OK, CreateFile(file, false)); |
790 base::RunLoop().RunUntilIdle(); | |
791 EXPECT_EQ(base::File::FILE_OK, status()); | |
792 EXPECT_TRUE(FileExists("file")); | 846 EXPECT_TRUE(FileExists("file")); |
793 | 847 |
794 // The file was already there; did nothing. | 848 // The file was already there; did nothing. |
795 EXPECT_TRUE(change_observer()->HasNoChange()); | 849 EXPECT_TRUE(change_observer()->HasNoChange()); |
796 } | 850 } |
797 | 851 |
798 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) { | 852 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) { |
799 // File doesn't exist but exclusive is true. | 853 // File doesn't exist but exclusive is true. |
800 operation_runner()->CreateFile(URLForPath("new"), true, | 854 EXPECT_EQ(base::File::FILE_OK, CreateFile(URLForPath("new"), true)); |
801 RecordStatusCallback()); | |
802 base::RunLoop().RunUntilIdle(); | |
803 EXPECT_EQ(base::File::FILE_OK, status()); | |
804 EXPECT_TRUE(FileExists("new")); | 855 EXPECT_TRUE(FileExists("new")); |
805 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 856 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
806 } | 857 } |
807 | 858 |
808 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) { | 859 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) { |
809 // Non existing file. | 860 // Non existing file. |
810 operation_runner()->CreateFile(URLForPath("nonexistent"), false, | 861 EXPECT_EQ(base::File::FILE_OK, CreateFile(URLForPath("nonexistent"), false)); |
811 RecordStatusCallback()); | |
812 base::RunLoop().RunUntilIdle(); | |
813 EXPECT_EQ(base::File::FILE_OK, status()); | |
814 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 862 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
815 } | 863 } |
816 | 864 |
817 TEST_F(FileSystemOperationImplTest, | 865 TEST_F(FileSystemOperationImplTest, |
818 TestCreateDirFailureDestParentDoesntExist) { | 866 TestCreateDirFailureDestParentDoesntExist) { |
819 // Dest. parent path does not exist. | 867 // Dest. parent path does not exist. |
820 operation_runner()->CreateDirectory( | 868 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
821 URLForPath("nonexistent/dir"), false, false, | 869 CreateDirectory(URLForPath("nonexistent/dir"), false, false)); |
822 RecordStatusCallback()); | |
823 base::RunLoop().RunUntilIdle(); | |
824 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
825 EXPECT_TRUE(change_observer()->HasNoChange()); | 870 EXPECT_TRUE(change_observer()->HasNoChange()); |
826 } | 871 } |
827 | 872 |
828 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) { | 873 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) { |
829 // Exclusive and dir existing at path. | 874 // Exclusive and dir existing at path. |
830 FileSystemURL dir(CreateDirectory("dir")); | 875 FileSystemURL dir(CreateDirectory("dir")); |
831 operation_runner()->CreateDirectory(dir, true, false, | 876 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, CreateDirectory(dir, true, false)); |
832 RecordStatusCallback()); | |
833 base::RunLoop().RunUntilIdle(); | |
834 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); | |
835 EXPECT_TRUE(change_observer()->HasNoChange()); | 877 EXPECT_TRUE(change_observer()->HasNoChange()); |
836 } | 878 } |
837 | 879 |
838 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) { | 880 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) { |
839 // Exclusive true and file existing at path. | 881 // Exclusive true and file existing at path. |
840 FileSystemURL file(CreateFile("file")); | 882 FileSystemURL file(CreateFile("file")); |
841 operation_runner()->CreateDirectory(file, true, false, | 883 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, CreateDirectory(file, true, false)); |
842 RecordStatusCallback()); | |
843 base::RunLoop().RunUntilIdle(); | |
844 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); | |
845 EXPECT_TRUE(change_observer()->HasNoChange()); | 884 EXPECT_TRUE(change_observer()->HasNoChange()); |
846 } | 885 } |
847 | 886 |
848 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) { | 887 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) { |
849 // Dir exists and exclusive is false. | 888 // Dir exists and exclusive is false. |
850 FileSystemURL dir(CreateDirectory("dir")); | 889 FileSystemURL dir(CreateDirectory("dir")); |
851 operation_runner()->CreateDirectory(dir, false, false, | 890 EXPECT_EQ(base::File::FILE_OK, CreateDirectory(dir, false, false)); |
852 RecordStatusCallback()); | |
853 base::RunLoop().RunUntilIdle(); | |
854 EXPECT_EQ(base::File::FILE_OK, status()); | |
855 EXPECT_TRUE(change_observer()->HasNoChange()); | 891 EXPECT_TRUE(change_observer()->HasNoChange()); |
856 | 892 |
857 // Dir doesn't exist. | 893 // Dir doesn't exist. |
858 operation_runner()->CreateDirectory(URLForPath("new"), false, false, | 894 EXPECT_EQ(base::File::FILE_OK, |
859 RecordStatusCallback()); | 895 CreateDirectory(URLForPath("new"), false, false)); |
860 base::RunLoop().RunUntilIdle(); | |
861 EXPECT_EQ(base::File::FILE_OK, status()); | |
862 EXPECT_TRUE(DirectoryExists("new")); | 896 EXPECT_TRUE(DirectoryExists("new")); |
863 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 897 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
864 } | 898 } |
865 | 899 |
866 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) { | 900 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) { |
867 // Dir doesn't exist. | 901 // Dir doesn't exist. |
868 operation_runner()->CreateDirectory(URLForPath("new"), true, false, | 902 EXPECT_EQ(base::File::FILE_OK, |
869 RecordStatusCallback()); | 903 CreateDirectory(URLForPath("new"), true, false)); |
870 base::RunLoop().RunUntilIdle(); | |
871 EXPECT_EQ(base::File::FILE_OK, status()); | |
872 EXPECT_TRUE(DirectoryExists("new")); | 904 EXPECT_TRUE(DirectoryExists("new")); |
873 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 905 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
874 EXPECT_TRUE(change_observer()->HasNoChange()); | 906 EXPECT_TRUE(change_observer()->HasNoChange()); |
875 } | 907 } |
876 | 908 |
877 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { | 909 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { |
878 operation_runner()->GetMetadata(URLForPath("nonexistent"), | 910 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
879 RecordMetadataCallback()); | 911 GetMetadata(URLForPath("nonexistent"))); |
880 base::RunLoop().RunUntilIdle(); | |
881 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
882 | 912 |
883 operation_runner()->FileExists(URLForPath("nonexistent"), | 913 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
884 RecordStatusCallback()); | 914 FileExists(URLForPath("nonexistent"))); |
885 base::RunLoop().RunUntilIdle(); | |
886 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
887 | 915 |
888 operation_runner()->DirectoryExists(URLForPath("nonexistent"), | 916 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
889 RecordStatusCallback()); | 917 DirectoryExists(URLForPath("nonexistent"))); |
890 base::RunLoop().RunUntilIdle(); | |
891 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
892 EXPECT_TRUE(change_observer()->HasNoChange()); | 918 EXPECT_TRUE(change_observer()->HasNoChange()); |
893 } | 919 } |
894 | 920 |
895 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { | 921 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { |
896 FileSystemURL dir(CreateDirectory("dir")); | 922 FileSystemURL dir(CreateDirectory("dir")); |
897 FileSystemURL file(CreateFile("dir/file")); | 923 FileSystemURL file(CreateFile("dir/file")); |
898 int read_access = 0; | 924 int read_access = 0; |
899 | 925 |
900 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); | 926 EXPECT_EQ(base::File::FILE_OK, DirectoryExists(dir)); |
901 base::RunLoop().RunUntilIdle(); | |
902 EXPECT_EQ(base::File::FILE_OK, status()); | |
903 ++read_access; | 927 ++read_access; |
904 | 928 |
905 operation_runner()->GetMetadata(dir, RecordMetadataCallback()); | 929 EXPECT_EQ(base::File::FILE_OK, GetMetadata(dir)); |
906 base::RunLoop().RunUntilIdle(); | |
907 EXPECT_EQ(base::File::FILE_OK, status()); | |
908 EXPECT_TRUE(info().is_directory); | 930 EXPECT_TRUE(info().is_directory); |
909 ++read_access; | 931 ++read_access; |
910 | 932 |
911 operation_runner()->FileExists(file, RecordStatusCallback()); | 933 EXPECT_EQ(base::File::FILE_OK, FileExists(file)); |
912 base::RunLoop().RunUntilIdle(); | |
913 EXPECT_EQ(base::File::FILE_OK, status()); | |
914 ++read_access; | 934 ++read_access; |
915 | 935 |
916 operation_runner()->GetMetadata(file, RecordMetadataCallback()); | 936 EXPECT_EQ(base::File::FILE_OK, GetMetadata(file)); |
917 base::RunLoop().RunUntilIdle(); | |
918 EXPECT_EQ(base::File::FILE_OK, status()); | |
919 EXPECT_FALSE(info().is_directory); | 937 EXPECT_FALSE(info().is_directory); |
920 ++read_access; | 938 ++read_access; |
921 | 939 |
922 EXPECT_EQ(read_access, | 940 EXPECT_EQ(read_access, |
923 quota_manager_proxy()->notify_storage_accessed_count()); | 941 quota_manager_proxy()->notify_storage_accessed_count()); |
924 EXPECT_TRUE(change_observer()->HasNoChange()); | 942 EXPECT_TRUE(change_observer()->HasNoChange()); |
925 } | 943 } |
926 | 944 |
927 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { | 945 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { |
928 FileSystemURL dir(CreateDirectory("dir")); | 946 FileSystemURL dir(CreateDirectory("dir")); |
929 operation_runner()->FileExists(dir, RecordStatusCallback()); | 947 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, FileExists(dir)); |
930 base::RunLoop().RunUntilIdle(); | |
931 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, status()); | |
932 | 948 |
933 FileSystemURL file(CreateFile("file")); | 949 FileSystemURL file(CreateFile("file")); |
934 operation_runner()->DirectoryExists(file, RecordStatusCallback()); | 950 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, DirectoryExists(file)); |
935 base::RunLoop().RunUntilIdle(); | |
936 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); | |
937 } | 951 } |
938 | 952 |
939 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) { | 953 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) { |
940 // Path doesn't exist | 954 // Path doesn't exist |
941 operation_runner()->ReadDirectory(URLForPath("nonexistent"), | 955 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
942 RecordReadDirectoryCallback()); | 956 ReadDirectory(URLForPath("nonexistent"))); |
943 base::RunLoop().RunUntilIdle(); | |
944 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
945 | 957 |
946 // File exists. | 958 // File exists. |
947 FileSystemURL file(CreateFile("file")); | 959 FileSystemURL file(CreateFile("file")); |
948 operation_runner()->ReadDirectory(file, RecordReadDirectoryCallback()); | 960 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, ReadDirectory(file)); |
949 base::RunLoop().RunUntilIdle(); | |
950 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); | |
951 EXPECT_TRUE(change_observer()->HasNoChange()); | 961 EXPECT_TRUE(change_observer()->HasNoChange()); |
952 } | 962 } |
953 | 963 |
954 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { | 964 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { |
955 // parent_dir | 965 // parent_dir |
956 // | | | 966 // | | |
957 // child_dir child_file | 967 // child_dir child_file |
958 // Verify reading parent_dir. | 968 // Verify reading parent_dir. |
959 FileSystemURL parent_dir(CreateDirectory("dir")); | 969 FileSystemURL parent_dir(CreateDirectory("dir")); |
960 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 970 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
961 FileSystemURL child_file(CreateFile("dir/child_file")); | 971 FileSystemURL child_file(CreateFile("dir/child_file")); |
962 | 972 |
963 operation_runner()->ReadDirectory(parent_dir, RecordReadDirectoryCallback()); | 973 EXPECT_EQ(base::File::FILE_OK, ReadDirectory(parent_dir)); |
964 base::RunLoop().RunUntilIdle(); | |
965 EXPECT_EQ(base::File::FILE_OK, status()); | |
966 EXPECT_EQ(2u, entries().size()); | 974 EXPECT_EQ(2u, entries().size()); |
967 | 975 |
968 for (size_t i = 0; i < entries().size(); ++i) { | 976 for (size_t i = 0; i < entries().size(); ++i) { |
969 if (entries()[i].is_directory) | 977 if (entries()[i].is_directory) |
970 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name); | 978 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name); |
971 else | 979 else |
972 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name); | 980 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name); |
973 } | 981 } |
974 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 982 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
975 EXPECT_TRUE(change_observer()->HasNoChange()); | 983 EXPECT_TRUE(change_observer()->HasNoChange()); |
976 } | 984 } |
977 | 985 |
978 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { | 986 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { |
979 // Path doesn't exist. | 987 // Path doesn't exist. |
980 operation_runner()->Remove(URLForPath("nonexistent"), false /* recursive */, | 988 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
981 RecordStatusCallback()); | 989 Remove(URLForPath("nonexistent"), false /* recursive */)); |
982 base::RunLoop().RunUntilIdle(); | |
983 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); | |
984 | 990 |
985 // It's an error to try to remove a non-empty directory if recursive flag | 991 // It's an error to try to remove a non-empty directory if recursive flag |
986 // is false. | 992 // is false. |
987 // parent_dir | 993 // parent_dir |
988 // | | | 994 // | | |
989 // child_dir child_file | 995 // child_dir child_file |
990 // Verify deleting parent_dir. | 996 // Verify deleting parent_dir. |
991 FileSystemURL parent_dir(CreateDirectory("dir")); | 997 FileSystemURL parent_dir(CreateDirectory("dir")); |
992 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 998 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
993 FileSystemURL child_file(CreateFile("dir/child_file")); | 999 FileSystemURL child_file(CreateFile("dir/child_file")); |
994 | 1000 |
995 operation_runner()->Remove(parent_dir, false /* recursive */, | 1001 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, |
996 RecordStatusCallback()); | 1002 Remove(parent_dir, false /* recursive */)); |
997 base::RunLoop().RunUntilIdle(); | |
998 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); | |
999 EXPECT_TRUE(change_observer()->HasNoChange()); | 1003 EXPECT_TRUE(change_observer()->HasNoChange()); |
1000 } | 1004 } |
1001 | 1005 |
1002 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) { | 1006 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) { |
1003 FileSystemURL empty_dir(CreateDirectory("empty_dir")); | 1007 FileSystemURL empty_dir(CreateDirectory("empty_dir")); |
1004 EXPECT_TRUE(DirectoryExists("empty_dir")); | 1008 EXPECT_TRUE(DirectoryExists("empty_dir")); |
1005 operation_runner()->Remove(empty_dir, false /* recursive */, | 1009 EXPECT_EQ(base::File::FILE_OK, Remove(empty_dir, false /* recursive */)); |
1006 RecordStatusCallback()); | |
1007 base::RunLoop().RunUntilIdle(); | |
1008 EXPECT_EQ(base::File::FILE_OK, status()); | |
1009 EXPECT_FALSE(DirectoryExists("empty_dir")); | 1010 EXPECT_FALSE(DirectoryExists("empty_dir")); |
1010 | 1011 |
1011 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 1012 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
1012 EXPECT_TRUE(change_observer()->HasNoChange()); | 1013 EXPECT_TRUE(change_observer()->HasNoChange()); |
1013 } | 1014 } |
1014 | 1015 |
1015 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) { | 1016 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) { |
1016 // Removing a non-empty directory with recursive flag == true should be ok. | 1017 // Removing a non-empty directory with recursive flag == true should be ok. |
1017 // parent_dir | 1018 // parent_dir |
1018 // | | | 1019 // | | |
1019 // child_dir child_files | 1020 // child_dir child_files |
1020 // | | 1021 // | |
1021 // child_files | 1022 // child_files |
1022 // | 1023 // |
1023 // Verify deleting parent_dir. | 1024 // Verify deleting parent_dir. |
1024 FileSystemURL parent_dir(CreateDirectory("dir")); | 1025 FileSystemURL parent_dir(CreateDirectory("dir")); |
1025 for (int i = 0; i < 8; ++i) | 1026 for (int i = 0; i < 8; ++i) |
1026 CreateFile(base::StringPrintf("dir/file-%d", i)); | 1027 CreateFile(base::StringPrintf("dir/file-%d", i)); |
1027 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 1028 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
1028 for (int i = 0; i < 8; ++i) | 1029 for (int i = 0; i < 8; ++i) |
1029 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); | 1030 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); |
1030 | 1031 |
1031 operation_runner()->Remove(parent_dir, true /* recursive */, | 1032 EXPECT_EQ(base::File::FILE_OK, Remove(parent_dir, true /* recursive */)); |
1032 RecordStatusCallback()); | |
1033 base::RunLoop().RunUntilIdle(); | |
1034 EXPECT_EQ(base::File::FILE_OK, status()); | |
1035 EXPECT_FALSE(DirectoryExists("parent_dir")); | 1033 EXPECT_FALSE(DirectoryExists("parent_dir")); |
1036 | 1034 |
1037 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 1035 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
1038 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count()); | 1036 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count()); |
1039 EXPECT_TRUE(change_observer()->HasNoChange()); | 1037 EXPECT_TRUE(change_observer()->HasNoChange()); |
1040 } | 1038 } |
1041 | 1039 |
1042 TEST_F(FileSystemOperationImplTest, TestTruncate) { | 1040 TEST_F(FileSystemOperationImplTest, TestTruncate) { |
1043 FileSystemURL file(CreateFile("file")); | 1041 FileSystemURL file(CreateFile("file")); |
1044 base::FilePath platform_path = PlatformPath("file"); | 1042 base::FilePath platform_path = PlatformPath("file"); |
1045 | 1043 |
1046 char test_data[] = "test data"; | 1044 char test_data[] = "test data"; |
1047 int data_size = static_cast<int>(sizeof(test_data)); | 1045 int data_size = static_cast<int>(sizeof(test_data)); |
1048 EXPECT_EQ(data_size, | 1046 EXPECT_EQ(data_size, |
1049 base::WriteFile(platform_path, test_data, data_size)); | 1047 base::WriteFile(platform_path, test_data, data_size)); |
1050 | 1048 |
1051 // Check that its length is the size of the data written. | 1049 // Check that its length is the size of the data written. |
1052 operation_runner()->GetMetadata(file, RecordMetadataCallback()); | 1050 EXPECT_EQ(base::File::FILE_OK, GetMetadata(file)); |
1053 base::RunLoop().RunUntilIdle(); | |
1054 EXPECT_EQ(base::File::FILE_OK, status()); | |
1055 EXPECT_FALSE(info().is_directory); | 1051 EXPECT_FALSE(info().is_directory); |
1056 EXPECT_EQ(data_size, info().size); | 1052 EXPECT_EQ(data_size, info().size); |
1057 | 1053 |
1058 // Extend the file by truncating it. | 1054 // Extend the file by truncating it. |
1059 int length = 17; | 1055 int length = 17; |
1060 operation_runner()->Truncate(file, length, RecordStatusCallback()); | 1056 EXPECT_EQ(base::File::FILE_OK, Truncate(file, length)); |
1061 base::RunLoop().RunUntilIdle(); | |
1062 EXPECT_EQ(base::File::FILE_OK, status()); | |
1063 | 1057 |
1064 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1058 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
1065 EXPECT_TRUE(change_observer()->HasNoChange()); | 1059 EXPECT_TRUE(change_observer()->HasNoChange()); |
1066 | 1060 |
1067 // Check that its length is now 17 and that it's all zeroes after the test | 1061 // Check that its length is now 17 and that it's all zeroes after the test |
1068 // data. | 1062 // data. |
1069 EXPECT_EQ(length, GetFileSize("file")); | 1063 EXPECT_EQ(length, GetFileSize("file")); |
1070 char data[100]; | 1064 char data[100]; |
1071 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); | 1065 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); |
1072 for (int i = 0; i < length; ++i) { | 1066 for (int i = 0; i < length; ++i) { |
1073 if (i < static_cast<int>(sizeof(test_data))) | 1067 if (i < static_cast<int>(sizeof(test_data))) |
1074 EXPECT_EQ(test_data[i], data[i]); | 1068 EXPECT_EQ(test_data[i], data[i]); |
1075 else | 1069 else |
1076 EXPECT_EQ(0, data[i]); | 1070 EXPECT_EQ(0, data[i]); |
1077 } | 1071 } |
1078 | 1072 |
1079 // Shorten the file by truncating it. | 1073 // Shorten the file by truncating it. |
1080 length = 3; | 1074 length = 3; |
1081 operation_runner()->Truncate(file, length, RecordStatusCallback()); | 1075 EXPECT_EQ(base::File::FILE_OK, Truncate(file, length)); |
1082 base::RunLoop().RunUntilIdle(); | |
1083 EXPECT_EQ(base::File::FILE_OK, status()); | |
1084 | 1076 |
1085 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1077 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
1086 EXPECT_TRUE(change_observer()->HasNoChange()); | 1078 EXPECT_TRUE(change_observer()->HasNoChange()); |
1087 | 1079 |
1088 // Check that its length is now 3 and that it contains only bits of test data. | 1080 // Check that its length is now 3 and that it contains only bits of test data. |
1089 EXPECT_EQ(length, GetFileSize("file")); | 1081 EXPECT_EQ(length, GetFileSize("file")); |
1090 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); | 1082 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); |
1091 for (int i = 0; i < length; ++i) | 1083 for (int i = 0; i < length; ++i) |
1092 EXPECT_EQ(test_data[i], data[i]); | 1084 EXPECT_EQ(test_data[i], data[i]); |
1093 | 1085 |
1094 // Truncate is not a 'read' access. (Here expected access count is 1 | 1086 // Truncate is not a 'read' access. (Here expected access count is 1 |
1095 // since we made 1 read access for GetMetadata.) | 1087 // since we made 1 read access for GetMetadata.) |
1096 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 1088 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
1097 } | 1089 } |
1098 | 1090 |
1099 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) { | 1091 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) { |
1100 FileSystemURL dir(CreateDirectory("dir")); | 1092 FileSystemURL dir(CreateDirectory("dir")); |
1101 FileSystemURL file(CreateFile("dir/file")); | 1093 FileSystemURL file(CreateFile("dir/file")); |
1102 | 1094 |
1103 GrantQuotaForCurrentUsage(); | 1095 GrantQuotaForCurrentUsage(); |
1104 AddQuota(10); | 1096 AddQuota(10); |
1105 | 1097 |
1106 operation_runner()->Truncate(file, 10, RecordStatusCallback()); | 1098 EXPECT_EQ(base::File::FILE_OK, Truncate(file, 10)); |
1107 base::RunLoop().RunUntilIdle(); | |
1108 EXPECT_EQ(base::File::FILE_OK, status()); | |
1109 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1099 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
1110 EXPECT_TRUE(change_observer()->HasNoChange()); | 1100 EXPECT_TRUE(change_observer()->HasNoChange()); |
1111 | 1101 |
1112 EXPECT_EQ(10, GetFileSize("dir/file")); | 1102 EXPECT_EQ(10, GetFileSize("dir/file")); |
1113 | 1103 |
1114 operation_runner()->Truncate(file, 11, RecordStatusCallback()); | 1104 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, Truncate(file, 11)); |
1115 base::RunLoop().RunUntilIdle(); | |
1116 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); | |
1117 EXPECT_TRUE(change_observer()->HasNoChange()); | 1105 EXPECT_TRUE(change_observer()->HasNoChange()); |
1118 | 1106 |
1119 EXPECT_EQ(10, GetFileSize("dir/file")); | 1107 EXPECT_EQ(10, GetFileSize("dir/file")); |
1120 } | 1108 } |
1121 | 1109 |
1122 TEST_F(FileSystemOperationImplTest, TestTouchFile) { | 1110 TEST_F(FileSystemOperationImplTest, TestTouchFile) { |
1123 FileSystemURL file(CreateFile("file")); | 1111 FileSystemURL file(CreateFile("file")); |
1124 base::FilePath platform_path = PlatformPath("file"); | 1112 base::FilePath platform_path = PlatformPath("file"); |
1125 | 1113 |
1126 base::File::Info info; | 1114 base::File::Info info; |
1127 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); | 1115 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); |
1128 EXPECT_FALSE(info.is_directory); | 1116 EXPECT_FALSE(info.is_directory); |
1129 EXPECT_EQ(0, info.size); | 1117 EXPECT_EQ(0, info.size); |
1130 const base::Time last_modified = info.last_modified; | 1118 const base::Time last_modified = info.last_modified; |
1131 const base::Time last_accessed = info.last_accessed; | 1119 const base::Time last_accessed = info.last_accessed; |
1132 | 1120 |
1133 const base::Time new_modified_time = base::Time::UnixEpoch(); | 1121 const base::Time new_modified_time = base::Time::UnixEpoch(); |
1134 const base::Time new_accessed_time = new_modified_time + | 1122 const base::Time new_accessed_time = new_modified_time + |
1135 base::TimeDelta::FromHours(77); | 1123 base::TimeDelta::FromHours(77); |
1136 ASSERT_NE(last_modified, new_modified_time); | 1124 ASSERT_NE(last_modified, new_modified_time); |
1137 ASSERT_NE(last_accessed, new_accessed_time); | 1125 ASSERT_NE(last_accessed, new_accessed_time); |
1138 | 1126 |
1139 operation_runner()->TouchFile(file, new_accessed_time, new_modified_time, | 1127 EXPECT_EQ(base::File::FILE_OK, |
1140 RecordStatusCallback()); | 1128 TouchFile(file, new_accessed_time, new_modified_time)); |
1141 base::RunLoop().RunUntilIdle(); | |
1142 EXPECT_EQ(base::File::FILE_OK, status()); | |
1143 EXPECT_TRUE(change_observer()->HasNoChange()); | 1129 EXPECT_TRUE(change_observer()->HasNoChange()); |
1144 | 1130 |
1145 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); | 1131 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); |
1146 // We compare as time_t here to lower our resolution, to avoid false | 1132 // We compare as time_t here to lower our resolution, to avoid false |
1147 // negatives caused by conversion to the local filesystem's native | 1133 // negatives caused by conversion to the local filesystem's native |
1148 // representation and back. | 1134 // representation and back. |
1149 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); | 1135 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); |
1150 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); | 1136 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); |
1151 } | 1137 } |
1152 | 1138 |
1153 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) { | 1139 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) { |
1154 FileSystemURL dir(CreateDirectory("dir")); | 1140 FileSystemURL dir(CreateDirectory("dir")); |
1155 | 1141 |
1156 // Create a file for the testing. | 1142 // Create a file for the testing. |
1157 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); | 1143 EXPECT_EQ(base::File::FILE_OK, DirectoryExists(dir)); |
1158 FileSystemURL file(CreateFile("dir/file")); | 1144 FileSystemURL file(CreateFile("dir/file")); |
1159 operation_runner()->FileExists(file, RecordStatusCallback()); | 1145 EXPECT_EQ(base::File::FILE_OK, FileExists(file)); |
1160 base::RunLoop().RunUntilIdle(); | |
1161 EXPECT_EQ(base::File::FILE_OK, status()); | |
1162 | 1146 |
1163 // See if we can get a 'snapshot' file info for the file. | 1147 // See if we can get a 'snapshot' file info for the file. |
1164 // Since FileSystemOperationImpl assumes the file exists in the local | 1148 // Since FileSystemOperationImpl assumes the file exists in the local |
1165 // directory it should just returns the same metadata and platform_path | 1149 // directory it should just returns the same metadata and platform_path |
1166 // as the file itself. | 1150 // as the file itself. |
1167 operation_runner()->CreateSnapshotFile(file, RecordSnapshotFileCallback()); | 1151 EXPECT_EQ(base::File::FILE_OK, CreateSnapshotFile(file)); |
1168 base::RunLoop().RunUntilIdle(); | |
1169 EXPECT_EQ(base::File::FILE_OK, status()); | |
1170 EXPECT_FALSE(info().is_directory); | 1152 EXPECT_FALSE(info().is_directory); |
1171 EXPECT_EQ(PlatformPath("dir/file"), path()); | 1153 EXPECT_EQ(PlatformPath("dir/file"), path()); |
1172 EXPECT_TRUE(change_observer()->HasNoChange()); | 1154 EXPECT_TRUE(change_observer()->HasNoChange()); |
1173 | 1155 |
1174 // The FileSystemOpration implementation does not create a | 1156 // The FileSystemOpration implementation does not create a |
1175 // shareable file reference. | 1157 // shareable file reference. |
1176 EXPECT_EQ(NULL, shareable_file_ref()); | 1158 EXPECT_EQ(NULL, shareable_file_ref()); |
1177 } | 1159 } |
1178 | 1160 |
1179 TEST_F(FileSystemOperationImplTest, | 1161 TEST_F(FileSystemOperationImplTest, |
1180 TestMoveSuccessSrcDirRecursiveWithQuota) { | 1162 TestMoveSuccessSrcDirRecursiveWithQuota) { |
1181 FileSystemURL src(CreateDirectory("src")); | 1163 FileSystemURL src(CreateDirectory("src")); |
1182 int src_path_cost = GetUsage(); | 1164 int src_path_cost = GetUsage(); |
1183 | 1165 |
1184 FileSystemURL dest(CreateDirectory("dest")); | 1166 FileSystemURL dest(CreateDirectory("dest")); |
1185 FileSystemURL child_file1(CreateFile("src/file1")); | 1167 FileSystemURL child_file1(CreateFile("src/file1")); |
1186 FileSystemURL child_file2(CreateFile("src/file2")); | 1168 FileSystemURL child_file2(CreateFile("src/file2")); |
1187 FileSystemURL child_dir(CreateDirectory("src/dir")); | 1169 FileSystemURL child_dir(CreateDirectory("src/dir")); |
1188 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); | 1170 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); |
1189 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); | 1171 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); |
1190 | 1172 |
1191 int total_path_cost = GetUsage(); | 1173 int total_path_cost = GetUsage(); |
1192 EXPECT_EQ(0, GetDataSizeOnDisk()); | 1174 EXPECT_EQ(0, GetDataSizeOnDisk()); |
1193 | 1175 |
1194 operation_runner()->Truncate( | 1176 EXPECT_EQ(base::File::FILE_OK, Truncate(child_file1, 5000)); |
1195 child_file1, 5000, | 1177 EXPECT_EQ(base::File::FILE_OK, Truncate(child_file2, 400)); |
1196 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | 1178 EXPECT_EQ(base::File::FILE_OK, Truncate(grandchild_file1, 30)); |
1197 operation_runner()->Truncate( | 1179 EXPECT_EQ(base::File::FILE_OK, Truncate(grandchild_file2, 2)); |
1198 child_file2, 400, | |
1199 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
1200 operation_runner()->Truncate( | |
1201 grandchild_file1, 30, | |
1202 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
1203 operation_runner()->Truncate( | |
1204 grandchild_file2, 2, | |
1205 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
1206 base::RunLoop().RunUntilIdle(); | |
1207 | 1180 |
1208 const int64 all_file_size = 5000 + 400 + 30 + 2; | 1181 const int64 all_file_size = 5000 + 400 + 30 + 2; |
1209 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1182 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
1210 EXPECT_EQ(all_file_size + total_path_cost, GetUsage()); | 1183 EXPECT_EQ(all_file_size + total_path_cost, GetUsage()); |
1211 | 1184 |
1212 operation_runner()->Move( | 1185 EXPECT_EQ(base::File::FILE_OK, |
1213 src, dest, FileSystemOperation::OPTION_NONE, | 1186 Move(src, dest, FileSystemOperation::OPTION_NONE)); |
1214 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
1215 base::RunLoop().RunUntilIdle(); | |
1216 | 1187 |
1217 EXPECT_FALSE(DirectoryExists("src/dir")); | 1188 EXPECT_FALSE(DirectoryExists("src/dir")); |
1218 EXPECT_FALSE(FileExists("src/dir/file2")); | 1189 EXPECT_FALSE(FileExists("src/dir/file2")); |
1219 EXPECT_TRUE(DirectoryExists("dest/dir")); | 1190 EXPECT_TRUE(DirectoryExists("dest/dir")); |
1220 EXPECT_TRUE(FileExists("dest/dir/file2")); | 1191 EXPECT_TRUE(FileExists("dest/dir/file2")); |
1221 | 1192 |
1222 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1193 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
1223 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, | 1194 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, |
1224 GetUsage()); | 1195 GetUsage()); |
1225 } | 1196 } |
(...skipping 11 matching lines...) Expand all Loading... |
1237 int64 child_path_cost = GetUsage() - usage; | 1208 int64 child_path_cost = GetUsage() - usage; |
1238 usage += child_path_cost; | 1209 usage += child_path_cost; |
1239 | 1210 |
1240 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); | 1211 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); |
1241 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); | 1212 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); |
1242 int64 total_path_cost = GetUsage(); | 1213 int64 total_path_cost = GetUsage(); |
1243 int64 grandchild_path_cost = total_path_cost - usage; | 1214 int64 grandchild_path_cost = total_path_cost - usage; |
1244 | 1215 |
1245 EXPECT_EQ(0, GetDataSizeOnDisk()); | 1216 EXPECT_EQ(0, GetDataSizeOnDisk()); |
1246 | 1217 |
1247 operation_runner()->Truncate( | 1218 EXPECT_EQ(base::File::FILE_OK, Truncate(child_file1, 8000)); |
1248 child_file1, 8000, | 1219 EXPECT_EQ(base::File::FILE_OK, Truncate(child_file2, 700)); |
1249 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | 1220 EXPECT_EQ(base::File::FILE_OK, Truncate(grandchild_file1, 60)); |
1250 operation_runner()->Truncate( | 1221 EXPECT_EQ(base::File::FILE_OK, Truncate(grandchild_file2, 5)); |
1251 child_file2, 700, | |
1252 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
1253 operation_runner()->Truncate( | |
1254 grandchild_file1, 60, | |
1255 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
1256 operation_runner()->Truncate( | |
1257 grandchild_file2, 5, | |
1258 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | |
1259 base::RunLoop().RunUntilIdle(); | |
1260 | 1222 |
1261 const int64 child_file_size = 8000 + 700; | 1223 const int64 child_file_size = 8000 + 700; |
1262 const int64 grandchild_file_size = 60 + 5; | 1224 const int64 grandchild_file_size = 60 + 5; |
1263 const int64 all_file_size = child_file_size + grandchild_file_size; | 1225 const int64 all_file_size = child_file_size + grandchild_file_size; |
1264 int64 expected_usage = all_file_size + total_path_cost; | 1226 int64 expected_usage = all_file_size + total_path_cost; |
1265 | 1227 |
1266 usage = GetUsage(); | 1228 usage = GetUsage(); |
1267 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1229 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
1268 EXPECT_EQ(expected_usage, usage); | 1230 EXPECT_EQ(expected_usage, usage); |
1269 | 1231 |
1270 { | 1232 EXPECT_EQ(base::File::FILE_OK, |
1271 base::RunLoop run_loop; | 1233 Copy(src, dest1, FileSystemOperation::OPTION_NONE)); |
1272 // Copy src to dest1. | |
1273 operation_runner()->Copy(src, | |
1274 dest1, | |
1275 FileSystemOperation::OPTION_NONE, | |
1276 FileSystemOperationRunner::CopyProgressCallback(), | |
1277 base::Bind(&AssertFileErrorEqWithClosure, | |
1278 FROM_HERE, | |
1279 base::File::FILE_OK, | |
1280 run_loop.QuitClosure())); | |
1281 run_loop.Run(); | |
1282 } | |
1283 | 1234 |
1284 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; | 1235 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; |
1285 EXPECT_TRUE(DirectoryExists("src/dir")); | 1236 EXPECT_TRUE(DirectoryExists("src/dir")); |
1286 EXPECT_TRUE(FileExists("src/dir/file2")); | 1237 EXPECT_TRUE(FileExists("src/dir/file2")); |
1287 EXPECT_TRUE(DirectoryExists("dest1/dir")); | 1238 EXPECT_TRUE(DirectoryExists("dest1/dir")); |
1288 EXPECT_TRUE(FileExists("dest1/dir/file2")); | 1239 EXPECT_TRUE(FileExists("dest1/dir/file2")); |
1289 | 1240 |
1290 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); | 1241 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); |
1291 EXPECT_EQ(expected_usage, GetUsage()); | 1242 EXPECT_EQ(expected_usage, GetUsage()); |
1292 | 1243 |
1293 { | 1244 EXPECT_EQ(base::File::FILE_OK, |
1294 base::RunLoop run_loop; | 1245 Copy(child_dir, dest2, FileSystemOperation::OPTION_NONE)); |
1295 // Copy src/dir to dest2. | |
1296 operation_runner()->Copy(child_dir, | |
1297 dest2, | |
1298 FileSystemOperation::OPTION_NONE, | |
1299 FileSystemOperationRunner::CopyProgressCallback(), | |
1300 base::Bind(&AssertFileErrorEqWithClosure, | |
1301 FROM_HERE, | |
1302 base::File::FILE_OK, | |
1303 run_loop.QuitClosure())); | |
1304 run_loop.Run(); | |
1305 } | |
1306 | 1246 |
1307 expected_usage += grandchild_file_size + grandchild_path_cost; | 1247 expected_usage += grandchild_file_size + grandchild_path_cost; |
1308 usage = GetUsage(); | 1248 usage = GetUsage(); |
1309 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, | 1249 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, |
1310 GetDataSizeOnDisk()); | 1250 GetDataSizeOnDisk()); |
1311 EXPECT_EQ(expected_usage, usage); | 1251 EXPECT_EQ(expected_usage, usage); |
1312 } | 1252 } |
1313 | 1253 |
1314 TEST_F(FileSystemOperationImplTest, | 1254 TEST_F(FileSystemOperationImplTest, |
1315 TestCopySuccessSrcFileWithDifferentFileSize) { | 1255 TestCopySuccessSrcFileWithDifferentFileSize) { |
1316 FileSystemURL src_file(CreateFile("src")); | 1256 FileSystemURL src_file(CreateFile("src")); |
1317 FileSystemURL dest_file(CreateFile("dest")); | 1257 FileSystemURL dest_file(CreateFile("dest")); |
1318 | 1258 |
1319 { | 1259 EXPECT_EQ(base::File::FILE_OK, Truncate(dest_file, 6)); |
1320 base::RunLoop run_loop; | 1260 EXPECT_EQ(base::File::FILE_OK, |
1321 operation_runner()->Truncate( | 1261 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); |
1322 dest_file, 6, | |
1323 base::Bind(&AssertFileErrorEqWithClosure, | |
1324 FROM_HERE, | |
1325 base::File::FILE_OK, | |
1326 run_loop.QuitClosure())); | |
1327 run_loop.Run(); | |
1328 } | |
1329 | |
1330 { | |
1331 base::RunLoop run_loop; | |
1332 operation_runner()->Copy( | |
1333 src_file, dest_file, FileSystemOperation::OPTION_NONE, | |
1334 FileSystemOperationRunner::CopyProgressCallback(), | |
1335 base::Bind(&AssertFileErrorEqWithClosure, | |
1336 FROM_HERE, | |
1337 base::File::FILE_OK, | |
1338 run_loop.QuitClosure())); | |
1339 run_loop.Run(); | |
1340 } | |
1341 EXPECT_EQ(0, GetFileSize("dest")); | 1262 EXPECT_EQ(0, GetFileSize("dest")); |
1342 } | 1263 } |
1343 | 1264 |
1344 } // namespace content | 1265 } // namespace content |
OLD | NEW |