Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/drive/drive_file_system.h" | 5 #include "chrome/browser/chromeos/drive/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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 | 120 |
| 121 base::MessageLoopProxy::current()->PostTask( | 121 base::MessageLoopProxy::current()->PostTask( |
| 122 FROM_HERE, | 122 FROM_HERE, |
| 123 base::Bind(callback, | 123 base::Bind(callback, |
| 124 google_apis::DRIVE_UPLOAD_OK, | 124 google_apis::DRIVE_UPLOAD_OK, |
| 125 drive_file_path, | 125 drive_file_path, |
| 126 local_file_path, | 126 local_file_path, |
| 127 base::Passed(&resource_entry))); | 127 base::Passed(&resource_entry))); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Pretends that an existing file ("drive/File 1.txt") was uploaded | 130 // Pretends that an existing file ("drive/root/File 1.txt") was uploaded |
| 131 // successfully, and returns an entry for the file in | 131 // successfully, and returns an entry for the file in |
| 132 // "chromeos/gdata/root_feed.json" to the caller. | 132 // "chromeos/gdata/root_feed.json" to the caller. |
| 133 virtual void UploadExistingFile( | 133 virtual void UploadExistingFile( |
| 134 const std::string& resource_id, | 134 const std::string& resource_id, |
| 135 const base::FilePath& drive_file_path, | 135 const base::FilePath& drive_file_path, |
| 136 const base::FilePath& local_file_path, | 136 const base::FilePath& local_file_path, |
| 137 const std::string& content_type, | 137 const std::string& content_type, |
| 138 const std::string& etag, | 138 const std::string& etag, |
| 139 const google_apis::UploadCompletionCallback& callback) OVERRIDE { | 139 const google_apis::UploadCompletionCallback& callback) OVERRIDE { |
| 140 DCHECK(!callback.is_null()); | 140 DCHECK(!callback.is_null()); |
| 141 | 141 |
| 142 // This function can only handle "drive/File 1.txt" whose resource ID is | 142 // This function can only handle "drive/root/File 1.txt" whose resource ID |
| 143 // "file:2_file_resource_id". | 143 // is "file:2_file_resource_id". |
| 144 DCHECK_EQ("drive/File 1.txt", drive_file_path.value()); | 144 DCHECK_EQ("drive/root/File 1.txt", drive_file_path.value()); |
| 145 const std::string kResourceId = "file:2_file_resource_id"; | 145 const std::string kResourceId = "file:2_file_resource_id"; |
| 146 EXPECT_EQ(kResourceId, resource_id); | 146 EXPECT_EQ(kResourceId, resource_id); |
| 147 | 147 |
| 148 // Create a google_apis::ResourceEntry, which is needed to return a value | 148 // Create a google_apis::ResourceEntry, which is needed to return a value |
| 149 // from this function. TODO(satorux): This should be cleaned | 149 // from this function. TODO(satorux): This should be cleaned |
| 150 // up. crbug.com/134240. | 150 // up. crbug.com/134240. |
| 151 scoped_ptr<google_apis::ResourceEntry> resource_entry; | 151 scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| 152 scoped_ptr<base::Value> value = | 152 scoped_ptr<base::Value> value = |
| 153 google_apis::test_util::LoadJSONFile("chromeos/gdata/root_feed.json"); | 153 google_apis::test_util::LoadJSONFile("chromeos/gdata/root_feed.json"); |
| 154 if (!value.get()) | 154 if (!value.get()) |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); | 390 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); |
| 391 } | 391 } |
| 392 | 392 |
| 393 // Flag for specifying the timestamp of the test filesystem cache. | 393 // Flag for specifying the timestamp of the test filesystem cache. |
| 394 enum SaveTestFileSystemParam { | 394 enum SaveTestFileSystemParam { |
| 395 USE_OLD_TIMESTAMP, | 395 USE_OLD_TIMESTAMP, |
| 396 USE_SERVER_TIMESTAMP, | 396 USE_SERVER_TIMESTAMP, |
| 397 }; | 397 }; |
| 398 | 398 |
| 399 // Saves a file representing a filesystem with directories: | 399 // Saves a file representing a filesystem with directories: |
| 400 // drive, drive/Dir1, drive/Dir1/SubDir2 | 400 // drive/root, drive/root/Dir1, drive/root/Dir1/SubDir2 |
| 401 // and files | 401 // and files |
| 402 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. | 402 // drive/root/File1, drive/root/Dir1/File2, drive/root/Dir1/SubDir2/File3. |
| 403 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321, | 403 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321, |
| 404 // equal to that of "account_metadata.json" test data, indicating the cache is | 404 // equal to that of "account_metadata.json" test data, indicating the cache is |
| 405 // holding the latest file system info. | 405 // holding the latest file system info. |
| 406 bool SaveTestFileSystem(SaveTestFileSystemParam param) { | 406 bool SaveTestFileSystem(SaveTestFileSystemParam param) { |
| 407 // Destroy the existing resource metadata to close DB. | 407 // Destroy the existing resource metadata to close DB. |
| 408 resource_metadata_.reset(); | 408 resource_metadata_.reset(); |
| 409 | 409 |
| 410 const std::string root_resource_id = | 410 const std::string root_resource_id = |
| 411 fake_drive_service_->GetRootResourceId(); | 411 fake_drive_service_->GetRootResourceId(); |
| 412 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> | 412 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> |
| 413 resource_metadata(new DriveResourceMetadata( | 413 resource_metadata(new DriveResourceMetadata( |
| 414 root_resource_id, | 414 root_resource_id, |
| 415 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META), | 415 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META), |
| 416 blocking_task_runner_)); | 416 blocking_task_runner_)); |
| 417 | 417 |
| 418 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 418 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 419 resource_metadata->Initialize( | 419 resource_metadata->Initialize( |
| 420 google_apis::test_util::CreateCopyResultCallback(&error)); | 420 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 421 google_apis::test_util::RunBlockingPoolTask(); | 421 google_apis::test_util::RunBlockingPoolTask(); |
| 422 if (error != DRIVE_FILE_OK) | 422 if (error != DRIVE_FILE_OK) |
| 423 return false; | 423 return false; |
| 424 | 424 |
| 425 resource_metadata->SetLargestChangestamp( | 425 resource_metadata->SetLargestChangestamp( |
| 426 param == USE_SERVER_TIMESTAMP ? 654321 : 1, | 426 param == USE_SERVER_TIMESTAMP ? 654321 : 1, |
| 427 google_apis::test_util::CreateCopyResultCallback(&error)); | 427 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 428 google_apis::test_util::RunBlockingPoolTask(); | 428 google_apis::test_util::RunBlockingPoolTask(); |
| 429 if (error != DRIVE_FILE_OK) | 429 if (error != DRIVE_FILE_OK) |
| 430 return false; | 430 return false; |
| 431 | 431 |
| 432 // drive/File1 | 432 // drive/root is already prepared by DriveResourceMetadata. |
| 433 // TODO(haruki): Create drive/root here when we start creating it in | |
| 434 // ChangeListLoader. | |
| 435 base::FilePath file_path; | |
| 436 | |
| 437 // drive/root/File1 | |
| 433 DriveEntryProto file1; | 438 DriveEntryProto file1; |
| 434 file1.set_title("File1"); | 439 file1.set_title("File1"); |
| 435 file1.set_resource_id("resource_id:File1"); | 440 file1.set_resource_id("resource_id:File1"); |
| 436 file1.set_parent_resource_id(root_resource_id); | 441 file1.set_parent_resource_id(root_resource_id); |
| 437 file1.set_upload_url("http://resumable-edit-media/1"); | 442 file1.set_upload_url("http://resumable-edit-media/1"); |
| 438 file1.mutable_file_specific_info()->set_file_md5("md5"); | 443 file1.mutable_file_specific_info()->set_file_md5("md5"); |
| 439 file1.mutable_file_info()->set_is_directory(false); | 444 file1.mutable_file_info()->set_is_directory(false); |
| 440 file1.mutable_file_info()->set_size(1048576); | 445 file1.mutable_file_info()->set_size(1048576); |
| 441 base::FilePath file_path; | |
| 442 resource_metadata->AddEntry( | 446 resource_metadata->AddEntry( |
| 443 file1, | 447 file1, |
| 444 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | 448 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
| 445 google_apis::test_util::RunBlockingPoolTask(); | 449 google_apis::test_util::RunBlockingPoolTask(); |
| 446 if (error != DRIVE_FILE_OK) | 450 if (error != DRIVE_FILE_OK) |
| 447 return false; | 451 return false; |
| 448 | 452 |
| 449 // drive/Dir1 | 453 // drive/root/Dir1 |
| 450 DriveEntryProto dir1; | 454 DriveEntryProto dir1; |
| 451 dir1.set_title("Dir1"); | 455 dir1.set_title("Dir1"); |
| 452 dir1.set_resource_id("resource_id:Dir1"); | 456 dir1.set_resource_id("resource_id:Dir1"); |
| 453 dir1.set_parent_resource_id(root_resource_id); | 457 dir1.set_parent_resource_id(root_resource_id); |
| 454 dir1.set_upload_url("http://resumable-create-media/2"); | 458 dir1.set_upload_url("http://resumable-create-media/2"); |
| 455 dir1.mutable_file_info()->set_is_directory(true); | 459 dir1.mutable_file_info()->set_is_directory(true); |
| 456 resource_metadata->AddEntry( | 460 resource_metadata->AddEntry( |
| 457 dir1, | 461 dir1, |
| 458 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | 462 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
| 459 google_apis::test_util::RunBlockingPoolTask(); | 463 google_apis::test_util::RunBlockingPoolTask(); |
| 460 if (error != DRIVE_FILE_OK) | 464 if (error != DRIVE_FILE_OK) |
| 461 return false; | 465 return false; |
| 462 | 466 |
| 463 // drive/Dir1/File2 | 467 // drive/root/Dir1/File2 |
| 464 DriveEntryProto file2; | 468 DriveEntryProto file2; |
| 465 file2.set_title("File2"); | 469 file2.set_title("File2"); |
| 466 file2.set_resource_id("resource_id:File2"); | 470 file2.set_resource_id("resource_id:File2"); |
| 467 file2.set_parent_resource_id(dir1.resource_id()); | 471 file2.set_parent_resource_id(dir1.resource_id()); |
| 468 file2.set_upload_url("http://resumable-edit-media/2"); | 472 file2.set_upload_url("http://resumable-edit-media/2"); |
| 469 file2.mutable_file_specific_info()->set_file_md5("md5"); | 473 file2.mutable_file_specific_info()->set_file_md5("md5"); |
| 470 file2.mutable_file_info()->set_is_directory(false); | 474 file2.mutable_file_info()->set_is_directory(false); |
| 471 file2.mutable_file_info()->set_size(555); | 475 file2.mutable_file_info()->set_size(555); |
| 472 resource_metadata->AddEntry( | 476 resource_metadata->AddEntry( |
| 473 file2, | 477 file2, |
| 474 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | 478 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
| 475 google_apis::test_util::RunBlockingPoolTask(); | 479 google_apis::test_util::RunBlockingPoolTask(); |
| 476 if (error != DRIVE_FILE_OK) | 480 if (error != DRIVE_FILE_OK) |
| 477 return false; | 481 return false; |
| 478 | 482 |
| 479 // drive/Dir1/SubDir2 | 483 // drive/root/Dir1/SubDir2 |
| 480 DriveEntryProto dir2; | 484 DriveEntryProto dir2; |
| 481 dir2.set_title("SubDir2"); | 485 dir2.set_title("SubDir2"); |
| 482 dir2.set_resource_id("resource_id:SubDir2"); | 486 dir2.set_resource_id("resource_id:SubDir2"); |
| 483 dir2.set_parent_resource_id(dir1.resource_id()); | 487 dir2.set_parent_resource_id(dir1.resource_id()); |
| 484 dir2.set_upload_url("http://resumable-create-media/3"); | 488 dir2.set_upload_url("http://resumable-create-media/3"); |
| 485 dir2.mutable_file_info()->set_is_directory(true); | 489 dir2.mutable_file_info()->set_is_directory(true); |
| 486 resource_metadata->AddEntry( | 490 resource_metadata->AddEntry( |
| 487 dir2, | 491 dir2, |
| 488 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | 492 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
| 489 google_apis::test_util::RunBlockingPoolTask(); | 493 google_apis::test_util::RunBlockingPoolTask(); |
| 490 if (error != DRIVE_FILE_OK) | 494 if (error != DRIVE_FILE_OK) |
| 491 return false; | 495 return false; |
| 492 | 496 |
| 493 // drive/Dir1/SubDir2/File3 | 497 // drive/root/Dir1/SubDir2/File3 |
| 494 DriveEntryProto file3; | 498 DriveEntryProto file3; |
| 495 file3.set_title("File3"); | 499 file3.set_title("File3"); |
| 496 file3.set_resource_id("resource_id:File3"); | 500 file3.set_resource_id("resource_id:File3"); |
| 497 file3.set_parent_resource_id(dir2.resource_id()); | 501 file3.set_parent_resource_id(dir2.resource_id()); |
| 498 file3.set_upload_url("http://resumable-edit-media/3"); | 502 file3.set_upload_url("http://resumable-edit-media/3"); |
| 499 file3.mutable_file_specific_info()->set_file_md5("md5"); | 503 file3.mutable_file_specific_info()->set_file_md5("md5"); |
| 500 file3.mutable_file_info()->set_is_directory(false); | 504 file3.mutable_file_info()->set_is_directory(false); |
| 501 file3.mutable_file_info()->set_size(12345); | 505 file3.mutable_file_info()->set_size(12345); |
| 502 resource_metadata->AddEntry( | 506 resource_metadata->AddEntry( |
| 503 file3, | 507 file3, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 ASSERT_FALSE(entries->empty()); | 575 ASSERT_FALSE(entries->empty()); |
| 572 | 576 |
| 573 (*counter)++; | 577 (*counter)++; |
| 574 if (*counter >= expected_counter) | 578 if (*counter >= expected_counter) |
| 575 message_loop->Quit(); | 579 message_loop->Quit(); |
| 576 } | 580 } |
| 577 | 581 |
| 578 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) { | 582 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) { |
| 579 // The root directory will be loaded that triggers the event. | 583 // The root directory will be loaded that triggers the event. |
| 580 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 584 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 581 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 585 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 582 | 586 |
| 583 int counter = 0; | 587 int counter = 0; |
| 584 ReadDirectoryWithSettingCallback callback = base::Bind( | 588 ReadDirectoryWithSettingCallback callback = base::Bind( |
| 585 &AsyncInitializationCallback, | 589 &AsyncInitializationCallback, |
| 586 &counter, | 590 &counter, |
| 587 2, | 591 2, |
| 588 &message_loop_); | 592 &message_loop_); |
| 589 | 593 |
| 590 file_system_->ReadDirectoryByPath( | 594 file_system_->ReadDirectoryByPath( |
| 591 base::FilePath(FILE_PATH_LITERAL("drive")), callback); | 595 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); |
| 592 file_system_->ReadDirectoryByPath( | 596 file_system_->ReadDirectoryByPath( |
| 593 base::FilePath(FILE_PATH_LITERAL("drive")), callback); | 597 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); |
| 594 message_loop_.Run(); // Wait to get our result | 598 message_loop_.Run(); // Wait to get our result |
| 595 EXPECT_EQ(2, counter); | 599 EXPECT_EQ(2, counter); |
| 596 | 600 |
| 597 // ReadDirectoryByPath() was called twice, but the account metadata should | 601 // ReadDirectoryByPath() was called twice, but the account metadata should |
| 598 // only be loaded once. In the past, there was a bug that caused it to be | 602 // only be loaded once. In the past, there was a bug that caused it to be |
| 599 // loaded twice. | 603 // loaded twice. |
| 600 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); | 604 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); |
| 601 // On the other hand, the resource list could be loaded twice. One for | 605 // On the other hand, the resource list could be loaded twice. One for |
| 602 // just the directory contents, and one for the entire resource list. | 606 // just the directory contents, and one for the entire resource list. |
| 603 // | 607 // |
| 604 // The |callback| function gets called back soon after the directory content | 608 // The |callback| function gets called back soon after the directory content |
| 605 // is loaded, and the full resource load is done in background asynchronously. | 609 // is loaded, and the full resource load is done in background asynchronously. |
| 606 // So it depends on timing whether we receive the full resource load request | 610 // So it depends on timing whether we receive the full resource load request |
| 607 // at this point. | 611 // at this point. |
| 608 EXPECT_TRUE(fake_drive_service_->resource_list_load_count() == 1 || | 612 EXPECT_TRUE(fake_drive_service_->resource_list_load_count() == 1 || |
| 609 fake_drive_service_->resource_list_load_count() == 2) | 613 fake_drive_service_->resource_list_load_count() == 2) |
| 610 << ": " << fake_drive_service_->resource_list_load_count(); | 614 << ": " << fake_drive_service_->resource_list_load_count(); |
| 611 } | 615 } |
| 612 | 616 |
| 613 TEST_F(DriveFileSystemTest, GetRootEntry) { | 617 TEST_F(DriveFileSystemTest, GetGrandRootEntry) { |
| 614 const base::FilePath kFilePath = base::FilePath(FILE_PATH_LITERAL("drive")); | 618 const base::FilePath kFilePath = |
| 619 base::FilePath(FILE_PATH_LITERAL("drive")); | |
| 620 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | |
| 621 ASSERT_TRUE(entry.get()); | |
| 622 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry->resource_id()); | |
| 623 | |
| 624 // Getting the grand root entry should not cause the resource load to happen. | |
| 625 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); | |
| 626 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); | |
| 627 } | |
| 628 | |
| 629 TEST_F(DriveFileSystemTest, GetMyDriveRootEntry) { | |
| 630 const base::FilePath kFilePath = | |
| 631 base::FilePath(FILE_PATH_LITERAL("drive/root")); | |
| 615 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 632 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 616 ASSERT_TRUE(entry.get()); | 633 ASSERT_TRUE(entry.get()); |
| 617 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); | 634 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); |
| 618 | 635 |
| 619 // Getting the root entry should not cause the resource load to happen. | 636 // Getting the "My Drive" root entry should not cause the resource load to |
| 637 // happen. | |
| 620 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); | 638 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); |
| 621 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); | 639 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); |
| 622 } | 640 } |
| 623 | 641 |
| 624 TEST_F(DriveFileSystemTest, GetNonRootEntry) { | 642 TEST_F(DriveFileSystemTest, GetNonRootEntry) { |
| 625 const base::FilePath kFilePath = | 643 const base::FilePath kFilePath = |
| 626 base::FilePath(FILE_PATH_LITERAL("drive/whatever.txt")); | 644 base::FilePath(FILE_PATH_LITERAL("drive/root/whatever.txt")); |
| 627 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 645 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 628 // The entry should not exist as the resource metadata only contains the | 646 // The entry should not exist as the resource metadata only contains the |
| 629 // root entry now. | 647 // root entry now. |
| 630 ASSERT_FALSE(entry.get()); | 648 ASSERT_FALSE(entry.get()); |
| 631 | 649 |
| 632 // The resource load should happen because non-root entry is requested. | 650 // The resource load should happen because non-root entry is requested. |
| 633 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); | 651 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); |
| 634 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); | 652 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); |
| 635 } | 653 } |
| 636 | 654 |
| 637 TEST_F(DriveFileSystemTest, SearchRootDirectory) { | 655 TEST_F(DriveFileSystemTest, SearchRootDirectory) { |
| 638 ASSERT_TRUE(LoadRootFeedDocument()); | 656 ASSERT_TRUE(LoadRootFeedDocument()); |
| 639 | 657 |
| 640 const base::FilePath kFilePath = base::FilePath(FILE_PATH_LITERAL("drive")); | 658 const base::FilePath kFilePath = |
| 659 base::FilePath(FILE_PATH_LITERAL("drive/root")); | |
| 641 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 660 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 642 ASSERT_TRUE(entry.get()); | 661 ASSERT_TRUE(entry.get()); |
| 643 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); | 662 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); |
| 644 | 663 |
| 645 // The changestamp should be propagated to the root directory. | 664 // The changestamp should be propagated to the root directory. |
| 646 EXPECT_EQ(fake_drive_service_->largest_changestamp(), | 665 EXPECT_EQ(fake_drive_service_->largest_changestamp(), |
| 647 entry->directory_specific_info().changestamp()); | 666 entry->directory_specific_info().changestamp()); |
| 648 } | 667 } |
| 649 | 668 |
| 650 TEST_F(DriveFileSystemTest, SearchExistingFile) { | 669 TEST_F(DriveFileSystemTest, SearchExistingFile) { |
| 651 ASSERT_TRUE(LoadRootFeedDocument()); | 670 ASSERT_TRUE(LoadRootFeedDocument()); |
| 652 | 671 |
| 653 const base::FilePath kFilePath = base::FilePath( | 672 const base::FilePath kFilePath = base::FilePath( |
| 654 FILE_PATH_LITERAL("drive/File 1.txt")); | 673 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 655 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 674 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 656 ASSERT_TRUE(entry.get()); | 675 ASSERT_TRUE(entry.get()); |
| 657 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); | 676 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); |
| 658 } | 677 } |
| 659 | 678 |
| 660 TEST_F(DriveFileSystemTest, SearchExistingDocument) { | 679 TEST_F(DriveFileSystemTest, SearchExistingDocument) { |
| 661 ASSERT_TRUE(LoadRootFeedDocument()); | 680 ASSERT_TRUE(LoadRootFeedDocument()); |
| 662 | 681 |
| 663 const base::FilePath kFilePath = base::FilePath( | 682 const base::FilePath kFilePath = base::FilePath( |
| 664 FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 683 FILE_PATH_LITERAL("drive/root/Document 1.gdoc")); |
| 665 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 684 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 666 ASSERT_TRUE(entry.get()); | 685 ASSERT_TRUE(entry.get()); |
| 667 EXPECT_EQ("document:5_document_resource_id", entry->resource_id()); | 686 EXPECT_EQ("document:5_document_resource_id", entry->resource_id()); |
| 668 } | 687 } |
| 669 | 688 |
| 670 TEST_F(DriveFileSystemTest, SearchNonExistingFile) { | 689 TEST_F(DriveFileSystemTest, SearchNonExistingFile) { |
| 671 ASSERT_TRUE(LoadRootFeedDocument()); | 690 ASSERT_TRUE(LoadRootFeedDocument()); |
| 672 | 691 |
| 673 const base::FilePath kFilePath = base::FilePath( | 692 const base::FilePath kFilePath = base::FilePath( |
| 674 FILE_PATH_LITERAL("drive/nonexisting.file")); | 693 FILE_PATH_LITERAL("drive/root/nonexisting.file")); |
| 675 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 694 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 676 ASSERT_FALSE(entry.get()); | 695 ASSERT_FALSE(entry.get()); |
| 677 } | 696 } |
| 678 | 697 |
| 679 TEST_F(DriveFileSystemTest, SearchEncodedFileNames) { | 698 TEST_F(DriveFileSystemTest, SearchEncodedFileNames) { |
| 680 ASSERT_TRUE(LoadRootFeedDocument()); | 699 ASSERT_TRUE(LoadRootFeedDocument()); |
| 681 | 700 |
| 682 const base::FilePath kFilePath1 = base::FilePath( | 701 const base::FilePath kFilePath1 = base::FilePath( |
| 683 FILE_PATH_LITERAL("drive/Slash / in file 1.txt")); | 702 FILE_PATH_LITERAL("drive/root/Slash / in file 1.txt")); |
| 684 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); | 703 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); |
| 685 ASSERT_FALSE(entry.get()); | 704 ASSERT_FALSE(entry.get()); |
| 686 | 705 |
| 687 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe( | 706 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe( |
| 688 "drive/Slash \xE2\x88\x95 in file 1.txt"); | 707 "drive/root/Slash \xE2\x88\x95 in file 1.txt"); |
| 689 entry = GetEntryInfoByPathSync(kFilePath2); | 708 entry = GetEntryInfoByPathSync(kFilePath2); |
| 690 ASSERT_TRUE(entry.get()); | 709 ASSERT_TRUE(entry.get()); |
| 691 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); | 710 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); |
| 692 | 711 |
| 693 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe( | 712 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe( |
| 694 "drive/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); | 713 "drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); |
| 695 entry = GetEntryInfoByPathSync(kFilePath3); | 714 entry = GetEntryInfoByPathSync(kFilePath3); |
| 696 ASSERT_TRUE(entry.get()); | 715 ASSERT_TRUE(entry.get()); |
| 697 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); | 716 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); |
| 698 } | 717 } |
| 699 | 718 |
| 700 TEST_F(DriveFileSystemTest, SearchEncodedFileNamesLoadingRoot) { | 719 TEST_F(DriveFileSystemTest, SearchEncodedFileNamesLoadingRoot) { |
| 701 ASSERT_TRUE(LoadRootFeedDocument()); | 720 ASSERT_TRUE(LoadRootFeedDocument()); |
| 702 | 721 |
| 703 const base::FilePath kFilePath1 = base::FilePath( | 722 const base::FilePath kFilePath1 = base::FilePath( |
| 704 FILE_PATH_LITERAL("drive/Slash / in file 1.txt")); | 723 FILE_PATH_LITERAL("drive/root/Slash / in file 1.txt")); |
| 705 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); | 724 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); |
| 706 ASSERT_FALSE(entry.get()); | 725 ASSERT_FALSE(entry.get()); |
| 707 | 726 |
| 708 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe( | 727 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe( |
| 709 "drive/Slash \xE2\x88\x95 in file 1.txt"); | 728 "drive/root/Slash \xE2\x88\x95 in file 1.txt"); |
| 710 entry = GetEntryInfoByPathSync(kFilePath2); | 729 entry = GetEntryInfoByPathSync(kFilePath2); |
| 711 ASSERT_TRUE(entry.get()); | 730 ASSERT_TRUE(entry.get()); |
| 712 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); | 731 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); |
| 713 | 732 |
| 714 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe( | 733 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe( |
| 715 "drive/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); | 734 "drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); |
| 716 entry = GetEntryInfoByPathSync(kFilePath3); | 735 entry = GetEntryInfoByPathSync(kFilePath3); |
| 717 ASSERT_TRUE(entry.get()); | 736 ASSERT_TRUE(entry.get()); |
| 718 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); | 737 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); |
| 719 } | 738 } |
| 720 | 739 |
| 721 TEST_F(DriveFileSystemTest, SearchDuplicateNames) { | 740 TEST_F(DriveFileSystemTest, SearchDuplicateNames) { |
| 722 ASSERT_TRUE(LoadRootFeedDocument()); | 741 ASSERT_TRUE(LoadRootFeedDocument()); |
| 723 | 742 |
| 724 const base::FilePath kFilePath1 = base::FilePath( | 743 const base::FilePath kFilePath1 = base::FilePath( |
| 725 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); | 744 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); |
| 726 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); | 745 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); |
| 727 ASSERT_TRUE(entry.get()); | 746 ASSERT_TRUE(entry.get()); |
| 728 const std::string resource_id1 = entry->resource_id(); | 747 const std::string resource_id1 = entry->resource_id(); |
| 729 | 748 |
| 730 const base::FilePath kFilePath2 = base::FilePath( | 749 const base::FilePath kFilePath2 = base::FilePath( |
| 731 FILE_PATH_LITERAL("drive/Duplicate Name (2).txt")); | 750 FILE_PATH_LITERAL("drive/root/Duplicate Name (2).txt")); |
| 732 entry = GetEntryInfoByPathSync(kFilePath2); | 751 entry = GetEntryInfoByPathSync(kFilePath2); |
| 733 ASSERT_TRUE(entry.get()); | 752 ASSERT_TRUE(entry.get()); |
| 734 const std::string resource_id2 = entry->resource_id(); | 753 const std::string resource_id2 = entry->resource_id(); |
| 735 | 754 |
| 736 // The entries are de-duped non-deterministically, so we shouldn't rely on the | 755 // The entries are de-duped non-deterministically, so we shouldn't rely on the |
| 737 // names matching specific resource ids. | 756 // names matching specific resource ids. |
| 738 const std::string file3_resource_id = "file:3_file_resource_id"; | 757 const std::string file3_resource_id = "file:3_file_resource_id"; |
| 739 const std::string file4_resource_id = "file:4_file_resource_id"; | 758 const std::string file4_resource_id = "file:4_file_resource_id"; |
| 740 EXPECT_TRUE(file3_resource_id == resource_id1 || | 759 EXPECT_TRUE(file3_resource_id == resource_id1 || |
| 741 file3_resource_id == resource_id2); | 760 file3_resource_id == resource_id2); |
| 742 EXPECT_TRUE(file4_resource_id == resource_id1 || | 761 EXPECT_TRUE(file4_resource_id == resource_id1 || |
| 743 file4_resource_id == resource_id2); | 762 file4_resource_id == resource_id2); |
| 744 } | 763 } |
| 745 | 764 |
| 746 TEST_F(DriveFileSystemTest, SearchExistingDirectory) { | 765 TEST_F(DriveFileSystemTest, SearchExistingDirectory) { |
| 747 ASSERT_TRUE(LoadRootFeedDocument()); | 766 ASSERT_TRUE(LoadRootFeedDocument()); |
| 748 | 767 |
| 749 const base::FilePath kFilePath = base::FilePath( | 768 const base::FilePath kFilePath = base::FilePath( |
| 750 FILE_PATH_LITERAL("drive/Directory 1")); | 769 FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 751 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 770 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 752 ASSERT_TRUE(entry.get()); | 771 ASSERT_TRUE(entry.get()); |
| 753 ASSERT_EQ("folder:1_folder_resource_id", entry->resource_id()); | 772 ASSERT_EQ("folder:1_folder_resource_id", entry->resource_id()); |
| 754 | 773 |
| 755 // The changestamp should be propagated to the directory. | 774 // The changestamp should be propagated to the directory. |
| 756 EXPECT_EQ(fake_drive_service_->largest_changestamp(), | 775 EXPECT_EQ(fake_drive_service_->largest_changestamp(), |
| 757 entry->directory_specific_info().changestamp()); | 776 entry->directory_specific_info().changestamp()); |
| 758 } | 777 } |
| 759 | 778 |
| 760 TEST_F(DriveFileSystemTest, SearchInSubdir) { | 779 TEST_F(DriveFileSystemTest, SearchInSubdir) { |
| 761 ASSERT_TRUE(LoadRootFeedDocument()); | 780 ASSERT_TRUE(LoadRootFeedDocument()); |
| 762 | 781 |
| 763 const base::FilePath kFilePath = base::FilePath( | 782 const base::FilePath kFilePath = base::FilePath( |
| 764 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 783 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 765 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 784 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 766 ASSERT_TRUE(entry.get()); | 785 ASSERT_TRUE(entry.get()); |
| 767 ASSERT_EQ("file:subdirectory_file_1_id", entry->resource_id()); | 786 ASSERT_EQ("file:subdirectory_file_1_id", entry->resource_id()); |
| 768 } | 787 } |
| 769 | 788 |
| 770 // Check the reconstruction of the directory structure from only the root feed. | 789 // Check the reconstruction of the directory structure from only the root feed. |
| 771 TEST_F(DriveFileSystemTest, SearchInSubSubdir) { | 790 TEST_F(DriveFileSystemTest, SearchInSubSubdir) { |
| 772 ASSERT_TRUE(LoadRootFeedDocument()); | 791 ASSERT_TRUE(LoadRootFeedDocument()); |
| 773 | 792 |
| 774 const base::FilePath kFilePath = base::FilePath( | 793 const base::FilePath kFilePath = base::FilePath( |
| 775 FILE_PATH_LITERAL("drive/Directory 1/Sub Directory Folder/" | 794 FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder/" |
| 776 "Sub Sub Directory Folder")); | 795 "Sub Sub Directory Folder")); |
| 777 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 796 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 778 ASSERT_TRUE(entry.get()); | 797 ASSERT_TRUE(entry.get()); |
| 779 ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id()); | 798 ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id()); |
| 780 } | 799 } |
| 781 | 800 |
| 782 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_Root) { | 801 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_Root) { |
| 783 // The root directory will be loaded that triggers the event. | |
| 784 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 802 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 785 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 803 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 786 | 804 |
| 787 // ReadDirectoryByPath() should kick off the resource list loading. | 805 // ReadDirectoryByPath() should kick off the resource list loading. |
| 788 scoped_ptr<DriveEntryProtoVector> entries( | 806 scoped_ptr<DriveEntryProtoVector> entries( |
| 789 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"))); | 807 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 790 // The root directory should be read correctly. | 808 // The root directory should be read correctly. |
| 791 ASSERT_TRUE(entries.get()); | 809 ASSERT_TRUE(entries.get()); |
| 792 EXPECT_EQ(8U, entries->size()); | 810 EXPECT_EQ(8U, entries->size()); |
| 793 } | 811 } |
| 794 | 812 |
| 795 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_NonRootDirectory) { | 813 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_NonRootDirectory) { |
| 796 // ReadDirectoryByPath() should kick off the resource list loading. | 814 // ReadDirectoryByPath() should kick off the resource list loading. |
| 797 scoped_ptr<DriveEntryProtoVector> entries( | 815 scoped_ptr<DriveEntryProtoVector> entries( |
| 798 ReadDirectoryByPathSync( | 816 ReadDirectoryByPathSync( |
| 799 base::FilePath::FromUTF8Unsafe("drive/Directory 1"))); | 817 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); |
| 800 // The non root directory should also be read correctly. | 818 // The non root directory should also be read correctly. |
| 801 // There was a bug (crbug.com/181487), which broke this behavior. | 819 // There was a bug (crbug.com/181487), which broke this behavior. |
| 802 // Make sure this is fixed. | 820 // Make sure this is fixed. |
| 803 ASSERT_TRUE(entries.get()); | 821 ASSERT_TRUE(entries.get()); |
| 804 EXPECT_EQ(3U, entries->size()); | 822 EXPECT_EQ(3U, entries->size()); |
| 805 } | 823 } |
| 806 | 824 |
| 807 TEST_F(DriveFileSystemTest, FilePathTests) { | 825 TEST_F(DriveFileSystemTest, FilePathTests) { |
| 808 ASSERT_TRUE(LoadRootFeedDocument()); | 826 ASSERT_TRUE(LoadRootFeedDocument()); |
| 809 | 827 |
| 810 EXPECT_TRUE( | 828 EXPECT_TRUE( |
| 811 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")))); | 829 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")))); |
| 812 EXPECT_TRUE( | 830 EXPECT_TRUE( |
| 813 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1")))); | 831 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))); |
| 814 EXPECT_TRUE(EntryExists( | 832 EXPECT_TRUE(EntryExists(base::FilePath( |
| 815 base::FilePath( | 833 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")))); |
| 816 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")))); | |
| 817 } | 834 } |
| 818 | 835 |
| 819 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) { | 836 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) { |
| 820 ASSERT_TRUE(LoadRootFeedDocument()); | 837 ASSERT_TRUE(LoadRootFeedDocument()); |
| 821 | 838 |
| 822 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 839 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 823 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(2); | 840 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2); |
| 824 | 841 |
| 825 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_added_in_root.json")); | 842 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_added_in_root.json")); |
| 826 EXPECT_TRUE( | 843 EXPECT_TRUE(EntryExists( |
| 827 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Added file.gdoc")))); | 844 base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc")))); |
| 828 | 845 |
| 829 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_root.json")); | 846 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_root.json")); |
| 830 EXPECT_FALSE( | 847 EXPECT_FALSE(EntryExists( |
| 831 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Added file.gdoc")))); | 848 base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc")))); |
| 832 } | 849 } |
| 833 | 850 |
| 834 | 851 |
| 835 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) { | 852 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) { |
| 836 ASSERT_TRUE(LoadRootFeedDocument()); | 853 ASSERT_TRUE(LoadRootFeedDocument()); |
| 837 | 854 |
| 838 EXPECT_TRUE( | 855 EXPECT_TRUE( |
| 839 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1")))); | 856 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))); |
| 840 | 857 |
| 841 // Add file to an existing directory. | 858 // Add file to an existing directory. |
| 842 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 859 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 843 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 860 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 844 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 861 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 845 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 862 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 863 .Times(1); | |
| 846 ASSERT_TRUE( | 864 ASSERT_TRUE( |
| 847 LoadChangeFeed("chromeos/gdata/delta_file_added_in_directory.json")); | 865 LoadChangeFeed("chromeos/gdata/delta_file_added_in_directory.json")); |
| 848 EXPECT_TRUE(EntryExists(base::FilePath( | 866 EXPECT_TRUE(EntryExists(base::FilePath( |
| 849 FILE_PATH_LITERAL("drive/Directory 1/Added file.gdoc")))); | 867 FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc")))); |
| 850 | 868 |
| 851 // Remove that file from the directory. | 869 // Remove that file from the directory. |
| 852 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 870 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 853 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 871 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 872 .Times(1); | |
| 854 ASSERT_TRUE( | 873 ASSERT_TRUE( |
| 855 LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_directory.json")); | 874 LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_directory.json")); |
| 856 EXPECT_TRUE( | 875 EXPECT_TRUE( |
| 857 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1")))); | 876 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))); |
| 858 EXPECT_FALSE(EntryExists(base::FilePath( | 877 EXPECT_FALSE(EntryExists(base::FilePath( |
| 859 FILE_PATH_LITERAL("drive/Directory 1/Added file.gdoc")))); | 878 FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc")))); |
| 860 } | 879 } |
| 861 | 880 |
| 862 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewDirectory) { | 881 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewDirectory) { |
| 863 ASSERT_TRUE(LoadRootFeedDocument()); | 882 ASSERT_TRUE(LoadRootFeedDocument()); |
| 864 // Add file to a new directory. | 883 // Add file to a new directory. |
| 865 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 884 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 866 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 885 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 867 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 886 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 868 Eq(base::FilePath(FILE_PATH_LITERAL("drive/New Directory"))))).Times(1); | 887 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Directory"))))) |
| 888 .Times(1); | |
| 869 | 889 |
| 870 ASSERT_TRUE( | 890 ASSERT_TRUE( |
| 871 LoadChangeFeed("chromeos/gdata/delta_file_added_in_new_directory.json")); | 891 LoadChangeFeed("chromeos/gdata/delta_file_added_in_new_directory.json")); |
| 872 | 892 |
| 873 EXPECT_TRUE( | 893 EXPECT_TRUE( |
| 874 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/New Directory")))); | 894 EntryExists(base::FilePath( |
| 895 FILE_PATH_LITERAL("drive/root/New Directory")))); | |
| 875 EXPECT_TRUE(EntryExists(base::FilePath( | 896 EXPECT_TRUE(EntryExists(base::FilePath( |
| 876 FILE_PATH_LITERAL("drive/New Directory/File in new dir.gdoc")))); | 897 FILE_PATH_LITERAL("drive/root/New Directory/File in new dir.gdoc")))); |
| 877 } | 898 } |
| 878 | 899 |
| 879 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewButDeletedDirectory) { | 900 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewButDeletedDirectory) { |
| 880 ASSERT_TRUE(LoadRootFeedDocument()); | 901 ASSERT_TRUE(LoadRootFeedDocument()); |
| 881 | 902 |
| 882 // This feed contains the following updates: | 903 // This feed contains the following updates: |
| 883 // 1) A new PDF file is added to a new directory | 904 // 1) A new PDF file is added to a new directory |
| 884 // 2) but the new directory is marked "deleted" (i.e. moved to Trash) | 905 // 2) but the new directory is marked "deleted" (i.e. moved to Trash) |
| 885 // Hence, the PDF file should be just ignored. | 906 // Hence, the PDF file should be just ignored. |
| 886 ASSERT_TRUE(LoadChangeFeed( | 907 ASSERT_TRUE(LoadChangeFeed( |
| 887 "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json")); | 908 "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json")); |
| 888 } | 909 } |
| 889 | 910 |
| 890 TEST_F(DriveFileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) { | 911 TEST_F(DriveFileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) { |
| 891 ASSERT_TRUE(LoadRootFeedDocument()); | 912 ASSERT_TRUE(LoadRootFeedDocument()); |
| 892 | 913 |
| 893 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 914 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 894 "drive/Directory 2")))); | 915 "drive/root/Directory 2")))); |
| 895 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 916 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 896 "drive/Directory 1")))); | 917 "drive/root/Directory 1")))); |
| 897 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 918 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 898 "drive/Directory 1/SubDirectory File 1.txt")))); | 919 "drive/root/Directory 1/SubDirectory File 1.txt")))); |
| 899 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 920 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 900 "drive/Directory 1/Sub Directory Folder")))); | 921 "drive/root/Directory 1/Sub Directory Folder")))); |
| 901 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 922 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 902 "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); | 923 "drive/root/Directory 1/Sub Directory Folder/" |
| 924 "Sub Sub Directory Folder")))); | |
| 903 | 925 |
| 904 // This will move "Directory 1" from "drive/" to "drive/Directory 2/". | 926 // This will move "Directory 1" from "drive/root/" to |
| 927 // "drive/root/Directory 2/". | |
| 905 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 928 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 906 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 929 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 907 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 930 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 908 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 931 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 932 .Times(1); | |
| 909 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 933 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 910 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 2"))))).Times(1); | 934 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 2"))))) |
| 935 .Times(1); | |
| 911 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 936 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 912 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 2/Directory 1"))))) | 937 Eq(base::FilePath( |
| 913 .Times(1); | 938 FILE_PATH_LITERAL("drive/root/Directory 2/Directory 1"))))).Times(1); |
| 914 ASSERT_TRUE(LoadChangeFeed( | 939 ASSERT_TRUE(LoadChangeFeed( |
| 915 "chromeos/gdata/delta_dir_moved_from_root_to_directory.json")); | 940 "chromeos/gdata/delta_dir_moved_from_root_to_directory.json")); |
| 916 | 941 |
| 917 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 942 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 918 "drive/Directory 2")))); | 943 "drive/root/Directory 2")))); |
| 919 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 944 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 920 "drive/Directory 1")))); | 945 "drive/root/Directory 1")))); |
| 921 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 946 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 922 "drive/Directory 2/Directory 1")))); | 947 "drive/root/Directory 2/Directory 1")))); |
| 923 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 948 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 924 "drive/Directory 2/Directory 1/SubDirectory File 1.txt")))); | 949 "drive/root/Directory 2/Directory 1/SubDirectory File 1.txt")))); |
| 925 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 950 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 926 "drive/Directory 2/Directory 1/Sub Directory Folder")))); | 951 "drive/root/Directory 2/Directory 1/Sub Directory Folder")))); |
| 927 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 952 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 928 "drive/Directory 2/Directory 1/Sub Directory Folder/" | 953 "drive/root/Directory 2/Directory 1/Sub Directory Folder/" |
| 929 "Sub Sub Directory Folder")))); | 954 "Sub Sub Directory Folder")))); |
| 930 } | 955 } |
| 931 | 956 |
| 932 TEST_F(DriveFileSystemTest, ChangeFeed_FileMovedFromDirectoryToRoot) { | 957 TEST_F(DriveFileSystemTest, ChangeFeed_FileMovedFromDirectoryToRoot) { |
| 933 ASSERT_TRUE(LoadRootFeedDocument()); | 958 ASSERT_TRUE(LoadRootFeedDocument()); |
| 934 | 959 |
| 935 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 960 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 936 "drive/Directory 1")))); | 961 "drive/root/Directory 1")))); |
| 937 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 962 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 938 "drive/Directory 1/Sub Directory Folder")))); | 963 "drive/root/Directory 1/Sub Directory Folder")))); |
| 939 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 964 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 940 "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); | 965 "drive/root/Directory 1/Sub Directory Folder/" |
| 966 "Sub Sub Directory Folder")))); | |
| 941 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 967 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 942 "drive/Directory 1/SubDirectory File 1.txt")))); | 968 "drive/root/Directory 1/SubDirectory File 1.txt")))); |
| 943 | 969 |
| 944 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 970 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 945 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 971 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 946 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 972 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 947 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 973 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 974 .Times(1); | |
| 948 ASSERT_TRUE(LoadChangeFeed( | 975 ASSERT_TRUE(LoadChangeFeed( |
| 949 "chromeos/gdata/delta_file_moved_from_directory_to_root.json")); | 976 "chromeos/gdata/delta_file_moved_from_directory_to_root.json")); |
| 950 | 977 |
| 951 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 978 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 952 "drive/Directory 1")))); | 979 "drive/root/Directory 1")))); |
| 953 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 980 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 954 "drive/Directory 1/Sub Directory Folder")))); | 981 "drive/root/Directory 1/Sub Directory Folder")))); |
| 955 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 982 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 956 "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); | 983 "drive/root/Directory 1/Sub Directory Folder/" |
| 984 "Sub Sub Directory Folder")))); | |
| 957 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 985 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 958 "drive/Directory 1/SubDirectory File 1.txt")))); | 986 "drive/root/Directory 1/SubDirectory File 1.txt")))); |
| 959 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 987 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 960 "drive/SubDirectory File 1.txt")))); | 988 "drive/root/SubDirectory File 1.txt")))); |
| 961 } | 989 } |
| 962 | 990 |
| 963 TEST_F(DriveFileSystemTest, ChangeFeed_FileRenamedInDirectory) { | 991 TEST_F(DriveFileSystemTest, ChangeFeed_FileRenamedInDirectory) { |
| 964 ASSERT_TRUE(LoadRootFeedDocument()); | 992 ASSERT_TRUE(LoadRootFeedDocument()); |
| 965 | 993 |
| 966 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 994 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 967 "drive/Directory 1")))); | 995 "drive/root/Directory 1")))); |
| 968 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 996 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 969 "drive/Directory 1/SubDirectory File 1.txt")))); | 997 "drive/root/Directory 1/SubDirectory File 1.txt")))); |
| 970 | 998 |
| 971 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 999 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 972 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1000 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 973 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1001 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 974 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1002 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1003 .Times(1); | |
| 975 ASSERT_TRUE(LoadChangeFeed( | 1004 ASSERT_TRUE(LoadChangeFeed( |
| 976 "chromeos/gdata/delta_file_renamed_in_directory.json")); | 1005 "chromeos/gdata/delta_file_renamed_in_directory.json")); |
| 977 | 1006 |
| 978 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 1007 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 979 "drive/Directory 1")))); | 1008 "drive/root/Directory 1")))); |
| 980 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 1009 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 981 "drive/Directory 1/SubDirectory File 1.txt")))); | 1010 "drive/root/Directory 1/SubDirectory File 1.txt")))); |
| 982 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( | 1011 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( |
| 983 "drive/Directory 1/New SubDirectory File 1.txt")))); | 1012 "drive/root/Directory 1/New SubDirectory File 1.txt")))); |
| 984 } | 1013 } |
| 985 | 1014 |
| 986 TEST_F(DriveFileSystemTest, CachedFeedLoading) { | 1015 TEST_F(DriveFileSystemTest, CachedFeedLoading) { |
| 987 ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP)); | 1016 ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP)); |
| 988 // Tests that cached data can be loaded even if the server is not reachable. | 1017 // Tests that cached data can be loaded even if the server is not reachable. |
| 989 fake_drive_service_->set_offline(true); | 1018 fake_drive_service_->set_offline(true); |
| 990 | 1019 |
| 991 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/File1")))); | 1020 EXPECT_TRUE(EntryExists(base::FilePath( |
| 992 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Dir1")))); | 1021 FILE_PATH_LITERAL("drive/root/File1")))); |
| 1022 EXPECT_TRUE(EntryExists(base::FilePath( | |
| 1023 FILE_PATH_LITERAL("drive/root/Dir1")))); | |
| 993 EXPECT_TRUE( | 1024 EXPECT_TRUE( |
| 994 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Dir1/File2")))); | 1025 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Dir1/File2")))); |
| 995 EXPECT_TRUE( | 1026 EXPECT_TRUE(EntryExists(base::FilePath( |
| 996 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2")))); | 1027 FILE_PATH_LITERAL("drive/root/Dir1/SubDir2")))); |
| 997 EXPECT_TRUE(EntryExists( | 1028 EXPECT_TRUE(EntryExists( |
| 998 base::FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3")))); | 1029 base::FilePath(FILE_PATH_LITERAL("drive/root/Dir1/SubDir2/File3")))); |
| 999 } | 1030 } |
| 1000 | 1031 |
| 1001 TEST_F(DriveFileSystemTest, CachedFeedLoadingThenServerFeedLoading) { | 1032 TEST_F(DriveFileSystemTest, CachedFeedLoadingThenServerFeedLoading) { |
| 1002 ASSERT_TRUE(SaveTestFileSystem(USE_SERVER_TIMESTAMP)); | 1033 ASSERT_TRUE(SaveTestFileSystem(USE_SERVER_TIMESTAMP)); |
| 1003 | 1034 |
| 1004 // Kicks loading of cached file system and query for server update. | 1035 // Kicks loading of cached file system and query for server update. |
| 1005 EXPECT_TRUE(ReadDirectoryByPathSync(util::GetDriveMyDriveRootPath())); | 1036 EXPECT_TRUE(ReadDirectoryByPathSync(util::GetDriveMyDriveRootPath())); |
| 1006 | 1037 |
| 1007 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, | 1038 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, |
| 1008 // so no request for new feeds (i.e., call to GetResourceList) should happen. | 1039 // so no request for new feeds (i.e., call to GetResourceList) should happen. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); | 1076 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); |
| 1046 } | 1077 } |
| 1047 | 1078 |
| 1048 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { | 1079 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { |
| 1049 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1080 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1050 | 1081 |
| 1051 ASSERT_TRUE(LoadRootFeedDocument()); | 1082 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1052 | 1083 |
| 1053 // We'll add a file to the Drive root directory. | 1084 // We'll add a file to the Drive root directory. |
| 1054 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1085 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1055 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1086 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1056 | 1087 |
| 1057 // Prepare a local file. | 1088 // Prepare a local file. |
| 1058 base::ScopedTempDir temp_dir; | 1089 base::ScopedTempDir temp_dir; |
| 1059 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1090 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1060 const base::FilePath local_src_file_path = | 1091 const base::FilePath local_src_file_path = |
| 1061 temp_dir.path().AppendASCII("local.txt"); | 1092 temp_dir.path().AppendASCII("local.txt"); |
| 1062 const std::string kContent = "hello"; | 1093 const std::string kContent = "hello"; |
| 1063 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); | 1094 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); |
| 1064 | 1095 |
| 1065 // Confirm that the remote file does not exist. | 1096 // Confirm that the remote file does not exist. |
| 1066 const base::FilePath remote_dest_file_path( | 1097 const base::FilePath remote_dest_file_path( |
| 1067 FILE_PATH_LITERAL("drive/remote.txt")); | 1098 FILE_PATH_LITERAL("drive/root/remote.txt")); |
| 1068 EXPECT_FALSE(EntryExists(remote_dest_file_path)); | 1099 EXPECT_FALSE(EntryExists(remote_dest_file_path)); |
| 1069 | 1100 |
| 1070 // Transfer the local file to Drive. | 1101 // Transfer the local file to Drive. |
| 1071 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1102 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1103 | |
|
hidehiko
2013/04/01 04:21:51
Don't need to edit?
Haruki Sato
2013/04/02 07:54:18
Done. Thanks.
| |
| 1072 file_system_->TransferFileFromLocalToRemote( | 1104 file_system_->TransferFileFromLocalToRemote( |
| 1073 local_src_file_path, | 1105 local_src_file_path, |
| 1074 remote_dest_file_path, | 1106 remote_dest_file_path, |
| 1075 google_apis::test_util::CreateCopyResultCallback(&error)); | 1107 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1076 google_apis::test_util::RunBlockingPoolTask(); | 1108 google_apis::test_util::RunBlockingPoolTask(); |
| 1077 | 1109 |
| 1078 EXPECT_EQ(DRIVE_FILE_OK, error); | 1110 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1079 | 1111 |
| 1080 // Now the remote file should exist. | 1112 // Now the remote file should exist. |
| 1081 EXPECT_TRUE(EntryExists(remote_dest_file_path)); | 1113 EXPECT_TRUE(EntryExists(remote_dest_file_path)); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1093 const std::string kEditUrl = | 1125 const std::string kEditUrl = |
| 1094 "https://3_document_self_link/document:5_document_resource_id"; | 1126 "https://3_document_self_link/document:5_document_resource_id"; |
| 1095 const std::string kResourceId = "document:5_document_resource_id"; | 1127 const std::string kResourceId = "document:5_document_resource_id"; |
| 1096 const std::string kContent = | 1128 const std::string kContent = |
| 1097 base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}", | 1129 base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}", |
| 1098 kEditUrl.c_str(), kResourceId.c_str()); | 1130 kEditUrl.c_str(), kResourceId.c_str()); |
| 1099 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); | 1131 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); |
| 1100 | 1132 |
| 1101 // Confirm that the remote file does not exist. | 1133 // Confirm that the remote file does not exist. |
| 1102 const base::FilePath remote_dest_file_path( | 1134 const base::FilePath remote_dest_file_path( |
| 1103 FILE_PATH_LITERAL("drive/Directory 1/Document 1.gdoc")); | 1135 FILE_PATH_LITERAL("drive/root/Directory 1/Document 1.gdoc")); |
| 1104 EXPECT_FALSE(EntryExists(remote_dest_file_path)); | 1136 EXPECT_FALSE(EntryExists(remote_dest_file_path)); |
| 1105 | 1137 |
| 1106 // We'll add a file to the Drive root and then move to "Directory 1". | 1138 // We'll add a file to the Drive root and then move to "Directory 1". |
| 1107 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1139 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1108 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1140 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1109 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1141 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1110 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1142 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1143 .Times(1); | |
| 1111 | 1144 |
| 1112 // We'll copy a hosted document using CopyHostedDocument. | 1145 // We'll copy a hosted document using CopyHostedDocument. |
| 1113 // ".gdoc" suffix should be stripped when copying. | 1146 // ".gdoc" suffix should be stripped when copying. |
| 1114 scoped_ptr<base::Value> value = | 1147 scoped_ptr<base::Value> value = |
| 1115 google_apis::test_util::LoadJSONFile( | 1148 google_apis::test_util::LoadJSONFile( |
| 1116 "chromeos/gdata/uploaded_document.json"); | 1149 "chromeos/gdata/uploaded_document.json"); |
| 1117 scoped_ptr<google_apis::ResourceEntry> resource_entry = | 1150 scoped_ptr<google_apis::ResourceEntry> resource_entry = |
| 1118 google_apis::ResourceEntry::ExtractAndParse(*value); | 1151 google_apis::ResourceEntry::ExtractAndParse(*value); |
| 1119 | 1152 |
| 1120 | 1153 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1131 // Now the remote file should exist. | 1164 // Now the remote file should exist. |
| 1132 EXPECT_TRUE(EntryExists(remote_dest_file_path)); | 1165 EXPECT_TRUE(EntryExists(remote_dest_file_path)); |
| 1133 } | 1166 } |
| 1134 | 1167 |
| 1135 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { | 1168 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { |
| 1136 ASSERT_TRUE(LoadRootFeedDocument()); | 1169 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1137 | 1170 |
| 1138 // The transfered file is cached and the change of "offline available" | 1171 // The transfered file is cached and the change of "offline available" |
| 1139 // attribute is notified. | 1172 // attribute is notified. |
| 1140 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1173 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1141 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1174 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1142 | 1175 |
| 1143 base::ScopedTempDir temp_dir; | 1176 base::ScopedTempDir temp_dir; |
| 1144 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1177 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1145 base::FilePath local_dest_file_path = | 1178 base::FilePath local_dest_file_path = |
| 1146 temp_dir.path().AppendASCII("local_copy.txt"); | 1179 temp_dir.path().AppendASCII("local_copy.txt"); |
| 1147 | 1180 |
| 1148 base::FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1181 base::FilePath remote_src_file_path( |
| 1182 FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
| 1149 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync( | 1183 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync( |
| 1150 remote_src_file_path); | 1184 remote_src_file_path); |
| 1151 const int64 file_size = file->file_info().size(); | 1185 const int64 file_size = file->file_info().size(); |
| 1152 | 1186 |
| 1153 // Pretend we have enough space. | 1187 // Pretend we have enough space. |
| 1154 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1188 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 1155 file_size + kMinFreeSpace); | 1189 file_size + kMinFreeSpace); |
| 1156 | 1190 |
| 1157 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1191 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1158 file_system_->TransferFileFromRemoteToLocal( | 1192 file_system_->TransferFileFromRemoteToLocal( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1184 } | 1218 } |
| 1185 | 1219 |
| 1186 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { | 1220 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { |
| 1187 ASSERT_TRUE(LoadRootFeedDocument()); | 1221 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1188 | 1222 |
| 1189 base::ScopedTempDir temp_dir; | 1223 base::ScopedTempDir temp_dir; |
| 1190 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1224 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1191 base::FilePath local_dest_file_path = | 1225 base::FilePath local_dest_file_path = |
| 1192 temp_dir.path().AppendASCII("local_copy.txt"); | 1226 temp_dir.path().AppendASCII("local_copy.txt"); |
| 1193 base::FilePath remote_src_file_path( | 1227 base::FilePath remote_src_file_path( |
| 1194 FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1228 FILE_PATH_LITERAL("drive/root/Document 1.gdoc")); |
| 1195 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1229 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1196 file_system_->TransferFileFromRemoteToLocal( | 1230 file_system_->TransferFileFromRemoteToLocal( |
| 1197 remote_src_file_path, | 1231 remote_src_file_path, |
| 1198 local_dest_file_path, | 1232 local_dest_file_path, |
| 1199 google_apis::test_util::CreateCopyResultCallback(&error)); | 1233 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1200 google_apis::test_util::RunBlockingPoolTask(); | 1234 google_apis::test_util::RunBlockingPoolTask(); |
| 1201 | 1235 |
| 1202 EXPECT_EQ(DRIVE_FILE_OK, error); | 1236 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1203 | 1237 |
| 1204 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( | 1238 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( |
| 1205 remote_src_file_path); | 1239 remote_src_file_path); |
| 1206 ASSERT_TRUE(entry_proto.get()); | 1240 ASSERT_TRUE(entry_proto.get()); |
| 1207 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); | 1241 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); |
| 1208 } | 1242 } |
| 1209 | 1243 |
| 1210 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { | 1244 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { |
| 1211 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1245 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| 1212 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1246 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1213 | 1247 |
| 1214 ASSERT_TRUE(LoadRootFeedDocument()); | 1248 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1215 | 1249 |
| 1216 EXPECT_FALSE(EntryExists(src_file_path)); | 1250 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1217 | 1251 |
| 1218 DriveFileError error = DRIVE_FILE_OK; | 1252 DriveFileError error = DRIVE_FILE_OK; |
| 1219 file_system_->Copy( | 1253 file_system_->Copy( |
| 1220 src_file_path, | 1254 src_file_path, |
| 1221 dest_file_path, | 1255 dest_file_path, |
| 1222 google_apis::test_util::CreateCopyResultCallback(&error)); | 1256 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1223 google_apis::test_util::RunBlockingPoolTask(); | 1257 google_apis::test_util::RunBlockingPoolTask(); |
| 1224 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 1258 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 1225 | 1259 |
| 1226 EXPECT_FALSE(EntryExists(src_file_path)); | 1260 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1227 EXPECT_FALSE(EntryExists(dest_file_path)); | 1261 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1228 } | 1262 } |
| 1229 | 1263 |
| 1230 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { | 1264 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { |
| 1231 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1265 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1232 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1266 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy")); |
| 1233 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1267 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); |
| 1234 | 1268 |
| 1235 ASSERT_TRUE(LoadRootFeedDocument()); | 1269 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1236 | 1270 |
| 1237 ASSERT_TRUE(EntryExists(src_file_path)); | 1271 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1238 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1272 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1239 src_file_path); | 1273 src_file_path); |
| 1240 ASSERT_TRUE(src_entry_proto.get()); | 1274 ASSERT_TRUE(src_entry_proto.get()); |
| 1241 std::string src_file_path_resource_id = | 1275 std::string src_file_path_resource_id = |
| 1242 src_entry_proto->resource_id(); | 1276 src_entry_proto->resource_id(); |
| 1243 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1277 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1244 | 1278 |
| 1245 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1279 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1246 | 1280 |
| 1247 DriveFileError error = DRIVE_FILE_OK; | 1281 DriveFileError error = DRIVE_FILE_OK; |
| 1248 file_system_->Move( | 1282 file_system_->Move( |
| 1249 src_file_path, | 1283 src_file_path, |
| 1250 dest_file_path, | 1284 dest_file_path, |
| 1251 google_apis::test_util::CreateCopyResultCallback(&error)); | 1285 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1252 google_apis::test_util::RunBlockingPoolTask(); | 1286 google_apis::test_util::RunBlockingPoolTask(); |
| 1253 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 1287 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 1254 | 1288 |
| 1255 EXPECT_TRUE(EntryExists(src_file_path)); | 1289 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1256 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1290 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1257 EXPECT_FALSE(EntryExists(dest_file_path)); | 1291 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1258 } | 1292 } |
| 1259 | 1293 |
| 1260 // Test the case where the parent of |dest_file_path| is an existing file, | 1294 // Test the case where the parent of |dest_file_path| is an existing file, |
| 1261 // not a directory. | 1295 // not a directory. |
| 1262 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { | 1296 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { |
| 1263 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1297 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Document 1.gdoc")); |
| 1264 base::FilePath dest_parent_path( | 1298 base::FilePath dest_parent_path( |
| 1265 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); | 1299 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); |
| 1266 base::FilePath dest_file_path(FILE_PATH_LITERAL( | 1300 base::FilePath dest_file_path(FILE_PATH_LITERAL( |
| 1267 "drive/Duplicate Name.txt/Document 1.gdoc")); | 1301 "drive/root/Duplicate Name.txt/Document 1.gdoc")); |
| 1268 | 1302 |
| 1269 ASSERT_TRUE(LoadRootFeedDocument()); | 1303 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1270 | 1304 |
| 1271 ASSERT_TRUE(EntryExists(src_file_path)); | 1305 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1272 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1306 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1273 src_file_path); | 1307 src_file_path); |
| 1274 ASSERT_TRUE(src_entry_proto.get()); | 1308 ASSERT_TRUE(src_entry_proto.get()); |
| 1275 std::string src_file_resource_id = | 1309 std::string src_file_resource_id = |
| 1276 src_entry_proto->resource_id(); | 1310 src_entry_proto->resource_id(); |
| 1277 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1311 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1291 | 1325 |
| 1292 EXPECT_TRUE(EntryExists(src_file_path)); | 1326 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1293 EXPECT_TRUE(EntryExists(src_file_path)); | 1327 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1294 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1328 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1295 | 1329 |
| 1296 EXPECT_FALSE(EntryExists(dest_file_path)); | 1330 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1297 } | 1331 } |
| 1298 | 1332 |
| 1299 TEST_F(DriveFileSystemTest, RenameFile) { | 1333 TEST_F(DriveFileSystemTest, RenameFile) { |
| 1300 const base::FilePath src_file_path( | 1334 const base::FilePath src_file_path( |
| 1301 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1335 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 1302 const base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1336 const base::FilePath src_parent_path( |
| 1337 FILE_PATH_LITERAL("drive/root/Directory 1")); | |
| 1303 const base::FilePath dest_file_path( | 1338 const base::FilePath dest_file_path( |
| 1304 FILE_PATH_LITERAL("drive/Directory 1/Test.log")); | 1339 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 1305 | 1340 |
| 1306 ASSERT_TRUE(LoadRootFeedDocument()); | 1341 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1307 | 1342 |
| 1308 ASSERT_TRUE(EntryExists(src_file_path)); | 1343 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1309 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1344 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1310 src_file_path); | 1345 src_file_path); |
| 1311 ASSERT_TRUE(src_entry_proto.get()); | 1346 ASSERT_TRUE(src_entry_proto.get()); |
| 1312 std::string src_file_resource_id = | 1347 std::string src_file_resource_id = |
| 1313 src_entry_proto->resource_id(); | 1348 src_entry_proto->resource_id(); |
| 1314 | 1349 |
| 1315 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1350 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1316 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1351 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1352 .Times(1); | |
| 1317 | 1353 |
| 1318 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1354 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1319 file_system_->Move( | 1355 file_system_->Move( |
| 1320 src_file_path, | 1356 src_file_path, |
| 1321 dest_file_path, | 1357 dest_file_path, |
| 1322 google_apis::test_util::CreateCopyResultCallback(&error)); | 1358 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1323 google_apis::test_util::RunBlockingPoolTask(); | 1359 google_apis::test_util::RunBlockingPoolTask(); |
| 1324 EXPECT_EQ(DRIVE_FILE_OK, error); | 1360 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1325 | 1361 |
| 1326 EXPECT_FALSE(EntryExists(src_file_path)); | 1362 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1327 EXPECT_TRUE(EntryExists(dest_file_path)); | 1363 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1328 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1364 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1329 } | 1365 } |
| 1330 | 1366 |
| 1331 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) { | 1367 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) { |
| 1332 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1368 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1333 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1369 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 1334 base::FilePath dest_file_path( | 1370 base::FilePath dest_file_path( |
| 1335 FILE_PATH_LITERAL("drive/Directory 1/Test.log")); | 1371 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 1336 | 1372 |
| 1337 ASSERT_TRUE(LoadRootFeedDocument()); | 1373 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1338 | 1374 |
| 1339 ASSERT_TRUE(EntryExists(src_file_path)); | 1375 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1340 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1376 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1341 src_file_path); | 1377 src_file_path); |
| 1342 ASSERT_TRUE(src_entry_proto.get()); | 1378 ASSERT_TRUE(src_entry_proto.get()); |
| 1343 std::string src_file_resource_id = | 1379 std::string src_file_resource_id = |
| 1344 src_entry_proto->resource_id(); | 1380 src_entry_proto->resource_id(); |
| 1345 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1381 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1346 | 1382 |
| 1347 ASSERT_TRUE(EntryExists(dest_parent_path)); | 1383 ASSERT_TRUE(EntryExists(dest_parent_path)); |
| 1348 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( | 1384 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( |
| 1349 dest_parent_path); | 1385 dest_parent_path); |
| 1350 ASSERT_TRUE(dest_parent_proto.get()); | 1386 ASSERT_TRUE(dest_parent_proto.get()); |
| 1351 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); | 1387 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); |
| 1352 EXPECT_FALSE(dest_parent_proto->download_url().empty()); | 1388 EXPECT_FALSE(dest_parent_proto->download_url().empty()); |
| 1353 | 1389 |
| 1354 // Expect notification for both source and destination directories. | 1390 // Expect notification for both source and destination directories. |
| 1355 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1391 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1356 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1392 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1357 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1393 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1358 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1394 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1395 .Times(1); | |
| 1359 | 1396 |
| 1360 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1397 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1361 file_system_->Move( | 1398 file_system_->Move( |
| 1362 src_file_path, | 1399 src_file_path, |
| 1363 dest_file_path, | 1400 dest_file_path, |
| 1364 google_apis::test_util::CreateCopyResultCallback(&error)); | 1401 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1365 google_apis::test_util::RunBlockingPoolTask(); | 1402 google_apis::test_util::RunBlockingPoolTask(); |
| 1366 EXPECT_EQ(DRIVE_FILE_OK, error); | 1403 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1367 | 1404 |
| 1368 EXPECT_FALSE(EntryExists(src_file_path)); | 1405 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1369 EXPECT_TRUE(EntryExists(dest_file_path)); | 1406 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1370 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1407 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1371 } | 1408 } |
| 1372 | 1409 |
| 1373 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) { | 1410 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) { |
| 1374 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1411 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 1375 base::FilePath src_file_path( | 1412 base::FilePath src_file_path( |
| 1376 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1413 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 1377 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1414 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1378 | 1415 |
| 1379 ASSERT_TRUE(LoadRootFeedDocument()); | 1416 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1380 | 1417 |
| 1381 ASSERT_TRUE(EntryExists(src_file_path)); | 1418 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1382 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1419 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1383 src_file_path); | 1420 src_file_path); |
| 1384 ASSERT_TRUE(src_entry_proto.get()); | 1421 ASSERT_TRUE(src_entry_proto.get()); |
| 1385 std::string src_file_resource_id = | 1422 std::string src_file_resource_id = |
| 1386 src_entry_proto->resource_id(); | 1423 src_entry_proto->resource_id(); |
| 1387 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1424 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1388 | 1425 |
| 1389 ASSERT_TRUE(EntryExists(src_parent_path)); | 1426 ASSERT_TRUE(EntryExists(src_parent_path)); |
| 1390 scoped_ptr<DriveEntryProto> src_parent_proto = GetEntryInfoByPathSync( | 1427 scoped_ptr<DriveEntryProto> src_parent_proto = GetEntryInfoByPathSync( |
| 1391 src_parent_path); | 1428 src_parent_path); |
| 1392 ASSERT_TRUE(src_parent_proto.get()); | 1429 ASSERT_TRUE(src_parent_proto.get()); |
| 1393 ASSERT_TRUE(src_parent_proto->file_info().is_directory()); | 1430 ASSERT_TRUE(src_parent_proto->file_info().is_directory()); |
| 1394 EXPECT_FALSE(src_parent_proto->download_url().empty()); | 1431 EXPECT_FALSE(src_parent_proto->download_url().empty()); |
| 1395 | 1432 |
| 1396 // Expect notification for both source and destination directories. | 1433 // Expect notification for both source and destination directories. |
| 1397 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1434 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1398 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1435 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1399 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1436 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1400 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1437 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1438 .Times(1); | |
| 1401 | 1439 |
| 1402 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1440 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1403 file_system_->Move( | 1441 file_system_->Move( |
| 1404 src_file_path, | 1442 src_file_path, |
| 1405 dest_file_path, | 1443 dest_file_path, |
| 1406 google_apis::test_util::CreateCopyResultCallback(&error)); | 1444 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1407 google_apis::test_util::RunBlockingPoolTask(); | 1445 google_apis::test_util::RunBlockingPoolTask(); |
| 1408 EXPECT_EQ(DRIVE_FILE_OK, error); | 1446 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1409 | 1447 |
| 1410 EXPECT_FALSE(EntryExists(src_file_path)); | 1448 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1411 ASSERT_TRUE(EntryExists(dest_file_path)); | 1449 ASSERT_TRUE(EntryExists(dest_file_path)); |
| 1412 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1450 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1413 } | 1451 } |
| 1414 | 1452 |
| 1415 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) { | 1453 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) { |
| 1416 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1454 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 1417 base::FilePath src_file_path( | 1455 base::FilePath src_file_path( |
| 1418 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1456 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 1419 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/New Folder 1")); | 1457 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); |
| 1420 base::FilePath dest_file_path( | 1458 base::FilePath dest_file_path( |
| 1421 FILE_PATH_LITERAL("drive/New Folder 1/Test.log")); | 1459 FILE_PATH_LITERAL("drive/root/New Folder 1/Test.log")); |
| 1422 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1460 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1423 | 1461 |
| 1424 ASSERT_TRUE(LoadRootFeedDocument()); | 1462 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1425 | 1463 |
| 1426 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1464 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1427 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1465 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1428 | 1466 |
| 1429 AddDirectoryFromFile(dest_parent_path, | 1467 AddDirectoryFromFile(dest_parent_path, |
| 1430 "chromeos/gdata/directory_entry_atom.json"); | 1468 "chromeos/gdata/directory_entry_atom.json"); |
| 1431 | 1469 |
| 1432 ASSERT_TRUE(EntryExists(src_file_path)); | 1470 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1433 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1471 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1434 src_file_path); | 1472 src_file_path); |
| 1435 ASSERT_TRUE(src_entry_proto.get()); | 1473 ASSERT_TRUE(src_entry_proto.get()); |
| 1436 std::string src_file_resource_id = | 1474 std::string src_file_resource_id = |
| 1437 src_entry_proto->resource_id(); | 1475 src_entry_proto->resource_id(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1448 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( | 1486 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( |
| 1449 dest_parent_path); | 1487 dest_parent_path); |
| 1450 ASSERT_TRUE(dest_parent_proto.get()); | 1488 ASSERT_TRUE(dest_parent_proto.get()); |
| 1451 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); | 1489 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); |
| 1452 EXPECT_FALSE(dest_parent_proto->download_url().empty()); | 1490 EXPECT_FALSE(dest_parent_proto->download_url().empty()); |
| 1453 | 1491 |
| 1454 EXPECT_FALSE(EntryExists(interim_file_path)); | 1492 EXPECT_FALSE(EntryExists(interim_file_path)); |
| 1455 | 1493 |
| 1456 // Expect notification for both source and destination directories. | 1494 // Expect notification for both source and destination directories. |
| 1457 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1495 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1458 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1496 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1497 .Times(1); | |
| 1459 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1498 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1460 Eq(base::FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); | 1499 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1"))))) |
| 1500 .Times(1); | |
| 1461 | 1501 |
| 1462 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1502 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1463 file_system_->Move( | 1503 file_system_->Move( |
| 1464 src_file_path, | 1504 src_file_path, |
| 1465 dest_file_path, | 1505 dest_file_path, |
| 1466 google_apis::test_util::CreateCopyResultCallback(&error)); | 1506 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1467 google_apis::test_util::RunBlockingPoolTask(); | 1507 google_apis::test_util::RunBlockingPoolTask(); |
| 1468 EXPECT_EQ(DRIVE_FILE_OK, error); | 1508 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1469 | 1509 |
| 1470 EXPECT_FALSE(EntryExists(src_file_path)); | 1510 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1471 EXPECT_FALSE(EntryExists(interim_file_path)); | 1511 EXPECT_FALSE(EntryExists(interim_file_path)); |
| 1472 | 1512 |
| 1473 EXPECT_FALSE(EntryExists(src_file_path)); | 1513 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1474 EXPECT_TRUE(EntryExists(dest_file_path)); | 1514 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1475 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1515 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1476 } | 1516 } |
| 1477 | 1517 |
| 1478 TEST_F(DriveFileSystemTest, MoveNotExistingFile) { | 1518 TEST_F(DriveFileSystemTest, MoveNotExistingFile) { |
| 1479 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1519 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| 1480 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1520 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1481 | 1521 |
| 1482 ASSERT_TRUE(LoadRootFeedDocument()); | 1522 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1483 | 1523 |
| 1484 EXPECT_FALSE(EntryExists(src_file_path)); | 1524 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1485 | 1525 |
| 1486 DriveFileError error = DRIVE_FILE_OK; | 1526 DriveFileError error = DRIVE_FILE_OK; |
| 1487 file_system_->Move( | 1527 file_system_->Move( |
| 1488 src_file_path, | 1528 src_file_path, |
| 1489 dest_file_path, | 1529 dest_file_path, |
| 1490 google_apis::test_util::CreateCopyResultCallback(&error)); | 1530 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1491 google_apis::test_util::RunBlockingPoolTask(); | 1531 google_apis::test_util::RunBlockingPoolTask(); |
| 1492 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 1532 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 1493 | 1533 |
| 1494 EXPECT_FALSE(EntryExists(src_file_path)); | 1534 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1495 EXPECT_FALSE(EntryExists(dest_file_path)); | 1535 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1496 } | 1536 } |
| 1497 | 1537 |
| 1498 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) { | 1538 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) { |
| 1499 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1539 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1500 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1540 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy")); |
| 1501 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1541 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); |
| 1502 | 1542 |
| 1503 ASSERT_TRUE(LoadRootFeedDocument()); | 1543 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1504 | 1544 |
| 1505 ASSERT_TRUE(EntryExists(src_file_path)); | 1545 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1506 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1546 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1507 src_file_path); | 1547 src_file_path); |
| 1508 ASSERT_TRUE(src_entry_proto.get()); | 1548 ASSERT_TRUE(src_entry_proto.get()); |
| 1509 std::string src_file_resource_id = | 1549 std::string src_file_resource_id = |
| 1510 src_entry_proto->resource_id(); | 1550 src_entry_proto->resource_id(); |
| 1511 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1551 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1512 | 1552 |
| 1513 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1553 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1514 | 1554 |
| 1515 DriveFileError error = DRIVE_FILE_OK; | 1555 DriveFileError error = DRIVE_FILE_OK; |
| 1516 file_system_->Move( | 1556 file_system_->Move( |
| 1517 src_file_path, | 1557 src_file_path, |
| 1518 dest_file_path, | 1558 dest_file_path, |
| 1519 google_apis::test_util::CreateCopyResultCallback(&error)); | 1559 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1520 google_apis::test_util::RunBlockingPoolTask(); | 1560 google_apis::test_util::RunBlockingPoolTask(); |
| 1521 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 1561 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 1522 | 1562 |
| 1523 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1563 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1524 EXPECT_FALSE(EntryExists(dest_file_path)); | 1564 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1525 } | 1565 } |
| 1526 | 1566 |
| 1527 // Test the case where the parent of |dest_file_path| is a existing file, | 1567 // Test the case where the parent of |dest_file_path| is a existing file, |
| 1528 // not a directory. | 1568 // not a directory. |
| 1529 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) { | 1569 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) { |
| 1530 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1570 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1531 base::FilePath dest_parent_path( | 1571 base::FilePath dest_parent_path( |
| 1532 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); | 1572 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); |
| 1533 base::FilePath dest_file_path(FILE_PATH_LITERAL( | 1573 base::FilePath dest_file_path(FILE_PATH_LITERAL( |
| 1534 "drive/Duplicate Name.txt/Test.log")); | 1574 "drive/root/Duplicate Name.txt/Test.log")); |
| 1535 | 1575 |
| 1536 ASSERT_TRUE(LoadRootFeedDocument()); | 1576 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1537 | 1577 |
| 1538 ASSERT_TRUE(EntryExists(src_file_path)); | 1578 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1539 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1579 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1540 src_file_path); | 1580 src_file_path); |
| 1541 ASSERT_TRUE(src_entry_proto.get()); | 1581 ASSERT_TRUE(src_entry_proto.get()); |
| 1542 std::string src_file_resource_id = | 1582 std::string src_file_resource_id = |
| 1543 src_entry_proto->resource_id(); | 1583 src_entry_proto->resource_id(); |
| 1544 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1584 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1557 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error); | 1597 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error); |
| 1558 | 1598 |
| 1559 EXPECT_TRUE(EntryExists(src_file_path)); | 1599 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1560 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1600 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1561 EXPECT_FALSE(EntryExists(dest_file_path)); | 1601 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1562 } | 1602 } |
| 1563 | 1603 |
| 1564 TEST_F(DriveFileSystemTest, RemoveEntries) { | 1604 TEST_F(DriveFileSystemTest, RemoveEntries) { |
| 1565 ASSERT_TRUE(LoadRootFeedDocument()); | 1605 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1566 | 1606 |
| 1567 base::FilePath nonexisting_file(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1607 base::FilePath nonexisting_file( |
| 1568 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1608 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| 1569 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/Directory 1")); | 1609 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1610 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/root/Directory 1")); | |
| 1570 base::FilePath file_in_subdir( | 1611 base::FilePath file_in_subdir( |
| 1571 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1612 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 1572 | 1613 |
| 1573 ASSERT_TRUE(EntryExists(file_in_root)); | 1614 ASSERT_TRUE(EntryExists(file_in_root)); |
| 1574 scoped_ptr<DriveEntryProto> file_in_root_proto = GetEntryInfoByPathSync( | 1615 scoped_ptr<DriveEntryProto> file_in_root_proto = GetEntryInfoByPathSync( |
| 1575 file_in_root); | 1616 file_in_root); |
| 1576 ASSERT_TRUE(file_in_root_proto.get()); | 1617 ASSERT_TRUE(file_in_root_proto.get()); |
| 1577 | 1618 |
| 1578 ASSERT_TRUE(EntryExists(dir_in_root)); | 1619 ASSERT_TRUE(EntryExists(dir_in_root)); |
| 1579 scoped_ptr<DriveEntryProto> dir_in_root_proto = GetEntryInfoByPathSync( | 1620 scoped_ptr<DriveEntryProto> dir_in_root_proto = GetEntryInfoByPathSync( |
| 1580 dir_in_root); | 1621 dir_in_root); |
| 1581 ASSERT_TRUE(dir_in_root_proto.get()); | 1622 ASSERT_TRUE(dir_in_root_proto.get()); |
| 1582 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory()); | 1623 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory()); |
| 1583 | 1624 |
| 1584 ASSERT_TRUE(EntryExists(file_in_subdir)); | 1625 ASSERT_TRUE(EntryExists(file_in_subdir)); |
| 1585 scoped_ptr<DriveEntryProto> file_in_subdir_proto = GetEntryInfoByPathSync( | 1626 scoped_ptr<DriveEntryProto> file_in_subdir_proto = GetEntryInfoByPathSync( |
| 1586 file_in_subdir); | 1627 file_in_subdir); |
| 1587 ASSERT_TRUE(file_in_subdir_proto.get()); | 1628 ASSERT_TRUE(file_in_subdir_proto.get()); |
| 1588 | 1629 |
| 1589 // Once for file in root and once for file... | 1630 // Once for file in root and once for file... |
| 1590 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1631 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1591 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(2); | 1632 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2); |
| 1592 | 1633 |
| 1593 // Remove first file in root. | 1634 // Remove first file in root. |
| 1594 EXPECT_TRUE(RemoveEntry(file_in_root)); | 1635 EXPECT_TRUE(RemoveEntry(file_in_root)); |
| 1595 EXPECT_FALSE(EntryExists(file_in_root)); | 1636 EXPECT_FALSE(EntryExists(file_in_root)); |
| 1596 EXPECT_TRUE(EntryExists(dir_in_root)); | 1637 EXPECT_TRUE(EntryExists(dir_in_root)); |
| 1597 EXPECT_TRUE(EntryExists(file_in_subdir)); | 1638 EXPECT_TRUE(EntryExists(file_in_subdir)); |
| 1598 | 1639 |
| 1599 // Remove directory. | 1640 // Remove directory. |
| 1600 EXPECT_TRUE(RemoveEntry(dir_in_root)); | 1641 EXPECT_TRUE(RemoveEntry(dir_in_root)); |
| 1601 EXPECT_FALSE(EntryExists(file_in_root)); | 1642 EXPECT_FALSE(EntryExists(file_in_root)); |
| 1602 EXPECT_FALSE(EntryExists(dir_in_root)); | 1643 EXPECT_FALSE(EntryExists(dir_in_root)); |
| 1603 EXPECT_FALSE(EntryExists(file_in_subdir)); | 1644 EXPECT_FALSE(EntryExists(file_in_subdir)); |
| 1604 | 1645 |
| 1605 // Try removing file in already removed subdirectory. | 1646 // Try removing file in already removed subdirectory. |
| 1606 EXPECT_FALSE(RemoveEntry(file_in_subdir)); | 1647 EXPECT_FALSE(RemoveEntry(file_in_subdir)); |
| 1607 | 1648 |
| 1608 // Try removing non-existing file. | 1649 // Try removing non-existing file. |
| 1609 EXPECT_FALSE(RemoveEntry(nonexisting_file)); | 1650 EXPECT_FALSE(RemoveEntry(nonexisting_file)); |
| 1610 | 1651 |
| 1611 // Try removing root file element. | 1652 // Try removing root file element. |
| 1612 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive")))); | 1653 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive/root")))); |
| 1613 | 1654 |
| 1614 // Need this to ensure OnDirectoryChanged() is run. | 1655 // Need this to ensure OnDirectoryChanged() is run. |
| 1615 google_apis::test_util::RunBlockingPoolTask(); | 1656 google_apis::test_util::RunBlockingPoolTask(); |
| 1616 } | 1657 } |
| 1617 | 1658 |
| 1618 TEST_F(DriveFileSystemTest, CreateDirectory) { | 1659 TEST_F(DriveFileSystemTest, CreateDirectory) { |
| 1619 ASSERT_TRUE(LoadRootFeedDocument()); | 1660 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1620 | 1661 |
| 1621 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1662 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1622 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1663 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1623 | 1664 |
| 1624 // Create directory in root. | 1665 // Create directory in root. |
| 1625 base::FilePath dir_path(FILE_PATH_LITERAL("drive/New Folder 1")); | 1666 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); |
| 1626 EXPECT_FALSE(EntryExists(dir_path)); | 1667 EXPECT_FALSE(EntryExists(dir_path)); |
| 1627 AddDirectoryFromFile(dir_path, "chromeos/gdata/directory_entry_atom.json"); | 1668 AddDirectoryFromFile(dir_path, "chromeos/gdata/directory_entry_atom.json"); |
| 1628 EXPECT_TRUE(EntryExists(dir_path)); | 1669 EXPECT_TRUE(EntryExists(dir_path)); |
| 1629 | 1670 |
| 1630 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1671 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1631 Eq(base::FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); | 1672 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1"))))) |
| 1673 .Times(1); | |
| 1632 | 1674 |
| 1633 // Create directory in a sub directory. | 1675 // Create directory in a sub directory. |
| 1634 base::FilePath subdir_path( | 1676 base::FilePath subdir_path( |
| 1635 FILE_PATH_LITERAL("drive/New Folder 1/New Folder 2")); | 1677 FILE_PATH_LITERAL("drive/root/New Folder 1/New Folder 2")); |
| 1636 EXPECT_FALSE(EntryExists(subdir_path)); | 1678 EXPECT_FALSE(EntryExists(subdir_path)); |
| 1637 AddDirectoryFromFile(subdir_path, | 1679 AddDirectoryFromFile(subdir_path, |
| 1638 "chromeos/gdata/directory_entry_atom2.json"); | 1680 "chromeos/gdata/directory_entry_atom2.json"); |
| 1639 EXPECT_TRUE(EntryExists(subdir_path)); | 1681 EXPECT_TRUE(EntryExists(subdir_path)); |
| 1640 } | 1682 } |
| 1641 | 1683 |
| 1642 // Create a directory through the document service | 1684 // Create a directory through the document service |
| 1643 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { | 1685 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { |
| 1644 ASSERT_TRUE(LoadRootFeedDocument()); | 1686 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1645 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1687 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1646 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1688 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1647 | 1689 |
| 1648 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1690 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1649 file_system_->CreateDirectory( | 1691 file_system_->CreateDirectory( |
| 1650 base::FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), | 1692 base::FilePath(FILE_PATH_LITERAL("drive/root/Sample Directory Title")), |
| 1651 false, // is_exclusive | 1693 false, // is_exclusive |
| 1652 true, // is_recursive | 1694 true, // is_recursive |
| 1653 google_apis::test_util::CreateCopyResultCallback(&error)); | 1695 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1654 google_apis::test_util::RunBlockingPoolTask(); | 1696 google_apis::test_util::RunBlockingPoolTask(); |
| 1655 | 1697 |
| 1656 EXPECT_EQ(DRIVE_FILE_OK, error); | 1698 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1657 } | 1699 } |
| 1658 | 1700 |
| 1659 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { | 1701 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { |
| 1660 ASSERT_TRUE(LoadRootFeedDocument()); | 1702 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1661 | 1703 |
| 1662 // The transfered file is cached and the change of "offline available" | 1704 // The transfered file is cached and the change of "offline available" |
| 1663 // attribute is notified. | 1705 // attribute is notified. |
| 1664 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1706 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1665 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1707 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1666 | 1708 |
| 1667 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1709 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1668 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1710 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1669 const int64 file_size = entry_proto->file_info().size(); | 1711 const int64 file_size = entry_proto->file_info().size(); |
| 1670 | 1712 |
| 1671 // Pretend we have enough space. | 1713 // Pretend we have enough space. |
| 1672 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1714 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 1673 file_size + kMinFreeSpace); | 1715 file_size + kMinFreeSpace); |
| 1674 | 1716 |
| 1675 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1717 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1676 base::FilePath file_path; | 1718 base::FilePath file_path; |
| 1677 std::string mime_type; | 1719 std::string mime_type; |
| 1678 DriveFileType file_type; | 1720 DriveFileType file_type; |
| 1679 file_system_->GetFileByPath(file_in_root, | 1721 file_system_->GetFileByPath(file_in_root, |
| 1680 google_apis::test_util::CreateCopyResultCallback( | 1722 google_apis::test_util::CreateCopyResultCallback( |
| 1681 &error, &file_path, &mime_type, &file_type)); | 1723 &error, &file_path, &mime_type, &file_type)); |
| 1682 google_apis::test_util::RunBlockingPoolTask(); | 1724 google_apis::test_util::RunBlockingPoolTask(); |
| 1683 | 1725 |
| 1684 EXPECT_EQ(DRIVE_FILE_OK, error); | 1726 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1685 EXPECT_EQ(REGULAR_FILE, file_type); | 1727 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1686 } | 1728 } |
| 1687 | 1729 |
| 1688 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { | 1730 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { |
| 1689 ASSERT_TRUE(LoadRootFeedDocument()); | 1731 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1690 | 1732 |
| 1691 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1733 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1692 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1734 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1693 | 1735 |
| 1694 // Pretend we have no space at all. | 1736 // Pretend we have no space at all. |
| 1695 fake_free_disk_space_getter_->set_fake_free_disk_space(0); | 1737 fake_free_disk_space_getter_->set_fake_free_disk_space(0); |
| 1696 | 1738 |
| 1697 DriveFileError error = DRIVE_FILE_OK; | 1739 DriveFileError error = DRIVE_FILE_OK; |
| 1698 base::FilePath file_path; | 1740 base::FilePath file_path; |
| 1699 std::string mime_type; | 1741 std::string mime_type; |
| 1700 DriveFileType file_type; | 1742 DriveFileType file_type; |
| 1701 file_system_->GetFileByPath(file_in_root, | 1743 file_system_->GetFileByPath(file_in_root, |
| 1702 google_apis::test_util::CreateCopyResultCallback( | 1744 google_apis::test_util::CreateCopyResultCallback( |
| 1703 &error, &file_path, &mime_type, &file_type)); | 1745 &error, &file_path, &mime_type, &file_type)); |
| 1704 google_apis::test_util::RunBlockingPoolTask(); | 1746 google_apis::test_util::RunBlockingPoolTask(); |
| 1705 | 1747 |
| 1706 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); | 1748 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); |
| 1707 } | 1749 } |
| 1708 | 1750 |
| 1709 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { | 1751 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { |
| 1710 ASSERT_TRUE(LoadRootFeedDocument()); | 1752 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1711 | 1753 |
| 1712 // The transfered file is cached and the change of "offline available" | 1754 // The transfered file is cached and the change of "offline available" |
| 1713 // attribute is notified. | 1755 // attribute is notified. |
| 1714 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1756 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1715 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1757 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1716 | 1758 |
| 1717 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1759 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1718 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1760 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1719 const int64 file_size = entry_proto->file_info().size(); | 1761 const int64 file_size = entry_proto->file_info().size(); |
| 1720 | 1762 |
| 1721 // Pretend we have no space first (checked before downloading a file), | 1763 // Pretend we have no space first (checked before downloading a file), |
| 1722 // but then start reporting we have space. This is to emulate that | 1764 // but then start reporting we have space. This is to emulate that |
| 1723 // the disk space was freed up by removing temporary files. | 1765 // the disk space was freed up by removing temporary files. |
| 1724 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1766 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 1725 file_size + kMinFreeSpace); | 1767 file_size + kMinFreeSpace); |
| 1726 fake_free_disk_space_getter_->set_fake_free_disk_space(0); | 1768 fake_free_disk_space_getter_->set_fake_free_disk_space(0); |
| 1727 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1769 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1757 EXPECT_EQ(DRIVE_FILE_OK, error); | 1799 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1758 EXPECT_EQ(REGULAR_FILE, file_type); | 1800 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1759 | 1801 |
| 1760 // The cache entry should be removed in order to free up space. | 1802 // The cache entry should be removed in order to free up space. |
| 1761 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); | 1803 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); |
| 1762 } | 1804 } |
| 1763 | 1805 |
| 1764 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) { | 1806 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) { |
| 1765 ASSERT_TRUE(LoadRootFeedDocument()); | 1807 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1766 | 1808 |
| 1767 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1809 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1768 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1810 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1769 const int64 file_size = entry_proto->file_info().size(); | 1811 const int64 file_size = entry_proto->file_info().size(); |
| 1770 | 1812 |
| 1771 // Pretend we have enough space first (checked before downloading a file), | 1813 // Pretend we have enough space first (checked before downloading a file), |
| 1772 // but then start reporting we have not enough space. This is to emulate that | 1814 // but then start reporting we have not enough space. This is to emulate that |
| 1773 // the disk space becomes full after the file is downloaded for some reason | 1815 // the disk space becomes full after the file is downloaded for some reason |
| 1774 // (ex. the actual file was larger than the expected size). | 1816 // (ex. the actual file was larger than the expected size). |
| 1775 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1817 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 1776 file_size + kMinFreeSpace); | 1818 file_size + kMinFreeSpace); |
| 1777 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1); | 1819 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1); |
| 1778 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1); | 1820 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1); |
| 1779 | 1821 |
| 1780 DriveFileError error = DRIVE_FILE_OK; | 1822 DriveFileError error = DRIVE_FILE_OK; |
| 1781 base::FilePath file_path; | 1823 base::FilePath file_path; |
| 1782 std::string mime_type; | 1824 std::string mime_type; |
| 1783 DriveFileType file_type; | 1825 DriveFileType file_type; |
| 1784 file_system_->GetFileByPath(file_in_root, | 1826 file_system_->GetFileByPath(file_in_root, |
| 1785 google_apis::test_util::CreateCopyResultCallback( | 1827 google_apis::test_util::CreateCopyResultCallback( |
| 1786 &error, &file_path, &mime_type, &file_type)); | 1828 &error, &file_path, &mime_type, &file_type)); |
| 1787 google_apis::test_util::RunBlockingPoolTask(); | 1829 google_apis::test_util::RunBlockingPoolTask(); |
| 1788 | 1830 |
| 1789 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); | 1831 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); |
| 1790 } | 1832 } |
| 1791 | 1833 |
| 1792 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) { | 1834 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) { |
| 1793 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1835 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1794 | 1836 |
| 1795 ASSERT_TRUE(LoadRootFeedDocument()); | 1837 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1796 | 1838 |
| 1797 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1839 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1798 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1840 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1799 | 1841 |
| 1800 // Store something as cached version of this file. | 1842 // Store something as cached version of this file. |
| 1801 DriveFileError error = DRIVE_FILE_OK; | 1843 DriveFileError error = DRIVE_FILE_OK; |
| 1802 cache_->Store(entry_proto->resource_id(), | 1844 cache_->Store(entry_proto->resource_id(), |
| 1803 entry_proto->file_specific_info().file_md5(), | 1845 entry_proto->file_specific_info().file_md5(), |
| 1804 google_apis::test_util::GetTestFilePath( | 1846 google_apis::test_util::GetTestFilePath( |
| 1805 "chromeos/gdata/root_feed.json"), | 1847 "chromeos/gdata/root_feed.json"), |
| 1806 DriveCache::FILE_OPERATION_COPY, | 1848 DriveCache::FILE_OPERATION_COPY, |
| 1807 google_apis::test_util::CreateCopyResultCallback(&error)); | 1849 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1808 google_apis::test_util::RunBlockingPoolTask(); | 1850 google_apis::test_util::RunBlockingPoolTask(); |
| 1809 EXPECT_EQ(DRIVE_FILE_OK, error); | 1851 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1810 | 1852 |
| 1811 base::FilePath file_path; | 1853 base::FilePath file_path; |
| 1812 std::string mime_type; | 1854 std::string mime_type; |
| 1813 DriveFileType file_type; | 1855 DriveFileType file_type; |
| 1814 file_system_->GetFileByPath(file_in_root, | 1856 file_system_->GetFileByPath(file_in_root, |
| 1815 google_apis::test_util::CreateCopyResultCallback( | 1857 google_apis::test_util::CreateCopyResultCallback( |
| 1816 &error, &file_path, &mime_type, &file_type)); | 1858 &error, &file_path, &mime_type, &file_type)); |
| 1817 google_apis::test_util::RunBlockingPoolTask(); | 1859 google_apis::test_util::RunBlockingPoolTask(); |
| 1818 | 1860 |
| 1819 EXPECT_EQ(DRIVE_FILE_OK, error); | 1861 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1820 EXPECT_EQ(REGULAR_FILE, file_type); | 1862 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1821 } | 1863 } |
| 1822 | 1864 |
| 1823 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) { | 1865 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) { |
| 1824 ASSERT_TRUE(LoadRootFeedDocument()); | 1866 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1825 | 1867 |
| 1826 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1868 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/Document 1.gdoc")); |
| 1827 scoped_ptr<DriveEntryProto> src_entry_proto = | 1869 scoped_ptr<DriveEntryProto> src_entry_proto = |
| 1828 GetEntryInfoByPathSync(file_in_root); | 1870 GetEntryInfoByPathSync(file_in_root); |
| 1829 ASSERT_TRUE(src_entry_proto.get()); | 1871 ASSERT_TRUE(src_entry_proto.get()); |
| 1830 | 1872 |
| 1831 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1873 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1832 base::FilePath file_path; | 1874 base::FilePath file_path; |
| 1833 std::string mime_type; | 1875 std::string mime_type; |
| 1834 DriveFileType file_type; | 1876 DriveFileType file_type; |
| 1835 file_system_->GetFileByPath(file_in_root, | 1877 file_system_->GetFileByPath(file_in_root, |
| 1836 google_apis::test_util::CreateCopyResultCallback( | 1878 google_apis::test_util::CreateCopyResultCallback( |
| 1837 &error, &file_path, &mime_type, &file_type)); | 1879 &error, &file_path, &mime_type, &file_type)); |
| 1838 google_apis::test_util::RunBlockingPoolTask(); | 1880 google_apis::test_util::RunBlockingPoolTask(); |
| 1839 | 1881 |
| 1840 EXPECT_EQ(HOSTED_DOCUMENT, file_type); | 1882 EXPECT_EQ(HOSTED_DOCUMENT, file_type); |
| 1841 EXPECT_FALSE(file_path.empty()); | 1883 EXPECT_FALSE(file_path.empty()); |
| 1842 | 1884 |
| 1843 ASSERT_TRUE(src_entry_proto.get()); | 1885 ASSERT_TRUE(src_entry_proto.get()); |
| 1844 VerifyHostedDocumentJSONFile(*src_entry_proto, file_path); | 1886 VerifyHostedDocumentJSONFile(*src_entry_proto, file_path); |
| 1845 } | 1887 } |
| 1846 | 1888 |
| 1847 TEST_F(DriveFileSystemTest, GetFileByResourceId) { | 1889 TEST_F(DriveFileSystemTest, GetFileByResourceId) { |
| 1848 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1890 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1849 | 1891 |
| 1850 // The transfered file is cached and the change of "offline available" | 1892 // The transfered file is cached and the change of "offline available" |
| 1851 // attribute is notified. | 1893 // attribute is notified. |
| 1852 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1894 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1853 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1895 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1854 | 1896 |
| 1855 ASSERT_TRUE(LoadRootFeedDocument()); | 1897 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1856 | 1898 |
| 1857 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1899 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1858 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1900 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1859 | 1901 |
| 1860 DriveFileError error = DRIVE_FILE_OK; | 1902 DriveFileError error = DRIVE_FILE_OK; |
| 1861 base::FilePath file_path; | 1903 base::FilePath file_path; |
| 1862 std::string mime_type; | 1904 std::string mime_type; |
| 1863 DriveFileType file_type; | 1905 DriveFileType file_type; |
| 1864 file_system_->GetFileByResourceId( | 1906 file_system_->GetFileByResourceId( |
| 1865 entry_proto->resource_id(), | 1907 entry_proto->resource_id(), |
| 1866 DriveClientContext(USER_INITIATED), | 1908 DriveClientContext(USER_INITIATED), |
| 1867 google_apis::test_util::CreateCopyResultCallback( | 1909 google_apis::test_util::CreateCopyResultCallback( |
| 1868 &error, &file_path, &mime_type, &file_type), | 1910 &error, &file_path, &mime_type, &file_type), |
| 1869 google_apis::GetContentCallback()); | 1911 google_apis::GetContentCallback()); |
| 1870 google_apis::test_util::RunBlockingPoolTask(); | 1912 google_apis::test_util::RunBlockingPoolTask(); |
| 1871 | 1913 |
| 1872 EXPECT_EQ(DRIVE_FILE_OK, error); | 1914 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1873 EXPECT_EQ(REGULAR_FILE, file_type); | 1915 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1874 } | 1916 } |
| 1875 | 1917 |
| 1876 TEST_F(DriveFileSystemTest, CancelGetFile) { | 1918 TEST_F(DriveFileSystemTest, CancelGetFile) { |
| 1877 base::FilePath cancel_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1919 base::FilePath cancel_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1878 file_system_->CancelGetFile(cancel_file_path); | 1920 file_system_->CancelGetFile(cancel_file_path); |
| 1879 EXPECT_EQ(cancel_file_path, fake_drive_service_->last_cancelled_file()); | 1921 EXPECT_EQ(cancel_file_path, fake_drive_service_->last_cancelled_file()); |
| 1880 } | 1922 } |
| 1881 | 1923 |
| 1882 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) { | 1924 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) { |
| 1883 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1925 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1884 | 1926 |
| 1885 ASSERT_TRUE(LoadRootFeedDocument()); | 1927 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1886 | 1928 |
| 1887 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1929 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1888 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1930 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1889 | 1931 |
| 1890 // Store something as cached version of this file. | 1932 // Store something as cached version of this file. |
| 1891 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1933 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1892 cache_->Store(entry_proto->resource_id(), | 1934 cache_->Store(entry_proto->resource_id(), |
| 1893 entry_proto->file_specific_info().file_md5(), | 1935 entry_proto->file_specific_info().file_md5(), |
| 1894 google_apis::test_util::GetTestFilePath( | 1936 google_apis::test_util::GetTestFilePath( |
| 1895 "chromeos/gdata/root_feed.json"), | 1937 "chromeos/gdata/root_feed.json"), |
| 1896 DriveCache::FILE_OPERATION_COPY, | 1938 DriveCache::FILE_OPERATION_COPY, |
| 1897 google_apis::test_util::CreateCopyResultCallback(&error)); | 1939 google_apis::test_util::CreateCopyResultCallback(&error)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1916 EXPECT_EQ(DRIVE_FILE_OK, error); | 1958 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1917 EXPECT_EQ(REGULAR_FILE, file_type); | 1959 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1918 } | 1960 } |
| 1919 | 1961 |
| 1920 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) { | 1962 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) { |
| 1921 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1963 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1922 | 1964 |
| 1923 ASSERT_TRUE(LoadRootFeedDocument()); | 1965 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1924 | 1966 |
| 1925 // This is a file defined in root_feed.json. | 1967 // This is a file defined in root_feed.json. |
| 1926 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt")); | 1968 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1927 const std::string kResourceId("file:2_file_resource_id"); | 1969 const std::string kResourceId("file:2_file_resource_id"); |
| 1928 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); | 1970 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); |
| 1929 | 1971 |
| 1930 // Pin the file so it'll be store in "persistent" directory. | 1972 // Pin the file so it'll be store in "persistent" directory. |
| 1931 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1); | 1973 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1); |
| 1932 DriveFileError error = DRIVE_FILE_OK; | 1974 DriveFileError error = DRIVE_FILE_OK; |
| 1933 cache_->Pin(kResourceId, kMd5, | 1975 cache_->Pin(kResourceId, kMd5, |
| 1934 google_apis::test_util::CreateCopyResultCallback(&error)); | 1976 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1935 google_apis::test_util::RunBlockingPoolTask(); | 1977 google_apis::test_util::RunBlockingPoolTask(); |
| 1936 EXPECT_EQ(DRIVE_FILE_OK, error); | 1978 EXPECT_EQ(DRIVE_FILE_OK, error); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1960 EXPECT_EQ(DRIVE_FILE_OK, error); | 2002 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1961 | 2003 |
| 1962 // We'll notify the directory change to the observer upon completion. | 2004 // We'll notify the directory change to the observer upon completion. |
| 1963 EXPECT_CALL(*mock_directory_observer_, | 2005 EXPECT_CALL(*mock_directory_observer_, |
| 1964 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath()))) | 2006 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath()))) |
| 1965 .Times(1); | 2007 .Times(1); |
| 1966 | 2008 |
| 1967 // Check the number of files in the root directory. We'll compare the | 2009 // Check the number of files in the root directory. We'll compare the |
| 1968 // number after updating a file. | 2010 // number after updating a file. |
| 1969 scoped_ptr<DriveEntryProtoVector> root_directory_entries( | 2011 scoped_ptr<DriveEntryProtoVector> root_directory_entries( |
| 1970 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"))); | 2012 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 1971 ASSERT_TRUE(root_directory_entries.get()); | 2013 ASSERT_TRUE(root_directory_entries.get()); |
| 1972 const int num_files_in_root = CountFiles(*root_directory_entries); | 2014 const int num_files_in_root = CountFiles(*root_directory_entries); |
| 1973 | 2015 |
| 1974 // The callback will be called upon completion of | 2016 // The callback will be called upon completion of |
| 1975 // UpdateFileByResourceId(). | 2017 // UpdateFileByResourceId(). |
| 1976 file_system_->UpdateFileByResourceId( | 2018 file_system_->UpdateFileByResourceId( |
| 1977 kResourceId, | 2019 kResourceId, |
| 1978 DriveClientContext(USER_INITIATED), | 2020 DriveClientContext(USER_INITIATED), |
| 1979 google_apis::test_util::CreateCopyResultCallback(&error)); | 2021 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1980 google_apis::test_util::RunBlockingPoolTask(); | 2022 google_apis::test_util::RunBlockingPoolTask(); |
| 1981 EXPECT_EQ(DRIVE_FILE_OK, error); | 2023 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1982 | 2024 |
| 1983 // Make sure that the number of files did not change (i.e. we updated an | 2025 // Make sure that the number of files did not change (i.e. we updated an |
| 1984 // existing file, rather than adding a new file. The number of files | 2026 // existing file, rather than adding a new file. The number of files |
| 1985 // increases if we don't handle the file update right). | 2027 // increases if we don't handle the file update right). |
| 1986 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); | 2028 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); |
| 1987 } | 2029 } |
| 1988 | 2030 |
| 1989 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { | 2031 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { |
| 1990 ASSERT_TRUE(LoadRootFeedDocument()); | 2032 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1991 | 2033 |
| 1992 // This is nonexistent in root_feed.json. | 2034 // This is nonexistent in root_feed.json. |
| 1993 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt")); | 2035 const base::FilePath kFilePath( |
| 2036 FILE_PATH_LITERAL("drive/root/Nonexistent.txt")); | |
| 1994 const std::string kResourceId("file:nonexistent_resource_id"); | 2037 const std::string kResourceId("file:nonexistent_resource_id"); |
| 1995 const std::string kMd5("nonexistent_md5"); | 2038 const std::string kMd5("nonexistent_md5"); |
| 1996 | 2039 |
| 1997 // The callback will be called upon completion of | 2040 // The callback will be called upon completion of |
| 1998 // UpdateFileByResourceId(). | 2041 // UpdateFileByResourceId(). |
| 1999 DriveFileError error = DRIVE_FILE_OK; | 2042 DriveFileError error = DRIVE_FILE_OK; |
| 2000 file_system_->UpdateFileByResourceId( | 2043 file_system_->UpdateFileByResourceId( |
| 2001 kResourceId, | 2044 kResourceId, |
| 2002 DriveClientContext(USER_INITIATED), | 2045 DriveClientContext(USER_INITIATED), |
| 2003 google_apis::test_util::CreateCopyResultCallback(&error)); | 2046 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 2004 google_apis::test_util::RunBlockingPoolTask(); | 2047 google_apis::test_util::RunBlockingPoolTask(); |
| 2005 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 2048 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 2006 } | 2049 } |
| 2007 | 2050 |
| 2008 TEST_F(DriveFileSystemTest, ContentSearch) { | 2051 TEST_F(DriveFileSystemTest, ContentSearch) { |
| 2009 ASSERT_TRUE(LoadRootFeedDocument()); | 2052 ASSERT_TRUE(LoadRootFeedDocument()); |
| 2010 | 2053 |
| 2011 const SearchResultPair kExpectedResults[] = { | 2054 const SearchResultPair kExpectedResults[] = { |
| 2012 { "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", | 2055 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", |
| 2013 true }, | 2056 true }, |
| 2014 { "drive/Directory 1/Sub Directory Folder", true }, | 2057 { "drive/root/Directory 1/Sub Directory Folder", true }, |
| 2015 { "drive/Directory 1/SubDirectory File 1.txt", false }, | 2058 { "drive/root/Directory 1/SubDirectory File 1.txt", false }, |
| 2016 { "drive/Directory 1", true }, | 2059 { "drive/root/Directory 1", true }, |
| 2017 { "drive/Directory 2", true }, | 2060 { "drive/root/Directory 2", true }, |
| 2018 }; | 2061 }; |
| 2019 | 2062 |
| 2020 SearchCallback callback = base::Bind(&DriveSearchCallback, | 2063 SearchCallback callback = base::Bind(&DriveSearchCallback, |
| 2021 &message_loop_, | 2064 &message_loop_, |
| 2022 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), | 2065 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), |
| 2023 GURL()); | 2066 GURL()); |
| 2024 | 2067 |
| 2025 file_system_->Search("Directory", false, GURL(), callback); | 2068 file_system_->Search("Directory", false, GURL(), callback); |
| 2026 message_loop_.Run(); // Wait to get our result. | 2069 message_loop_.Run(); // Wait to get our result. |
| 2027 } | 2070 } |
| 2028 | 2071 |
| 2029 TEST_F(DriveFileSystemTest, ContentSearchWithNewEntry) { | 2072 TEST_F(DriveFileSystemTest, ContentSearchWithNewEntry) { |
| 2030 ASSERT_TRUE(LoadRootFeedDocument()); | 2073 ASSERT_TRUE(LoadRootFeedDocument()); |
| 2031 | 2074 |
| 2032 // Create a new directory in the drive service. | 2075 // Create a new directory in the drive service. |
| 2033 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 2076 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 2034 scoped_ptr<google_apis::ResourceEntry> resource_entry; | 2077 scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| 2035 fake_drive_service_->AddNewDirectory( | 2078 fake_drive_service_->AddNewDirectory( |
| 2036 fake_drive_service_->GetRootResourceId(), // Add to the root directory. | 2079 fake_drive_service_->GetRootResourceId(), // Add to the root directory. |
| 2037 "New Directory 1!", | 2080 "New Directory 1!", |
| 2038 google_apis::test_util::CreateCopyResultCallback( | 2081 google_apis::test_util::CreateCopyResultCallback( |
| 2039 &error, &resource_entry)); | 2082 &error, &resource_entry)); |
| 2040 message_loop_.RunUntilIdle(); | 2083 message_loop_.RunUntilIdle(); |
| 2041 | 2084 |
| 2042 // As the result of the first Search(), only entries in the current file | 2085 // As the result of the first Search(), only entries in the current file |
| 2043 // system snapshot are expected to be returned (i.e. "New Directory 1!" | 2086 // system snapshot are expected to be returned (i.e. "New Directory 1!" |
| 2044 // shouldn't be included in the search result even though it matches | 2087 // shouldn't be included in the search result even though it matches |
| 2045 // "Directory 1". | 2088 // "Directory 1". |
| 2046 const SearchResultPair kExpectedResults[] = { | 2089 const SearchResultPair kExpectedResults[] = { |
| 2047 { "drive/Directory 1", true } | 2090 { "drive/root/Directory 1", true } |
| 2048 }; | 2091 }; |
| 2049 | 2092 |
| 2050 // At the same time, unknown entry should trigger delta feed request. | 2093 // At the same time, unknown entry should trigger delta feed request. |
| 2051 // This will cause notification to directory observers (e.g., File Browser) | 2094 // This will cause notification to directory observers (e.g., File Browser) |
| 2052 // so that they can request search again. | 2095 // so that they can request search again. |
| 2053 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) | 2096 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) |
| 2054 .Times(AtLeast(1)); | 2097 .Times(AtLeast(1)); |
| 2055 | 2098 |
| 2056 SearchCallback callback = base::Bind(&DriveSearchCallback, | 2099 SearchCallback callback = base::Bind(&DriveSearchCallback, |
| 2057 &message_loop_, | 2100 &message_loop_, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2102 google_apis::test_util::RunBlockingPoolTask(); | 2145 google_apis::test_util::RunBlockingPoolTask(); |
| 2103 EXPECT_EQ(DRIVE_FILE_OK, error); | 2146 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 2104 } | 2147 } |
| 2105 | 2148 |
| 2106 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { | 2149 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { |
| 2107 ASSERT_TRUE(LoadRootFeedDocument()); | 2150 ASSERT_TRUE(LoadRootFeedDocument()); |
| 2108 | 2151 |
| 2109 // The transfered file is cached and the change of "offline available" | 2152 // The transfered file is cached and the change of "offline available" |
| 2110 // attribute is notified. | 2153 // attribute is notified. |
| 2111 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 2154 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 2112 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 2155 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 2113 | 2156 |
| 2114 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/File 1.txt")); | 2157 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 2115 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot)); | 2158 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot)); |
| 2116 const int64 file_size = entry_proto->file_info().size(); | 2159 const int64 file_size = entry_proto->file_info().size(); |
| 2117 const std::string& file_resource_id = | 2160 const std::string& file_resource_id = |
| 2118 entry_proto->resource_id(); | 2161 entry_proto->resource_id(); |
| 2119 const std::string& file_md5 = entry_proto->file_specific_info().file_md5(); | 2162 const std::string& file_md5 = entry_proto->file_specific_info().file_md5(); |
| 2120 | 2163 |
| 2121 // A dirty file is created on close. | 2164 // A dirty file is created on close. |
| 2122 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id)) | 2165 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id)) |
| 2123 .Times(1); | 2166 .Times(1); |
| 2124 | 2167 |
| 2125 // Pretend we have enough space. | 2168 // Pretend we have enough space. |
| 2126 fake_free_disk_space_getter_->set_fake_free_disk_space( | 2169 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 2127 file_size + kMinFreeSpace); | 2170 file_size + kMinFreeSpace); |
| 2128 | 2171 |
| 2129 // Open kFileInRoot ("drive/File 1.txt"). | 2172 // Open kFileInRoot ("drive/root/File 1.txt"). |
| 2130 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 2173 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 2131 base::FilePath file_path; | 2174 base::FilePath file_path; |
| 2132 file_system_->OpenFile( | 2175 file_system_->OpenFile( |
| 2133 kFileInRoot, | 2176 kFileInRoot, |
| 2134 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | 2177 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
| 2135 google_apis::test_util::RunBlockingPoolTask(); | 2178 google_apis::test_util::RunBlockingPoolTask(); |
| 2136 const base::FilePath opened_file_path = file_path; | 2179 const base::FilePath opened_file_path = file_path; |
| 2137 | 2180 |
| 2138 // Verify that the file was properly opened. | 2181 // Verify that the file was properly opened. |
| 2139 EXPECT_EQ(DRIVE_FILE_OK, error); | 2182 EXPECT_EQ(DRIVE_FILE_OK, error); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 2162 EXPECT_TRUE(cache_entry.is_persistent()); | 2205 EXPECT_TRUE(cache_entry.is_persistent()); |
| 2163 | 2206 |
| 2164 base::FilePath cache_file_path; | 2207 base::FilePath cache_file_path; |
| 2165 cache_->GetFile(file_resource_id, file_md5, | 2208 cache_->GetFile(file_resource_id, file_md5, |
| 2166 google_apis::test_util::CreateCopyResultCallback( | 2209 google_apis::test_util::CreateCopyResultCallback( |
| 2167 &error, &cache_file_path)); | 2210 &error, &cache_file_path)); |
| 2168 google_apis::test_util::RunBlockingPoolTask(); | 2211 google_apis::test_util::RunBlockingPoolTask(); |
| 2169 EXPECT_EQ(DRIVE_FILE_OK, error); | 2212 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 2170 EXPECT_EQ(cache_file_path, opened_file_path); | 2213 EXPECT_EQ(cache_file_path, opened_file_path); |
| 2171 | 2214 |
| 2172 // Close kFileInRoot ("drive/File 1.txt"). | 2215 // Close kFileInRoot ("drive/root/File 1.txt"). |
| 2173 file_system_->CloseFile( | 2216 file_system_->CloseFile( |
| 2174 kFileInRoot, | 2217 kFileInRoot, |
| 2175 google_apis::test_util::CreateCopyResultCallback(&error)); | 2218 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 2176 google_apis::test_util::RunBlockingPoolTask(); | 2219 google_apis::test_util::RunBlockingPoolTask(); |
| 2177 | 2220 |
| 2178 // Verify that the file was properly closed. | 2221 // Verify that the file was properly closed. |
| 2179 EXPECT_EQ(DRIVE_FILE_OK, error); | 2222 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 2180 | 2223 |
| 2181 // Verify that the cache state was changed as expected. | 2224 // Verify that the cache state was changed as expected. |
| 2182 EXPECT_TRUE(GetCacheEntryFromOriginThread(file_resource_id, file_md5, | 2225 EXPECT_TRUE(GetCacheEntryFromOriginThread(file_resource_id, file_md5, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2215 | 2258 |
| 2216 // An app for foo.exe should now be found, as the registry was loaded. | 2259 // An app for foo.exe should now be found, as the registry was loaded. |
| 2217 drive_webapps_registry_->GetWebAppsForFile( | 2260 drive_webapps_registry_->GetWebAppsForFile( |
| 2218 base::FilePath(FILE_PATH_LITERAL("foo.exe")), | 2261 base::FilePath(FILE_PATH_LITERAL("foo.exe")), |
| 2219 "" /* mime_type */, | 2262 "" /* mime_type */, |
| 2220 &apps); | 2263 &apps); |
| 2221 EXPECT_EQ(1U, apps.size()); | 2264 EXPECT_EQ(1U, apps.size()); |
| 2222 } | 2265 } |
| 2223 | 2266 |
| 2224 } // namespace drive | 2267 } // namespace drive |
| OLD | NEW |