OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/file_system.h" | 5 #include "chrome/browser/chromeos/drive/file_system.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 scoped_ptr<MockDirectoryChangeObserver> mock_directory_observer_; | 306 scoped_ptr<MockDirectoryChangeObserver> mock_directory_observer_; |
307 | 307 |
308 scoped_ptr<internal::ResourceMetadataStorage, | 308 scoped_ptr<internal::ResourceMetadataStorage, |
309 test_util::DestroyHelperForTests> metadata_storage_; | 309 test_util::DestroyHelperForTests> metadata_storage_; |
310 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; | 310 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; |
311 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> | 311 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> |
312 resource_metadata_; | 312 resource_metadata_; |
313 scoped_ptr<FileSystem> file_system_; | 313 scoped_ptr<FileSystem> file_system_; |
314 }; | 314 }; |
315 | 315 |
316 TEST_F(FileSystemTest, Copy) { | |
317 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
318 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Copied.txt")); | |
319 EXPECT_TRUE(GetResourceEntrySync(src_file_path)); | |
320 EXPECT_FALSE(GetResourceEntrySync(dest_file_path)); | |
321 | |
322 FileError error = FILE_ERROR_FAILED; | |
323 file_system_->Copy(src_file_path, | |
324 dest_file_path, | |
325 false, // preserve_last_modified, | |
326 google_apis::test_util::CreateCopyResultCallback(&error)); | |
327 test_util::RunBlockingPoolTask(); | |
328 EXPECT_EQ(FILE_ERROR_OK, error); | |
329 | |
330 // Entry is added on the server. | |
331 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path); | |
332 ASSERT_TRUE(entry); | |
333 | |
334 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; | |
335 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
336 fake_drive_service_->GetResourceEntry( | |
337 entry->resource_id(), | |
338 google_apis::test_util::CreateCopyResultCallback(&status, | |
339 &resource_entry)); | |
340 test_util::RunBlockingPoolTask(); | |
341 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | |
342 ASSERT_TRUE(resource_entry); | |
343 EXPECT_EQ(entry->title(), resource_entry->title()); | |
344 EXPECT_TRUE(resource_entry->is_file()); | |
345 } | |
346 | |
347 TEST_F(FileSystemTest, Move) { | |
kinaba
2014/02/11 00:31:59
Could you also test the case when the file is move
hashimoto
2014/02/19 07:01:33
Done.
| |
348 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
349 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Moved.txt")); | |
350 EXPECT_TRUE(GetResourceEntrySync(src_file_path)); | |
351 EXPECT_FALSE(GetResourceEntrySync(dest_file_path)); | |
352 | |
353 FileError error = FILE_ERROR_FAILED; | |
354 file_system_->Move(src_file_path, | |
355 dest_file_path, | |
356 false, // preserve_last_modified, | |
357 google_apis::test_util::CreateCopyResultCallback(&error)); | |
358 test_util::RunBlockingPoolTask(); | |
359 EXPECT_EQ(FILE_ERROR_OK, error); | |
360 | |
361 // Entry is moved on the server. | |
362 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path); | |
363 ASSERT_TRUE(entry); | |
364 | |
365 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; | |
366 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
367 fake_drive_service_->GetResourceEntry( | |
368 entry->resource_id(), | |
369 google_apis::test_util::CreateCopyResultCallback(&status, | |
370 &resource_entry)); | |
371 test_util::RunBlockingPoolTask(); | |
372 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | |
373 ASSERT_TRUE(resource_entry); | |
374 EXPECT_EQ(entry->title(), resource_entry->title()); | |
375 } | |
376 | |
377 TEST_F(FileSystemTest, Remove) { | |
378 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
379 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); | |
380 ASSERT_TRUE(entry); | |
381 | |
382 FileError error = FILE_ERROR_FAILED; | |
383 file_system_->Remove( | |
384 file_path, | |
385 false, // is_resursive | |
386 google_apis::test_util::CreateCopyResultCallback(&error)); | |
387 test_util::RunBlockingPoolTask(); | |
388 EXPECT_EQ(FILE_ERROR_OK, error); | |
389 | |
390 // Entry is removed on the server. | |
391 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; | |
392 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
393 fake_drive_service_->GetResourceEntry( | |
394 entry->resource_id(), | |
395 google_apis::test_util::CreateCopyResultCallback(&status, | |
396 &resource_entry)); | |
397 test_util::RunBlockingPoolTask(); | |
398 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | |
399 ASSERT_TRUE(resource_entry); | |
400 EXPECT_TRUE(resource_entry->deleted()); | |
401 } | |
402 | |
403 TEST_F(FileSystemTest, CreateDirectory) { | |
404 base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory")); | |
405 EXPECT_FALSE(GetResourceEntrySync(directory_path)); | |
406 | |
407 FileError error = FILE_ERROR_FAILED; | |
408 file_system_->CreateDirectory( | |
409 directory_path, | |
410 true, // is_exclusive | |
411 false, // is_recursive | |
412 google_apis::test_util::CreateCopyResultCallback(&error)); | |
413 test_util::RunBlockingPoolTask(); | |
414 EXPECT_EQ(FILE_ERROR_OK, error); | |
415 | |
416 // Directory is created on the server. | |
417 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(directory_path); | |
418 ASSERT_TRUE(entry); | |
419 | |
420 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; | |
421 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
422 fake_drive_service_->GetResourceEntry( | |
423 entry->resource_id(), | |
424 google_apis::test_util::CreateCopyResultCallback(&status, | |
425 &resource_entry)); | |
426 test_util::RunBlockingPoolTask(); | |
427 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | |
428 ASSERT_TRUE(resource_entry); | |
429 EXPECT_EQ(entry->title(), resource_entry->title()); | |
430 EXPECT_TRUE(resource_entry->is_folder()); | |
431 } | |
432 | |
433 TEST_F(FileSystemTest, CreateFile) { | |
434 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt")); | |
435 EXPECT_FALSE(GetResourceEntrySync(file_path)); | |
436 | |
437 FileError error = FILE_ERROR_FAILED; | |
438 file_system_->CreateFile( | |
439 file_path, | |
440 true, // is_exclusive | |
441 "text/plain", | |
442 google_apis::test_util::CreateCopyResultCallback(&error)); | |
443 test_util::RunBlockingPoolTask(); | |
444 EXPECT_EQ(FILE_ERROR_OK, error); | |
445 | |
446 // File is created on the server. | |
447 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); | |
448 ASSERT_TRUE(entry); | |
449 | |
450 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; | |
451 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
452 fake_drive_service_->GetResourceEntry( | |
453 entry->resource_id(), | |
454 google_apis::test_util::CreateCopyResultCallback(&status, | |
455 &resource_entry)); | |
456 test_util::RunBlockingPoolTask(); | |
457 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | |
458 ASSERT_TRUE(resource_entry); | |
459 EXPECT_EQ(entry->title(), resource_entry->title()); | |
460 EXPECT_TRUE(resource_entry->is_file()); | |
461 } | |
462 | |
463 TEST_F(FileSystemTest, TouchFile) { | |
464 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
465 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); | |
466 ASSERT_TRUE(entry); | |
467 | |
468 base::Time last_accessed = | |
469 base::Time::FromInternalValue(entry->file_info().last_accessed()) + | |
470 base::TimeDelta::FromSeconds(1); | |
471 base::Time last_modified = | |
472 base::Time::FromInternalValue(entry->file_info().last_modified()) + | |
473 base::TimeDelta::FromSeconds(1); | |
474 | |
475 FileError error = FILE_ERROR_FAILED; | |
476 file_system_->TouchFile( | |
477 file_path, | |
478 last_accessed, | |
479 last_modified, | |
480 google_apis::test_util::CreateCopyResultCallback(&error)); | |
481 test_util::RunBlockingPoolTask(); | |
482 EXPECT_EQ(FILE_ERROR_OK, error); | |
483 | |
484 // File is touched on the server. | |
485 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; | |
486 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
487 fake_drive_service_->GetResourceEntry( | |
488 entry->resource_id(), | |
489 google_apis::test_util::CreateCopyResultCallback(&status, | |
490 &resource_entry)); | |
491 test_util::RunBlockingPoolTask(); | |
492 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | |
493 ASSERT_TRUE(resource_entry); | |
494 EXPECT_EQ(last_accessed, resource_entry->last_viewed_time()); | |
495 EXPECT_EQ(last_modified, resource_entry->updated_time()); | |
496 } | |
497 | |
498 TEST_F(FileSystemTest, TruncateFile) { | |
499 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
500 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); | |
501 ASSERT_TRUE(entry); | |
502 | |
503 const int64 kLength = entry->file_info().size() + 100; | |
504 | |
505 FileError error = FILE_ERROR_FAILED; | |
506 file_system_->TruncateFile( | |
507 file_path, | |
508 kLength, | |
509 google_apis::test_util::CreateCopyResultCallback(&error)); | |
510 test_util::RunBlockingPoolTask(); | |
511 EXPECT_EQ(FILE_ERROR_OK, error); | |
512 | |
513 // File is touched on the server. | |
514 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; | |
515 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
516 fake_drive_service_->GetResourceEntry( | |
517 entry->resource_id(), | |
518 google_apis::test_util::CreateCopyResultCallback(&status, | |
519 &resource_entry)); | |
520 test_util::RunBlockingPoolTask(); | |
521 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | |
522 ASSERT_TRUE(resource_entry); | |
523 EXPECT_EQ(kLength, resource_entry->file_size()); | |
524 } | |
525 | |
316 TEST_F(FileSystemTest, DuplicatedAsyncInitialization) { | 526 TEST_F(FileSystemTest, DuplicatedAsyncInitialization) { |
317 base::RunLoop loop; | 527 base::RunLoop loop; |
318 | 528 |
319 int counter = 0; | 529 int counter = 0; |
320 const GetResourceEntryCallback& callback = base::Bind( | 530 const GetResourceEntryCallback& callback = base::Bind( |
321 &AsyncInitializationCallback, &counter, 2, loop.QuitClosure()); | 531 &AsyncInitializationCallback, &counter, 2, loop.QuitClosure()); |
322 | 532 |
323 file_system_->GetResourceEntry( | 533 file_system_->GetResourceEntry( |
324 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); | 534 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); |
325 file_system_->GetResourceEntry( | 535 file_system_->GetResourceEntry( |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 kEmbedOrigin, | 940 kEmbedOrigin, |
731 google_apis::test_util::CreateCopyResultCallback(&error, &share_url)); | 941 google_apis::test_util::CreateCopyResultCallback(&error, &share_url)); |
732 test_util::RunBlockingPoolTask(); | 942 test_util::RunBlockingPoolTask(); |
733 | 943 |
734 // Verify the error and the share url, which should be empty. | 944 // Verify the error and the share url, which should be empty. |
735 EXPECT_EQ(FILE_ERROR_FAILED, error); | 945 EXPECT_EQ(FILE_ERROR_FAILED, error); |
736 EXPECT_TRUE(share_url.is_empty()); | 946 EXPECT_TRUE(share_url.is_empty()); |
737 } | 947 } |
738 | 948 |
739 } // namespace drive | 949 } // namespace drive |
OLD | NEW |