Chromium Code Reviews| Index: chrome/browser/chromeos/drive/file_system_unittest.cc |
| diff --git a/chrome/browser/chromeos/drive/file_system_unittest.cc b/chrome/browser/chromeos/drive/file_system_unittest.cc |
| index 49380ffc2f78f5e38476fac8094f1d52ff5a04fc..b0fea6b00df8b58562b8a7a8c4a2df23d6e181da 100644 |
| --- a/chrome/browser/chromeos/drive/file_system_unittest.cc |
| +++ b/chrome/browser/chromeos/drive/file_system_unittest.cc |
| @@ -313,6 +313,216 @@ class FileSystemTest : public testing::Test { |
| scoped_ptr<FileSystem> file_system_; |
| }; |
| +TEST_F(FileSystemTest, Copy) { |
| + base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| + base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Copied.txt")); |
| + EXPECT_TRUE(GetResourceEntrySync(src_file_path)); |
| + EXPECT_FALSE(GetResourceEntrySync(dest_file_path)); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + file_system_->Copy(src_file_path, |
| + dest_file_path, |
| + false, // preserve_last_modified, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + // Entry is added on the server. |
| + scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path); |
| + ASSERT_TRUE(entry); |
| + |
| + google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; |
| + scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| + fake_drive_service_->GetResourceEntry( |
| + entry->resource_id(), |
| + google_apis::test_util::CreateCopyResultCallback(&status, |
| + &resource_entry)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
| + ASSERT_TRUE(resource_entry); |
| + EXPECT_EQ(entry->title(), resource_entry->title()); |
| + EXPECT_TRUE(resource_entry->is_file()); |
| +} |
| + |
| +TEST_F(FileSystemTest, Move) { |
|
kinaba
2014/02/11 00:31:59
Could you also test the case when the file is move
hashimoto
2014/02/19 07:01:33
Done.
|
| + base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| + base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Moved.txt")); |
| + EXPECT_TRUE(GetResourceEntrySync(src_file_path)); |
| + EXPECT_FALSE(GetResourceEntrySync(dest_file_path)); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + file_system_->Move(src_file_path, |
| + dest_file_path, |
| + false, // preserve_last_modified, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + // Entry is moved on the server. |
| + scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path); |
| + ASSERT_TRUE(entry); |
| + |
| + google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; |
| + scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| + fake_drive_service_->GetResourceEntry( |
| + entry->resource_id(), |
| + google_apis::test_util::CreateCopyResultCallback(&status, |
| + &resource_entry)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
| + ASSERT_TRUE(resource_entry); |
| + EXPECT_EQ(entry->title(), resource_entry->title()); |
| +} |
| + |
| +TEST_F(FileSystemTest, Remove) { |
| + base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| + scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); |
| + ASSERT_TRUE(entry); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + file_system_->Remove( |
| + file_path, |
| + false, // is_resursive |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + // Entry is removed on the server. |
| + google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; |
| + scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| + fake_drive_service_->GetResourceEntry( |
| + entry->resource_id(), |
| + google_apis::test_util::CreateCopyResultCallback(&status, |
| + &resource_entry)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
| + ASSERT_TRUE(resource_entry); |
| + EXPECT_TRUE(resource_entry->deleted()); |
| +} |
| + |
| +TEST_F(FileSystemTest, CreateDirectory) { |
| + base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory")); |
| + EXPECT_FALSE(GetResourceEntrySync(directory_path)); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + file_system_->CreateDirectory( |
| + directory_path, |
| + true, // is_exclusive |
| + false, // is_recursive |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + // Directory is created on the server. |
| + scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(directory_path); |
| + ASSERT_TRUE(entry); |
| + |
| + google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; |
| + scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| + fake_drive_service_->GetResourceEntry( |
| + entry->resource_id(), |
| + google_apis::test_util::CreateCopyResultCallback(&status, |
| + &resource_entry)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
| + ASSERT_TRUE(resource_entry); |
| + EXPECT_EQ(entry->title(), resource_entry->title()); |
| + EXPECT_TRUE(resource_entry->is_folder()); |
| +} |
| + |
| +TEST_F(FileSystemTest, CreateFile) { |
| + base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt")); |
| + EXPECT_FALSE(GetResourceEntrySync(file_path)); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + file_system_->CreateFile( |
| + file_path, |
| + true, // is_exclusive |
| + "text/plain", |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + // File is created on the server. |
| + scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); |
| + ASSERT_TRUE(entry); |
| + |
| + google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; |
| + scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| + fake_drive_service_->GetResourceEntry( |
| + entry->resource_id(), |
| + google_apis::test_util::CreateCopyResultCallback(&status, |
| + &resource_entry)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
| + ASSERT_TRUE(resource_entry); |
| + EXPECT_EQ(entry->title(), resource_entry->title()); |
| + EXPECT_TRUE(resource_entry->is_file()); |
| +} |
| + |
| +TEST_F(FileSystemTest, TouchFile) { |
| + base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| + scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); |
| + ASSERT_TRUE(entry); |
| + |
| + base::Time last_accessed = |
| + base::Time::FromInternalValue(entry->file_info().last_accessed()) + |
| + base::TimeDelta::FromSeconds(1); |
| + base::Time last_modified = |
| + base::Time::FromInternalValue(entry->file_info().last_modified()) + |
| + base::TimeDelta::FromSeconds(1); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + file_system_->TouchFile( |
| + file_path, |
| + last_accessed, |
| + last_modified, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + // File is touched on the server. |
| + google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; |
| + scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| + fake_drive_service_->GetResourceEntry( |
| + entry->resource_id(), |
| + google_apis::test_util::CreateCopyResultCallback(&status, |
| + &resource_entry)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
| + ASSERT_TRUE(resource_entry); |
| + EXPECT_EQ(last_accessed, resource_entry->last_viewed_time()); |
| + EXPECT_EQ(last_modified, resource_entry->updated_time()); |
| +} |
| + |
| +TEST_F(FileSystemTest, TruncateFile) { |
| + base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| + scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); |
| + ASSERT_TRUE(entry); |
| + |
| + const int64 kLength = entry->file_info().size() + 100; |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + file_system_->TruncateFile( |
| + file_path, |
| + kLength, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + // File is touched on the server. |
| + google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; |
| + scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| + fake_drive_service_->GetResourceEntry( |
| + entry->resource_id(), |
| + google_apis::test_util::CreateCopyResultCallback(&status, |
| + &resource_entry)); |
| + test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
| + ASSERT_TRUE(resource_entry); |
| + EXPECT_EQ(kLength, resource_entry->file_size()); |
| +} |
| + |
| TEST_F(FileSystemTest, DuplicatedAsyncInitialization) { |
| base::RunLoop loop; |