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; | |
|
hidehiko
2013/04/02 08:09:30
Unnecessary variable?
Haruki Sato
2013/04/03 04:33:42
It actually is necessary one, just moved from L441
| |
| 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; |
| 1072 file_system_->TransferFileFromLocalToRemote( | 1103 file_system_->TransferFileFromLocalToRemote( |
| 1073 local_src_file_path, | 1104 local_src_file_path, |
| 1074 remote_dest_file_path, | 1105 remote_dest_file_path, |
| 1075 google_apis::test_util::CreateCopyResultCallback(&error)); | 1106 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1076 google_apis::test_util::RunBlockingPoolTask(); | 1107 google_apis::test_util::RunBlockingPoolTask(); |
| 1077 | 1108 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1093 const std::string kEditUrl = | 1124 const std::string kEditUrl = |
| 1094 "https://3_document_self_link/document:5_document_resource_id"; | 1125 "https://3_document_self_link/document:5_document_resource_id"; |
| 1095 const std::string kResourceId = "document:5_document_resource_id"; | 1126 const std::string kResourceId = "document:5_document_resource_id"; |
| 1096 const std::string kContent = | 1127 const std::string kContent = |
| 1097 base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}", | 1128 base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}", |
| 1098 kEditUrl.c_str(), kResourceId.c_str()); | 1129 kEditUrl.c_str(), kResourceId.c_str()); |
| 1099 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); | 1130 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); |
| 1100 | 1131 |
| 1101 // Confirm that the remote file does not exist. | 1132 // Confirm that the remote file does not exist. |
| 1102 const base::FilePath remote_dest_file_path( | 1133 const base::FilePath remote_dest_file_path( |
| 1103 FILE_PATH_LITERAL("drive/Directory 1/Document 1.gdoc")); | 1134 FILE_PATH_LITERAL("drive/root/Directory 1/Document 1.gdoc")); |
| 1104 EXPECT_FALSE(EntryExists(remote_dest_file_path)); | 1135 EXPECT_FALSE(EntryExists(remote_dest_file_path)); |
| 1105 | 1136 |
| 1106 // We'll add a file to the Drive root and then move to "Directory 1". | 1137 // We'll add a file to the Drive root and then move to "Directory 1". |
| 1107 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1138 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1108 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1139 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1109 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1140 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1110 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1141 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1142 .Times(1); | |
| 1111 | 1143 |
| 1112 // We'll copy a hosted document using CopyHostedDocument. | 1144 // We'll copy a hosted document using CopyHostedDocument. |
| 1113 // ".gdoc" suffix should be stripped when copying. | 1145 // ".gdoc" suffix should be stripped when copying. |
| 1114 scoped_ptr<base::Value> value = | 1146 scoped_ptr<base::Value> value = |
| 1115 google_apis::test_util::LoadJSONFile( | 1147 google_apis::test_util::LoadJSONFile( |
| 1116 "chromeos/gdata/uploaded_document.json"); | 1148 "chromeos/gdata/uploaded_document.json"); |
| 1117 scoped_ptr<google_apis::ResourceEntry> resource_entry = | 1149 scoped_ptr<google_apis::ResourceEntry> resource_entry = |
| 1118 google_apis::ResourceEntry::ExtractAndParse(*value); | 1150 google_apis::ResourceEntry::ExtractAndParse(*value); |
| 1119 | 1151 |
| 1120 | 1152 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1131 // Now the remote file should exist. | 1163 // Now the remote file should exist. |
| 1132 EXPECT_TRUE(EntryExists(remote_dest_file_path)); | 1164 EXPECT_TRUE(EntryExists(remote_dest_file_path)); |
| 1133 } | 1165 } |
| 1134 | 1166 |
| 1135 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { | 1167 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { |
| 1136 ASSERT_TRUE(LoadRootFeedDocument()); | 1168 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1137 | 1169 |
| 1138 // The transfered file is cached and the change of "offline available" | 1170 // The transfered file is cached and the change of "offline available" |
| 1139 // attribute is notified. | 1171 // attribute is notified. |
| 1140 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1172 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1141 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1173 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1142 | 1174 |
| 1143 base::ScopedTempDir temp_dir; | 1175 base::ScopedTempDir temp_dir; |
| 1144 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1176 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1145 base::FilePath local_dest_file_path = | 1177 base::FilePath local_dest_file_path = |
| 1146 temp_dir.path().AppendASCII("local_copy.txt"); | 1178 temp_dir.path().AppendASCII("local_copy.txt"); |
| 1147 | 1179 |
| 1148 base::FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1180 base::FilePath remote_src_file_path( |
| 1181 FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
| 1149 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync( | 1182 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync( |
| 1150 remote_src_file_path); | 1183 remote_src_file_path); |
| 1151 const int64 file_size = file->file_info().size(); | 1184 const int64 file_size = file->file_info().size(); |
| 1152 | 1185 |
| 1153 // Pretend we have enough space. | 1186 // Pretend we have enough space. |
| 1154 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1187 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 1155 file_size + kMinFreeSpace); | 1188 file_size + kMinFreeSpace); |
| 1156 | 1189 |
| 1157 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1190 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1158 file_system_->TransferFileFromRemoteToLocal( | 1191 file_system_->TransferFileFromRemoteToLocal( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1184 } | 1217 } |
| 1185 | 1218 |
| 1186 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { | 1219 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { |
| 1187 ASSERT_TRUE(LoadRootFeedDocument()); | 1220 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1188 | 1221 |
| 1189 base::ScopedTempDir temp_dir; | 1222 base::ScopedTempDir temp_dir; |
| 1190 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1223 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1191 base::FilePath local_dest_file_path = | 1224 base::FilePath local_dest_file_path = |
| 1192 temp_dir.path().AppendASCII("local_copy.txt"); | 1225 temp_dir.path().AppendASCII("local_copy.txt"); |
| 1193 base::FilePath remote_src_file_path( | 1226 base::FilePath remote_src_file_path( |
| 1194 FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1227 FILE_PATH_LITERAL("drive/root/Document 1.gdoc")); |
| 1195 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1228 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1196 file_system_->TransferFileFromRemoteToLocal( | 1229 file_system_->TransferFileFromRemoteToLocal( |
| 1197 remote_src_file_path, | 1230 remote_src_file_path, |
| 1198 local_dest_file_path, | 1231 local_dest_file_path, |
| 1199 google_apis::test_util::CreateCopyResultCallback(&error)); | 1232 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1200 google_apis::test_util::RunBlockingPoolTask(); | 1233 google_apis::test_util::RunBlockingPoolTask(); |
| 1201 | 1234 |
| 1202 EXPECT_EQ(DRIVE_FILE_OK, error); | 1235 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1203 | 1236 |
| 1204 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( | 1237 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( |
| 1205 remote_src_file_path); | 1238 remote_src_file_path); |
| 1206 ASSERT_TRUE(entry_proto.get()); | 1239 ASSERT_TRUE(entry_proto.get()); |
| 1207 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); | 1240 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); |
| 1208 } | 1241 } |
| 1209 | 1242 |
| 1210 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { | 1243 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { |
| 1211 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1244 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")); | 1245 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1213 | 1246 |
| 1214 ASSERT_TRUE(LoadRootFeedDocument()); | 1247 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1215 | 1248 |
| 1216 EXPECT_FALSE(EntryExists(src_file_path)); | 1249 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1217 | 1250 |
| 1218 DriveFileError error = DRIVE_FILE_OK; | 1251 DriveFileError error = DRIVE_FILE_OK; |
| 1219 file_system_->Copy( | 1252 file_system_->Copy( |
| 1220 src_file_path, | 1253 src_file_path, |
| 1221 dest_file_path, | 1254 dest_file_path, |
| 1222 google_apis::test_util::CreateCopyResultCallback(&error)); | 1255 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1223 google_apis::test_util::RunBlockingPoolTask(); | 1256 google_apis::test_util::RunBlockingPoolTask(); |
| 1224 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 1257 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 1225 | 1258 |
| 1226 EXPECT_FALSE(EntryExists(src_file_path)); | 1259 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1227 EXPECT_FALSE(EntryExists(dest_file_path)); | 1260 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1228 } | 1261 } |
| 1229 | 1262 |
| 1230 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { | 1263 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { |
| 1231 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1264 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1232 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1265 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy")); |
| 1233 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1266 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); |
| 1234 | 1267 |
| 1235 ASSERT_TRUE(LoadRootFeedDocument()); | 1268 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1236 | 1269 |
| 1237 ASSERT_TRUE(EntryExists(src_file_path)); | 1270 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1238 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1271 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1239 src_file_path); | 1272 src_file_path); |
| 1240 ASSERT_TRUE(src_entry_proto.get()); | 1273 ASSERT_TRUE(src_entry_proto.get()); |
| 1241 std::string src_file_path_resource_id = | 1274 std::string src_file_path_resource_id = |
| 1242 src_entry_proto->resource_id(); | 1275 src_entry_proto->resource_id(); |
| 1243 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1276 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1244 | 1277 |
| 1245 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1278 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1246 | 1279 |
| 1247 DriveFileError error = DRIVE_FILE_OK; | 1280 DriveFileError error = DRIVE_FILE_OK; |
| 1248 file_system_->Move( | 1281 file_system_->Move( |
| 1249 src_file_path, | 1282 src_file_path, |
| 1250 dest_file_path, | 1283 dest_file_path, |
| 1251 google_apis::test_util::CreateCopyResultCallback(&error)); | 1284 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1252 google_apis::test_util::RunBlockingPoolTask(); | 1285 google_apis::test_util::RunBlockingPoolTask(); |
| 1253 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 1286 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 1254 | 1287 |
| 1255 EXPECT_TRUE(EntryExists(src_file_path)); | 1288 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1256 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1289 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1257 EXPECT_FALSE(EntryExists(dest_file_path)); | 1290 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1258 } | 1291 } |
| 1259 | 1292 |
| 1260 // Test the case where the parent of |dest_file_path| is an existing file, | 1293 // Test the case where the parent of |dest_file_path| is an existing file, |
| 1261 // not a directory. | 1294 // not a directory. |
| 1262 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { | 1295 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { |
| 1263 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1296 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Document 1.gdoc")); |
| 1264 base::FilePath dest_parent_path( | 1297 base::FilePath dest_parent_path( |
| 1265 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); | 1298 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); |
| 1266 base::FilePath dest_file_path(FILE_PATH_LITERAL( | 1299 base::FilePath dest_file_path(FILE_PATH_LITERAL( |
| 1267 "drive/Duplicate Name.txt/Document 1.gdoc")); | 1300 "drive/root/Duplicate Name.txt/Document 1.gdoc")); |
| 1268 | 1301 |
| 1269 ASSERT_TRUE(LoadRootFeedDocument()); | 1302 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1270 | 1303 |
| 1271 ASSERT_TRUE(EntryExists(src_file_path)); | 1304 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1272 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1305 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1273 src_file_path); | 1306 src_file_path); |
| 1274 ASSERT_TRUE(src_entry_proto.get()); | 1307 ASSERT_TRUE(src_entry_proto.get()); |
| 1275 std::string src_file_resource_id = | 1308 std::string src_file_resource_id = |
| 1276 src_entry_proto->resource_id(); | 1309 src_entry_proto->resource_id(); |
| 1277 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1310 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1291 | 1324 |
| 1292 EXPECT_TRUE(EntryExists(src_file_path)); | 1325 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1293 EXPECT_TRUE(EntryExists(src_file_path)); | 1326 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1294 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1327 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1295 | 1328 |
| 1296 EXPECT_FALSE(EntryExists(dest_file_path)); | 1329 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1297 } | 1330 } |
| 1298 | 1331 |
| 1299 TEST_F(DriveFileSystemTest, RenameFile) { | 1332 TEST_F(DriveFileSystemTest, RenameFile) { |
| 1300 const base::FilePath src_file_path( | 1333 const base::FilePath src_file_path( |
| 1301 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1334 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 1302 const base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1335 const base::FilePath src_parent_path( |
| 1336 FILE_PATH_LITERAL("drive/root/Directory 1")); | |
| 1303 const base::FilePath dest_file_path( | 1337 const base::FilePath dest_file_path( |
| 1304 FILE_PATH_LITERAL("drive/Directory 1/Test.log")); | 1338 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 1305 | 1339 |
| 1306 ASSERT_TRUE(LoadRootFeedDocument()); | 1340 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1307 | 1341 |
| 1308 ASSERT_TRUE(EntryExists(src_file_path)); | 1342 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1309 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1343 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1310 src_file_path); | 1344 src_file_path); |
| 1311 ASSERT_TRUE(src_entry_proto.get()); | 1345 ASSERT_TRUE(src_entry_proto.get()); |
| 1312 std::string src_file_resource_id = | 1346 std::string src_file_resource_id = |
| 1313 src_entry_proto->resource_id(); | 1347 src_entry_proto->resource_id(); |
| 1314 | 1348 |
| 1315 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1349 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1316 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1350 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1351 .Times(1); | |
| 1317 | 1352 |
| 1318 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1353 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1319 file_system_->Move( | 1354 file_system_->Move( |
| 1320 src_file_path, | 1355 src_file_path, |
| 1321 dest_file_path, | 1356 dest_file_path, |
| 1322 google_apis::test_util::CreateCopyResultCallback(&error)); | 1357 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1323 google_apis::test_util::RunBlockingPoolTask(); | 1358 google_apis::test_util::RunBlockingPoolTask(); |
| 1324 EXPECT_EQ(DRIVE_FILE_OK, error); | 1359 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1325 | 1360 |
| 1326 EXPECT_FALSE(EntryExists(src_file_path)); | 1361 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1327 EXPECT_TRUE(EntryExists(dest_file_path)); | 1362 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1328 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1363 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1329 } | 1364 } |
| 1330 | 1365 |
| 1331 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) { | 1366 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) { |
| 1332 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1367 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")); | 1368 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 1334 base::FilePath dest_file_path( | 1369 base::FilePath dest_file_path( |
| 1335 FILE_PATH_LITERAL("drive/Directory 1/Test.log")); | 1370 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 1336 | 1371 |
| 1337 ASSERT_TRUE(LoadRootFeedDocument()); | 1372 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1338 | 1373 |
| 1339 ASSERT_TRUE(EntryExists(src_file_path)); | 1374 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1340 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1375 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1341 src_file_path); | 1376 src_file_path); |
| 1342 ASSERT_TRUE(src_entry_proto.get()); | 1377 ASSERT_TRUE(src_entry_proto.get()); |
| 1343 std::string src_file_resource_id = | 1378 std::string src_file_resource_id = |
| 1344 src_entry_proto->resource_id(); | 1379 src_entry_proto->resource_id(); |
| 1345 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1380 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1346 | 1381 |
| 1347 ASSERT_TRUE(EntryExists(dest_parent_path)); | 1382 ASSERT_TRUE(EntryExists(dest_parent_path)); |
| 1348 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( | 1383 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( |
| 1349 dest_parent_path); | 1384 dest_parent_path); |
| 1350 ASSERT_TRUE(dest_parent_proto.get()); | 1385 ASSERT_TRUE(dest_parent_proto.get()); |
| 1351 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); | 1386 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); |
| 1352 EXPECT_FALSE(dest_parent_proto->download_url().empty()); | 1387 EXPECT_FALSE(dest_parent_proto->download_url().empty()); |
| 1353 | 1388 |
| 1354 // Expect notification for both source and destination directories. | 1389 // Expect notification for both source and destination directories. |
| 1355 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1390 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1356 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1391 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1357 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1392 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1358 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1393 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1394 .Times(1); | |
| 1359 | 1395 |
| 1360 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1396 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1361 file_system_->Move( | 1397 file_system_->Move( |
| 1362 src_file_path, | 1398 src_file_path, |
| 1363 dest_file_path, | 1399 dest_file_path, |
| 1364 google_apis::test_util::CreateCopyResultCallback(&error)); | 1400 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1365 google_apis::test_util::RunBlockingPoolTask(); | 1401 google_apis::test_util::RunBlockingPoolTask(); |
| 1366 EXPECT_EQ(DRIVE_FILE_OK, error); | 1402 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1367 | 1403 |
| 1368 EXPECT_FALSE(EntryExists(src_file_path)); | 1404 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1369 EXPECT_TRUE(EntryExists(dest_file_path)); | 1405 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1370 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1406 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1371 } | 1407 } |
| 1372 | 1408 |
| 1373 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) { | 1409 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) { |
| 1374 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1410 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 1375 base::FilePath src_file_path( | 1411 base::FilePath src_file_path( |
| 1376 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1412 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 1377 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1413 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1378 | 1414 |
| 1379 ASSERT_TRUE(LoadRootFeedDocument()); | 1415 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1380 | 1416 |
| 1381 ASSERT_TRUE(EntryExists(src_file_path)); | 1417 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1382 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1418 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1383 src_file_path); | 1419 src_file_path); |
| 1384 ASSERT_TRUE(src_entry_proto.get()); | 1420 ASSERT_TRUE(src_entry_proto.get()); |
| 1385 std::string src_file_resource_id = | 1421 std::string src_file_resource_id = |
| 1386 src_entry_proto->resource_id(); | 1422 src_entry_proto->resource_id(); |
| 1387 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1423 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1388 | 1424 |
| 1389 ASSERT_TRUE(EntryExists(src_parent_path)); | 1425 ASSERT_TRUE(EntryExists(src_parent_path)); |
| 1390 scoped_ptr<DriveEntryProto> src_parent_proto = GetEntryInfoByPathSync( | 1426 scoped_ptr<DriveEntryProto> src_parent_proto = GetEntryInfoByPathSync( |
| 1391 src_parent_path); | 1427 src_parent_path); |
| 1392 ASSERT_TRUE(src_parent_proto.get()); | 1428 ASSERT_TRUE(src_parent_proto.get()); |
| 1393 ASSERT_TRUE(src_parent_proto->file_info().is_directory()); | 1429 ASSERT_TRUE(src_parent_proto->file_info().is_directory()); |
| 1394 EXPECT_FALSE(src_parent_proto->download_url().empty()); | 1430 EXPECT_FALSE(src_parent_proto->download_url().empty()); |
| 1395 | 1431 |
| 1396 // Expect notification for both source and destination directories. | 1432 // Expect notification for both source and destination directories. |
| 1397 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1433 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1398 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1434 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1399 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1435 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1400 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1436 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1437 .Times(1); | |
| 1401 | 1438 |
| 1402 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1439 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1403 file_system_->Move( | 1440 file_system_->Move( |
| 1404 src_file_path, | 1441 src_file_path, |
| 1405 dest_file_path, | 1442 dest_file_path, |
| 1406 google_apis::test_util::CreateCopyResultCallback(&error)); | 1443 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1407 google_apis::test_util::RunBlockingPoolTask(); | 1444 google_apis::test_util::RunBlockingPoolTask(); |
| 1408 EXPECT_EQ(DRIVE_FILE_OK, error); | 1445 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1409 | 1446 |
| 1410 EXPECT_FALSE(EntryExists(src_file_path)); | 1447 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1411 ASSERT_TRUE(EntryExists(dest_file_path)); | 1448 ASSERT_TRUE(EntryExists(dest_file_path)); |
| 1412 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1449 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1413 } | 1450 } |
| 1414 | 1451 |
| 1415 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) { | 1452 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) { |
| 1416 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1453 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 1417 base::FilePath src_file_path( | 1454 base::FilePath src_file_path( |
| 1418 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1455 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 1419 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/New Folder 1")); | 1456 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); |
| 1420 base::FilePath dest_file_path( | 1457 base::FilePath dest_file_path( |
| 1421 FILE_PATH_LITERAL("drive/New Folder 1/Test.log")); | 1458 FILE_PATH_LITERAL("drive/root/New Folder 1/Test.log")); |
| 1422 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1459 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1423 | 1460 |
| 1424 ASSERT_TRUE(LoadRootFeedDocument()); | 1461 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1425 | 1462 |
| 1426 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1463 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1427 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1464 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1428 | 1465 |
| 1429 AddDirectoryFromFile(dest_parent_path, | 1466 AddDirectoryFromFile(dest_parent_path, |
| 1430 "chromeos/gdata/directory_entry_atom.json"); | 1467 "chromeos/gdata/directory_entry_atom.json"); |
| 1431 | 1468 |
| 1432 ASSERT_TRUE(EntryExists(src_file_path)); | 1469 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1433 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1470 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1434 src_file_path); | 1471 src_file_path); |
| 1435 ASSERT_TRUE(src_entry_proto.get()); | 1472 ASSERT_TRUE(src_entry_proto.get()); |
| 1436 std::string src_file_resource_id = | 1473 std::string src_file_resource_id = |
| 1437 src_entry_proto->resource_id(); | 1474 src_entry_proto->resource_id(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1448 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( | 1485 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( |
| 1449 dest_parent_path); | 1486 dest_parent_path); |
| 1450 ASSERT_TRUE(dest_parent_proto.get()); | 1487 ASSERT_TRUE(dest_parent_proto.get()); |
| 1451 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); | 1488 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); |
| 1452 EXPECT_FALSE(dest_parent_proto->download_url().empty()); | 1489 EXPECT_FALSE(dest_parent_proto->download_url().empty()); |
| 1453 | 1490 |
| 1454 EXPECT_FALSE(EntryExists(interim_file_path)); | 1491 EXPECT_FALSE(EntryExists(interim_file_path)); |
| 1455 | 1492 |
| 1456 // Expect notification for both source and destination directories. | 1493 // Expect notification for both source and destination directories. |
| 1457 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1494 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1458 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1495 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 1496 .Times(1); | |
| 1459 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1497 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1460 Eq(base::FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); | 1498 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1"))))) |
| 1499 .Times(1); | |
| 1461 | 1500 |
| 1462 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1501 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1463 file_system_->Move( | 1502 file_system_->Move( |
| 1464 src_file_path, | 1503 src_file_path, |
| 1465 dest_file_path, | 1504 dest_file_path, |
| 1466 google_apis::test_util::CreateCopyResultCallback(&error)); | 1505 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1467 google_apis::test_util::RunBlockingPoolTask(); | 1506 google_apis::test_util::RunBlockingPoolTask(); |
| 1468 EXPECT_EQ(DRIVE_FILE_OK, error); | 1507 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1469 | 1508 |
| 1470 EXPECT_FALSE(EntryExists(src_file_path)); | 1509 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1471 EXPECT_FALSE(EntryExists(interim_file_path)); | 1510 EXPECT_FALSE(EntryExists(interim_file_path)); |
| 1472 | 1511 |
| 1473 EXPECT_FALSE(EntryExists(src_file_path)); | 1512 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1474 EXPECT_TRUE(EntryExists(dest_file_path)); | 1513 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1475 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1514 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1476 } | 1515 } |
| 1477 | 1516 |
| 1478 TEST_F(DriveFileSystemTest, MoveNotExistingFile) { | 1517 TEST_F(DriveFileSystemTest, MoveNotExistingFile) { |
| 1479 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1518 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")); | 1519 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1481 | 1520 |
| 1482 ASSERT_TRUE(LoadRootFeedDocument()); | 1521 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1483 | 1522 |
| 1484 EXPECT_FALSE(EntryExists(src_file_path)); | 1523 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1485 | 1524 |
| 1486 DriveFileError error = DRIVE_FILE_OK; | 1525 DriveFileError error = DRIVE_FILE_OK; |
| 1487 file_system_->Move( | 1526 file_system_->Move( |
| 1488 src_file_path, | 1527 src_file_path, |
| 1489 dest_file_path, | 1528 dest_file_path, |
| 1490 google_apis::test_util::CreateCopyResultCallback(&error)); | 1529 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1491 google_apis::test_util::RunBlockingPoolTask(); | 1530 google_apis::test_util::RunBlockingPoolTask(); |
| 1492 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 1531 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 1493 | 1532 |
| 1494 EXPECT_FALSE(EntryExists(src_file_path)); | 1533 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1495 EXPECT_FALSE(EntryExists(dest_file_path)); | 1534 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1496 } | 1535 } |
| 1497 | 1536 |
| 1498 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) { | 1537 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) { |
| 1499 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1538 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1500 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1539 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy")); |
| 1501 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1540 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); |
| 1502 | 1541 |
| 1503 ASSERT_TRUE(LoadRootFeedDocument()); | 1542 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1504 | 1543 |
| 1505 ASSERT_TRUE(EntryExists(src_file_path)); | 1544 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1506 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1545 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1507 src_file_path); | 1546 src_file_path); |
| 1508 ASSERT_TRUE(src_entry_proto.get()); | 1547 ASSERT_TRUE(src_entry_proto.get()); |
| 1509 std::string src_file_resource_id = | 1548 std::string src_file_resource_id = |
| 1510 src_entry_proto->resource_id(); | 1549 src_entry_proto->resource_id(); |
| 1511 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1550 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1512 | 1551 |
| 1513 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1552 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1514 | 1553 |
| 1515 DriveFileError error = DRIVE_FILE_OK; | 1554 DriveFileError error = DRIVE_FILE_OK; |
| 1516 file_system_->Move( | 1555 file_system_->Move( |
| 1517 src_file_path, | 1556 src_file_path, |
| 1518 dest_file_path, | 1557 dest_file_path, |
| 1519 google_apis::test_util::CreateCopyResultCallback(&error)); | 1558 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1520 google_apis::test_util::RunBlockingPoolTask(); | 1559 google_apis::test_util::RunBlockingPoolTask(); |
| 1521 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 1560 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 1522 | 1561 |
| 1523 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1562 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1524 EXPECT_FALSE(EntryExists(dest_file_path)); | 1563 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1525 } | 1564 } |
| 1526 | 1565 |
| 1527 // Test the case where the parent of |dest_file_path| is a existing file, | 1566 // Test the case where the parent of |dest_file_path| is a existing file, |
| 1528 // not a directory. | 1567 // not a directory. |
| 1529 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) { | 1568 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) { |
| 1530 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1569 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1531 base::FilePath dest_parent_path( | 1570 base::FilePath dest_parent_path( |
| 1532 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); | 1571 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); |
| 1533 base::FilePath dest_file_path(FILE_PATH_LITERAL( | 1572 base::FilePath dest_file_path(FILE_PATH_LITERAL( |
| 1534 "drive/Duplicate Name.txt/Test.log")); | 1573 "drive/root/Duplicate Name.txt/Test.log")); |
| 1535 | 1574 |
| 1536 ASSERT_TRUE(LoadRootFeedDocument()); | 1575 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1537 | 1576 |
| 1538 ASSERT_TRUE(EntryExists(src_file_path)); | 1577 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1539 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1578 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1540 src_file_path); | 1579 src_file_path); |
| 1541 ASSERT_TRUE(src_entry_proto.get()); | 1580 ASSERT_TRUE(src_entry_proto.get()); |
| 1542 std::string src_file_resource_id = | 1581 std::string src_file_resource_id = |
| 1543 src_entry_proto->resource_id(); | 1582 src_entry_proto->resource_id(); |
| 1544 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1583 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); | 1596 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error); |
| 1558 | 1597 |
| 1559 EXPECT_TRUE(EntryExists(src_file_path)); | 1598 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1560 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1599 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1561 EXPECT_FALSE(EntryExists(dest_file_path)); | 1600 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1562 } | 1601 } |
| 1563 | 1602 |
| 1564 TEST_F(DriveFileSystemTest, RemoveEntries) { | 1603 TEST_F(DriveFileSystemTest, RemoveEntries) { |
| 1565 ASSERT_TRUE(LoadRootFeedDocument()); | 1604 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1566 | 1605 |
| 1567 base::FilePath nonexisting_file(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1606 base::FilePath nonexisting_file( |
| 1568 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1607 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| 1569 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/Directory 1")); | 1608 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1609 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/root/Directory 1")); | |
| 1570 base::FilePath file_in_subdir( | 1610 base::FilePath file_in_subdir( |
| 1571 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); | 1611 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 1572 | 1612 |
| 1573 ASSERT_TRUE(EntryExists(file_in_root)); | 1613 ASSERT_TRUE(EntryExists(file_in_root)); |
| 1574 scoped_ptr<DriveEntryProto> file_in_root_proto = GetEntryInfoByPathSync( | 1614 scoped_ptr<DriveEntryProto> file_in_root_proto = GetEntryInfoByPathSync( |
| 1575 file_in_root); | 1615 file_in_root); |
| 1576 ASSERT_TRUE(file_in_root_proto.get()); | 1616 ASSERT_TRUE(file_in_root_proto.get()); |
| 1577 | 1617 |
| 1578 ASSERT_TRUE(EntryExists(dir_in_root)); | 1618 ASSERT_TRUE(EntryExists(dir_in_root)); |
| 1579 scoped_ptr<DriveEntryProto> dir_in_root_proto = GetEntryInfoByPathSync( | 1619 scoped_ptr<DriveEntryProto> dir_in_root_proto = GetEntryInfoByPathSync( |
| 1580 dir_in_root); | 1620 dir_in_root); |
| 1581 ASSERT_TRUE(dir_in_root_proto.get()); | 1621 ASSERT_TRUE(dir_in_root_proto.get()); |
| 1582 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory()); | 1622 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory()); |
| 1583 | 1623 |
| 1584 ASSERT_TRUE(EntryExists(file_in_subdir)); | 1624 ASSERT_TRUE(EntryExists(file_in_subdir)); |
| 1585 scoped_ptr<DriveEntryProto> file_in_subdir_proto = GetEntryInfoByPathSync( | 1625 scoped_ptr<DriveEntryProto> file_in_subdir_proto = GetEntryInfoByPathSync( |
| 1586 file_in_subdir); | 1626 file_in_subdir); |
| 1587 ASSERT_TRUE(file_in_subdir_proto.get()); | 1627 ASSERT_TRUE(file_in_subdir_proto.get()); |
| 1588 | 1628 |
| 1589 // Once for file in root and once for file... | 1629 // Once for file in root and once for file... |
| 1590 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1630 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1591 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(2); | 1631 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2); |
| 1592 | 1632 |
| 1593 // Remove first file in root. | 1633 // Remove first file in root. |
| 1594 EXPECT_TRUE(RemoveEntry(file_in_root)); | 1634 EXPECT_TRUE(RemoveEntry(file_in_root)); |
| 1595 EXPECT_FALSE(EntryExists(file_in_root)); | 1635 EXPECT_FALSE(EntryExists(file_in_root)); |
| 1596 EXPECT_TRUE(EntryExists(dir_in_root)); | 1636 EXPECT_TRUE(EntryExists(dir_in_root)); |
| 1597 EXPECT_TRUE(EntryExists(file_in_subdir)); | 1637 EXPECT_TRUE(EntryExists(file_in_subdir)); |
| 1598 | 1638 |
| 1599 // Remove directory. | 1639 // Remove directory. |
| 1600 EXPECT_TRUE(RemoveEntry(dir_in_root)); | 1640 EXPECT_TRUE(RemoveEntry(dir_in_root)); |
| 1601 EXPECT_FALSE(EntryExists(file_in_root)); | 1641 EXPECT_FALSE(EntryExists(file_in_root)); |
| 1602 EXPECT_FALSE(EntryExists(dir_in_root)); | 1642 EXPECT_FALSE(EntryExists(dir_in_root)); |
| 1603 EXPECT_FALSE(EntryExists(file_in_subdir)); | 1643 EXPECT_FALSE(EntryExists(file_in_subdir)); |
| 1604 | 1644 |
| 1605 // Try removing file in already removed subdirectory. | 1645 // Try removing file in already removed subdirectory. |
| 1606 EXPECT_FALSE(RemoveEntry(file_in_subdir)); | 1646 EXPECT_FALSE(RemoveEntry(file_in_subdir)); |
| 1607 | 1647 |
| 1608 // Try removing non-existing file. | 1648 // Try removing non-existing file. |
| 1609 EXPECT_FALSE(RemoveEntry(nonexisting_file)); | 1649 EXPECT_FALSE(RemoveEntry(nonexisting_file)); |
| 1610 | 1650 |
| 1611 // Try removing root file element. | 1651 // Try removing root file element. |
| 1612 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive")))); | 1652 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive/root")))); |
| 1613 | 1653 |
| 1614 // Need this to ensure OnDirectoryChanged() is run. | 1654 // Need this to ensure OnDirectoryChanged() is run. |
| 1615 google_apis::test_util::RunBlockingPoolTask(); | 1655 google_apis::test_util::RunBlockingPoolTask(); |
| 1616 } | 1656 } |
| 1617 | 1657 |
| 1618 TEST_F(DriveFileSystemTest, CreateDirectory) { | 1658 TEST_F(DriveFileSystemTest, CreateDirectory) { |
| 1619 ASSERT_TRUE(LoadRootFeedDocument()); | 1659 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1620 | 1660 |
| 1621 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1661 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1622 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1662 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1623 | 1663 |
| 1624 // Create directory in root. | 1664 // Create directory in root. |
| 1625 base::FilePath dir_path(FILE_PATH_LITERAL("drive/New Folder 1")); | 1665 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); |
| 1626 EXPECT_FALSE(EntryExists(dir_path)); | 1666 EXPECT_FALSE(EntryExists(dir_path)); |
| 1627 AddDirectoryFromFile(dir_path, "chromeos/gdata/directory_entry_atom.json"); | 1667 AddDirectoryFromFile(dir_path, "chromeos/gdata/directory_entry_atom.json"); |
| 1628 EXPECT_TRUE(EntryExists(dir_path)); | 1668 EXPECT_TRUE(EntryExists(dir_path)); |
| 1629 | 1669 |
| 1630 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1670 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1631 Eq(base::FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); | 1671 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1"))))) |
| 1672 .Times(1); | |
| 1632 | 1673 |
| 1633 // Create directory in a sub directory. | 1674 // Create directory in a sub directory. |
| 1634 base::FilePath subdir_path( | 1675 base::FilePath subdir_path( |
| 1635 FILE_PATH_LITERAL("drive/New Folder 1/New Folder 2")); | 1676 FILE_PATH_LITERAL("drive/root/New Folder 1/New Folder 2")); |
| 1636 EXPECT_FALSE(EntryExists(subdir_path)); | 1677 EXPECT_FALSE(EntryExists(subdir_path)); |
| 1637 AddDirectoryFromFile(subdir_path, | 1678 AddDirectoryFromFile(subdir_path, |
| 1638 "chromeos/gdata/directory_entry_atom2.json"); | 1679 "chromeos/gdata/directory_entry_atom2.json"); |
| 1639 EXPECT_TRUE(EntryExists(subdir_path)); | 1680 EXPECT_TRUE(EntryExists(subdir_path)); |
| 1640 } | 1681 } |
| 1641 | 1682 |
| 1642 // Create a directory through the document service | 1683 // Create a directory through the document service |
| 1643 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { | 1684 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { |
| 1644 ASSERT_TRUE(LoadRootFeedDocument()); | 1685 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1645 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1686 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1646 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1687 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1647 | 1688 |
| 1648 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1689 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1649 file_system_->CreateDirectory( | 1690 file_system_->CreateDirectory( |
| 1650 base::FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), | 1691 base::FilePath(FILE_PATH_LITERAL("drive/root/Sample Directory Title")), |
| 1651 false, // is_exclusive | 1692 false, // is_exclusive |
| 1652 true, // is_recursive | 1693 true, // is_recursive |
| 1653 google_apis::test_util::CreateCopyResultCallback(&error)); | 1694 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1654 google_apis::test_util::RunBlockingPoolTask(); | 1695 google_apis::test_util::RunBlockingPoolTask(); |
| 1655 | 1696 |
| 1656 EXPECT_EQ(DRIVE_FILE_OK, error); | 1697 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1657 } | 1698 } |
| 1658 | 1699 |
| 1659 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { | 1700 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { |
| 1660 ASSERT_TRUE(LoadRootFeedDocument()); | 1701 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1661 | 1702 |
| 1662 // The transfered file is cached and the change of "offline available" | 1703 // The transfered file is cached and the change of "offline available" |
| 1663 // attribute is notified. | 1704 // attribute is notified. |
| 1664 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1705 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1665 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1706 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1666 | 1707 |
| 1667 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1708 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1668 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1709 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1669 const int64 file_size = entry_proto->file_info().size(); | 1710 const int64 file_size = entry_proto->file_info().size(); |
| 1670 | 1711 |
| 1671 // Pretend we have enough space. | 1712 // Pretend we have enough space. |
| 1672 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1713 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 1673 file_size + kMinFreeSpace); | 1714 file_size + kMinFreeSpace); |
| 1674 | 1715 |
| 1675 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1716 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1676 base::FilePath file_path; | 1717 base::FilePath file_path; |
| 1677 std::string mime_type; | 1718 std::string mime_type; |
| 1678 DriveFileType file_type; | 1719 DriveFileType file_type; |
| 1679 file_system_->GetFileByPath(file_in_root, | 1720 file_system_->GetFileByPath(file_in_root, |
| 1680 google_apis::test_util::CreateCopyResultCallback( | 1721 google_apis::test_util::CreateCopyResultCallback( |
| 1681 &error, &file_path, &mime_type, &file_type)); | 1722 &error, &file_path, &mime_type, &file_type)); |
| 1682 google_apis::test_util::RunBlockingPoolTask(); | 1723 google_apis::test_util::RunBlockingPoolTask(); |
| 1683 | 1724 |
| 1684 EXPECT_EQ(DRIVE_FILE_OK, error); | 1725 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1685 EXPECT_EQ(REGULAR_FILE, file_type); | 1726 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1686 } | 1727 } |
| 1687 | 1728 |
| 1688 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { | 1729 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { |
| 1689 ASSERT_TRUE(LoadRootFeedDocument()); | 1730 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1690 | 1731 |
| 1691 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1732 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1692 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1733 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1693 | 1734 |
| 1694 // Pretend we have no space at all. | 1735 // Pretend we have no space at all. |
| 1695 fake_free_disk_space_getter_->set_fake_free_disk_space(0); | 1736 fake_free_disk_space_getter_->set_fake_free_disk_space(0); |
| 1696 | 1737 |
| 1697 DriveFileError error = DRIVE_FILE_OK; | 1738 DriveFileError error = DRIVE_FILE_OK; |
| 1698 base::FilePath file_path; | 1739 base::FilePath file_path; |
| 1699 std::string mime_type; | 1740 std::string mime_type; |
| 1700 DriveFileType file_type; | 1741 DriveFileType file_type; |
| 1701 file_system_->GetFileByPath(file_in_root, | 1742 file_system_->GetFileByPath(file_in_root, |
| 1702 google_apis::test_util::CreateCopyResultCallback( | 1743 google_apis::test_util::CreateCopyResultCallback( |
| 1703 &error, &file_path, &mime_type, &file_type)); | 1744 &error, &file_path, &mime_type, &file_type)); |
| 1704 google_apis::test_util::RunBlockingPoolTask(); | 1745 google_apis::test_util::RunBlockingPoolTask(); |
| 1705 | 1746 |
| 1706 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); | 1747 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); |
| 1707 } | 1748 } |
| 1708 | 1749 |
| 1709 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { | 1750 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { |
| 1710 ASSERT_TRUE(LoadRootFeedDocument()); | 1751 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1711 | 1752 |
| 1712 // The transfered file is cached and the change of "offline available" | 1753 // The transfered file is cached and the change of "offline available" |
| 1713 // attribute is notified. | 1754 // attribute is notified. |
| 1714 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1755 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1715 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1756 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1716 | 1757 |
| 1717 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1758 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1718 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1759 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1719 const int64 file_size = entry_proto->file_info().size(); | 1760 const int64 file_size = entry_proto->file_info().size(); |
| 1720 | 1761 |
| 1721 // Pretend we have no space first (checked before downloading a file), | 1762 // Pretend we have no space first (checked before downloading a file), |
| 1722 // but then start reporting we have space. This is to emulate that | 1763 // but then start reporting we have space. This is to emulate that |
| 1723 // the disk space was freed up by removing temporary files. | 1764 // the disk space was freed up by removing temporary files. |
| 1724 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1765 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 1725 file_size + kMinFreeSpace); | 1766 file_size + kMinFreeSpace); |
| 1726 fake_free_disk_space_getter_->set_fake_free_disk_space(0); | 1767 fake_free_disk_space_getter_->set_fake_free_disk_space(0); |
| 1727 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1768 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1757 EXPECT_EQ(DRIVE_FILE_OK, error); | 1798 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1758 EXPECT_EQ(REGULAR_FILE, file_type); | 1799 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1759 | 1800 |
| 1760 // The cache entry should be removed in order to free up space. | 1801 // The cache entry should be removed in order to free up space. |
| 1761 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); | 1802 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); |
| 1762 } | 1803 } |
| 1763 | 1804 |
| 1764 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) { | 1805 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) { |
| 1765 ASSERT_TRUE(LoadRootFeedDocument()); | 1806 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1766 | 1807 |
| 1767 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1808 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1768 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1809 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1769 const int64 file_size = entry_proto->file_info().size(); | 1810 const int64 file_size = entry_proto->file_info().size(); |
| 1770 | 1811 |
| 1771 // Pretend we have enough space first (checked before downloading a file), | 1812 // 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 | 1813 // 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 | 1814 // the disk space becomes full after the file is downloaded for some reason |
| 1774 // (ex. the actual file was larger than the expected size). | 1815 // (ex. the actual file was larger than the expected size). |
| 1775 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1816 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 1776 file_size + kMinFreeSpace); | 1817 file_size + kMinFreeSpace); |
| 1777 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1); | 1818 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); | 1819 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1); |
| 1779 | 1820 |
| 1780 DriveFileError error = DRIVE_FILE_OK; | 1821 DriveFileError error = DRIVE_FILE_OK; |
| 1781 base::FilePath file_path; | 1822 base::FilePath file_path; |
| 1782 std::string mime_type; | 1823 std::string mime_type; |
| 1783 DriveFileType file_type; | 1824 DriveFileType file_type; |
| 1784 file_system_->GetFileByPath(file_in_root, | 1825 file_system_->GetFileByPath(file_in_root, |
| 1785 google_apis::test_util::CreateCopyResultCallback( | 1826 google_apis::test_util::CreateCopyResultCallback( |
| 1786 &error, &file_path, &mime_type, &file_type)); | 1827 &error, &file_path, &mime_type, &file_type)); |
| 1787 google_apis::test_util::RunBlockingPoolTask(); | 1828 google_apis::test_util::RunBlockingPoolTask(); |
| 1788 | 1829 |
| 1789 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); | 1830 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); |
| 1790 } | 1831 } |
| 1791 | 1832 |
| 1792 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) { | 1833 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) { |
| 1793 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1834 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1794 | 1835 |
| 1795 ASSERT_TRUE(LoadRootFeedDocument()); | 1836 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1796 | 1837 |
| 1797 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1838 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1798 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1839 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1799 | 1840 |
| 1800 // Store something as cached version of this file. | 1841 // Store something as cached version of this file. |
| 1801 DriveFileError error = DRIVE_FILE_OK; | 1842 DriveFileError error = DRIVE_FILE_OK; |
| 1802 cache_->Store(entry_proto->resource_id(), | 1843 cache_->Store(entry_proto->resource_id(), |
| 1803 entry_proto->file_specific_info().file_md5(), | 1844 entry_proto->file_specific_info().file_md5(), |
| 1804 google_apis::test_util::GetTestFilePath( | 1845 google_apis::test_util::GetTestFilePath( |
| 1805 "chromeos/gdata/root_feed.json"), | 1846 "chromeos/gdata/root_feed.json"), |
| 1806 DriveCache::FILE_OPERATION_COPY, | 1847 DriveCache::FILE_OPERATION_COPY, |
| 1807 google_apis::test_util::CreateCopyResultCallback(&error)); | 1848 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1808 google_apis::test_util::RunBlockingPoolTask(); | 1849 google_apis::test_util::RunBlockingPoolTask(); |
| 1809 EXPECT_EQ(DRIVE_FILE_OK, error); | 1850 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1810 | 1851 |
| 1811 base::FilePath file_path; | 1852 base::FilePath file_path; |
| 1812 std::string mime_type; | 1853 std::string mime_type; |
| 1813 DriveFileType file_type; | 1854 DriveFileType file_type; |
| 1814 file_system_->GetFileByPath(file_in_root, | 1855 file_system_->GetFileByPath(file_in_root, |
| 1815 google_apis::test_util::CreateCopyResultCallback( | 1856 google_apis::test_util::CreateCopyResultCallback( |
| 1816 &error, &file_path, &mime_type, &file_type)); | 1857 &error, &file_path, &mime_type, &file_type)); |
| 1817 google_apis::test_util::RunBlockingPoolTask(); | 1858 google_apis::test_util::RunBlockingPoolTask(); |
| 1818 | 1859 |
| 1819 EXPECT_EQ(DRIVE_FILE_OK, error); | 1860 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1820 EXPECT_EQ(REGULAR_FILE, file_type); | 1861 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1821 } | 1862 } |
| 1822 | 1863 |
| 1823 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) { | 1864 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) { |
| 1824 ASSERT_TRUE(LoadRootFeedDocument()); | 1865 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1825 | 1866 |
| 1826 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/Document 1.gdoc")); | 1867 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/Document 1.gdoc")); |
| 1827 scoped_ptr<DriveEntryProto> src_entry_proto = | 1868 scoped_ptr<DriveEntryProto> src_entry_proto = |
| 1828 GetEntryInfoByPathSync(file_in_root); | 1869 GetEntryInfoByPathSync(file_in_root); |
| 1829 ASSERT_TRUE(src_entry_proto.get()); | 1870 ASSERT_TRUE(src_entry_proto.get()); |
| 1830 | 1871 |
| 1831 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1872 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1832 base::FilePath file_path; | 1873 base::FilePath file_path; |
| 1833 std::string mime_type; | 1874 std::string mime_type; |
| 1834 DriveFileType file_type; | 1875 DriveFileType file_type; |
| 1835 file_system_->GetFileByPath(file_in_root, | 1876 file_system_->GetFileByPath(file_in_root, |
| 1836 google_apis::test_util::CreateCopyResultCallback( | 1877 google_apis::test_util::CreateCopyResultCallback( |
| 1837 &error, &file_path, &mime_type, &file_type)); | 1878 &error, &file_path, &mime_type, &file_type)); |
| 1838 google_apis::test_util::RunBlockingPoolTask(); | 1879 google_apis::test_util::RunBlockingPoolTask(); |
| 1839 | 1880 |
| 1840 EXPECT_EQ(HOSTED_DOCUMENT, file_type); | 1881 EXPECT_EQ(HOSTED_DOCUMENT, file_type); |
| 1841 EXPECT_FALSE(file_path.empty()); | 1882 EXPECT_FALSE(file_path.empty()); |
| 1842 | 1883 |
| 1843 ASSERT_TRUE(src_entry_proto.get()); | 1884 ASSERT_TRUE(src_entry_proto.get()); |
| 1844 VerifyHostedDocumentJSONFile(*src_entry_proto, file_path); | 1885 VerifyHostedDocumentJSONFile(*src_entry_proto, file_path); |
| 1845 } | 1886 } |
| 1846 | 1887 |
| 1847 TEST_F(DriveFileSystemTest, GetFileByResourceId) { | 1888 TEST_F(DriveFileSystemTest, GetFileByResourceId) { |
| 1848 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1889 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1849 | 1890 |
| 1850 // The transfered file is cached and the change of "offline available" | 1891 // The transfered file is cached and the change of "offline available" |
| 1851 // attribute is notified. | 1892 // attribute is notified. |
| 1852 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1893 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1853 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1894 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1854 | 1895 |
| 1855 ASSERT_TRUE(LoadRootFeedDocument()); | 1896 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1856 | 1897 |
| 1857 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1898 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1858 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1899 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1859 | 1900 |
| 1860 DriveFileError error = DRIVE_FILE_OK; | 1901 DriveFileError error = DRIVE_FILE_OK; |
| 1861 base::FilePath file_path; | 1902 base::FilePath file_path; |
| 1862 std::string mime_type; | 1903 std::string mime_type; |
| 1863 DriveFileType file_type; | 1904 DriveFileType file_type; |
| 1864 file_system_->GetFileByResourceId( | 1905 file_system_->GetFileByResourceId( |
| 1865 entry_proto->resource_id(), | 1906 entry_proto->resource_id(), |
| 1866 DriveClientContext(USER_INITIATED), | 1907 DriveClientContext(USER_INITIATED), |
| 1867 google_apis::test_util::CreateCopyResultCallback( | 1908 google_apis::test_util::CreateCopyResultCallback( |
| 1868 &error, &file_path, &mime_type, &file_type), | 1909 &error, &file_path, &mime_type, &file_type), |
| 1869 google_apis::GetContentCallback()); | 1910 google_apis::GetContentCallback()); |
| 1870 google_apis::test_util::RunBlockingPoolTask(); | 1911 google_apis::test_util::RunBlockingPoolTask(); |
| 1871 | 1912 |
| 1872 EXPECT_EQ(DRIVE_FILE_OK, error); | 1913 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1873 EXPECT_EQ(REGULAR_FILE, file_type); | 1914 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1874 } | 1915 } |
| 1875 | 1916 |
| 1876 TEST_F(DriveFileSystemTest, CancelGetFile) { | 1917 TEST_F(DriveFileSystemTest, CancelGetFile) { |
| 1877 base::FilePath cancel_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1918 base::FilePath cancel_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1878 file_system_->CancelGetFile(cancel_file_path); | 1919 file_system_->CancelGetFile(cancel_file_path); |
| 1879 EXPECT_EQ(cancel_file_path, fake_drive_service_->last_cancelled_file()); | 1920 EXPECT_EQ(cancel_file_path, fake_drive_service_->last_cancelled_file()); |
| 1880 } | 1921 } |
| 1881 | 1922 |
| 1882 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) { | 1923 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) { |
| 1883 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1924 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1884 | 1925 |
| 1885 ASSERT_TRUE(LoadRootFeedDocument()); | 1926 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1886 | 1927 |
| 1887 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 1928 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1888 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); | 1929 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); |
| 1889 | 1930 |
| 1890 // Store something as cached version of this file. | 1931 // Store something as cached version of this file. |
| 1891 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1932 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 1892 cache_->Store(entry_proto->resource_id(), | 1933 cache_->Store(entry_proto->resource_id(), |
| 1893 entry_proto->file_specific_info().file_md5(), | 1934 entry_proto->file_specific_info().file_md5(), |
| 1894 google_apis::test_util::GetTestFilePath( | 1935 google_apis::test_util::GetTestFilePath( |
| 1895 "chromeos/gdata/root_feed.json"), | 1936 "chromeos/gdata/root_feed.json"), |
| 1896 DriveCache::FILE_OPERATION_COPY, | 1937 DriveCache::FILE_OPERATION_COPY, |
| 1897 google_apis::test_util::CreateCopyResultCallback(&error)); | 1938 google_apis::test_util::CreateCopyResultCallback(&error)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1916 EXPECT_EQ(DRIVE_FILE_OK, error); | 1957 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1917 EXPECT_EQ(REGULAR_FILE, file_type); | 1958 EXPECT_EQ(REGULAR_FILE, file_type); |
| 1918 } | 1959 } |
| 1919 | 1960 |
| 1920 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) { | 1961 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) { |
| 1921 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1962 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
| 1922 | 1963 |
| 1923 ASSERT_TRUE(LoadRootFeedDocument()); | 1964 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1924 | 1965 |
| 1925 // This is a file defined in root_feed.json. | 1966 // This is a file defined in root_feed.json. |
| 1926 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt")); | 1967 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1927 const std::string kResourceId("file:2_file_resource_id"); | 1968 const std::string kResourceId("file:2_file_resource_id"); |
| 1928 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); | 1969 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); |
| 1929 | 1970 |
| 1930 // Pin the file so it'll be store in "persistent" directory. | 1971 // Pin the file so it'll be store in "persistent" directory. |
| 1931 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1); | 1972 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1); |
| 1932 DriveFileError error = DRIVE_FILE_OK; | 1973 DriveFileError error = DRIVE_FILE_OK; |
| 1933 cache_->Pin(kResourceId, kMd5, | 1974 cache_->Pin(kResourceId, kMd5, |
| 1934 google_apis::test_util::CreateCopyResultCallback(&error)); | 1975 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1935 google_apis::test_util::RunBlockingPoolTask(); | 1976 google_apis::test_util::RunBlockingPoolTask(); |
| 1936 EXPECT_EQ(DRIVE_FILE_OK, error); | 1977 EXPECT_EQ(DRIVE_FILE_OK, error); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1960 EXPECT_EQ(DRIVE_FILE_OK, error); | 2001 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1961 | 2002 |
| 1962 // We'll notify the directory change to the observer upon completion. | 2003 // We'll notify the directory change to the observer upon completion. |
| 1963 EXPECT_CALL(*mock_directory_observer_, | 2004 EXPECT_CALL(*mock_directory_observer_, |
| 1964 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath()))) | 2005 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath()))) |
| 1965 .Times(1); | 2006 .Times(1); |
| 1966 | 2007 |
| 1967 // Check the number of files in the root directory. We'll compare the | 2008 // Check the number of files in the root directory. We'll compare the |
| 1968 // number after updating a file. | 2009 // number after updating a file. |
| 1969 scoped_ptr<DriveEntryProtoVector> root_directory_entries( | 2010 scoped_ptr<DriveEntryProtoVector> root_directory_entries( |
| 1970 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"))); | 2011 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 1971 ASSERT_TRUE(root_directory_entries.get()); | 2012 ASSERT_TRUE(root_directory_entries.get()); |
| 1972 const int num_files_in_root = CountFiles(*root_directory_entries); | 2013 const int num_files_in_root = CountFiles(*root_directory_entries); |
| 1973 | 2014 |
| 1974 // The callback will be called upon completion of | 2015 // The callback will be called upon completion of |
| 1975 // UpdateFileByResourceId(). | 2016 // UpdateFileByResourceId(). |
| 1976 file_system_->UpdateFileByResourceId( | 2017 file_system_->UpdateFileByResourceId( |
| 1977 kResourceId, | 2018 kResourceId, |
| 1978 DriveClientContext(USER_INITIATED), | 2019 DriveClientContext(USER_INITIATED), |
| 1979 google_apis::test_util::CreateCopyResultCallback(&error)); | 2020 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1980 google_apis::test_util::RunBlockingPoolTask(); | 2021 google_apis::test_util::RunBlockingPoolTask(); |
| 1981 EXPECT_EQ(DRIVE_FILE_OK, error); | 2022 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 1982 | 2023 |
| 1983 // Make sure that the number of files did not change (i.e. we updated an | 2024 // 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 | 2025 // existing file, rather than adding a new file. The number of files |
| 1985 // increases if we don't handle the file update right). | 2026 // increases if we don't handle the file update right). |
| 1986 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); | 2027 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); |
| 1987 } | 2028 } |
| 1988 | 2029 |
| 1989 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { | 2030 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { |
| 1990 ASSERT_TRUE(LoadRootFeedDocument()); | 2031 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1991 | 2032 |
| 1992 // This is nonexistent in root_feed.json. | 2033 // This is nonexistent in root_feed.json. |
| 1993 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt")); | 2034 const base::FilePath kFilePath( |
| 2035 FILE_PATH_LITERAL("drive/root/Nonexistent.txt")); | |
| 1994 const std::string kResourceId("file:nonexistent_resource_id"); | 2036 const std::string kResourceId("file:nonexistent_resource_id"); |
| 1995 const std::string kMd5("nonexistent_md5"); | 2037 const std::string kMd5("nonexistent_md5"); |
| 1996 | 2038 |
| 1997 // The callback will be called upon completion of | 2039 // The callback will be called upon completion of |
| 1998 // UpdateFileByResourceId(). | 2040 // UpdateFileByResourceId(). |
| 1999 DriveFileError error = DRIVE_FILE_OK; | 2041 DriveFileError error = DRIVE_FILE_OK; |
| 2000 file_system_->UpdateFileByResourceId( | 2042 file_system_->UpdateFileByResourceId( |
| 2001 kResourceId, | 2043 kResourceId, |
| 2002 DriveClientContext(USER_INITIATED), | 2044 DriveClientContext(USER_INITIATED), |
| 2003 google_apis::test_util::CreateCopyResultCallback(&error)); | 2045 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 2004 google_apis::test_util::RunBlockingPoolTask(); | 2046 google_apis::test_util::RunBlockingPoolTask(); |
| 2005 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 2047 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 2006 } | 2048 } |
| 2007 | 2049 |
| 2008 TEST_F(DriveFileSystemTest, ContentSearch) { | 2050 TEST_F(DriveFileSystemTest, ContentSearch) { |
| 2009 ASSERT_TRUE(LoadRootFeedDocument()); | 2051 ASSERT_TRUE(LoadRootFeedDocument()); |
| 2010 | 2052 |
| 2011 const SearchResultPair kExpectedResults[] = { | 2053 const SearchResultPair kExpectedResults[] = { |
| 2012 { "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", | 2054 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", |
| 2013 true }, | 2055 true }, |
| 2014 { "drive/Directory 1/Sub Directory Folder", true }, | 2056 { "drive/root/Directory 1/Sub Directory Folder", true }, |
| 2015 { "drive/Directory 1/SubDirectory File 1.txt", false }, | 2057 { "drive/root/Directory 1/SubDirectory File 1.txt", false }, |
| 2016 { "drive/Directory 1", true }, | 2058 { "drive/root/Directory 1", true }, |
| 2017 { "drive/Directory 2", true }, | 2059 { "drive/root/Directory 2", true }, |
| 2018 }; | 2060 }; |
| 2019 | 2061 |
| 2020 SearchCallback callback = base::Bind(&DriveSearchCallback, | 2062 SearchCallback callback = base::Bind(&DriveSearchCallback, |
| 2021 &message_loop_, | 2063 &message_loop_, |
| 2022 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), | 2064 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), |
| 2023 GURL()); | 2065 GURL()); |
| 2024 | 2066 |
| 2025 file_system_->Search("Directory", false, GURL(), callback); | 2067 file_system_->Search("Directory", false, GURL(), callback); |
| 2026 message_loop_.Run(); // Wait to get our result. | 2068 message_loop_.Run(); // Wait to get our result. |
| 2027 } | 2069 } |
| 2028 | 2070 |
| 2029 TEST_F(DriveFileSystemTest, ContentSearchWithNewEntry) { | 2071 TEST_F(DriveFileSystemTest, ContentSearchWithNewEntry) { |
| 2030 ASSERT_TRUE(LoadRootFeedDocument()); | 2072 ASSERT_TRUE(LoadRootFeedDocument()); |
| 2031 | 2073 |
| 2032 // Create a new directory in the drive service. | 2074 // Create a new directory in the drive service. |
| 2033 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 2075 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 2034 scoped_ptr<google_apis::ResourceEntry> resource_entry; | 2076 scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| 2035 fake_drive_service_->AddNewDirectory( | 2077 fake_drive_service_->AddNewDirectory( |
| 2036 fake_drive_service_->GetRootResourceId(), // Add to the root directory. | 2078 fake_drive_service_->GetRootResourceId(), // Add to the root directory. |
| 2037 "New Directory 1!", | 2079 "New Directory 1!", |
| 2038 google_apis::test_util::CreateCopyResultCallback( | 2080 google_apis::test_util::CreateCopyResultCallback( |
| 2039 &error, &resource_entry)); | 2081 &error, &resource_entry)); |
| 2040 message_loop_.RunUntilIdle(); | 2082 message_loop_.RunUntilIdle(); |
| 2041 | 2083 |
| 2042 // As the result of the first Search(), only entries in the current file | 2084 // 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!" | 2085 // 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 | 2086 // shouldn't be included in the search result even though it matches |
| 2045 // "Directory 1". | 2087 // "Directory 1". |
| 2046 const SearchResultPair kExpectedResults[] = { | 2088 const SearchResultPair kExpectedResults[] = { |
| 2047 { "drive/Directory 1", true } | 2089 { "drive/root/Directory 1", true } |
| 2048 }; | 2090 }; |
| 2049 | 2091 |
| 2050 // At the same time, unknown entry should trigger delta feed request. | 2092 // At the same time, unknown entry should trigger delta feed request. |
| 2051 // This will cause notification to directory observers (e.g., File Browser) | 2093 // This will cause notification to directory observers (e.g., File Browser) |
| 2052 // so that they can request search again. | 2094 // so that they can request search again. |
| 2053 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) | 2095 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) |
| 2054 .Times(AtLeast(1)); | 2096 .Times(AtLeast(1)); |
| 2055 | 2097 |
| 2056 SearchCallback callback = base::Bind(&DriveSearchCallback, | 2098 SearchCallback callback = base::Bind(&DriveSearchCallback, |
| 2057 &message_loop_, | 2099 &message_loop_, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2102 google_apis::test_util::RunBlockingPoolTask(); | 2144 google_apis::test_util::RunBlockingPoolTask(); |
| 2103 EXPECT_EQ(DRIVE_FILE_OK, error); | 2145 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 2104 } | 2146 } |
| 2105 | 2147 |
| 2106 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { | 2148 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { |
| 2107 ASSERT_TRUE(LoadRootFeedDocument()); | 2149 ASSERT_TRUE(LoadRootFeedDocument()); |
| 2108 | 2150 |
| 2109 // The transfered file is cached and the change of "offline available" | 2151 // The transfered file is cached and the change of "offline available" |
| 2110 // attribute is notified. | 2152 // attribute is notified. |
| 2111 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 2153 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 2112 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 2154 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 2113 | 2155 |
| 2114 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/File 1.txt")); | 2156 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 2115 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot)); | 2157 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot)); |
| 2116 const int64 file_size = entry_proto->file_info().size(); | 2158 const int64 file_size = entry_proto->file_info().size(); |
| 2117 const std::string& file_resource_id = | 2159 const std::string& file_resource_id = |
| 2118 entry_proto->resource_id(); | 2160 entry_proto->resource_id(); |
| 2119 const std::string& file_md5 = entry_proto->file_specific_info().file_md5(); | 2161 const std::string& file_md5 = entry_proto->file_specific_info().file_md5(); |
| 2120 | 2162 |
| 2121 // A dirty file is created on close. | 2163 // A dirty file is created on close. |
| 2122 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id)) | 2164 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id)) |
| 2123 .Times(1); | 2165 .Times(1); |
| 2124 | 2166 |
| 2125 // Pretend we have enough space. | 2167 // Pretend we have enough space. |
| 2126 fake_free_disk_space_getter_->set_fake_free_disk_space( | 2168 fake_free_disk_space_getter_->set_fake_free_disk_space( |
| 2127 file_size + kMinFreeSpace); | 2169 file_size + kMinFreeSpace); |
| 2128 | 2170 |
| 2129 // Open kFileInRoot ("drive/File 1.txt"). | 2171 // Open kFileInRoot ("drive/root/File 1.txt"). |
| 2130 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 2172 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 2131 base::FilePath file_path; | 2173 base::FilePath file_path; |
| 2132 file_system_->OpenFile( | 2174 file_system_->OpenFile( |
| 2133 kFileInRoot, | 2175 kFileInRoot, |
| 2134 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | 2176 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
| 2135 google_apis::test_util::RunBlockingPoolTask(); | 2177 google_apis::test_util::RunBlockingPoolTask(); |
| 2136 const base::FilePath opened_file_path = file_path; | 2178 const base::FilePath opened_file_path = file_path; |
| 2137 | 2179 |
| 2138 // Verify that the file was properly opened. | 2180 // Verify that the file was properly opened. |
| 2139 EXPECT_EQ(DRIVE_FILE_OK, error); | 2181 EXPECT_EQ(DRIVE_FILE_OK, error); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 2162 EXPECT_TRUE(cache_entry.is_persistent()); | 2204 EXPECT_TRUE(cache_entry.is_persistent()); |
| 2163 | 2205 |
| 2164 base::FilePath cache_file_path; | 2206 base::FilePath cache_file_path; |
| 2165 cache_->GetFile(file_resource_id, file_md5, | 2207 cache_->GetFile(file_resource_id, file_md5, |
| 2166 google_apis::test_util::CreateCopyResultCallback( | 2208 google_apis::test_util::CreateCopyResultCallback( |
| 2167 &error, &cache_file_path)); | 2209 &error, &cache_file_path)); |
| 2168 google_apis::test_util::RunBlockingPoolTask(); | 2210 google_apis::test_util::RunBlockingPoolTask(); |
| 2169 EXPECT_EQ(DRIVE_FILE_OK, error); | 2211 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 2170 EXPECT_EQ(cache_file_path, opened_file_path); | 2212 EXPECT_EQ(cache_file_path, opened_file_path); |
| 2171 | 2213 |
| 2172 // Close kFileInRoot ("drive/File 1.txt"). | 2214 // Close kFileInRoot ("drive/root/File 1.txt"). |
| 2173 file_system_->CloseFile( | 2215 file_system_->CloseFile( |
| 2174 kFileInRoot, | 2216 kFileInRoot, |
| 2175 google_apis::test_util::CreateCopyResultCallback(&error)); | 2217 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 2176 google_apis::test_util::RunBlockingPoolTask(); | 2218 google_apis::test_util::RunBlockingPoolTask(); |
| 2177 | 2219 |
| 2178 // Verify that the file was properly closed. | 2220 // Verify that the file was properly closed. |
| 2179 EXPECT_EQ(DRIVE_FILE_OK, error); | 2221 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 2180 | 2222 |
| 2181 // Verify that the cache state was changed as expected. | 2223 // Verify that the cache state was changed as expected. |
| 2182 EXPECT_TRUE(GetCacheEntryFromOriginThread(file_resource_id, file_md5, | 2224 EXPECT_TRUE(GetCacheEntryFromOriginThread(file_resource_id, file_md5, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2215 | 2257 |
| 2216 // An app for foo.exe should now be found, as the registry was loaded. | 2258 // An app for foo.exe should now be found, as the registry was loaded. |
| 2217 drive_webapps_registry_->GetWebAppsForFile( | 2259 drive_webapps_registry_->GetWebAppsForFile( |
| 2218 base::FilePath(FILE_PATH_LITERAL("foo.exe")), | 2260 base::FilePath(FILE_PATH_LITERAL("foo.exe")), |
| 2219 "" /* mime_type */, | 2261 "" /* mime_type */, |
| 2220 &apps); | 2262 &apps); |
| 2221 EXPECT_EQ(1U, apps.size()); | 2263 EXPECT_EQ(1U, apps.size()); |
| 2222 } | 2264 } |
| 2223 | 2265 |
| 2224 } // namespace drive | 2266 } // namespace drive |
| OLD | NEW |